cf9d13109e9a7eb7136444e3073c6b503b2738b8
[jquery.git] / test / unit / effects.js
1 module("effects");
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("body").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
408 test("animate hyphenated properties", function(){
409         expect(1);
410         stop();
411
412         jQuery("#nothiddendiv")
413                 .css("font-size", 10)
414                 .animate({"font-size": 20}, 200, function(){
415                         equals( this.style.fontSize, "20px", "The font-size property was animated." );
416                         start();
417                 });
418 });
419
420 test("animate non-element", function(){
421         expect(1);
422         stop();
423
424         var obj = { test: 0 };
425
426         jQuery(obj).animate({test: 200}, 200, function(){
427                 equals( obj.test, 200, "The custom property should be modified." );
428                 start();
429         });
430 });
431
432 test("stop()", function() {
433         expect(3);
434         stop();
435
436         var $foo = jQuery("#nothiddendiv");
437         var w = 0;
438         $foo.hide().width(200).width();
439
440         $foo.animate({ width:'show' }, 1000);
441         setTimeout(function(){
442                 var nw = $foo.width();
443                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
444                 $foo.stop();
445
446                 nw = $foo.width();
447                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
448                 setTimeout(function(){
449                         equals( nw, $foo.width(), "The animation didn't continue" );
450                         start();
451                 }, 100);
452         }, 100);
453 });
454
455 test("stop() - several in queue", function() {
456         expect(3);
457         stop();
458
459         var $foo = jQuery("#nothiddendivchild");
460         var w = 0;
461         $foo.hide().width(200).width();
462
463         $foo.animate({ width:'show' }, 1000);
464         $foo.animate({ width:'hide' }, 1000);
465         $foo.animate({ width:'show' }, 1000);
466         setTimeout(function(){
467                 equals( $foo.queue().length, 3, "All 3 still in the queue" );
468                 var nw = $foo.width();
469                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
470                 $foo.stop();
471
472                 nw = $foo.width();
473                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
474
475                 $foo.stop(true);
476                 start();
477         }, 100);
478 });
479
480 test("stop(clearQueue)", function() {
481         expect(4);
482         stop();
483
484         var $foo = jQuery("#nothiddendiv");
485         var w = 0;
486         $foo.hide().width(200).width();
487
488         $foo.animate({ width:'show' }, 1000);
489         $foo.animate({ width:'hide' }, 1000);
490         $foo.animate({ width:'show' }, 1000);
491         setTimeout(function(){
492                 var nw = $foo.width();
493                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
494                 $foo.stop(true);
495
496                 nw = $foo.width();
497                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
498
499                 equals( $foo.queue().length, 0, "The animation queue was cleared" );
500                 setTimeout(function(){
501                         equals( nw, $foo.width(), "The animation didn't continue" );
502                         start();
503                 }, 100);
504         }, 100);
505 });
506
507 test("stop(clearQueue, gotoEnd)", function() {
508         expect(1);
509         stop();
510
511         var $foo = jQuery("#nothiddendivchild");
512         var w = 0;
513         $foo.hide().width(200).width();
514
515         $foo.animate({ width:'show' }, 1000);
516         $foo.animate({ width:'hide' }, 1000);
517         $foo.animate({ width:'show' }, 1000);
518         $foo.animate({ width:'hide' }, 1000);
519         setTimeout(function(){
520                 var nw = $foo.width();
521                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
522                 $foo.stop(false, true);
523
524                 nw = $foo.width();
525                 // Disabled, being flaky
526                 //equals( nw, 1, "Stop() reset the animation" );
527
528                 setTimeout(function(){
529                         // Disabled, being flaky
530                         //equals( $foo.queue().length, 2, "The next animation continued" );
531                         $foo.stop(true);
532                         start();
533                 }, 100);
534         }, 100);
535 });
536
537 test("toggle()", function() {
538         expect(6);
539         var x = jQuery("#nothiddendiv");
540         ok( x.is(":visible"), "is visible" );
541         x.toggle();
542         ok( x.is(":hidden"), "is hidden" );
543         x.toggle();
544         ok( x.is(":visible"), "is visible again" );
545
546         x.toggle(true);
547         ok( x.is(":visible"), "is visible" );
548         x.toggle(false);
549         ok( x.is(":hidden"), "is hidden" );
550         x.toggle(true);
551         ok( x.is(":visible"), "is visible again" );
552 });
553
554 jQuery.checkOverflowDisplay = function(){
555         var o = jQuery.css( this, "overflow" );
556
557         equals(o, "visible", "Overflow should be visible: " + o);
558         equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
559
560         start();
561 }
562
563 test("support negative values < -10000 (bug #7193)", function () {
564         expect(1);
565         stop();
566
567         jQuery.extend(jQuery.fx.step, {
568                 "marginBottom": function(fx) {
569                         equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
570                         delete jQuery.fx.step.marginBottom;
571                 }
572     });
573
574         jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
575                 duration: 1,
576                 complete: start
577         });
578 });
579
580 test("JS Overflow and Display", function() {
581         expect(2);
582         stop();
583         jQuery.makeTest( "JS Overflow and Display" )
584                 .addClass("widewidth")
585                 .css({ overflow: "visible", display: "inline" })
586                 .addClass("widewidth")
587                 .text("Some sample text.")
588                 .before("text before")
589                 .after("text after")
590                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
591 });
592
593 test("CSS Overflow and Display", function() {
594         expect(2);
595         stop();
596         jQuery.makeTest( "CSS Overflow and Display" )
597                 .addClass("overflow inline")
598                 .addClass("widewidth")
599                 .text("Some sample text.")
600                 .before("text before")
601                 .after("text after")
602                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
603 });
604
605 jQuery.each( {
606         "CSS Auto": function(elem,prop){
607                 jQuery(elem).addClass("auto" + prop)
608                         .text("This is a long string of text.");
609                 return "";
610         },
611         "JS Auto": function(elem,prop){
612                 jQuery(elem).css(prop,"")
613                         .text("This is a long string of text.");
614                 return "";
615         },
616         "CSS 100": function(elem,prop){
617                 jQuery(elem).addClass("large" + prop);
618                 return "";
619         },
620         "JS 100": function(elem,prop){
621                 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
622                 return prop == "opacity" ? 1 : 100;
623         },
624         "CSS 50": function(elem,prop){
625                 jQuery(elem).addClass("med" + prop);
626                 return "";
627         },
628         "JS 50": function(elem,prop){
629                 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
630                 return prop == "opacity" ? 0.5 : 50;
631         },
632         "CSS 0": function(elem,prop){
633                 jQuery(elem).addClass("no" + prop);
634                 return "";
635         },
636         "JS 0": function(elem,prop){
637                 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
638                 return 0;
639         }
640 }, function(fn, f){
641         jQuery.each( {
642                 "show": function(elem,prop){
643                         jQuery(elem).hide().addClass("wide"+prop);
644                         return "show";
645                 },
646                 "hide": function(elem,prop){
647                         jQuery(elem).addClass("wide"+prop);
648                         return "hide";
649                 },
650                 "100": function(elem,prop){
651                         jQuery(elem).addClass("wide"+prop);
652                         return prop == "opacity" ? 1 : 100;
653                 },
654                 "50": function(elem,prop){
655                         return prop == "opacity" ? 0.50 : 50;
656                 },
657                 "0": function(elem,prop){
658                         jQuery(elem).addClass("noback");
659                         return 0;
660                 }
661         }, function(tn, t){
662                 test(fn + " to " + tn, function() {
663                         var elem = jQuery.makeTest( fn + " to " + tn );
664
665                         var t_w = t( elem, "width" );
666                         var f_w = f( elem, "width" );
667                         var t_h = t( elem, "height" );
668                         var f_h = f( elem, "height" );
669                         var t_o = t( elem, "opacity" );
670                         var f_o = f( elem, "opacity" );
671
672                         var num = 0;
673
674                         if ( t_h == "show" ) num++;
675                         if ( t_w == "show" ) num++;
676                         if ( t_w == "hide"||t_w == "show" ) num++;
677                         if ( t_h == "hide"||t_h == "show" ) num++;
678                         if ( t_o == "hide"||t_o == "show" ) num++;
679                         if ( t_w == "hide" ) num++;
680                         if ( t_o.constructor == Number ) num += 2;
681                         if ( t_w.constructor == Number ) num += 2;
682                         if ( t_h.constructor == Number ) num +=2;
683
684                         expect(num);
685                         stop();
686
687                         var anim = { width: t_w, height: t_h, opacity: t_o };
688
689                         elem.animate(anim, 50, function(){
690                                 if ( t_w == "show" )
691                                         equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
692
693                                 if ( t_w == "hide"||t_w == "show" )
694                                         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);
695
696                                 if ( t_h == "hide"||t_h == "show" )
697                                         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);
698
699                                 var cur_o = jQuery.style(this, "opacity");
700
701                                 if ( t_o == "hide" || t_o == "show" )
702                                         equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
703
704                                 if ( t_w == "hide" )
705                                         equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
706
707                                 if ( t_o.constructor == Number ) {
708                                         equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
709
710                                         ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
711                                 }
712
713                                 if ( t_w.constructor == Number ) {
714                                         equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
715
716                                         var cur_w = jQuery.css(this,"width");
717
718                                         ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
719                                 }
720
721                                 if ( t_h.constructor == Number ) {
722                                         equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
723
724                                         var cur_h = jQuery.css(this,"height");
725
726                                         ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
727                                 }
728
729                                 if ( t_h == "show" ) {
730                                         var old_h = jQuery.css(this, "height");
731                                         jQuery(this).append("<br/>Some more text<br/>and some more...");
732
733                                         if ( /Auto/.test( fn ) ) {
734                                                 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
735                                         } else {
736                                                 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
737                                         }
738                                 }
739
740                                 start();
741                         });
742                 });
743         });
744 });
745
746 jQuery.fn.saveState = function(hiddenOverflow){
747         var check = ['opacity','height','width','display','overflow'];
748         expect(check.length);
749
750         stop();
751         return this.each(function(){
752                 var self = this;
753                 self.save = {};
754                 jQuery.each(check, function(i,c){
755                         self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
756                 });
757         });
758 };
759
760 jQuery.checkState = function(){
761         var self = this;
762         jQuery.each(this.save, function(c,v){
763                 var cur = self.style[ c ] || jQuery.css(self, c);
764                 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
765         });
766         start();
767 }
768
769 // Chaining Tests
770 test("Chain fadeOut fadeIn", function() {
771         jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
772 });
773 test("Chain fadeIn fadeOut", function() {
774         jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
775 });
776
777 test("Chain hide show", function() {
778         jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
779 });
780 test("Chain show hide", function() {
781         jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
782 });
783 test("Chain show hide with easing and callback", function() {
784         jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
785 });
786
787 test("Chain toggle in", function() {
788         jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
789 });
790 test("Chain toggle out", function() {
791         jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
792 });
793 test("Chain toggle out with easing and callback", function() {
794  jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
795 });
796 test("Chain slideDown slideUp", function() {
797         jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
798 });
799 test("Chain slideUp slideDown", function() {
800         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
801 });
802 test("Chain slideUp slideDown with easing and callback", function() {
803         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
804 });
805
806 test("Chain slideToggle in", function() {
807         jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
808 });
809 test("Chain slideToggle out", function() {
810         jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
811 });
812
813 test("Chain fadeToggle in", function() {
814         jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
815 });
816 test("Chain fadeToggle out", function() {
817         jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
818 });
819
820 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
821         jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
822 });
823
824 jQuery.makeTest = function( text ){
825         var elem = jQuery("<div></div>")
826                 .attr("id", "test" + jQuery.makeTest.id++)
827                 .addClass("box");
828
829         jQuery("<h4></h4>")
830                 .text( text )
831                 .appendTo("#fx-tests")
832                 .click(function(){
833                         jQuery(this).next().toggle();
834                 })
835                 .after( elem );
836
837         return elem;
838 }
839
840 jQuery.makeTest.id = 1;
841
842 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
843         expect(4);
844   stop();
845
846         var $checkedtest = jQuery("#checkedtest");
847         // IE6 was clearing "checked" in jQuery(elem).show("fast");
848         $checkedtest.hide().show("fast", function() {
849         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
850         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
851         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
852         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
853         start();
854         });
855 });
856
857 test("animate with per-property easing", function(){
858
859         expect(3);
860         stop();
861
862         var _test1_called = false;
863         var _test2_called = false;
864         var _default_test_called = false;
865
866         jQuery.easing['_test1'] = function() {
867                 _test1_called = true;
868         };
869
870         jQuery.easing['_test2'] = function() {
871                 _test2_called = true;
872         };
873
874         jQuery.easing['_default_test'] = function() {
875                 _default_test_called = true;
876         };
877
878         jQuery({a:0,b:0,c:0}).animate({
879                 a: [100, '_test1'],
880                 b: [100, '_test2'],
881                 c: 100
882         }, 400, '_default_test', function(){
883                 start();
884                 ok(_test1_called, "Easing function (1) called");
885                 ok(_test2_called, "Easing function (2) called");
886                 ok(_default_test_called, "Easing function (_default) called");
887         });
888
889 });
890
891 test("hide hidden elements (bug #7141)", function() {
892         expect(3);
893         QUnit.reset();
894
895         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
896         equals( div.css("display"), "none", "Element is hidden by default" );
897         div.hide();
898         ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
899         div.show();
900         equals( div.css("display"), "block", "Show a double-hidden element" );
901
902         div.remove();
903 });
904
905 test("hide hidden elements, with animation (bug #7141)", function() {
906         expect(3);
907         QUnit.reset();
908         stop();
909
910         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
911         equals( div.css("display"), "none", "Element is hidden by default" );
912         div.hide(1, function () {
913                 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
914                 div.show(1, function () {
915                         equals( div.css("display"), "block", "Show a double-hidden element" );
916                         start();
917                 });
918         });
919 });