Ensure display: inline-block when animating width/height on inline elements. Fixes...
[jquery.git] / test / unit / effects.js
blob2a5ff402b3935b46491c353d532c1a41c315ac81
1 (function() {
3 // Can't test what ain't there
4 if ( !jQuery.fx ) {
5         return;
8 var off = jQuery.fx.off;
10 module("effects", {
11         teardown: function() {
12                 jQuery.fx.off = off;
13                 return moduleTeardown.apply( this, arguments );
14         }
15 });
17 test("sanity check", function() {
18         expect(1);
19         ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
20 });
22 test("show() basic", 2, function() {
23         var div,
24                 hiddendiv = jQuery("div.hidden");
26         hiddendiv.hide().show();
28         equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
30         div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
32         equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
34         // Clean up the detached node
35         div.remove();
37         QUnit.expectJqData(hiddendiv, "olddisplay");
38 });
40 test("show()", 27, function () {
41         var div, speeds, old, test,
42                 displaysActual, displaysExpected,
43                 hiddendiv = jQuery("div.hidden");
45         equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
47         hiddendiv.css("display", "block");
48         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
50         hiddendiv.show();
51         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
53         hiddendiv.css("display","");
55         displaysActual = [];
56         displaysExpected = [];
58         div = jQuery("#fx-queue div").slice(0, 4);
59         div.show().each(function() {
60                 notEqual(this.style.display, "none", "don't change any <div> with display block");
61         });
63         speeds = {
64                 "null speed": null,
65                 "undefined speed": undefined,
66                 "false speed": false
67         };
69         jQuery.each(speeds, function(name, speed) {
70                 var pass = true;
71                 div.hide().show(speed).each(function() {
72                         if ( this.style.display === "none" ) {
73                                 pass = false;
74                         }
75                 });
76                 ok( pass, "Show with " + name);
77         });
79         jQuery.each(speeds, function(name, speed) {
80                 var pass = true;
81                 div.hide().show(speed, function() {
82                         pass = false;
83                 });
84                 ok( pass, "Show with " + name + " does not call animate callback" );
85         });
87         // Tolerate data from show()/hide()
88         QUnit.expectJqData(div, "olddisplay");
90         // #show-tests * is set display: none in CSS
91         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>");
93         old = jQuery("#test-table").show().css("display") !== "table";
94         jQuery("#test-table").remove();
96         test = {
97                 "div"      : "block",
98                 "p"        : "block",
99                 "a"        : "inline",
100                 "code"     : "inline",
101                 "pre"      : "block",
102                 "span"     : "inline",
103                 "table"    : old ? "block" : "table",
104                 "thead"    : old ? "block" : "table-header-group",
105                 "tbody"    : old ? "block" : "table-row-group",
106                 "tr"       : old ? "block" : "table-row",
107                 "th"       : old ? "block" : "table-cell",
108                 "td"       : old ? "block" : "table-cell",
109                 "ul"       : "block",
110                 "li"       : old ? "block" : "list-item"
111         };
113         jQuery.each(test, function(selector, expected) {
114                 var elem = jQuery(selector, "#show-tests").show();
115                 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
116         });
118         jQuery("#show-tests").remove();
120         // Make sure that showing or hiding a text node doesn't cause an error
121         jQuery("<div>test</div> text <span>test</span>").show().remove();
122         jQuery("<div>test</div> text <span>test</span>").hide().remove();
125 test("show(Number) - other displays", function() {
126         expect(15);
127         QUnit.reset();
128         stop();
130         // #show-tests * is set display: none in CSS
131         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>");
133         var test,
134                 old = jQuery("#test-table").show().css("display") !== "table",
135                 num = 0;
136         jQuery("#test-table").remove();
138         // Note: inline elements are expected to be inline-block
139         // because we're showing width/height
140         // Can't animate width/height inline
141         // See #14344
142         test = {
143                 "div"      : "block",
144                 "p"        : "block",
145                 "a"        : "inline-block",
146                 "code"     : "inline-block",
147                 "pre"      : "block",
148                 "span"     : "inline-block",
149                 "table"    : old ? "block" : "table",
150                 "thead"    : old ? "block" : "table-header-group",
151                 "tbody"    : old ? "block" : "table-row-group",
152                 "tr"       : old ? "block" : "table-row",
153                 "th"       : old ? "block" : "table-cell",
154                 "td"       : old ? "block" : "table-cell",
155                 "ul"       : "block",
156                 "li"       : old ? "block" : "list-item"
157         };
159         jQuery.each(test, function(selector, expected) {
160                 var elem = jQuery(selector, "#show-tests").show(1, function() {
161                         equal( elem.css("display"), expected, "Show using correct display type for " + selector );
162                         if ( ++num === 15 ) {
163                                 start();
164                         }
165                 });
166         });
168         jQuery("#show-tests").remove();
171 // Supports #7397
172 test("Persist correct display value", function() {
173         expect(3);
174         QUnit.reset();
175         stop();
177         // #show-tests * is set display: none in CSS
178         jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
180         var $span = jQuery("#show-tests span"),
181                 displayNone = $span.css("display"),
182                 display = "";
184         $span.show();
186         display = $span.css("display");
188         $span.hide();
190         $span.fadeIn(100, function() {
191                 equal($span.css("display"), display, "Expecting display: " + display);
192                 $span.fadeOut(100, function () {
193                         equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
194                         $span.fadeIn(100, function() {
195                                 equal($span.css("display"), display, "Expecting display: " + display);
196                                 start();
197                         });
198                 });
199         });
201         QUnit.expectJqData($span, "olddisplay");
204 test("animate(Hash, Object, Function)", function() {
205         expect(1);
206         stop();
207         var hash = {opacity: "show"},
208                 hashCopy = jQuery.extend({}, hash);
209         jQuery("#foo").animate(hash, 0, function() {
210                 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
211                 start();
212         });
215 test("animate relative values", function() {
216         stop();
218         var value = 40,
219                 bases = [ "%", "px", "em" ],
220                 adjustments = [ "px", "em" ],
221                 container = jQuery("<div></div>")
222                         .css({ position: "absolute", height: "50em", width: "50em" }),
223                 animations = bases.length * adjustments.length;
225         expect( 2 * animations );
227         jQuery.each( bases, function( _, baseUnit ) {
228                 jQuery.each( adjustments, function( _, adjustUnit ) {
229                         var base = value + baseUnit,
230                                 adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
231                                 elem = jQuery("<div></div>")
232                                         .appendTo( container.clone().appendTo("#qunit-fixture") )
233                                         .css({
234                                                 position: "absolute",
235                                                 height: base,
236                                                 width: value + adjustUnit
237                                         }),
238                                 baseScale = elem[ 0 ].offsetHeight / value,
239                                 adjustScale = elem[ 0 ].offsetWidth / value;
241                         elem.css( "width", base ).animate( adjust, 100, function() {
242                                 equal( this.offsetHeight, value * baseScale + 2 * adjustScale,
243                                         baseUnit + "+=" + adjustUnit );
244                                 equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
245                                         baseUnit + "-=" + adjustUnit );
247                                 if ( --animations === 0 ) {
248                                         start();
249                                 }
250                         });
251                 });
252         });
255 test("animate negative height", function() {
256         expect(1);
257         stop();
258         jQuery("#foo").animate({ height: -100 }, 100, function() {
259                 equal( this.offsetHeight, 0, "Verify height." );
260                 start();
261         });
264 test("animate negative margin", function() {
265         expect(1);
266         stop();
267         jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
268                 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
269                 start();
270         });
273 test("animate negative margin with px", function() {
274         expect(1);
275         stop();
276         jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
277                 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
278                 start();
279         });
282 test("animate negative padding", function() {
283         expect(1);
284         stop();
285         jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
286                 equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
287                 start();
288         });
291 test("animate block as 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();
302                 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
303                         equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
304                         equal( this.offsetWidth, 42, "width was animated" );
305                         equal( this.offsetHeight, 42, "height was animated" );
306                         start();
307                 });
309         // Browser doesn't support inline-block
310         } else {
311                 ok( true, "Browser doesn't support inline-block" );
312                 ok( true, "Browser doesn't support inline-block" );
313                 ok( true, "Browser doesn't support inline-block" );
314         }
317 test("animate native inline width/height", function() {
318         expect(3);
320         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
321                 expected = span.css("display");
323         span.remove();
325         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
326                 stop();
327                 jQuery("#foo").css({ display: "", width: "", height: "" })
328                         .append("<span>text</span>")
329                         .children("span")
330                                 .animate({ width: 42, height: 42 }, 100, function() {
331                                         equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
332                                         equal( this.offsetWidth, 42, "width was animated" );
333                                         equal( this.offsetHeight, 42, "height was animated" );
334                                         start();
335                                 });
337         // Browser doesn't support inline-block
338         } else {
339                 ok( true, "Browser doesn't support inline-block" );
340                 ok( true, "Browser doesn't support inline-block" );
341                 ok( true, "Browser doesn't support inline-block" );
342         }
345 test( "animate block width/height", function() {
346         expect( 3 );
347         stop();
349         jQuery("<div>").appendTo("#qunit-fixture").css({
350                 display: "block",
351                 width: 20,
352                 height: 20,
353                 paddingLeft: 60
354         }).animate({
355                 width: 42,
356                 height: 42
357         }, {
358                 duration: 100,
359                 step: function() {
360                         if ( jQuery( this ).width() > 42 ) {
361                                 ok( false, "width was incorrectly augmented during animation" );
362                         }
363                 },
364                 complete: function() {
365                         equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
366                         equal( jQuery( this ).width(), 42, "width was animated" );
367                         equal( jQuery( this ).height(), 42, "height was animated" );
368                         start();
369                 }
370         });
373 test("animate table width/height", function() {
374         expect(1);
375         stop();
377         var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
379         jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
380                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
381                 start();
382         });
385 test("animate table-row width/height", function() {
386         expect(3);
387         stop();
388         var displayMode,
389                 tr = jQuery("#table")
390                         .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
391                         .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
392                         .find("tr");
394         // IE<8 uses "block" instead of the correct display type
395         displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
397         tr.animate({ width: 10, height: 10 }, 100, function() {
398                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
399                 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
400                 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
401                 start();
402         });
405 test("animate table-cell width/height", function() {
406         expect(3);
407         stop();
408         var displayMode,
409                 td = jQuery("#table")
410                         .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
411                         .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
412                         .find("td");
414         // IE<8 uses "block" instead of the correct display type
415         displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
417         td.animate({ width: 10, height: 10 }, 100, function() {
418                 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
419                 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
420                 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
421                 start();
422         });
425 test("animate percentage(%) on width/height", function() {
426         expect( 2 );
428         var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
429                 .appendTo("#qunit-fixture").children("div");
431         stop();
432         $div.animate({ width: "25%", height: "25%" }, 13, function() {
433                 var $this = jQuery(this);
434                 equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
435                 equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
436                 start();
437         });
440 test("animate resets overflow-x and overflow-y when finished", function() {
441         expect(2);
442         stop();
443         jQuery("#foo")
444                 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
445                 .animate({ width: 42, height: 42 }, 100, function() {
446                         equal( this.style.overflowX, "visible", "overflow-x is visible" );
447                         equal( this.style.overflowY, "auto", "overflow-y is auto" );
448                         start();
449                 });
452 /* // This test ends up being flaky depending upon the CPU load
453 test("animate option (queue === false)", function () {
454         expect(1);
455         stop();
457         var order = [];
459         var $foo = jQuery("#foo");
460         $foo.animate({width:"100px"}, 3000, function () {
461                 // should finish after unqueued animation so second
462                 order.push(2);
463                 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
464                 start();
465         });
466         $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
467                 // short duration and out of queue so should finish first
468                 order.push(1);
469         }});
473 asyncTest( "animate option { queue: false }", function() {
474         expect( 2 );
475         var foo = jQuery( "#foo" );
477         foo.animate({
478                 fontSize: "2em"
479         }, {
480                 queue: false,
481                 duration: 10,
482                 complete: function() {
483                         ok( true, "Animation Completed" );
484                         start();
485                 }
486         });
488         equal( foo.queue().length, 0, "Queue is empty" );
491 asyncTest( "animate option { queue: true }", function() {
492         expect( 2 );
493         var foo = jQuery( "#foo" );
495         foo.animate({
496                 fontSize: "2em"
497         }, {
498                 queue: true,
499                 duration: 10,
500                 complete: function() {
501                         ok( true, "Animation Completed" );
502                         start();
503                 }
504         });
506         notEqual( foo.queue().length, 0, "Default queue is not empty" );
509 asyncTest( "animate option { queue: 'name' }", function() {
510         expect( 5 );
511         var foo = jQuery( "#foo" ),
512                 origWidth = parseFloat( foo.css("width") ),
513                 order = [];
515         foo.animate( { width: origWidth + 100 }, {
516                 queue: "name",
517                 duration: 1,
518                 complete: function() {
520                         // second callback function
521                         order.push( 2 );
522                         equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
523                         equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
524                 }
525         }).queue( "name", function() {
527                 // last callback function
528                 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
529                 start();
530         });
532         setTimeout( function() {
534                 // this is the first callback function that should be called
535                 order.push( 1 );
536                 equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
537                 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
538                 foo.dequeue( "name" );
539         }, 100 );
543 test("animate with no properties", function() {
544         expect(2);
546         var foo,
547                 divs = jQuery("div"),
548                 count = 0;
550         divs.animate({}, function(){
551                 count++;
552         });
554         equal( divs.length, count, "Make sure that callback is called for each element in the set." );
556         stop();
558         foo = jQuery("#foo");
560         foo.animate({});
561         foo.animate({top: 10}, 100, function(){
562                 ok( true, "Animation was properly dequeued." );
563                 start();
564         });
567 test("animate duration 0", function() {
568         expect(11);
570         stop();
572         var $elem,
573                 $elems = jQuery([{ a:0 },{ a:0 }]),
574                 counter = 0;
576         equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
578         $elems.eq(0).animate( {a:1}, 0, function(){
579                 ok( true, "Animate a simple property." );
580                 counter++;
581         });
583         // Failed until [6115]
584         equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
586         equal( counter, 1, "One synchronic animations" );
588         $elems.animate( { a:2 }, 0, function(){
589                 ok( true, "Animate a second simple property." );
590                 counter++;
591         });
593         equal( counter, 3, "Multiple synchronic animations" );
595         $elems.eq(0).animate( {a:3}, 0, function(){
596                 ok( true, "Animate a third simple property." );
597                 counter++;
598         });
599         $elems.eq(1).animate( {a:3}, 200, function(){
600                 counter++;
601                 // Failed until [6115]
602                 equal( counter, 5, "One synchronic and one asynchronic" );
603                 start();
604         });
606         $elem = jQuery("<div />");
607         $elem.show(0, function(){
608                 ok(true, "Show callback with no duration");
609         });
610         $elem.hide(0, function(){
611                 ok(true, "Hide callback with no duration");
612         });
614         // manually clean up detached elements
615         $elem.remove();
618 test("animate hyphenated properties", function() {
619         expect(1);
620         stop();
622         jQuery("#foo")
623                 .css("font-size", 10)
624                 .animate({"font-size": 20}, 200, function() {
625                         equal( this.style.fontSize, "20px", "The font-size property was animated." );
626                         start();
627                 });
630 test("animate non-element", function() {
631         expect(1);
632         stop();
634         var obj = { test: 0 };
636         jQuery(obj).animate({test: 200}, 200, function(){
637                 equal( obj.test, 200, "The custom property should be modified." );
638                 start();
639         });
642 test("stop()", function() {
643         expect( 4 );
644         stop();
646         var $one, $two,
647                 $foo = jQuery("#foo"),
648                 tests = 2,
649                 w = 0;
651         $foo.hide().css( "width", 200 )
652                 .animate( { "width": "show" }, 1500 );
654         setTimeout(function() {
655                 var nw = $foo.css("width");
656                 notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
657                 $foo.stop();
659                 nw = $foo.css("width");
660                 notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
661                 setTimeout(function() {
662                         $foo.removeData();
663                         $foo.removeData(undefined, true);
664                         equal( nw, $foo.css("width"), "The animation didn't continue" );
665                         if ( --tests === 0 ) {
666                                 start();
667                         }
668                 }, 100);
669         }, 100);
671         $one = jQuery("#fadein");
672         $two = jQuery("#show");
673         $one.fadeTo(100, 0, function() {
674                 $one.stop();
675         });
676         setTimeout(function() {
677                 $two.fadeTo(100, 0, function() {
678                         equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
679                         // Reset styles
680                         $one.add( $two ).css("opacity", "");
681                         if ( --tests === 0 ) {
682                                 start();
683                         }
684                 });
685         }, 50);
688 test("stop() - several in queue", function() {
689         expect( 5 );
691         var nw, time,
692                 $foo = jQuery( "#foo" );
694         // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
695         $foo.hide().css( "width", 800 );
697         $foo.animate({ "width": "show" }, 400, "linear");
698         $foo.animate({ "width": "hide" });
699         $foo.animate({ "width": "show" });
701         // could be replaced by something nicer using sinon.
702         time = jQuery.now();
703         while( time === jQuery.now() ) {}
705         jQuery.fx.tick();
706         equal( $foo.queue().length, 3, "3 in the queue" );
708         nw = $foo.css( "width" );
709         notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
710         $foo.stop();
712         equal( $foo.queue().length, 2, "2 in the queue" );
713         nw = $foo.css( "width" );
714         notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
716         $foo.stop( true );
718         equal( $foo.queue().length, 0, "0 in the queue" );
721 test("stop(clearQueue)", function() {
722         expect(4);
723         stop();
725         var $foo = jQuery("#foo"),
726                 w = 0;
727         $foo.hide().css( "width", 200 ).css("width");
729         $foo.animate({ "width": "show" }, 1000);
730         $foo.animate({ "width": "hide" }, 1000);
731         $foo.animate({ "width": "show" }, 1000);
732         setTimeout(function(){
733                 var nw = $foo.css("width");
734                 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
735                 $foo.stop(true);
737                 nw = $foo.css("width");
738                 ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
740                 equal( $foo.queue().length, 0, "The animation queue was cleared" );
741                 setTimeout(function(){
742                         equal( nw, $foo.css("width"), "The animation didn't continue" );
743                         start();
744                 }, 100);
745         }, 100);
748 test("stop(clearQueue, gotoEnd)", function() {
749         expect(1);
750         stop();
752         var $foo = jQuery("#foo"),
753                 w = 0;
754         $foo.hide().css( "width", 200 ).css("width");
756         $foo.animate({ width: "show" }, 1000);
757         $foo.animate({ width: "hide" }, 1000);
758         $foo.animate({ width: "show" }, 1000);
759         $foo.animate({ width: "hide" }, 1000);
760         setTimeout(function(){
761                 var nw = $foo.css("width");
762                 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
763                 $foo.stop(false, true);
765                 nw = $foo.css("width");
766                 // Disabled, being flaky
767                 //equal( nw, 1, "Stop() reset the animation" );
769                 setTimeout(function(){
770                         // Disabled, being flaky
771                         //equal( $foo.queue().length, 2, "The next animation continued" );
772                         $foo.stop(true);
773                         start();
774                 }, 100);
775         }, 100);
778 asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
779         expect( 3 );
780         var saved,
781                 foo = jQuery("#foo").css({ width: 200, height: 200 });
783         foo.animate({
784                 width: 400
785         },{
786                 duration: 500,
787                 complete: function() {
788                         equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
789                         equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
790                         start();
791                 }
792         });
794         foo.animate({
795                 height: 400
796         },{
797                 duration: 1000,
798                 queue: "height"
799         }).dequeue("height").stop( "height", false, true );
801         equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
803         foo.animate({
804                 height: 200
805         },{
806                 duration: 1000,
807                 queue: "height"
808         }).dequeue( "height" ).stop( "height", false, false );
809         saved = parseFloat( foo.css("height") );
812 test("toggle()", function() {
813         expect(6);
814         var x = jQuery("#foo");
815         ok( x.is(":visible"), "is visible" );
816         x.toggle();
817         ok( x.is(":hidden"), "is hidden" );
818         x.toggle();
819         ok( x.is(":visible"), "is visible again" );
821         x.toggle(true);
822         ok( x.is(":visible"), "is visible" );
823         x.toggle(false);
824         ok( x.is(":hidden"), "is hidden" );
825         x.toggle(true);
826         ok( x.is(":visible"), "is visible again" );
829 test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
830         var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
831                         color: "#ABC",
832                         border: "5px solid black",
833                         left: "auto",
834                         marginBottom: "-11000px"
835                 })[0];
837         equal(
838                 ( new jQuery.fx( div, {}, "color" ) ).cur(),
839                 jQuery.css( div, "color" ),
840                 "Return the same value as jQuery.css for complex properties (bug #7912)"
841         );
843         strictEqual(
844                 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
845                 5,
846                 "Return simple values parsed as Float"
847         );
849         // backgroundPosition actually returns 0% 0% in most browser
850         // this fakes a "" return
851         // hook now gets called twice because Tween will grab the current
852         // value as it is being newed
853         jQuery.cssHooks.backgroundPosition = {
854                 get: function() {
855                         ok( true, "hook used" );
856                         return "";
857                 }
858         };
860         strictEqual(
861                 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
862                 0,
863                 "Return 0 when jQuery.css returns an empty string"
864         );
866         delete jQuery.cssHooks.backgroundPosition;
868         strictEqual(
869                 ( new jQuery.fx( div, {}, "left" ) ).cur(),
870                 0,
871                 "Return 0 when jQuery.css returns 'auto'"
872         );
874         equal(
875                 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
876                 -11000,
877                 "support negative values < -10000 (bug #7193)"
878         );
880         jQuery( div ).remove();
883 test("Overflow and Display", function() {
884         expect(4);
885         stop();
887         var
888                 testClass = jQuery.makeTest("Overflow and Display")
889                         .addClass("overflow inline"),
890                 testStyle = jQuery.makeTest("Overflow and Display (inline style)")
891                         .css({ overflow: "visible", display: "inline" }),
892                 remaining = 2,
893                 done = function() {
894                         equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
895                         equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
897                         if ( --remaining === 0 ) {
898                                 start();
899                         }
900                 };
902         testClass.add( testStyle )
903                 .addClass("widewidth")
904                 .text("Some sample text.")
905                 .before("text before")
906                 .after("text after")
907                 .animate({ opacity: 0.5 }, "slow", done );
910 jQuery.each({
911         "CSS Auto": function( elem, prop ) {
912                 jQuery( elem ).addClass( "auto" + prop )
913                         .text( "This is a long string of text." );
914                 return "";
915         },
916         "JS Auto": function( elem, prop ) {
917                 jQuery( elem ).css( prop, "" )
918                         .text( "This is a long string of text." );
919                 return "";
920         },
921         "CSS 100": function( elem, prop ) {
922                 jQuery( elem ).addClass( "large" + prop );
923                 return "";
924         },
925         "JS 100": function( elem, prop ) {
926                 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
927                 return prop === "opacity" ? 1 : 100;
928         },
929         "CSS 50": function( elem, prop ) {
930                 jQuery( elem ).addClass( "med" + prop );
931                 return "";
932         },
933         "JS 50": function( elem, prop ) {
934                 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
935                 return prop === "opacity" ? 0.5 : 50;
936         },
937         "CSS 0": function( elem, prop ) {
938                 jQuery( elem ).addClass( "no" + prop );
939                 return "";
940         },
941         "JS 0": function( elem, prop ) {
942                 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
943                 return 0;
944         }
945 }, function( fn, f ) {
946         jQuery.each({
947                 "show": function( elem, prop ) {
948                         jQuery( elem ).hide( ).addClass( "wide" + prop );
949                         return "show";
950                 },
951                 "hide": function( elem, prop ) {
952                         jQuery( elem ).addClass( "wide" + prop );
953                         return "hide";
954                 },
955                 "100": function( elem, prop ) {
956                         jQuery( elem ).addClass( "wide" + prop );
957                         return prop === "opacity" ? 1 : 100;
958                 },
959                 "50": function( elem, prop ) {
960                         return prop === "opacity" ? 0.50 : 50;
961                 },
962                 "0": function( elem ) {
963                         jQuery( elem ).addClass( "noback" );
964                         return 0;
965                 }
966         }, function( tn, t ) {
967                 test(fn + " to " + tn, function() {
968                         var num, anim,
969                                 elem = jQuery.makeTest( fn + " to " + tn ),
970                                 t_w = t( elem, "width" ),
971                                 f_w = f( elem, "width" ),
972                                 t_h = t( elem, "height" ),
973                                 f_h = f( elem, "height" ),
974                                 t_o = t( elem, "opacity" ),
975                                 f_o = f( elem, "opacity" );
977                         if ( f_o === "" ) {
978                                 f_o = 1;
979                         }
981                         num = 0;
982                         // TODO: uncrowd this
983                         if ( t_h === "show" ) {num++;}
984                         if ( t_w === "show" ) {num++;}
985                         if ( t_w === "hide" || t_w === "show" ) {num++;}
986                         if ( t_h === "hide" || t_h === "show" ) {num++;}
987                         if ( t_o === "hide" || t_o === "show" ) {num++;}
988                         if ( t_w === "hide" ) {num++;}
989                         if ( t_o.constructor === Number ) {num += 2;}
990                         if ( t_w.constructor === Number ) {num += 2;}
991                         if ( t_h.constructor === Number ) {num +=2;}
993                         expect( num );
994                         stop();
996                         anim = { width: t_w, height: t_h, opacity: t_o };
998                         elem.animate(anim, 50);
1000                         jQuery.when( elem ).done(function( elem ) {
1001                                 var cur_o, cur_w, cur_h, old_h;
1003                                 elem = elem[ 0 ];
1005                                 if ( t_w === "show" ) {
1006                                         equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
1007                                 }
1009                                 if ( t_w === "hide" || t_w === "show" ) {
1010                                         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 );
1011                                 }
1013                                 if ( t_h === "hide" || t_h === "show" ) {
1014                                         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 );
1015                                 }
1017                                 cur_o = jQuery.style(elem, "opacity");
1019                                 if ( f_o !== jQuery.css(elem, "opacity") ) {
1020                                         f_o = f( elem, "opacity" );
1021                                 }
1023                                 // The only time an _empty_string_ will be matched is in IE
1024                                 // otherwise, the correct values will be tested as usual
1025                                 if ( f_o === "" ) {
1026                                         f_o = 1;
1027                                 }
1028                                 // See above
1029                                 if ( cur_o === "" ) {
1030                                         cur_o = 1;
1031                                 }
1033                                 if ( t_o === "hide" || t_o === "show" ) {
1034                                         equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
1035                                 }
1037                                 if ( t_w === "hide" ) {
1038                                         equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
1039                                 }
1041                                 if ( t_o.constructor === Number ) {
1042                                         equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
1044                                         ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
1045                                 }
1047                                 if ( t_w.constructor === Number ) {
1048                                         equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
1050                                         cur_w = jQuery.css( elem,"width" );
1052                                         ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
1053                                 }
1055                                 if ( t_h.constructor === Number ) {
1056                                         equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
1058                                         cur_h = jQuery.css( elem,"height" );
1060                                         ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
1061                                 }
1063                                 if ( t_h === "show" ) {
1064                                         old_h = jQuery.css( elem, "height" );
1065                                         jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1067                                         if ( /Auto/.test( fn ) ) {
1068                                                 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1069                                         } else {
1070                                                 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1071                                         }
1072                                 }
1074                                 // manually remove generated element
1075                                 jQuery( elem ).remove();
1077                                 start();
1078                         });
1079                 });
1080         });
1083 asyncTest("Effects chaining", function() {
1084         var remaining = 16,
1085                 shrinkwrap = jQuery.support.shrinkWrapBlocks(),
1086                 props = [ "opacity", "height", "width", "display", "overflow" ],
1087                 setup = function( name, selector, hiddenOverflow ) {
1088                         var $el = jQuery( selector );
1089                         return $el.data( getProps( $el[0], hiddenOverflow ) ).data( "name", name );
1090                 },
1091                 assert = function() {
1092                         var data = jQuery.data( this ),
1093                                 name = data.name;
1094                         delete data.name;
1096                         deepEqual( getProps( this ), data, name );
1098                         jQuery.removeData( this );
1099                         if ( --remaining === 0 ) {
1100                                 start();
1101                         }
1102                 },
1103                 getProps = function( el, hiddenOverflow ) {
1104                         var obj = {};
1105                         jQuery.each( props, function( i, prop ) {
1106                                 obj[ prop ] = prop === "overflow" && hiddenOverflow ? "hidden" : el.style[ prop ] || jQuery.css( el, prop );
1107                         });
1108                         return obj;
1109                 };
1111         expect( remaining );
1113         // We need to pass jQuery.support.shrinkWrapBlocks for all methods that
1114         // set overflow hidden (slide* and show/hide with speed)
1115         setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
1116         setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
1117         setup( ".hide().show()", "#show div",  shrinkwrap ).hide("fast").show( "fast", assert );
1118         setup( ".show().hide()", "#hide div",  shrinkwrap ).show("fast").hide( "fast", assert );
1119         setup( ".show().hide(easing)", "#easehide div", shrinkwrap ).show("fast").hide( "fast", "linear", assert );
1120         setup( ".toggle().toggle() - in", "#togglein div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1121         setup( ".toggle().toggle() - out", "#toggleout div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1122         setup( ".toggle().toggle(easing) - out", "#easetoggleout div", shrinkwrap ).toggle("fast").toggle( "fast", "linear", assert );
1123         setup( ".slideDown().slideUp()", "#slidedown div", shrinkwrap ).slideDown("fast").slideUp( "fast", assert );
1124         setup( ".slideUp().slideDown()", "#slideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", assert );
1125         setup( ".slideUp().slideDown(easing)", "#easeslideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", "linear", assert );
1126         setup( ".slideToggle().slideToggle() - in", "#slidetogglein div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
1127         setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
1128         setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1129         setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1130         setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
1133 jQuery.makeTest = function( text ){
1134         var elem = jQuery("<div></div>")
1135                 .attr( "id", "test" + jQuery.makeTest.id++ )
1136                 .addClass("box");
1138         jQuery("<h4></h4>")
1139                 .text( text )
1140                 .appendTo("#fx-tests")
1141                 .after( elem );
1143         return elem;
1146 jQuery.makeTest.id = 1;
1148 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1149         expect(4);
1150         stop();
1152         var $checkedtest = jQuery("#checkedtest");
1153         $checkedtest.hide().show("fast", function() {
1154                 ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
1155                 ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
1156                 ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
1157                 ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
1158                 start();
1159         });
1162 test( "interrupt toggle", function() {
1163         expect( 24 );
1164         stop();
1166         var longDuration = 2000,
1167                 shortDuration = 500,
1168                 remaining = 0,
1169                 $elems = jQuery(".chain-test"),
1170                 finish = function() {
1171                         if ( !(--remaining) ) {
1172                                 start();
1173                         }
1174                 };
1176         jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
1177                 var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
1178                         // Don't end test until we're done with this element
1179                         remaining++;
1181                         // Save original property value for comparison
1182                         jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
1184                         // Expect olddisplay data from our .hide() call below
1185                         QUnit.expectJqData( this, "olddisplay" );
1186                 });
1188                 // Interrupt a hiding toggle
1189                 $methodElems[ method ]( longDuration );
1190                 setTimeout(function() {
1191                         $methodElems.stop().each(function() {
1192                                 notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
1193                         });
1195                         // Restore
1196                         $methodElems[ method ]( shortDuration, function() {
1197                                 var id = this.id,
1198                                         $elem = jQuery( this ),
1199                                         startVal = $elem.data("startVal");
1201                                 $elem.removeData("startVal");
1203                                 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1205                                 // Interrupt a showing toggle
1206                                 $elem.hide()[ method ]( longDuration );
1207                                 setTimeout(function() {
1208                                         $elem.stop();
1209                                         notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
1211                                         // Restore
1212                                         $elem[ method ]( shortDuration, function() {
1213                                                 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1214                                                 finish();
1215                                         });
1216                                 }, shortDuration );
1217                         });
1218                 }, shortDuration );
1219         });
1222 test("animate with per-property easing", function(){
1224         expect(5);
1225         stop();
1227         var data = { a:0, b:0, c:0 },
1228                 _test1_called = false,
1229                 _test2_called = false,
1230                 _default_test_called = false,
1231                 props = {
1232                         a: [ 100, "_test1" ],
1233                         b: [ 100, "_test2" ],
1234                         c: 100
1235                 };
1237         jQuery.easing["_test1"] = function(p) {
1238                 _test1_called = true;
1239                 return p;
1240         };
1242         jQuery.easing["_test2"] = function(p) {
1243                 _test2_called = true;
1244                 return p;
1245         };
1247         jQuery.easing["_default_test"] = function(p) {
1248                 _default_test_called = true;
1249                 return p;
1250         };
1252         jQuery(data).animate( props, 400, "_default_test", function(){
1253                 start();
1255                 ok( _test1_called, "Easing function (_test1) called" );
1256                 ok( _test2_called, "Easing function (_test2) called" );
1257                 ok( _default_test_called, "Easing function (_default) called" );
1258                 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1259                 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1260         });
1264 test("animate with CSS shorthand properties", function(){
1265         expect(11);
1266         stop();
1268         var _default_count = 0,
1269                 _special_count = 0,
1270                 propsBasic = { "padding": "10 20 30" },
1271                 propsSpecial = { "padding": [ "1 2 3", "_special" ] };
1273         jQuery.easing._default = function(p) {
1274                 if ( p >= 1 ) {
1275                         _default_count++;
1276                 }
1277                 return p;
1278         };
1280         jQuery.easing._special = function(p) {
1281                 if ( p >= 1 ) {
1282                         _special_count++;
1283                 }
1284                 return p;
1285         };
1287         jQuery("#foo")
1288                 .animate( propsBasic, 200, "_default", function() {
1289                         equal( this.style.paddingTop, "10px", "padding-top was animated" );
1290                         equal( this.style.paddingLeft, "20px", "padding-left was animated" );
1291                         equal( this.style.paddingRight, "20px", "padding-right was animated" );
1292                         equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1293                         equal( _default_count, 4, "per-animation default easing called for each property" );
1294                         _default_count = 0;
1295                 })
1296                 .animate( propsSpecial, 200, "_default", function() {
1297                         equal( this.style.paddingTop, "1px", "padding-top was animated again" );
1298                         equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
1299                         equal( this.style.paddingRight, "2px", "padding-right was animated again" );
1300                         equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1301                         equal( _default_count, 0, "per-animation default easing not called" );
1302                         equal( _special_count, 4, "special easing called for each property" );
1304                         jQuery(this).css("padding", "0");
1305                         delete jQuery.easing._default;
1306                         delete jQuery.easing._special;
1307                         start();
1308                 });
1311 test("hide hidden elements, with animation (bug #7141)", function() {
1312         expect(3);
1313         QUnit.reset();
1314         stop();
1316         var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1317         equal( div.css("display"), "none", "Element is hidden by default" );
1318         div.hide(1, function () {
1319                 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1320                 div.show(1, function () {
1321                         equal( div.css("display"), "block", "Show a double-hidden element" );
1322                         start();
1323                 });
1324         });
1327 test("animate unit-less properties (#4966)", 2, function() {
1328         stop();
1329         var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1330         equal( div.css( "z-index" ), "0", "z-index is 0" );
1331         div.animate({ zIndex: 2 }, function() {
1332                 equal( div.css( "z-index" ), "2", "z-index is 2" );
1333                 start();
1334         });
1337 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1338         expect( 6 );
1339         stop();
1340         var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1341                 .appendTo( "#qunit-fixture" );
1342         function cssInt( prop ) {
1343                 return parseInt( div.css( prop ), 10 );
1344         }
1345         equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1346         equal( cssInt( "left" ), 0, "Left is 0" );
1347         div.animate({
1348                 left: 200,
1349                 marginLeft: 200,
1350                 opacity: 0
1351         }, 2000);
1352         setTimeout(function() {
1353                 var ml = cssInt( "marginLeft" ),
1354                         l = cssInt( "left" );
1355                 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1356                 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1357                 notEqual( l, 0, "Left is not 0 after partial animate" );
1358                 notEqual( l, 200, "Left is not 200 after partial animate" );
1359                 div.stop().remove();
1360                 start();
1361         }, 500);
1364 test("callbacks should fire in correct order (#9100)", function() {
1365         expect( 1 );
1367         stop();
1368         var a = 1,
1369                 cb = 0;
1371         jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>")
1372                 .appendTo("#qunit-fixture")
1373                 // The test will always pass if no properties are animated or if the duration is 0
1374                 .animate({ fontSize: 12 }, 13, function() {
1375                         a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1376                         cb++;
1377                         if ( cb === 2 ) {
1378                                 equal( a, 4, "test value has been *2 and _then_ ^2");
1379                                 start();
1380                         }
1381                 });
1384 asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
1385         expect( 2 );
1387         var foo = jQuery( "#foo" );
1389         function testException() {
1390         }
1392         foo.animate({ height: 1 }, 1, function() {
1393                 throw new testException();
1394         });
1396         // this test thoroughly abuses undocumented methods - please feel free to update
1397         // with any changes internally to these functions.
1399         // make sure that the standard timer loop will NOT run.
1400         jQuery.fx.stop();
1402         setTimeout(function() {
1404                 // the first call to fx.tick should raise the callback exception
1405                 raises( jQuery.fx.tick, testException, "Exception was thrown" );
1407                 // the second call shouldn't
1408                 jQuery.fx.tick();
1410                 ok( true, "Test completed without throwing a second exception" );
1412                 start();
1413         }, 1);
1416 test("animate will scale margin properties individually", function() {
1417         expect( 2 );
1418         stop();
1420         var foo = jQuery( "#foo" ).css({
1421                 "margin": 0,
1422                 "marginLeft": 100
1423         });
1425         ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
1427         foo.animate({
1428                 "margin": 200
1429         }).stop();
1431         ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
1433         // clean up for next test
1434         foo.css({
1435                 "marginLeft": "",
1436                 "marginRight": "",
1437                 "marginTop": "",
1438                 "marginBottom": ""
1439         });
1440         start();
1443 test("Do not append px to 'fill-opacity' #9548", 1, function() {
1444         var $div = jQuery("<div>").appendTo("#qunit-fixture");
1446         $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
1447                 equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'");
1448                 $div.remove();
1449         });
1452 asyncTest("line-height animates correctly (#13855)", 12, function() {
1453         var longDuration = 2000,
1454                 shortDuration = 500,
1455                 animated = jQuery(
1456                         "<p style='line-height: 100;'>unitless</p>" +
1457                         "<p style='line-height: 5000px;'>px</p>" +
1458                         "<p style='line-height: 5000%;'>percent</p>" +
1459                         "<p style='line-height: 100em;'>em</p>"
1460                 ).appendTo("#qunit-fixture"),
1461                 initialHeight = jQuery.map( animated, function( el ) {
1462                         return jQuery( el ).height();
1463                 }),
1464                 tolerance = 1.5,
1465                 t0 = +(new Date());
1467         animated.animate( { "line-height": "hide" }, longDuration );
1468         setTimeout(function() {
1469                 var progress = ( (new Date()) - t0 ) / longDuration;
1471                 animated.each(function( i ) {
1472                         var label = jQuery.text( this ),
1473                                 initial = initialHeight[ i ],
1474                                 height = jQuery( this ).height(),
1475                                 lower = initial * ( 1 - progress ) / tolerance;
1476                         ok( height < initial, "hide " + label + ": upper bound; " +
1477                                 height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
1478                         ok( height > lower, "hide " + label + ": lower bound; "  +
1479                                 height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
1480                 });
1482                 t0 = +(new Date());
1483                 animated.stop( true, true ).hide().animate( { "line-height": "show" }, longDuration );
1484                 setTimeout(function() {
1485                         var progress = ( (new Date()) - t0 ) / longDuration;
1487                         animated.each(function( i ) {
1488                                 var label = jQuery.text( this ),
1489                                         initial = initialHeight[ i ],
1490                                         height = jQuery( this ).height(),
1491                                         upper = initial * progress * tolerance;
1492                                 ok( height < upper, "show " + label + ": upper bound; " +
1493                                         height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
1494                         });
1496                         animated.stop( true, true );
1497                         start();
1498                 }, shortDuration );
1499         }, shortDuration );
1502 // Start 1.8 Animation tests
1503 asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
1504         var animation,
1505                 testObject = {
1506                         "foo": 0,
1507                         "bar": 1,
1508                         "width": 100
1509                 },
1510                 testDest = {
1511                         "foo": 1,
1512                         "bar": 0,
1513                         "width": 200
1514                 };
1516         animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
1517         animation.done(function() {
1518                 for ( var prop in testDest ) {
1519                         equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
1520                 }
1521                 animation.done(function() {
1522                         deepEqual( testObject, testDest, "No unexpected properties" );
1523                         start();
1524                 });
1525         });
1528 asyncTest( "Animate Option: step: function( percent, tween )", 1, function() {
1529         var counter = {};
1530         jQuery( "#foo" ).animate({
1531                 prop1: 1,
1532                 prop2: 2,
1533                 prop3: 3
1534         }, {
1535                 duration: 1,
1536                 step: function( value, tween ) {
1537                         var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
1538                         // in case this is called multiple times for either, lets store it in
1539                         // 0 or 1 in the array
1540                         calls[ value === 0 ? 0 : 1 ] = value;
1541                 }
1542         }).queue( function( next ) {
1543                 deepEqual( counter, {
1544                         prop1: [0, 1],
1545                         prop2: [0, 2],
1546                         prop3: [0, 3]
1547                 }, "Step function was called once at 0% and once at 100% for each property");
1548                 next();
1549                 start();
1550         });
1553 asyncTest( "Animate callbacks have correct context", 2, function() {
1554         var foo = jQuery( "#foo" );
1555         foo.animate({
1556                 height: 10
1557         }, 10, function() {
1558                 equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
1559         }).stop( true, true );
1560         foo.animate({
1561                 height: 100
1562         }, 10, function() {
1563                 equal( foo[ 0 ], this, "Complete callback `this` is element" );
1564                 start();
1565         });
1568 asyncTest( "User supplied callback called after show when fx off (#8892)", 2, function() {
1569         var foo = jQuery( "#foo" );
1570         jQuery.fx.off = true;
1571         foo.hide();
1572         foo.fadeIn( 500, function() {
1573                 ok( jQuery( this ).is( ":visible" ), "Element is visible in callback" );
1574                 foo.fadeOut( 500, function() {
1575                         ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
1576                         jQuery.fx.off = false;
1577                         start();
1578                 });
1579         });
1582 test( "animate should set display for disconnected nodes", function() {
1583         expect( 18 );
1585         var i = 0,
1586                 methods = {
1587                         toggle: [ 1 ],
1588                         slideToggle: [],
1589                         fadeIn: [],
1590                         fadeTo: [ "fast", 0.5 ],
1591                         slideDown: [ "fast" ],
1592                         show: [ 1 ],
1593                         animate: [{ width: "show" }]
1594                 },
1595                 $divTest = jQuery("<div>test</div>"),
1596                 // parentNode = null
1597                 $divEmpty = jQuery("<div/>"),
1598                 $divNone = jQuery("<div style='display: none;'/>"),
1599                 $divInline = jQuery("<div style='display: inline;'/>");
1601         strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
1602         strictEqual( $divEmpty.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = null" );
1603         strictEqual( $divNone.show()[ 0 ].style.display, "block", "show() should change display if it already set to none" );
1604         strictEqual( $divInline.show()[ 0 ].style.display, "inline", "show() should not change display if it already set" );
1606         QUnit.expectJqData( $divTest[ 0 ], "olddisplay" );
1607         QUnit.expectJqData( $divEmpty[ 0 ], "olddisplay" );
1608         QUnit.expectJqData( $divNone[ 0 ], "olddisplay" );
1610         stop();
1611         jQuery.each( methods, function( name, opt ) {
1612                 jQuery.each([
1614                         // parentNode = document fragment
1615                         jQuery("<div>test</div>"),
1617                         // parentNode = null
1618                         jQuery("<div/>")
1620                 ], function() {
1621                         var callback = [function () {
1622                                         strictEqual( this.style.display, "block", "set display to block with " + name );
1624                                         QUnit.expectJqData( this, "olddisplay" );
1626                                         if ( ++i === 14 ) {
1627                                                 start();
1628                                         }
1629                         }];
1630                         jQuery.fn[ name ].apply( this, opt.concat( callback ) );
1631                 });
1632         });
1635 asyncTest("Animation callback should not show animated element as :animated (#7157)", 1, function() {
1636         var foo = jQuery( "#foo" );
1638         foo.animate({
1639                 opacity: 0
1640         }, 100, function() {
1641                 ok( !foo.is(":animated"), "The element is not animated" );
1642                 start();
1643         });
1646 asyncTest( "hide called on element within hidden parent should set display to none (#10045)", 3, function() {
1647         var hidden = jQuery(".hidden"),
1648                 elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
1650         hidden.append( elems );
1652         jQuery.when(
1653                 elems.eq( 0 ).hide(),
1654                 elems.eq( 1 ).hide( 0 ),
1655                 elems.eq( 2 ).hide( 1 )
1656         ).done(function() {
1657                 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
1658                 strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
1659                 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
1661                 elems.remove();
1662                 start();
1663         });
1666 asyncTest( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() {
1667         var foo = jQuery("#foo"),
1668                 i = 0,
1669                 elems = jQuery();
1671         for ( ; i < 5; i++ ) {
1672                 elems = elems.add("<div style='width:0;height:0;'></div>");
1673         }
1675         foo.append( elems );
1677         jQuery.when(
1678                 elems.eq( 0 ).hide(),
1679                 elems.eq( 1 ).hide( jQuery.noop ),
1680                 elems.eq( 2 ).hide( 1 ),
1681                 elems.eq( 3 ).fadeOut(),
1682                 elems.eq( 4 ).slideUp()
1683         ).done(function() {
1684                 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
1685                 strictEqual( elems.get( 1 ).style.display, "none",
1686                                                                                                 "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
1687                 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element width height and width = 0 should set display to none" );
1688                 strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
1689                 strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
1691                 start();
1692         });
1695 asyncTest( "Handle queue:false promises", 10, function() {
1696         var foo = jQuery( "#foo" ).clone().andSelf(),
1697                 step = 1;
1699         foo.animate({
1700                 top: 1
1701         }, {
1702                 duration: 10,
1703                 queue: false,
1704                 complete: function() {
1705                         ok( step++ <= 2, "Step one or two" );
1706                 }
1707         }).animate({
1708                 bottom: 1
1709         }, {
1710                 duration: 10,
1711                 complete: function() {
1712                         ok( step > 2 && step < 5, "Step three or four" );
1713                         step++;
1714                 }
1715         });
1717         foo.promise().done( function() {
1718                 equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
1719                 foo.animate({
1720                         top: 10
1721                 }, {
1722                         duration: 10,
1723                         complete: function() {
1724                                 ok( step > 5 && step < 8, "Step six or seven" );
1725                                 step++;
1726                         }
1727                 }).animate({
1728                         bottom: 10
1729                 }, {
1730                         duration: 10,
1731                         queue: false,
1732                         complete: function() {
1733                                 ok( step > 7 && step < 10, "Step eight or nine" );
1734                                 step++;
1735                         }
1736                 }).promise().done( function() {
1737                         equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
1738                         start();
1739                 });
1741         });
1744 asyncTest( "multiple unqueued and promise", 4, function() {
1745         var foo = jQuery( "#foo" ),
1746                 step = 1;
1747         foo.animate({
1748                 marginLeft: 300
1749         }, {
1750                 duration: 500,
1751                 queue: false,
1752                 complete: function() {
1753                         strictEqual( step++, 2, "Step 2" );
1754                 }
1755         }).animate({
1756                 top: 100
1757         }, {
1758                 duration: 1000,
1759                 queue: false,
1760                 complete: function() {
1761                         strictEqual( step++, 3, "Step 3" );
1762                 }
1763         }).animate({}, {
1764                 duration: 2000,
1765                 queue: false,
1766                 complete: function() {
1767                         // no properties is a non-op and finishes immediately
1768                         strictEqual( step++, 1, "Step 1" );
1769                 }
1770         }).promise().done( function() {
1771                 strictEqual( step++, 4, "Step 4" );
1772                 start();
1773         });
1776 asyncTest( "animate does not change start value for non-px animation (#7109)", 1, function() {
1777         var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
1778                 child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
1779                 actual = parseFloat( child.css( "width" ) ),
1780                 computed = [];
1782         child.animate({ width: "0%" }, {
1783                 duration: 1,
1784                 step: function() {
1785                         computed.push( parseFloat( child.css( "width" ) ) );
1786                 }
1787         }).queue( function( next ) {
1788                 var ratio = computed[ 0 ] / actual;
1789                 ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
1790                 next();
1791                 parent.remove();
1792                 start();
1793         });
1796 asyncTest( "non-px animation handles non-numeric start (#11971)", 2, function() {
1797         var foo = jQuery("#foo"),
1798                 initial = foo.css("backgroundPositionX");
1800         if ( !initial ) {
1801                 expect(1);
1802                 ok( true, "Style property not understood" );
1803                 start();
1804                 return;
1805         }
1807         foo.animate({ backgroundPositionX: "42%" }, {
1808                 duration: 1,
1809                 progress: function( anim, percent ) {
1810                         if ( percent ) {
1811                                 return;
1812                         }
1814                         if ( parseFloat( initial ) ) {
1815                                 equal( jQuery.style( this, "backgroundPositionX" ), initial, "Numeric start preserved" );
1816                         } else {
1817                                 equal( jQuery.style( this, "backgroundPositionX" ), "0%", "Non-numeric start zeroed" );
1818                         }
1819                 },
1820                 done: function() {
1821                         equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
1822                         start();
1823                 }
1824         });
1827 asyncTest("Animation callbacks (#11797)", 15, function() {
1828         var targets = jQuery("#foo").children(),
1829                 done = false,
1830                 expectedProgress = 0;
1832         targets.eq( 0 ).animate( {}, {
1833                 duration: 1,
1834                 start: function() {
1835                         ok( true, "empty: start" );
1836                 },
1837                 progress: function( anim, percent ) {
1838                         equal( percent, 0, "empty: progress 0" );
1839                 },
1840                 done: function() {
1841                         ok( true, "empty: done" );
1842                 },
1843                 fail: function() {
1844                         ok( false, "empty: fail" );
1845                 },
1846                 always: function() {
1847                         ok( true, "empty: always" );
1848                         done = true;
1849                 }
1850         });
1852         ok( done, "empty: done immediately" );
1854         done = false;
1855         targets.eq( 1 ).animate({
1856                 opacity: 0
1857         }, {
1858                 duration: 1,
1859                 start: function() {
1860                         ok( true, "stopped: start" );
1861                 },
1862                 progress: function( anim, percent ) {
1863                         equal( percent, 0, "stopped: progress 0" );
1864                 },
1865                 done: function() {
1866                         ok( false, "stopped: done" );
1867                 },
1868                 fail: function() {
1869                         ok( true, "stopped: fail" );
1870                 },
1871                 always: function() {
1872                         ok( true, "stopped: always" );
1873                         done = true;
1874                 }
1875         }).stop();
1877         ok( done, "stopped: stopped immediately" );
1879         targets.eq( 2 ).animate({
1880                 opacity: 0
1881         }, {
1882                 duration: 1,
1883                 start: function() {
1884                         ok( true, "async: start" );
1885                 },
1886                 progress: function( anim, percent ) {
1887                         // occasionally the progress handler is called twice in first frame.... *shrug*
1888                         if ( percent === 0 && expectedProgress === 1 ) {
1889                                 return;
1890                         }
1891                         equal( percent, expectedProgress, "async: progress " + expectedProgress );
1892                         // once at 0, once at 1
1893                         expectedProgress++;
1894                 },
1895                 done: function() {
1896                         ok( true, "async: done" );
1897                 },
1898                 fail: function() {
1899                         ok( false, "async: fail" );
1900                 },
1901                 always: function() {
1902                         ok( true, "async: always" );
1903                         start();
1904                 }
1905         });
1908 test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() {
1909         jQuery.each( [ "height", "width" ], function( _, prop ) {
1910                 jQuery.each( [ 100, 0 ], function( _, value ) {
1911                         var div = jQuery("<div>").css( "overflow", "auto" ),
1912                                 props = {};
1913                         props[ prop ] = value;
1914                         div.animate( props, 1 );
1915                         equal( div.css( "overflow" ), "hidden",
1916                                 "overflow: hidden set when animating " + prop + " to " + value );
1917                         div.stop();
1918                         if ( jQuery.support.shrinkWrapBlocks ) {
1919                                 ok( true, "cannot restore overflow, shrinkWrapBlocks" );
1920                         } else {
1921                                 equal( div.css( "overflow" ), "auto",
1922                                         "overflow: auto restored after animating " + prop + " to " + value );
1923                         }
1924                 });
1925         });
1928 test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
1929         var lastVal, current,
1930                 tmp = jQuery({
1931                         test: 0
1932                 });
1933         expect( 3 );
1934         tmp.animate({
1935                 test: 100
1936         }, {
1937                 step: function( p, fx ) {
1938                         ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
1939                         lastVal = fx.now;
1940                 }
1941         });
1942         current = jQuery.now();
1943         // intentionally empty, we want to spin wheels until the time changes.
1944         while ( current === jQuery.now() ) { }
1946         // now that we have a new time, run another tick
1947         jQuery.fx.tick();
1949         current = jQuery.now();
1950         // intentionally empty, we want to spin wheels until the time changes.
1951         while ( current === jQuery.now() ) { }
1953         jQuery.fx.tick();
1954         tmp.stop();
1957 test( "Animations with 0 duration don't ease (#12273)", 1, function() {
1958         jQuery.easing.test = function() {
1959                 ok( false, "Called easing" );
1960         };
1962         jQuery( "#foo" ).animate({
1963                 height: 100
1964         }, {
1965                 duration: 0,
1966                 easing: "test",
1967                 complete: function() {
1968                         equal( jQuery( this ).height(), 100, "Height is 100" );
1969                 }
1970         });
1972         delete jQuery.easing.test;
1975 jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
1976         // this test would look a lot better if we were using something to override
1977         // the default timers
1978         var duration = 1500;
1979         asyncTest( "toggle state tests: " + method + " (#8685)", function() {
1980                 function secondToggle() {
1981                         var stopped = parseFloat( element.css( check ) );
1982                         tested = false;
1983                         element[ method ]({
1984                                 duration: duration,
1985                                 step: function( p, fx ) {
1986                                         if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
1987                                                 tested = true;
1988                                                 equal( fx.start, stopped, check + " starts at " + stopped + " where it stopped" );
1989                                                 equal( fx.end, original, check + " ending value is " + original );
1990                                                 element.stop();
1991                                         }
1992                                 },
1993                                 always: start
1994                         });
1995                 }
1997                 var tested,
1998                         original,
1999                         check = method === "slideToggle" ? "height" : "opacity",
2000                         element = jQuery("#foo").height( 200 );
2002                 expect( 4 );
2004                 element[ method ]({
2005                         duration: duration,
2006                         easing: "linear",
2007                         step: function( p, fx ) {
2008                                 if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
2009                                         tested = true;
2010                                         original = fx.start;
2011                                         ok( fx.start !== 0, check + " is starting at " + original + " on first toggle (non-zero)" );
2012                                         equal( fx.end, 0, check + " is ending at 0 on first toggle" );
2013                                         element.stop();
2014                                 }
2015                         },
2016                         always: secondToggle
2017                 });
2018         });
2021 test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
2022         var oldStart = jQuery.fx.start,
2023                 oldStop = jQuery.fx.stop,
2024                 foo = jQuery({ foo: 0 });
2026         expect( 3 );
2028         jQuery.fx.start = function() {
2029                 ok( true, "start called" );
2030         };
2031         jQuery.fx.stop = function() {
2032                 ok( true, "stop called" );
2033         };
2035         // calls start
2036         foo.animate({ foo: 1 }, { queue: false });
2037         // calls start
2038         foo.animate({ foo: 2 }, { queue: false });
2039         foo.stop();
2040         // calls stop
2041         jQuery.fx.tick();
2043         // cleanup
2044         jQuery.fx.start = oldStart;
2045         jQuery.fx.stop = oldStop;
2048 test( ".finish() completes all queued animations", function() {
2049         var animations = {
2050                         top: 100,
2051                         left: 100,
2052                         height: 100,
2053                         width: 100
2054                 },
2055                 div = jQuery("<div>");
2057         expect( 11 );
2059         jQuery.each( animations, function( prop, value ) {
2060                 var anim = {};
2061                 anim[ prop ] = value;
2062                 // the delay shouldn't matter at all!
2063                 div.css( prop, 1 ).animate( anim, function() {
2064                         ok( true, "Called animation callback for " + prop );
2065                 }).delay( 100 );
2066         });
2067         equal( div.queue().length, 8, "8 animations in the queue" );
2068         div.finish();
2069         jQuery.each( animations, function( prop, value ) {
2070                 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2071         });
2072         equal( div.queue().length, 0, "empty queue when done" );
2073         equal( div.is(":animated"), false, ":animated doesn't match" );
2075         // cleanup
2076         div.remove();
2077         // leaves a "shadow timer" which does nothing around, need to force a tick
2078         jQuery.fx.tick();
2081 test( ".finish( false ) - unqueued animations", function() {
2082         var animations = {
2083                         top: 100,
2084                         left: 100,
2085                         height: 100,
2086                         width: 100
2087                 },
2088                 div = jQuery("<div>");
2090         expect( 10 );
2092         jQuery.each( animations, function( prop, value ) {
2093                 var anim = {};
2094                 anim[ prop ] = value;
2095                 div.css( prop, 1 ).animate( anim, {
2096                         queue: false,
2097                         complete: function() {
2098                                 ok( true, "Called animation callback for " + prop );
2099                         }
2100                 });
2101         });
2102         equal( div.queue().length, 0, "0 animations in the queue" );
2103         div.finish( false );
2104         jQuery.each( animations, function( prop, value ) {
2105                 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2106         });
2107         equal( div.is(":animated"), false, ":animated doesn't match" );
2109         // cleanup
2110         div.remove();
2111         // leaves a "shadow timer" which does nothing around, need to force a tick
2112         jQuery.fx.tick();
2115 test( ".finish( \"custom\" ) - custom queue animations", function() {
2116         var animations = {
2117                         top: 100,
2118                         left: 100,
2119                         height: 100,
2120                         width: 100
2121                 },
2122                 div = jQuery("<div>");
2124         expect( 11 );
2126         jQuery.each( animations, function( prop, value ) {
2127                 var anim = {};
2128                 anim[ prop ] = value;
2129                 div.css( prop, 1 ).animate( anim, {
2130                         queue: "custom",
2131                         complete: function() {
2132                                 ok( true, "Called animation callback for " + prop );
2133                         }
2134                 });
2135         });
2136         equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
2137         // start the first animation
2138         div.dequeue( "custom" );
2139         equal( div.is(":animated"), true, ":animated matches" );
2140         div.finish( "custom" );
2141         jQuery.each( animations, function( prop, value ) {
2142                 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2143         });
2144         equal( div.is(":animated"), false, ":animated doesn't match" );
2146         // cleanup
2147         div.remove();
2148         // leaves a "shadow timer" which does nothing around, need to force a tick
2149         jQuery.fx.tick();
2152 test( ".finish() calls finish of custom queue functions", function() {
2153         function queueTester( next, hooks ) {
2154                 hooks.stop = function( gotoEnd ) {
2155                         inside++;
2156                         equal( this, div[0] );
2157                         ok( gotoEnd, "hooks.stop(true) called");
2158                 };
2159         }
2160         var div = jQuery( "<div>" ),
2161                 inside = 0,
2162                 outside = 0;
2164         expect( 6 );
2165         queueTester.finish = function() {
2166                 outside++;
2167                 ok( true, "Finish called on custom queue function" );
2168         };
2170         div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
2172         equal( inside, 1, "1 stop(true) callback" );
2173         equal( outside, 2, "2 finish callbacks" );
2175         div.remove();
2178 asyncTest( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
2179         expect( 3 );
2181         var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
2183         elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
2184         setTimeout(function() {
2185                 elems.eq( 1 ).finish();
2186                 ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
2187                 ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
2188                 ok( elems.eq( 2 ).queue().length, "non-empty queue for following element" );
2189                 elems.stop( true );
2191                 // setTimeout needed in order to avoid setInterval/setTimeout execution bug in FF
2192                 window.setTimeout(function() {
2193                         start();
2194                 }, 1000 );
2195         }, 100 );
2198 asyncTest( "slideDown() after stop() (#13483)", 2, function() {
2199         var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2200                         .appendTo("#qunit-fixture"),
2201                 origHeight = ul.height();
2203         // First test. slideUp() -> stop() in the middle -> slideDown() until the end
2204         ul.slideUp( 1000 );
2205         setTimeout( function() {
2206                 ul.stop( true );
2207                 ul.slideDown( 1, function() {
2208                         equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" );
2210                         // Second test. slideDown() -> stop() in the middle -> slideDown() until the end
2211                         ul.slideUp( 1, function() {
2212                                 ul.slideDown( 1000 );
2213                                 setTimeout( function() {
2214                                         ul.stop( true );
2215                                         ul.slideDown( 1, function() {
2216                                                 equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" );
2218                                                 // Cleanup
2219                                                 ul.remove();
2220                                                 start();
2221                                         });
2222                                 }, 500 );
2223                         });
2225                 });
2226         }, 500 );
2229 asyncTest( "fadeIn() after stop() (related to #13483)", 5, function() {
2230         var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2231                         .appendTo("#qunit-fixture").css( "opacity", 1 ),
2232                 origOpacity = ul.css( "opacity" );
2234         // First test. fadeOut() -> stop() in the middle -> fadeIn() until the end
2235         ul.fadeOut( 2000 );
2236         setTimeout( function() {
2237                 ul.stop( true );
2238                 ok( ul.css( "opacity" ) > 0, "fadeOut() interrupted" );
2239                 ul.fadeIn( 1, function() {
2240                         equal( ul.css( "opacity" ), origOpacity, "fadeIn() restored original opacity after interrupted fadeOut()" );
2242                         // Second test. fadeIn() -> stop() in the middle -> fadeIn() until the end
2243                         ul.fadeOut( 1, function() {
2244                                 equal( ul.css( "opacity" ), origOpacity, "fadeOut() completed" );
2245                                 ul.fadeIn( 2000 );
2246                                 setTimeout( function() {
2247                                         ul.stop( true );
2248                                         ok( ul.css( "opacity" ) < origOpacity, "fadeIn() interrupted" );
2249                                         ul.fadeIn( 1, function() {
2250                                                 equal( ul.css("opacity"), origOpacity, "fadeIn() restored original opacity after interrupted fadeIn()" );
2252                                                 // Cleanup
2253                                                 ul.remove();
2254                                                 start();
2255                                         });
2256                                 }, 500 );
2257                         });
2259                 });
2260         }, 500 );
2263 })();