Merge branch '8099' of https://github.com/rwldrn/jquery into rwldrn-8099
[jquery.git] / test / unit / effects.js
1 module("effects", { teardown: moduleTeardown });
2
3 test("sanity check", function() {
4         expect(1);
5         ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
6 });
7
8 test("show()", function() {
9         expect(28);
10
11         var hiddendiv = jQuery("div.hidden");
12
13         hiddendiv.hide().show();
14
15         equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
16
17         var div = jQuery("<div>").hide().appendTo("#main").show();
18
19         equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
20
21         QUnit.reset();
22
23         hiddendiv = jQuery("div.hidden");
24
25         equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
26
27         hiddendiv.css("display", "block");
28         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
29
30         hiddendiv.show();
31         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
32
33         hiddendiv.css("display","");
34
35         var pass = true, div = jQuery("#main div");
36         div.show().each(function(){
37                 if ( this.style.display == "none" ) pass = false;
38         });
39         ok( pass, "Show" );
40
41         var speeds = {
42                 "null speed": null,
43                 "undefined speed": undefined,
44                 "empty string speed": "",
45                 "false speed": false
46         };
47
48         jQuery.each(speeds, function(name, speed) {
49                 pass = true;
50                 div.hide().show(speed).each(function() {
51                         if ( this.style.display == "none" ) pass = false;
52                 });
53                 ok( pass, "Show with " + name);
54         });
55
56         jQuery.each(speeds, function(name, speed) {
57         pass = true;
58         div.hide().show(speed, function() {
59                         pass = false;
60                 });
61                 ok( pass, "Show with " + name + " does not call animate callback" );
62         });
63
64         // #show-tests * is set display: none in CSS
65         jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>');
66
67         var old = jQuery("#test-table").show().css("display") !== "table";
68         jQuery("#test-table").remove();
69
70         var test = {
71                 "div"      : "block",
72                 "p"        : "block",
73                 "a"        : "inline",
74                 "code"     : "inline",
75                 "pre"      : "block",
76                 "span"     : "inline",
77                 "table"    : old ? "block" : "table",
78                 "thead"    : old ? "block" : "table-header-group",
79                 "tbody"    : old ? "block" : "table-row-group",
80                 "tr"       : old ? "block" : "table-row",
81                 "th"       : old ? "block" : "table-cell",
82                 "td"       : old ? "block" : "table-cell",
83                 "ul"       : "block",
84                 "li"       : old ? "block" : "list-item"
85         };
86
87         jQuery.each(test, function(selector, expected) {
88                 var elem = jQuery(selector, "#show-tests").show();
89                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
90         });
91 });
92
93 test("show(Number) - other displays", function() {
94         expect(15);
95         QUnit.reset();
96         stop();
97
98         // #show-tests * is set display: none in CSS
99         jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>');
100
101         var old = jQuery("#test-table").show().css("display") !== "table",
102                 num = 0;
103         jQuery("#test-table").remove();
104
105         var test = {
106                 "div"      : "block",
107                 "p"        : "block",
108                 "a"        : "inline",
109                 "code"     : "inline",
110                 "pre"      : "block",
111                 "span"     : "inline",
112                 "table"    : old ? "block" : "table",
113                 "thead"    : old ? "block" : "table-header-group",
114                 "tbody"    : old ? "block" : "table-row-group",
115                 "tr"       : old ? "block" : "table-row",
116                 "th"       : old ? "block" : "table-cell",
117                 "td"       : old ? "block" : "table-cell",
118                 "ul"       : "block",
119                 "li"       : old ? "block" : "list-item"
120         };
121
122         jQuery.each(test, function(selector, expected) {
123                 var elem = jQuery(selector, "#show-tests").show(1, function() {
124                         equals( elem.css("display"), expected, "Show using correct display type for " + selector );
125                         if ( ++num === 15 ) {
126                                 start();
127                         }
128                 });
129         });
130 });
131
132
133
134 // Supports #7397
135 test("Persist correct display value", function() {
136         expect(3);
137         QUnit.reset();
138         stop();
139
140         // #show-tests * is set display: none in CSS
141         jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>');
142
143         var $span = jQuery("#show-tests span"),
144                 displayNone = $span.css("display"),
145                 display = '', num = 0;
146
147         $span.show();
148
149         display = $span.css("display");
150
151         $span.hide();
152
153         $span.fadeIn(100, function() {
154                 equals($span.css("display"), display, "Expecting display: " + display);
155                 $span.fadeOut(100, function () {
156                         equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
157                         $span.fadeIn(100, function() {
158                                 equals($span.css("display"), display, "Expecting display: " + display);
159                                 start();
160                         });
161                 });
162         });
163 });
164
165 test("show() resolves correct default display #8099", function() {
166         expect(3);
167         var bug8099 = jQuery("<tt/>").appendTo("#main");
168
169         equals( bug8099.css("display"), "none", "default display override for all tt" );
170         equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
171
172         bug8099.remove();
173
174         equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
175 });
176
177 test("animate(Hash, Object, Function)", function() {
178         expect(1);
179         stop();
180         var hash = {opacity: 'show'};
181         var hashCopy = jQuery.extend({}, hash);
182         jQuery('#foo').animate(hash, 0, function() {
183                 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
184                 start();
185         });
186 });
187
188 test("animate negative height", function() {
189         expect(1);
190         stop();
191         jQuery("#foo").animate({ height: -100 }, 100, function() {
192                 equals( this.offsetHeight, 0, "Verify height." );
193                 start();
194         });
195 });
196
197 test("animate block as inline width/height", function() {
198         expect(3);
199
200         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
201                 expected = span.css("display");
202
203         span.remove();
204
205         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
206                 stop();
207
208                 jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
209                         equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
210                         equals( this.offsetWidth, 42, "width was animated" );
211                         equals( this.offsetHeight, 42, "height was animated" );
212                         start();
213                 });
214
215         // Browser doesn't support inline-block
216         } else {
217                 ok( true, "Browser doesn't support inline-block" );
218                 ok( true, "Browser doesn't support inline-block" );
219                 ok( true, "Browser doesn't support inline-block" );
220         }
221 });
222
223 test("animate native inline width/height", function() {
224         expect(3);
225
226         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
227                 expected = span.css("display");
228
229         span.remove();
230
231         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
232                 stop();
233                 jQuery("#foo").css({ display: "", width: '', height: '' })
234                         .append('<span>text</span>')
235                         .children('span')
236                                 .animate({ width: 42, height: 42 }, 100, function() {
237                                         equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
238                                         equals( this.offsetWidth, 42, "width was animated" );
239                                         equals( this.offsetHeight, 42, "height was animated" );
240                                         start();
241                                 });
242
243         // Browser doesn't support inline-block
244         } else {
245                 ok( true, "Browser doesn't support inline-block" );
246                 ok( true, "Browser doesn't support inline-block" );
247                 ok( true, "Browser doesn't support inline-block" );
248         }
249 });
250
251 test("animate block width/height", function() {
252         expect(3);
253         stop();
254         jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
255                 equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
256                 equals( this.offsetWidth, 42, "width was animated" );
257                 equals( this.offsetHeight, 42, "height was animated" );
258                 start();
259         });
260 });
261
262 test("animate table width/height", function() {
263         expect(1);
264         stop();
265
266         var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
267
268         jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
269                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
270                 start();
271         });
272 });
273
274 test("animate table-row width/height", function() {
275         expect(3);
276         stop();
277         var tr = jQuery("#table")
278                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
279                 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
280                 .find("tr");
281
282         // IE<8 uses “block” instead of the correct display type
283         var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
284
285         tr.animate({ width: 10, height: 10 }, 100, function() {
286                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
287                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
288                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
289                 start();
290         });
291 });
292
293 test("animate table-cell width/height", function() {
294         expect(3);
295         stop();
296         var td = jQuery("#table")
297                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
298                 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
299                 .find("td");
300
301         // IE<8 uses “block” instead of the correct display type
302         var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
303
304         td.animate({ width: 10, height: 10 }, 100, function() {
305                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
306                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
307                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
308                 start();
309         });
310 });
311
312 test("animate resets overflow-x and overflow-y when finished", function() {
313         expect(2);
314         stop();
315         jQuery("#foo")
316                 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
317                 .animate({ width: 42, height: 42 }, 100, function() {
318                         equals( this.style.overflowX, "visible", "overflow-x is visible" );
319                         equals( this.style.overflowY, "auto", "overflow-y is auto" );
320                         start();
321                 });
322 });
323
324 /* // This test ends up being flaky depending upon the CPU load
325 test("animate option (queue === false)", function () {
326         expect(1);
327         stop();
328
329         var order = [];
330
331         var $foo = jQuery("#foo");
332         $foo.animate({width:'100px'}, 3000, function () {
333                 // should finish after unqueued animation so second
334                 order.push(2);
335                 same( order, [ 1, 2 ], "Animations finished in the correct order" );
336                 start();
337         });
338         $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
339                 // short duration and out of queue so should finish first
340                 order.push(1);
341         }});
342 });
343 */
344
345 test("animate with no properties", function() {
346         expect(2);
347
348         var divs = jQuery("div"), count = 0;
349
350         divs.animate({}, function(){
351                 count++;
352         });
353
354         equals( divs.length, count, "Make sure that callback is called for each element in the set." );
355
356         stop();
357
358         var foo = jQuery("#foo");
359
360         foo.animate({});
361         foo.animate({top: 10}, 100, function(){
362                 ok( true, "Animation was properly dequeued." );
363                 start();
364         });
365 });
366
367 test("animate duration 0", function() {
368         expect(11);
369
370         stop();
371
372         var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
373
374         equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
375
376         $elems.eq(0).animate( {a:1}, 0, function(){
377                 ok( true, "Animate a simple property." );
378                 counter++;
379         });
380
381         // Failed until [6115]
382         equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
383
384         equals( counter, 1, "One synchronic animations" );
385
386         $elems.animate( { a:2 }, 0, function(){
387                 ok( true, "Animate a second simple property." );
388                 counter++;
389         });
390
391         equals( counter, 3, "Multiple synchronic animations" );
392
393         $elems.eq(0).animate( {a:3}, 0, function(){
394                 ok( true, "Animate a third simple property." );
395                 counter++;
396         });
397         $elems.eq(1).animate( {a:3}, 200, function(){
398                 counter++;
399                 // Failed until [6115]
400                 equals( counter, 5, "One synchronic and one asynchronic" );
401                 start();
402         });
403
404         var $elem = jQuery("<div />");
405         $elem.show(0, function(){
406                 ok(true, "Show callback with no duration");
407         });
408         $elem.hide(0, function(){
409                 ok(true, "Hide callback with no duration");
410         });
411
412         // manually clean up detached elements
413         $elem.remove();
414 });
415
416 test("animate hyphenated properties", function(){
417         expect(1);
418         stop();
419
420         jQuery("#foo")
421                 .css("font-size", 10)
422                 .animate({"font-size": 20}, 200, function(){
423                         equals( this.style.fontSize, "20px", "The font-size property was animated." );
424                         start();
425                 });
426 });
427
428 test("animate non-element", function(){
429         expect(1);
430         stop();
431
432         var obj = { test: 0 };
433
434         jQuery(obj).animate({test: 200}, 200, function(){
435                 equals( obj.test, 200, "The custom property should be modified." );
436                 start();
437         });
438 });
439
440 test("stop()", function() {
441         expect(3);
442         stop();
443
444         var $foo = jQuery("#foo");
445         var w = 0;
446         $foo.hide().width(200).width();
447
448         $foo.animate({ width:'show' }, 1000);
449         setTimeout(function(){
450                 var nw = $foo.width();
451                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
452                 $foo.stop();
453
454                 nw = $foo.width();
455                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
456                 setTimeout(function(){
457                         $foo.removeData();
458                         $foo.removeData(undefined, true);
459                         equals( nw, $foo.width(), "The animation didn't continue" );
460                         start();
461                 }, 100);
462         }, 100);
463 });
464
465 test("stop() - several in queue", function() {
466         expect(3);
467         stop();
468
469         var $foo = jQuery("#foo");
470         var w = 0;
471         $foo.hide().width(200).width();
472
473         $foo.animate({ width:'show' }, 1000);
474         $foo.animate({ width:'hide' }, 1000);
475         $foo.animate({ width:'show' }, 1000);
476         setTimeout(function(){
477                 equals( $foo.queue().length, 3, "All 3 still in the queue" );
478                 var nw = $foo.width();
479                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
480                 $foo.stop();
481
482                 nw = $foo.width();
483                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
484
485                 $foo.stop(true);
486                 start();
487         }, 100);
488 });
489
490 test("stop(clearQueue)", function() {
491         expect(4);
492         stop();
493
494         var $foo = jQuery("#foo");
495         var w = 0;
496         $foo.hide().width(200).width();
497
498         $foo.animate({ width:'show' }, 1000);
499         $foo.animate({ width:'hide' }, 1000);
500         $foo.animate({ width:'show' }, 1000);
501         setTimeout(function(){
502                 var nw = $foo.width();
503                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
504                 $foo.stop(true);
505
506                 nw = $foo.width();
507                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
508
509                 equals( $foo.queue().length, 0, "The animation queue was cleared" );
510                 setTimeout(function(){
511                         equals( nw, $foo.width(), "The animation didn't continue" );
512                         start();
513                 }, 100);
514         }, 100);
515 });
516
517 test("stop(clearQueue, gotoEnd)", function() {
518         expect(1);
519         stop();
520
521         var $foo = jQuery("#foo");
522         var w = 0;
523         $foo.hide().width(200).width();
524
525         $foo.animate({ width:'show' }, 1000);
526         $foo.animate({ width:'hide' }, 1000);
527         $foo.animate({ width:'show' }, 1000);
528         $foo.animate({ width:'hide' }, 1000);
529         setTimeout(function(){
530                 var nw = $foo.width();
531                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
532                 $foo.stop(false, true);
533
534                 nw = $foo.width();
535                 // Disabled, being flaky
536                 //equals( nw, 1, "Stop() reset the animation" );
537
538                 setTimeout(function(){
539                         // Disabled, being flaky
540                         //equals( $foo.queue().length, 2, "The next animation continued" );
541                         $foo.stop(true);
542                         start();
543                 }, 100);
544         }, 100);
545 });
546
547 test("toggle()", function() {
548         expect(6);
549         var x = jQuery("#foo");
550         ok( x.is(":visible"), "is visible" );
551         x.toggle();
552         ok( x.is(":hidden"), "is hidden" );
553         x.toggle();
554         ok( x.is(":visible"), "is visible again" );
555
556         x.toggle(true);
557         ok( x.is(":visible"), "is visible" );
558         x.toggle(false);
559         ok( x.is(":hidden"), "is hidden" );
560         x.toggle(true);
561         ok( x.is(":visible"), "is visible again" );
562 });
563
564 jQuery.checkOverflowDisplay = function(){
565         var o = jQuery.css( this, "overflow" );
566
567         equals(o, "visible", "Overflow should be visible: " + o);
568         equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
569
570         start();
571 }
572
573 test("support negative values < -10000 (bug #7193)", function () {
574         expect(1);
575         stop();
576
577         jQuery.extend(jQuery.fx.step, {
578                 "marginBottom": function(fx) {
579                         equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
580                         delete jQuery.fx.step.marginBottom;
581                 }
582         });
583
584         jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
585                 duration: 1,
586                 complete: start
587         });
588 });
589
590 test("JS Overflow and Display", function() {
591         expect(2);
592         stop();
593         jQuery.makeTest( "JS Overflow and Display" )
594                 .addClass("widewidth")
595                 .css({ overflow: "visible", display: "inline" })
596                 .addClass("widewidth")
597                 .text("Some sample text.")
598                 .before("text before")
599                 .after("text after")
600                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
601 });
602
603 test("CSS Overflow and Display", function() {
604         expect(2);
605         stop();
606         jQuery.makeTest( "CSS Overflow and Display" )
607                 .addClass("overflow inline")
608                 .addClass("widewidth")
609                 .text("Some sample text.")
610                 .before("text before")
611                 .after("text after")
612                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
613 });
614
615 jQuery.each( {
616         "CSS Auto": function(elem,prop){
617                 jQuery(elem).addClass("auto" + prop)
618                         .text("This is a long string of text.");
619                 return "";
620         },
621         "JS Auto": function(elem,prop){
622                 jQuery(elem).css(prop,"")
623                         .text("This is a long string of text.");
624                 return "";
625         },
626         "CSS 100": function(elem,prop){
627                 jQuery(elem).addClass("large" + prop);
628                 return "";
629         },
630         "JS 100": function(elem,prop){
631                 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
632                 return prop == "opacity" ? 1 : 100;
633         },
634         "CSS 50": function(elem,prop){
635                 jQuery(elem).addClass("med" + prop);
636                 return "";
637         },
638         "JS 50": function(elem,prop){
639                 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
640                 return prop == "opacity" ? 0.5 : 50;
641         },
642         "CSS 0": function(elem,prop){
643                 jQuery(elem).addClass("no" + prop);
644                 return "";
645         },
646         "JS 0": function(elem,prop){
647                 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
648                 return 0;
649         }
650 }, function(fn, f){
651         jQuery.each( {
652                 "show": function(elem,prop){
653                         jQuery(elem).hide().addClass("wide"+prop);
654                         return "show";
655                 },
656                 "hide": function(elem,prop){
657                         jQuery(elem).addClass("wide"+prop);
658                         return "hide";
659                 },
660                 "100": function(elem,prop){
661                         jQuery(elem).addClass("wide"+prop);
662                         return prop == "opacity" ? 1 : 100;
663                 },
664                 "50": function(elem,prop){
665                         return prop == "opacity" ? 0.50 : 50;
666                 },
667                 "0": function(elem,prop){
668                         jQuery(elem).addClass("noback");
669                         return 0;
670                 }
671         }, function(tn, t){
672                 test(fn + " to " + tn, function() {
673                         var elem = jQuery.makeTest( fn + " to " + tn );
674
675                         var t_w = t( elem, "width" );
676                         var f_w = f( elem, "width" );
677                         var t_h = t( elem, "height" );
678                         var f_h = f( elem, "height" );
679                         var t_o = t( elem, "opacity" );
680                         var f_o = f( elem, "opacity" );
681
682                         var num = 0;
683
684                         if ( t_h == "show" ) num++;
685                         if ( t_w == "show" ) num++;
686                         if ( t_w == "hide"||t_w == "show" ) num++;
687                         if ( t_h == "hide"||t_h == "show" ) num++;
688                         if ( t_o == "hide"||t_o == "show" ) num++;
689                         if ( t_w == "hide" ) num++;
690                         if ( t_o.constructor == Number ) num += 2;
691                         if ( t_w.constructor == Number ) num += 2;
692                         if ( t_h.constructor == Number ) num +=2;
693
694                         expect(num);
695                         stop();
696
697                         var anim = { width: t_w, height: t_h, opacity: t_o };
698
699                         elem.animate(anim, 50, function(){
700                                 if ( t_w == "show" )
701                                         equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
702
703                                 if ( t_w == "hide"||t_w == "show" )
704                                         ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width);
705
706                                 if ( t_h == "hide"||t_h == "show" )
707                                         ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height);
708
709                                 var cur_o = jQuery.style(this, "opacity");
710
711                                 if ( t_o == "hide" || t_o == "show" )
712                                         equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
713
714                                 if ( t_w == "hide" )
715                                         equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
716
717                                 if ( t_o.constructor == Number ) {
718                                         equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
719
720                                         ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
721                                 }
722
723                                 if ( t_w.constructor == Number ) {
724                                         equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
725
726                                         var cur_w = jQuery.css(this,"width");
727
728                                         ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
729                                 }
730
731                                 if ( t_h.constructor == Number ) {
732                                         equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
733
734                                         var cur_h = jQuery.css(this,"height");
735
736                                         ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
737                                 }
738
739                                 if ( t_h == "show" ) {
740                                         var old_h = jQuery.css(this, "height");
741                                         jQuery(this).append("<br/>Some more text<br/>and some more...");
742
743                                         if ( /Auto/.test( fn ) ) {
744                                                 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
745                                         } else {
746                                                 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
747                                         }
748                                 }
749
750                                 // manually remove generated element
751                                 jQuery(this).remove();
752
753                                 start();
754                         });
755                 });
756         });
757 });
758
759 jQuery.fn.saveState = function(hiddenOverflow){
760         var check = ['opacity','height','width','display','overflow'];
761         expect(check.length);
762
763         stop();
764         return this.each(function(){
765                 var self = this;
766                 self.save = {};
767                 jQuery.each(check, function(i,c){
768                         self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
769                 });
770         });
771 };
772
773 jQuery.checkState = function(){
774         var self = this;
775         jQuery.each(this.save, function(c,v){
776                 var cur = self.style[ c ] || jQuery.css(self, c);
777                 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
778         });
779
780         // manually clean data on modified element
781         jQuery.removeData(this, 'olddisplay', true);
782
783         start();
784 }
785
786 // Chaining Tests
787 test("Chain fadeOut fadeIn", function() {
788         jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
789 });
790 test("Chain fadeIn fadeOut", function() {
791         jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
792 });
793
794 test("Chain hide show", function() {
795         jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
796 });
797 test("Chain show hide", function() {
798         jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
799 });
800 test("Chain show hide with easing and callback", function() {
801         jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
802 });
803
804 test("Chain toggle in", function() {
805         jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
806 });
807 test("Chain toggle out", function() {
808         jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
809 });
810 test("Chain toggle out with easing and callback", function() {
811         jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
812 });
813 test("Chain slideDown slideUp", function() {
814         jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
815 });
816 test("Chain slideUp slideDown", function() {
817         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
818 });
819 test("Chain slideUp slideDown with easing and callback", function() {
820         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
821 });
822
823 test("Chain slideToggle in", function() {
824         jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
825 });
826 test("Chain slideToggle out", function() {
827         jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
828 });
829
830 test("Chain fadeToggle in", function() {
831         jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
832 });
833 test("Chain fadeToggle out", function() {
834         jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
835 });
836
837 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
838         jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
839 });
840
841 jQuery.makeTest = function( text ){
842         var elem = jQuery("<div></div>")
843                 .attr("id", "test" + jQuery.makeTest.id++)
844                 .addClass("box");
845
846         jQuery("<h4></h4>")
847                 .text( text )
848                 .appendTo("#fx-tests")
849                 .after( elem );
850
851         return elem;
852 }
853
854 jQuery.makeTest.id = 1;
855
856 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
857         expect(4);
858         stop();
859
860         var $checkedtest = jQuery("#checkedtest");
861         // IE6 was clearing "checked" in jQuery(elem).show("fast");
862         $checkedtest.hide().show("fast", function() {
863                 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
864                 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
865                 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
866                 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
867                 start();
868         });
869 });
870
871 test("animate with per-property easing", function(){
872
873         expect(3);
874         stop();
875
876         var _test1_called = false;
877         var _test2_called = false;
878         var _default_test_called = false;
879
880         jQuery.easing['_test1'] = function() {
881                 _test1_called = true;
882         };
883
884         jQuery.easing['_test2'] = function() {
885                 _test2_called = true;
886         };
887
888         jQuery.easing['_default_test'] = function() {
889                 _default_test_called = true;
890         };
891
892         jQuery({a:0,b:0,c:0}).animate({
893                 a: [100, '_test1'],
894                 b: [100, '_test2'],
895                 c: 100
896         }, 400, '_default_test', function(){
897                 start();
898                 ok(_test1_called, "Easing function (1) called");
899                 ok(_test2_called, "Easing function (2) called");
900                 ok(_default_test_called, "Easing function (_default) called");
901         });
902
903 });
904
905 test("hide hidden elements (bug #7141)", function() {
906         expect(3);
907         QUnit.reset();
908
909         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
910         equals( div.css("display"), "none", "Element is hidden by default" );
911         div.hide();
912         ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
913         div.show();
914         equals( div.css("display"), "block", "Show a double-hidden element" );
915
916         div.remove();
917 });
918
919 test("hide hidden elements, with animation (bug #7141)", function() {
920         expect(3);
921         QUnit.reset();
922         stop();
923
924         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
925         equals( div.css("display"), "none", "Element is hidden by default" );
926         div.hide(1, function () {
927                 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
928                 div.show(1, function () {
929                         equals( div.css("display"), "block", "Show a double-hidden element" );
930                         start();
931                 });
932         });
933 });
934
935 test("animate unit-less properties (#4966)", 2, function() {
936         stop();
937         var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#main" );
938         equal( div.css( "z-index" ), "0", "z-index is 0" );
939         div.animate({ zIndex: 2 }, function() {
940                 equal( div.css( "z-index" ), "2", "z-index is 2" );
941                 start();
942         });
943 });