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