Landing pull request 581. Updates original patch by Orkel. Fixes #10006.
[jquery.git] / test / unit / effects.js
blob02ddd973d3bcf0b1f948dde2f77333f5f75c70c7
1 module("effects", { teardown: moduleTeardown });
3 test("sanity check", function() {
4         expect(1);
5         ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
6 });
8 test("show()", function() {
9         expect(28);
11         var hiddendiv = jQuery("div.hidden");
13         hiddendiv.hide().show();
15         equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
17         var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
19         equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
21         QUnit.reset();
23         hiddendiv = jQuery("div.hidden");
25         equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
27         hiddendiv.css("display", "block");
28         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
30         hiddendiv.show();
31         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
33         hiddendiv.css("display","");
35         var pass = true;
36         div = jQuery("#qunit-fixture div");
37         div.show().each(function(){
38                 if ( this.style.display == "none" ) pass = false;
39         });
40         ok( pass, "Show" );
42         var speeds = {
43                 "null speed": null,
44                 "undefined speed": undefined,
45                 "empty string speed": "",
46                 "false speed": false
47         };
49         jQuery.each(speeds, function(name, speed) {
50                 pass = true;
51                 div.hide().show(speed).each(function() {
52                         if ( this.style.display == "none" ) pass = false;
53                 });
54                 ok( pass, "Show with " + name);
55         });
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         });
65         // #show-tests * is set display: none in CSS
66         jQuery("#qunit-fixture").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>");
68         var old = jQuery("#test-table").show().css("display") !== "table";
69         jQuery("#test-table").remove();
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         };
88         jQuery.each(test, function(selector, expected) {
89                 var elem = jQuery(selector, "#show-tests").show();
90                 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
91         });
93         // Make sure that showing or hiding a text node doesn't cause an error
94         jQuery("<div>test</div> text <span>test</span>").show().remove();
95         jQuery("<div>test</div> text <span>test</span>").hide().remove();
96 });
98 test("show(Number) - other displays", function() {
99         expect(15);
100         QUnit.reset();
101         stop();
103         // #show-tests * is set display: none in CSS
104         jQuery("#qunit-fixture").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>");
106         var old = jQuery("#test-table").show().css("display") !== "table",
107                 num = 0;
108         jQuery("#test-table").remove();
110         var test = {
111                 "div"      : "block",
112                 "p"        : "block",
113                 "a"        : "inline",
114                 "code"     : "inline",
115                 "pre"      : "block",
116                 "span"     : "inline",
117                 "table"    : old ? "block" : "table",
118                 "thead"    : old ? "block" : "table-header-group",
119                 "tbody"    : old ? "block" : "table-row-group",
120                 "tr"       : old ? "block" : "table-row",
121                 "th"       : old ? "block" : "table-cell",
122                 "td"       : old ? "block" : "table-cell",
123                 "ul"       : "block",
124                 "li"       : old ? "block" : "list-item"
125         };
127         jQuery.each(test, function(selector, expected) {
128                 var elem = jQuery(selector, "#show-tests").show(1, function() {
129                         equal( elem.css("display"), expected, "Show using correct display type for " + selector );
130                         if ( ++num === 15 ) {
131                                 start();
132                         }
133                 });
134         });
139 // Supports #7397
140 test("Persist correct display value", function() {
141         expect(3);
142         QUnit.reset();
143         stop();
145         // #show-tests * is set display: none in CSS
146         jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
148         var $span = jQuery("#show-tests span"),
149                 displayNone = $span.css("display"),
150                 display = "", num = 0;
152         $span.show();
154         display = $span.css("display");
156         $span.hide();
158         $span.fadeIn(100, function() {
159                 equal($span.css("display"), display, "Expecting display: " + display);
160                 $span.fadeOut(100, function () {
161                         equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
162                         $span.fadeIn(100, function() {
163                                 equal($span.css("display"), display, "Expecting display: " + display);
164                                 start();
165                         });
166                 });
167         });
170 test("show() resolves correct default display (#8099)", function() {
171         expect(7);
172         var tt8099 = jQuery("<tt/>").appendTo("body"),
173                         dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
175         equal( tt8099.css("display"), "none", "default display override for all tt" );
176         equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
178         equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
180         equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
181         equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
183         equal( dfn8099.css("display"), "none", "default display override for all dfn" );
184         equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
186         tt8099.remove();
187         dfn8099.remove();
190 test( "show() resolves correct default display, detached nodes (#10006)", function(){
191         // Tests originally contributed by Orkel in
192         // https://github.com/jquery/jquery/pull/458
193         expect( 11 );
195         var div, span;
197         div = jQuery("<div class='hidden'>");
198         div.show().appendTo("#qunit-fixture");
199         equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
201         div = jQuery("<div style='display: none'>");
202         div.show().appendTo("#qunit-fixture");
203         equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
205         span = jQuery("<span class='hidden'/>");
206         span.show().appendTo("#qunit-fixture");
207         equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
209         span = jQuery("<span style='display: inline'/>");
210         span.show().appendTo("#qunit-fixture");
211         equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
213         div = jQuery("<div><div class='hidden'></div></div>").children("div");
214         div.show().appendTo("#qunit-fixture");
215         equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
217         div = jQuery("<div><div style='display: none'></div></div>").children("div");
218         div.show().appendTo("#qunit-fixture");
219         equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
221         div = jQuery("div.hidden");
222         div.detach().show();
223         equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
224         div.remove();
226         span = jQuery("<span>");
227         span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
228         equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
229         span.remove();
231         div = jQuery("<div>");
232         div.show().appendTo("#qunit-fixture");
233         ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
235         div = jQuery( document.createElement("div") );
236         div.show().appendTo("#qunit-fixture");
237         equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
239         div = jQuery("<div style='display: inline'/>");
240         div.show().appendTo("#qunit-fixture");
241         equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
245 test("animate(Hash, Object, Function)", function() {
246         expect(1);
247         stop();
248         var hash = {opacity: "show"};
249         var hashCopy = jQuery.extend({}, hash);
250         jQuery("#foo").animate(hash, 0, function() {
251                 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
252                 start();
253         });
256 test("animate negative height", function() {
257         expect(1);
258         stop();
259         jQuery("#foo").animate({ height: -100 }, 100, function() {
260                 equal( this.offsetHeight, 0, "Verify height." );
261                 start();
262         });
265 test("animate block as inline width/height", function() {
266         expect(3);
268         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
269                 expected = span.css("display");
271         span.remove();
273         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
274                 stop();
276                 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
277                         equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
278                         equal( this.offsetWidth, 42, "width was animated" );
279                         equal( this.offsetHeight, 42, "height was animated" );
280                         start();
281                 });
283         // Browser doesn't support inline-block
284         } else {
285                 ok( true, "Browser doesn't support inline-block" );
286                 ok( true, "Browser doesn't support inline-block" );
287                 ok( true, "Browser doesn't support inline-block" );
288         }
291 test("animate native inline width/height", function() {
292         expect(3);
294         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
295                 expected = span.css("display");
297         span.remove();
299         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
300                 stop();
301                 jQuery("#foo").css({ display: "", width: "", height: "" })
302                         .append("<span>text</span>")
303                         .children("span")
304                                 .animate({ width: 42, height: 42 }, 100, function() {
305                                         equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
306                                         equal( this.offsetWidth, 42, "width was animated" );
307                                         equal( this.offsetHeight, 42, "height was animated" );
308                                         start();
309                                 });
311         // Browser doesn't support inline-block
312         } else {
313                 ok( true, "Browser doesn't support inline-block" );
314                 ok( true, "Browser doesn't support inline-block" );
315                 ok( true, "Browser doesn't support inline-block" );
316         }
319 test("animate block width/height", function() {
320         expect(3);
321         stop();
322         jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
323                 equal( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
324                 equal( this.offsetWidth, 42, "width was animated" );
325                 equal( this.offsetHeight, 42, "height was animated" );
326                 start();
327         });
330 test("animate table width/height", function() {
331         expect(1);
332         stop();
334         var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
336         jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
337                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
338                 start();
339         });
342 test("animate table-row width/height", function() {
343         expect(3);
344         stop();
345         var tr = jQuery("#table")
346                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
347                 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
348                 .find("tr");
350         // IE<8 uses "block" instead of the correct display type
351         var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
353         tr.animate({ width: 10, height: 10 }, 100, function() {
354                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
355                 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
356                 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
357                 start();
358         });
361 test("animate table-cell width/height", function() {
362         expect(3);
363         stop();
364         var td = jQuery("#table")
365                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
366                 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
367                 .find("td");
369         // IE<8 uses "block" instead of the correct display type
370         var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
372         td.animate({ width: 10, height: 10 }, 100, function() {
373                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
374                 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
375                 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
376                 start();
377         });
380 test("animate percentage(%) on width/height", function() {
381         expect( 2 );
383         var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
384                 .appendTo("#qunit-fixture").children("div");
386         stop();
387         $div.animate({ width: "25%", height: "25%" }, 13, function() {
388                 var $this = jQuery(this);
389                 equal( $this.width(), 15, "Width was animated to 15px rather than 25px");
390                 equal( $this.height(), 15, "Height was animated to 15px rather than 25px");
391                 start();
392         });
395 test("animate resets overflow-x and overflow-y when finished", function() {
396         expect(2);
397         stop();
398         jQuery("#foo")
399                 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
400                 .animate({ width: 42, height: 42 }, 100, function() {
401                         equal( this.style.overflowX, "visible", "overflow-x is visible" );
402                         equal( this.style.overflowY, "auto", "overflow-y is auto" );
403                         start();
404                 });
407 /* // This test ends up being flaky depending upon the CPU load
408 test("animate option (queue === false)", function () {
409         expect(1);
410         stop();
412         var order = [];
414         var $foo = jQuery("#foo");
415         $foo.animate({width:"100px"}, 3000, function () {
416                 // should finish after unqueued animation so second
417                 order.push(2);
418                 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
419                 start();
420         });
421         $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
422                 // short duration and out of queue so should finish first
423                 order.push(1);
424         }});
428 asyncTest( "animate option { queue: false }", function() {
429         expect( 2 );
430         var foo = jQuery( "#foo" );
432         foo.animate({
433                 fontSize: "2em"
434         }, {
435                 queue: false,
436                 duration: 10,
437                 complete: function() {
438                         ok( true, "Animation Completed" );
439                         start();
440                 }
441         });
443         equal( foo.queue().length, 0, "Queue is empty" );
446 asyncTest( "animate option { queue: true }", function() {
447         expect( 2 );
448         var foo = jQuery( "#foo" );
450         foo.animate({
451                 fontSize: "2em"
452         }, {
453                 queue: true,
454                 duration: 10,
455                 complete: function() {
456                         ok( true, "Animation Completed" );
457                         start();
458                 }
459         });
461         notEqual( foo.queue().length, 0, "Default queue is not empty" );
465 asyncTest( "animate option { queue: 'name' }", function() {
466         expect( 5 );
467         var foo = jQuery( "#foo" ),
468                 origWidth = foo.width(),
469                 order = [];
471         foo.animate( { width: origWidth + 100 }, {
472                 queue: 'name',
473                 duration: 1,
474                 complete: function() {
476                         // second callback function
477                         order.push( 2 );
478                         equal( foo.width(), origWidth + 100, "Animation ended" );
479                         equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
480                 }
481         }).queue( "name", function( next ) {
483                 // last callback function
484                 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
485                 start();
486         });
488         setTimeout( function() {
490                 // this is the first callback function that should be called
491                 order.push( 1 );
492                 equal( foo.width(), origWidth, "Animation does not start on its own." );
493                 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
494                 foo.dequeue( "name" );
495         }, 100 );
499 test("animate with no properties", function() {
500         expect(2);
502         var divs = jQuery("div"), count = 0;
504         divs.animate({}, function(){
505                 count++;
506         });
508         equal( divs.length, count, "Make sure that callback is called for each element in the set." );
510         stop();
512         var foo = jQuery("#foo");
514         foo.animate({});
515         foo.animate({top: 10}, 100, function(){
516                 ok( true, "Animation was properly dequeued." );
517                 start();
518         });
521 test("animate duration 0", function() {
522         expect(11);
524         stop();
526         var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
528         equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
530         $elems.eq(0).animate( {a:1}, 0, function(){
531                 ok( true, "Animate a simple property." );
532                 counter++;
533         });
535         // Failed until [6115]
536         equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
538         equal( counter, 1, "One synchronic animations" );
540         $elems.animate( { a:2 }, 0, function(){
541                 ok( true, "Animate a second simple property." );
542                 counter++;
543         });
545         equal( counter, 3, "Multiple synchronic animations" );
547         $elems.eq(0).animate( {a:3}, 0, function(){
548                 ok( true, "Animate a third simple property." );
549                 counter++;
550         });
551         $elems.eq(1).animate( {a:3}, 200, function(){
552                 counter++;
553                 // Failed until [6115]
554                 equal( counter, 5, "One synchronic and one asynchronic" );
555                 start();
556         });
558         var $elem = jQuery("<div />");
559         $elem.show(0, function(){
560                 ok(true, "Show callback with no duration");
561         });
562         $elem.hide(0, function(){
563                 ok(true, "Hide callback with no duration");
564         });
566         // manually clean up detached elements
567         $elem.remove();
570 test("animate hyphenated properties", function() {
571         expect(1);
572         stop();
574         jQuery("#foo")
575                 .css("font-size", 10)
576                 .animate({"font-size": 20}, 200, function() {
577                         equal( this.style.fontSize, "20px", "The font-size property was animated." );
578                         start();
579                 });
582 test("animate non-element", function() {
583         expect(1);
584         stop();
586         var obj = { test: 0 };
588         jQuery(obj).animate({test: 200}, 200, function(){
589                 equal( obj.test, 200, "The custom property should be modified." );
590                 start();
591         });
594 test("stop()", function() {
595         expect(4);
596         stop();
598         var $foo = jQuery("#foo");
599         var w = 0;
601         $foo.hide().width(200)
602                 .animate({ width: "show" }, 1000);
604         setTimeout(function() {
605                 var nw = $foo.width();
606                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
607                 $foo.stop();
609                 nw = $foo.width();
610                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
611                 setTimeout(function() {
612                         $foo.removeData();
613                         $foo.removeData(undefined, true);
614                         equal( nw, $foo.width(), "The animation didn't continue" );
615                         start();
616                 }, 100);
617         }, 100);
619         var $one = jQuery("#fadein");
620         var $two = jQuery("#show");
621         $one.fadeTo(100, 0, function() {
622                 $one.stop();
623         });
624         setTimeout(function() {
625                 $two.fadeTo(100, 0, function() {
626                         equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
627                         // Reset styles
628                         $one.add( $two ).css("opacity", "");
629                 });
630         }, 50);
633 test("stop() - several in queue", function() {
634         expect(3);
635         stop();
637         var $foo = jQuery("#foo");
638         var w = 0;
639         $foo.hide().width(200).width();
641         $foo.animate({ width: "show" }, 1000);
642         $foo.animate({ width: "hide" }, 1000);
643         $foo.animate({ width: "show" }, 1000);
644         setTimeout(function(){
645                 equal( $foo.queue().length, 3, "All 3 still in the queue" );
646                 var nw = $foo.width();
647                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
648                 $foo.stop();
650                 nw = $foo.width();
651                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
653                 $foo.stop(true);
654                 start();
655         }, 100);
658 test("stop(clearQueue)", function() {
659         expect(4);
660         stop();
662         var $foo = jQuery("#foo");
663         var w = 0;
664         $foo.hide().width(200).width();
666         $foo.animate({ width: "show" }, 1000);
667         $foo.animate({ width: "hide" }, 1000);
668         $foo.animate({ width: "show" }, 1000);
669         setTimeout(function(){
670                 var nw = $foo.width();
671                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
672                 $foo.stop(true);
674                 nw = $foo.width();
675                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
677                 equal( $foo.queue().length, 0, "The animation queue was cleared" );
678                 setTimeout(function(){
679                         equal( nw, $foo.width(), "The animation didn't continue" );
680                         start();
681                 }, 100);
682         }, 100);
685 test("stop(clearQueue, gotoEnd)", function() {
686         expect(1);
687         stop();
689         var $foo = jQuery("#foo");
690         var w = 0;
691         $foo.hide().width(200).width();
693         $foo.animate({ width: "show" }, 1000);
694         $foo.animate({ width: "hide" }, 1000);
695         $foo.animate({ width: "show" }, 1000);
696         $foo.animate({ width: "hide" }, 1000);
697         setTimeout(function(){
698                 var nw = $foo.width();
699                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
700                 $foo.stop(false, true);
702                 nw = $foo.width();
703                 // Disabled, being flaky
704                 //equal( nw, 1, "Stop() reset the animation" );
706                 setTimeout(function(){
707                         // Disabled, being flaky
708                         //equal( $foo.queue().length, 2, "The next animation continued" );
709                         $foo.stop(true);
710                         start();
711                 }, 100);
712         }, 100);
715 asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
716         expect( 3 );
717         var foo = jQuery( "#foo" ),
718                 saved;
720         foo.width( 200 ).height( 200 );
721         foo.animate({
722                 width: 400
723         },{
724                 duration: 1000,
725                 complete: function() {
726                         equal( foo.width(), 400, "Animation completed for standard queue" );
727                         equal( foo.height(), saved, "Height was not changed after the second stop");
728                         start();
729                 }
730         });
732         foo.animate({
733                 height: 400
734         },{
735                 duration: 1000,
736                 queue: "height"
737         }).dequeue( "height" ).stop( "height", false, true );
739         equal( foo.height(), 400, "Height was stopped with gotoEnd" );
741         foo.animate({
742                 height: 200
743         },{
744                 duration: 1000,
745                 queue: "height"
746         }).dequeue( "height" ).stop( "height", false, false );
747         saved = foo.height();
750 test("toggle()", function() {
751         expect(6);
752         var x = jQuery("#foo");
753         ok( x.is(":visible"), "is visible" );
754         x.toggle();
755         ok( x.is(":hidden"), "is hidden" );
756         x.toggle();
757         ok( x.is(":visible"), "is visible again" );
759         x.toggle(true);
760         ok( x.is(":visible"), "is visible" );
761         x.toggle(false);
762         ok( x.is(":hidden"), "is hidden" );
763         x.toggle(true);
764         ok( x.is(":visible"), "is visible again" );
767 jQuery.checkOverflowDisplay = function(){
768         var o = jQuery.css( this, "overflow" );
770         equal(o, "visible", "Overflow should be visible: " + o);
771         equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
773         start();
776 test( "jQuery.fx.prototype.cur()", 6, function() {
777         var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
778                         color: "#ABC",
779                         border: "5px solid black",
780                         left: "auto",
781                         marginBottom: "-11000px"
782                 })[0];
784         equal(
785                 ( new jQuery.fx( div, {}, "color" ) ).cur(),
786                 jQuery.css( div, "color" ),
787                 "Return the same value as jQuery.css for complex properties (bug #7912)"
788         );
790         strictEqual(
791                 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
792                 5,
793                 "Return simple values parsed as Float"
794         );
796         // backgroundPosition actually returns 0% 0% in most browser
797         // this fakes a "" return
798         jQuery.cssHooks.backgroundPosition = {
799                 get: function() {
800                         ok( true, "hook used" );
801                         return "";
802                 }
803         };
805         strictEqual(
806                 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
807                 0,
808                 "Return 0 when jQuery.css returns an empty string"
809         );
811         delete jQuery.cssHooks.backgroundPosition;
813         strictEqual(
814                 ( new jQuery.fx( div, {}, "left" ) ).cur(),
815                 0,
816                 "Return 0 when jQuery.css returns 'auto'"
817         );
819         equal(
820                 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
821                 -11000,
822                 "support negative values < -10000 (bug #7193)"
823         );
826 test("JS Overflow and Display", function() {
827         expect(2);
828         stop();
829         jQuery.makeTest( "JS Overflow and Display" )
830                 .addClass("widewidth")
831                 .css({ overflow: "visible", display: "inline" })
832                 .addClass("widewidth")
833                 .text("Some sample text.")
834                 .before("text before")
835                 .after("text after")
836                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
839 test("CSS Overflow and Display", function() {
840         expect(2);
841         stop();
842         jQuery.makeTest( "CSS Overflow and Display" )
843                 .addClass("overflow inline")
844                 .addClass("widewidth")
845                 .text("Some sample text.")
846                 .before("text before")
847                 .after("text after")
848                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
851 jQuery.each({
852         "CSS Auto": function( elem, prop ) {
853                 jQuery( elem ).addClass( "auto" + prop )
854                         .text( "This is a long string of text." );
855                 return "";
856         },
857         "JS Auto": function( elem, prop ) {
858                 jQuery( elem ).css( prop, "" )
859                         .text( "This is a long string of text." );
860                 return "";
861         },
862         "CSS 100": function( elem, prop ) {
863                 jQuery( elem ).addClass( "large" + prop );
864                 return "";
865         },
866         "JS 100": function( elem, prop ) {
867                 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
868                 return prop === "opacity" ? 1 : 100;
869         },
870         "CSS 50": function( elem, prop ) {
871                 jQuery( elem ).addClass( "med" + prop );
872                 return "";
873         },
874         "JS 50": function( elem, prop ) {
875                 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
876                 return prop === "opacity" ? 0.5 : 50;
877         },
878         "CSS 0": function( elem, prop ) {
879                 jQuery( elem ).addClass( "no" + prop );
880                 return "";
881         },
882         "JS 0": function( elem, prop ) {
883                 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
884                 return 0;
885         }
886 }, function( fn, f ) {
887         jQuery.each({
888                 "show": function( elem, prop ) {
889                         jQuery( elem ).hide( ).addClass( "wide" + prop );
890                         return "show";
891                 },
892                 "hide": function( elem, prop ) {
893                         jQuery( elem ).addClass( "wide" + prop );
894                         return "hide";
895                 },
896                 "100": function( elem, prop ) {
897                         jQuery( elem ).addClass( "wide" + prop );
898                         return prop == "opacity" ? 1 : 100;
899                 },
900                 "50": function( elem, prop ) {
901                         return prop == "opacity" ? 0.50 : 50;
902                 },
903                 "0": function( elem, prop ) {
904                         jQuery( elem ).addClass( "noback" );
905                         return 0;
906                 }
907         }, function( tn, t ) {
908                 test(fn + " to " + tn, function() {
909                         var elem = jQuery.makeTest( fn + " to " + tn );
911                         var t_w = t( elem, "width" );
912                         var f_w = f( elem, "width" );
913                         var t_h = t( elem, "height" );
914                         var f_h = f( elem, "height" );
915                         var t_o = t( elem, "opacity" );
916                         var f_o = f( elem, "opacity" );
918                         if ( f_o === "" ) {
919                                 f_o = 1;
920                         }
922                         var num = 0;
924                         if ( t_h == "show" ) num++;
925                         if ( t_w == "show" ) num++;
926                         if ( t_w == "hide" || t_w == "show" ) num++;
927                         if ( t_h == "hide" || t_h == "show" ) num++;
928                         if ( t_o == "hide" || t_o == "show" ) num++;
929                         if ( t_w == "hide" ) num++;
930                         if ( t_o.constructor == Number ) num += 2;
931                         if ( t_w.constructor == Number ) num += 2;
932                         if ( t_h.constructor == Number ) num +=2;
934                         expect( num );
935                         stop();
937                         var anim = { width: t_w, height: t_h, opacity: t_o };
939                         elem.animate(anim, 50);
941                         jQuery.when( elem ).done(function( elem ) {
943                                 elem = elem[ 0 ];
945                                 if ( t_w == "show" ) {
946                                         equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
947                                 }
949                                 if ( t_w == "hide" || t_w == "show" ) {
950                                         ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width );
951                                 }
953                                 if ( t_h == "hide" || t_h == "show" ) {
954                                         ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
955                                 }
957                                 var cur_o = jQuery.style(elem, "opacity");
959                                 if ( f_o !== jQuery.css(elem, "opacity") ) {
960                                         f_o = f( elem, "opacity" );
961                                 }
963                                 // The only time an _empty_string_ will be matched is in IE
964                                 // otherwise, the correct values will be tested as usual
965                                 if ( f_o === "" ) {
966                                         f_o = 1;
967                                 }
968                                 // See above
969                                 if ( cur_o === "" ) {
970                                         cur_o = 1;
971                                 }
973                                 if ( t_o == "hide" || t_o == "show" ) {
974                                         equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
975                                 }
977                                 if ( t_w == "hide" ) {
978                                         equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
979                                 }
981                                 if ( t_o.constructor == Number ) {
982                                         equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
984                                         ok( jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
985                                 }
987                                 if ( t_w.constructor == Number ) {
988                                         equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
990                                         var cur_w = jQuery.css( elem,"width" );
992                                         ok( elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
993                                 }
995                                 if ( t_h.constructor == Number ) {
996                                         equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
998                                         var cur_h = jQuery.css( elem,"height" );
1000                                         ok( elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w );
1001                                 }
1003                                 if ( t_h == "show" ) {
1004                                         var old_h = jQuery.css( elem, "height" );
1005                                         jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1007                                         if ( /Auto/.test( fn ) ) {
1008                                                 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1009                                         } else {
1010                                                 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1011                                         }
1012                                 }
1014                                 // manually remove generated element
1015                                 jQuery( elem ).remove();
1017                                 start();
1018                         });
1019                 });
1020         });
1023 jQuery.fn.saveState = function( hiddenOverflow ) {
1024         var check = ["opacity", "height", "width", "display", "overflow"];
1025         expect(check.length);
1027         stop();
1028         return this.each(function(){
1029                 var self = this;
1030                 self.save = {};
1031                 jQuery.each(check, function( i, c ) {
1032                         self.save[ c ] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css( self, c );
1033                 });
1034         });
1037 jQuery.checkState = function() {
1038         var self = this;
1039         jQuery.each(this.save, function( c, v ) {
1040                 var cur = self.style[ c ] || jQuery.css( self, c );
1041                 equal( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
1042         });
1044         // manually clean data on modified element
1045         jQuery.removeData( this, "olddisplay", true );
1047         start();
1050 // Chaining Tests
1051 test("Chain fadeOut fadeIn", function() {
1052         jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast", jQuery.checkState );
1054 test("Chain fadeIn fadeOut", function() {
1055         jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast", jQuery.checkState );
1058 test("Chain hide show", function() {
1059         jQuery("#show div").saveState( jQuery.support.shrinkWrapBlocks ).hide("fast").show("fast", jQuery.checkState );
1061 test("Chain show hide", function() {
1062         jQuery("#hide div").saveState( jQuery.support.shrinkWrapBlocks ).show("fast").hide("fast", jQuery.checkState );
1064 test("Chain show hide with easing and callback", function() {
1065         jQuery("#hide div").saveState().show("fast").hide("fast","linear", jQuery.checkState );
1068 test("Chain toggle in", function() {
1069         jQuery("#togglein div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1071 test("Chain toggle out", function() {
1072         jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1074 test("Chain toggle out with easing and callback", function() {
1075         jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast","linear", jQuery.checkState );
1077 test("Chain slideDown slideUp", function() {
1078         jQuery("#slidedown div").saveState( jQuery.support.shrinkWrapBlocks ).slideDown("fast").slideUp("fast", jQuery.checkState );
1080 test("Chain slideUp slideDown", function() {
1081         jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast", jQuery.checkState );
1083 test("Chain slideUp slideDown with easing and callback", function() {
1084         jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast","linear", jQuery.checkState );
1087 test("Chain slideToggle in", function() {
1088         jQuery("#slidetogglein div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1090 test("Chain slideToggle out", function() {
1091         jQuery("#slidetoggleout div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1094 test("Chain fadeToggle in", function() {
1095         jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1097 test("Chain fadeToggle out", function() {
1098         jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1101 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
1102         jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear", jQuery.checkState );
1105 jQuery.makeTest = function( text ){
1106         var elem = jQuery("<div></div>")
1107                 .attr( "id", "test" + jQuery.makeTest.id++ )
1108                 .addClass("box");
1110         jQuery("<h4></h4>")
1111                 .text( text )
1112                 .appendTo("#fx-tests")
1113                 .after( elem );
1115         return elem;
1118 jQuery.makeTest.id = 1;
1120 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1121         expect(4);
1122         stop();
1124         var $checkedtest = jQuery("#checkedtest");
1125         // IE6 was clearing "checked" in jQuery(elem).show("fast");
1126         $checkedtest.hide().show("fast", function() {
1127                 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
1128                 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
1129                 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
1130                 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
1131                 start();
1132         });
1135 jQuery.each({
1136         "slideToggle": function( $elem ) {
1137                 return $elem.height();
1138         },
1139         "fadeToggle": function( $elem ) {
1140                 return $elem.css("opacity");
1141         },
1142         "toggle": function( $elem ) {
1143                 return $elem.width();
1144         }
1146 function( method, defProp ) {
1147         test( method + "().stop()." + method + "()", function() {
1148                 expect( 4 );
1150                 jQuery.each([ "in", "out" ], function( i, type ) {
1151                         var $elem = jQuery( "#" + method.toLowerCase() + type ),
1152                                 startVal = defProp( $elem );
1154                         $elem[ method ]("fast");
1155                         stop();
1157                         setTimeout( function() {
1158                                 $elem.stop();
1160                                 notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1162                                 $elem[ method ]("fast", function() {
1163                                         equal( defProp( jQuery(this) ), startVal, "After doing .stop() halfway, check that state has been saved for returning to original property value." );
1164                                         start();
1165                                 });
1166                         }, 100);
1167                 });
1168         });
1171 test("animate with per-property easing", function(){
1173         expect(5);
1174         stop();
1176         var data = { a:0, b:0, c:0 },
1177                 _test1_called = false,
1178                 _test2_called = false,
1179                 _default_test_called = false,
1180                 props = {
1181                         a: [ 100, "_test1" ],
1182                         b: [ 100, "_test2" ],
1183                         c: 100
1184                 };
1186         jQuery.easing["_test1"] = function(p) {
1187                 _test1_called = true;
1188                 return p;
1189         };
1191         jQuery.easing["_test2"] = function(p) {
1192                 _test2_called = true;
1193                 return p;
1194         };
1196         jQuery.easing["_default_test"] = function(p) {
1197                 _default_test_called = true;
1198                 return p;
1199         };
1201         jQuery(data).animate( props, 400, "_default_test", function(){
1202                 start();
1204                 ok( _test1_called, "Easing function (_test1) called" );
1205                 ok( _test2_called, "Easing function (_test2) called" );
1206                 ok( _default_test_called, "Easing function (_default) called" );
1207                 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1208                 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1209         });
1213 test("hide hidden elements (bug #7141)", function() {
1214         expect(3);
1215         QUnit.reset();
1217         var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1218         equal( div.css("display"), "none", "Element is hidden by default" );
1219         div.hide();
1220         ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1221         div.show();
1222         equal( div.css("display"), "block", "Show a double-hidden element" );
1224         div.remove();
1227 test("hide hidden elements, with animation (bug #7141)", function() {
1228         expect(3);
1229         QUnit.reset();
1230         stop();
1232         var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1233         equal( div.css("display"), "none", "Element is hidden by default" );
1234         div.hide(1, function () {
1235                 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1236                 div.show(1, function () {
1237                         equal( div.css("display"), "block", "Show a double-hidden element" );
1238                         start();
1239                 });
1240         });
1243 test("animate unit-less properties (#4966)", 2, function() {
1244         stop();
1245         var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1246         equal( div.css( "z-index" ), "0", "z-index is 0" );
1247         div.animate({ zIndex: 2 }, function() {
1248                 equal( div.css( "z-index" ), "2", "z-index is 2" );
1249                 start();
1250         });
1253 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1254         expect( 6 );
1255         stop();
1256         var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1257                 .appendTo( "#qunit-fixture" );
1258         function cssInt( prop ) {
1259                 return parseInt( div.css( prop ), 10 );
1260         }
1261         equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1262         equal( cssInt( "left" ), 0, "Left is 0" );
1263         div.animate({
1264                 left: 200,
1265                 marginLeft: 200,
1266                 opacity: 0
1267         }, 1000);
1268         setTimeout(function() {
1269                 var ml = cssInt( "marginLeft" ),
1270                         l = cssInt( "left" );
1271                 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1272                 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1273                 notEqual( l, 0, "Left is not 0 after partial animate" );
1274                 notEqual( l, 200, "Left is not 200 after partial animate" );
1275                 div.stop().remove();
1276                 start();
1277         }, 100);
1280 test("callbacks should fire in correct order (#9100)", function() {
1281         stop();
1282         var a = 1,
1283                 cb = 0,
1284                 $lis = jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
1285                         // The test will always pass if no properties are animated or if the duration is 0
1286                         .animate({fontSize: 12}, 13, function() {
1287                                 a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1288                                 cb++;
1289                                 if ( cb === 2 ) {
1290                                         equal( a, 4, "test value has been *2 and _then_ ^2");
1291                                         start();
1292                                 }
1293                         });
1296 asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
1297         expect( 2 );
1299         var foo = jQuery( "#foo" );
1301         function testException() {
1302         }
1304         foo.animate({ height: 1 }, 1, function() {
1305                 throw new testException;
1306         });
1308         // this test thoroughly abuses undocumented methods - please feel free to update
1309         // with any changes internally to these functions.
1311         // make sure that the standard timer loop will NOT run.
1312         jQuery.fx.stop();
1314         setTimeout(function() {
1316                 // the first call to fx.tick should raise the callback exception
1317                 raises( jQuery.fx.tick, testException, "Exception was thrown" );
1319                 // the second call shouldn't
1320                 jQuery.fx.tick();
1322                 ok( true, "Test completed without throwing a second exception" );
1324                 start();
1325         }, 1);