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