dom/tests/mochitest/ajax/jquery/test/unit/fx.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 module("fx");
michael@0 2
michael@0 3 test("animate(Hash, Object, Function)", function() {
michael@0 4 expect(1);
michael@0 5 stop();
michael@0 6 var hash = {opacity: 'show'};
michael@0 7 var hashCopy = $.extend({}, hash);
michael@0 8 $('#foo').animate(hash, 0, function() {
michael@0 9 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
michael@0 10 start();
michael@0 11 });
michael@0 12 });
michael@0 13
michael@0 14 /* Commented out because of bug 450190
michael@0 15 test("animate option (queue === false)", function () {
michael@0 16 expect(1);
michael@0 17 stop();
michael@0 18
michael@0 19 var order = [];
michael@0 20
michael@0 21 var $foo = $("#foo");
michael@0 22 $foo.animate({width:'100px'}, 200, function () {
michael@0 23 // should finish after unqueued animation so second
michael@0 24 order.push(2);
michael@0 25 });
michael@0 26 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
michael@0 27 // short duration and out of queue so should finish first
michael@0 28 order.push(1);
michael@0 29 }});
michael@0 30 $foo.animate({height:'100px'}, 10, function() {
michael@0 31 // queued behind the first animation so should finish third
michael@0 32 order.push(3);
michael@0 33 isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
michael@0 34 start();
michael@0 35 });
michael@0 36 });
michael@0 37 */
michael@0 38
michael@0 39 test("queue() defaults to 'fx' type", function () {
michael@0 40 expect(2);
michael@0 41 stop();
michael@0 42
michael@0 43 var $foo = $("#foo");
michael@0 44 $foo.queue("fx", [ "sample", "array" ]);
michael@0 45 var arr = $foo.queue();
michael@0 46 isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
michael@0 47 $foo.queue([ "another", "one" ]);
michael@0 48 var arr = $foo.queue("fx");
michael@0 49 isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
michael@0 50 // clean up after test
michael@0 51 $foo.queue([]);
michael@0 52
michael@0 53 start();
michael@0 54 });
michael@0 55
michael@0 56 test("stop()", function() {
michael@0 57 expect(3);
michael@0 58 stop();
michael@0 59
michael@0 60 var $foo = $("#nothiddendiv");
michael@0 61 var w = 0;
michael@0 62 $foo.hide().width(200).width();
michael@0 63
michael@0 64 $foo.animate({ width:'show' }, 1000);
michael@0 65 setTimeout(function(){
michael@0 66 var nw = $foo.width();
michael@0 67 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
michael@0 68 $foo.stop();
michael@0 69
michael@0 70 nw = $foo.width();
michael@0 71 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
michael@0 72 setTimeout(function(){
michael@0 73 equals( nw, $foo.width(), "The animation didn't continue" );
michael@0 74 start();
michael@0 75 }, 100);
michael@0 76 }, 100);
michael@0 77 });
michael@0 78
michael@0 79 test("stop() - several in queue", function() {
michael@0 80 // Merge from jquery test 1.3.2
michael@0 81 expect(2);
michael@0 82 stop();
michael@0 83
michael@0 84 var $foo = $("#nothiddendiv");
michael@0 85 var w = 0;
michael@0 86 $foo.hide().width(200).width();
michael@0 87
michael@0 88 $foo.animate({ width:'show' }, 1000);
michael@0 89 $foo.animate({ width:'hide' }, 1000);
michael@0 90 $foo.animate({ width:'show' }, 1000);
michael@0 91 setTimeout(function(){
michael@0 92 // Unreliable. See bug 484994.
michael@0 93 // equals( $foo.queue().length, 3, "All 3 still in the queue" );
michael@0 94 var nw = $foo.width();
michael@0 95 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
michael@0 96 $foo.stop();
michael@0 97
michael@0 98 nw = $foo.width();
michael@0 99 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
michael@0 100 // Merged from 1.3.2, commented out for being flaky in 1.3.2 test suite
michael@0 101 //equals( $foo.queue().length, 2, "The next animation continued" );
michael@0 102 $foo.stop(true);
michael@0 103 start();
michael@0 104 }, 100);
michael@0 105 });
michael@0 106
michael@0 107 test("stop(clearQueue)", function() {
michael@0 108 expect(4);
michael@0 109 stop();
michael@0 110
michael@0 111 var $foo = $("#nothiddendiv");
michael@0 112 var w = 0;
michael@0 113 $foo.hide().width(200).width();
michael@0 114
michael@0 115 $foo.animate({ width:'show' }, 1000);
michael@0 116 $foo.animate({ width:'hide' }, 1000);
michael@0 117 $foo.animate({ width:'show' }, 1000);
michael@0 118 setTimeout(function(){
michael@0 119 var nw = $foo.width();
michael@0 120 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
michael@0 121 $foo.stop(true);
michael@0 122
michael@0 123 nw = $foo.width();
michael@0 124 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
michael@0 125
michael@0 126 equals( $foo.queue().length, 0, "The animation queue was cleared" );
michael@0 127 setTimeout(function(){
michael@0 128 equals( nw, $foo.width(), "The animation didn't continue" );
michael@0 129 start();
michael@0 130 }, 100);
michael@0 131 }, 100);
michael@0 132 });
michael@0 133
michael@0 134 test("stop(clearQueue, gotoEnd)", function() {
michael@0 135 // Merge from 1.3.2 - this test marked as being flaky
michael@0 136 expect(1);
michael@0 137 stop();
michael@0 138
michael@0 139 var $foo = $("#nothiddendiv");
michael@0 140 var w = 0;
michael@0 141 $foo.hide().width(200).width();
michael@0 142
michael@0 143 $foo.animate({ width:'show' }, 1000);
michael@0 144 $foo.animate({ width:'hide' }, 1000);
michael@0 145 $foo.animate({ width:'show' }, 1000);
michael@0 146 $foo.animate({ width:'hide' }, 1000);
michael@0 147 setTimeout(function(){
michael@0 148 var nw = $foo.width();
michael@0 149 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
michael@0 150 $foo.stop(false, true);
michael@0 151
michael@0 152 nw = $foo.width();
michael@0 153 // Merge from 1.3.2 - marked as flaky in that release
michael@0 154 //equals( nw, 200, "Stop() reset the animation" );
michael@0 155
michael@0 156 setTimeout(function(){
michael@0 157 // Merge from 1.3.2 - marked as flaky in that release
michael@0 158 //equals( $foo.queue().length, 3, "The next animation continued" );
michael@0 159 $foo.stop(true);
michael@0 160 start();
michael@0 161 }, 100);
michael@0 162 }, 100);
michael@0 163 });
michael@0 164
michael@0 165 test("toggle()", function() {
michael@0 166 expect(3);
michael@0 167 var x = $("#foo");
michael@0 168 ok( x.is(":visible"), "is visible" );
michael@0 169 x.toggle();
michael@0 170 ok( x.is(":hidden"), "is hidden" );
michael@0 171 x.toggle();
michael@0 172 ok( x.is(":visible"), "is visible again" );
michael@0 173 });
michael@0 174
michael@0 175 var visible = {
michael@0 176 Normal: function(elem){},
michael@0 177 "CSS Hidden": function(elem){
michael@0 178 $(this).addClass("hidden");
michael@0 179 },
michael@0 180 "JS Hidden": function(elem){
michael@0 181 $(this).hide();
michael@0 182 }
michael@0 183 };
michael@0 184
michael@0 185 var from = {
michael@0 186 "CSS Auto": function(elem,prop){
michael@0 187 $(elem).addClass("auto" + prop)
michael@0 188 .text("This is a long string of text.");
michael@0 189 return "";
michael@0 190 },
michael@0 191 "JS Auto": function(elem,prop){
michael@0 192 $(elem).css(prop,"auto")
michael@0 193 .text("This is a long string of text.");
michael@0 194 return "";
michael@0 195 },
michael@0 196 "CSS 100": function(elem,prop){
michael@0 197 $(elem).addClass("large" + prop);
michael@0 198 return "";
michael@0 199 },
michael@0 200 "JS 100": function(elem,prop){
michael@0 201 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
michael@0 202 return prop == "opacity" ? 1 : 100;
michael@0 203 },
michael@0 204 "CSS 50": function(elem,prop){
michael@0 205 $(elem).addClass("med" + prop);
michael@0 206 return "";
michael@0 207 },
michael@0 208 "JS 50": function(elem,prop){
michael@0 209 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
michael@0 210 return prop == "opacity" ? 0.5 : 50;
michael@0 211 },
michael@0 212 "CSS 0": function(elem,prop){
michael@0 213 $(elem).addClass("no" + prop);
michael@0 214 return "";
michael@0 215 },
michael@0 216 "JS 0": function(elem,prop){
michael@0 217 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
michael@0 218 return 0;
michael@0 219 }
michael@0 220 };
michael@0 221
michael@0 222 var to = {
michael@0 223 "show": function(elem,prop){
michael@0 224 $(elem).hide().addClass("wide"+prop);
michael@0 225 return "show";
michael@0 226 },
michael@0 227 "hide": function(elem,prop){
michael@0 228 $(elem).addClass("wide"+prop);
michael@0 229 return "hide";
michael@0 230 },
michael@0 231 "100": function(elem,prop){
michael@0 232 $(elem).addClass("wide"+prop);
michael@0 233 return prop == "opacity" ? 1 : 100;
michael@0 234 },
michael@0 235 "50": function(elem,prop){
michael@0 236 return prop == "opacity" ? 0.50 : 50;
michael@0 237 },
michael@0 238 "0": function(elem,prop){
michael@0 239 $(elem).addClass("noback");
michael@0 240 return 0;
michael@0 241 }
michael@0 242 };
michael@0 243
michael@0 244 function checkOverflowDisplay(){
michael@0 245 var o = jQuery.css( this, "overflow" );
michael@0 246
michael@0 247 equals(o, "visible", "Overflow should be visible: " + o);
michael@0 248 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
michael@0 249
michael@0 250 start();
michael@0 251 }
michael@0 252
michael@0 253 test("JS Overflow and Display", function() {
michael@0 254 expect(2);
michael@0 255 stop();
michael@0 256 makeTest( "JS Overflow and Display" )
michael@0 257 .addClass("widewidth")
michael@0 258 .css({ overflow: "visible", display: "inline" })
michael@0 259 .addClass("widewidth")
michael@0 260 .text("Some sample text.")
michael@0 261 .before("text before")
michael@0 262 .after("text after")
michael@0 263 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
michael@0 264 });
michael@0 265
michael@0 266 test("CSS Overflow and Display", function() {
michael@0 267 expect(2);
michael@0 268 stop();
michael@0 269 makeTest( "CSS Overflow and Display" )
michael@0 270 .addClass("overflow inline")
michael@0 271 .addClass("widewidth")
michael@0 272 .text("Some sample text.")
michael@0 273 .before("text before")
michael@0 274 .after("text after")
michael@0 275 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
michael@0 276 });
michael@0 277
michael@0 278 jQuery.each( from, function(fn, f){
michael@0 279 jQuery.each( to, function(tn, t){
michael@0 280 test(fn + " to " + tn, function() {
michael@0 281 var elem = makeTest( fn + " to " + tn );
michael@0 282
michael@0 283 var t_w = t( elem, "width" );
michael@0 284 var f_w = f( elem, "width" );
michael@0 285 var t_h = t( elem, "height" );
michael@0 286 var f_h = f( elem, "height" );
michael@0 287 var t_o = t( elem, "opacity" );
michael@0 288 var f_o = f( elem, "opacity" );
michael@0 289
michael@0 290 var num = 0;
michael@0 291
michael@0 292 if ( t_h == "show" ) num++;
michael@0 293 if ( t_w == "show" ) num++;
michael@0 294 if ( t_w == "hide"||t_w == "show" ) num++;
michael@0 295 if ( t_h == "hide"||t_h == "show" ) num++;
michael@0 296 if ( t_o == "hide"||t_o == "show" ) num++;
michael@0 297 if ( t_w == "hide" ) num++;
michael@0 298 if ( t_o.constructor == Number ) num += 2;
michael@0 299 if ( t_w.constructor == Number ) num += 2;
michael@0 300 if ( t_h.constructor == Number ) num +=2;
michael@0 301
michael@0 302 expect(num);
michael@0 303 stop();
michael@0 304
michael@0 305 var anim = { width: t_w, height: t_h, opacity: t_o };
michael@0 306
michael@0 307 elem.animate(anim, 50, function(){
michael@0 308 if ( t_w == "show" )
michael@0 309 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
michael@0 310
michael@0 311 if ( t_w == "hide"||t_w == "show" )
michael@0 312 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
michael@0 313
michael@0 314 if ( t_h == "hide"||t_h == "show" )
michael@0 315 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
michael@0 316
michael@0 317 var cur_o = jQuery.attr(this.style, "opacity");
michael@0 318 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
michael@0 319
michael@0 320 if ( t_o == "hide"||t_o == "show" )
michael@0 321 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
michael@0 322
michael@0 323 if ( t_w == "hide" )
michael@0 324 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
michael@0 325
michael@0 326 if ( t_o.constructor == Number ) {
michael@0 327 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
michael@0 328
michael@0 329 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
michael@0 330 }
michael@0 331
michael@0 332 if ( t_w.constructor == Number ) {
michael@0 333 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
michael@0 334
michael@0 335 var cur_w = jQuery.css(this,"width");
michael@0 336
michael@0 337 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
michael@0 338 }
michael@0 339
michael@0 340 if ( t_h.constructor == Number ) {
michael@0 341 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
michael@0 342
michael@0 343 var cur_h = jQuery.css(this,"height");
michael@0 344
michael@0 345 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
michael@0 346 }
michael@0 347
michael@0 348 if ( t_h == "show" ) {
michael@0 349 var old_h = jQuery.curCSS(this, "height");
michael@0 350 $(elem).append("<br/>Some more text<br/>and some more...");
michael@0 351 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
michael@0 352 }
michael@0 353
michael@0 354 start();
michael@0 355 });
michael@0 356 });
michael@0 357 });
michael@0 358 });
michael@0 359
michael@0 360 var check = ['opacity','height','width','display','overflow'];
michael@0 361
michael@0 362 jQuery.fn.saveState = function(){
michael@0 363 expect(check.length);
michael@0 364 stop();
michael@0 365 return this.each(function(){
michael@0 366 var self = this;
michael@0 367 self.save = {};
michael@0 368 jQuery.each(check, function(i,c){
michael@0 369 self.save[c] = jQuery.css(self,c);
michael@0 370 });
michael@0 371 });
michael@0 372 };
michael@0 373
michael@0 374 function checkState(){
michael@0 375 var self = this;
michael@0 376 jQuery.each(this.save, function(c,v){
michael@0 377 var cur = jQuery.css(self,c);
michael@0 378 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
michael@0 379 });
michael@0 380 start();
michael@0 381 }
michael@0 382
michael@0 383 // Chaining Tests
michael@0 384 test("Chain fadeOut fadeIn", function() {
michael@0 385 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
michael@0 386 });
michael@0 387 test("Chain fadeIn fadeOut", function() {
michael@0 388 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
michael@0 389 });
michael@0 390
michael@0 391 test("Chain hide show", function() {
michael@0 392 $('#show div').saveState().hide('fast').show('fast',checkState);
michael@0 393 });
michael@0 394 test("Chain show hide", function() {
michael@0 395 $('#hide div').saveState().show('fast').hide('fast',checkState);
michael@0 396 });
michael@0 397
michael@0 398 test("Chain toggle in", function() {
michael@0 399 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
michael@0 400 });
michael@0 401 test("Chain toggle out", function() {
michael@0 402 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
michael@0 403 });
michael@0 404
michael@0 405 test("Chain slideDown slideUp", function() {
michael@0 406 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
michael@0 407 });
michael@0 408 test("Chain slideUp slideDown", function() {
michael@0 409 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
michael@0 410 });
michael@0 411
michael@0 412 test("Chain slideToggle in", function() {
michael@0 413 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
michael@0 414 });
michael@0 415 test("Chain slideToggle out", function() {
michael@0 416 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
michael@0 417 });
michael@0 418
michael@0 419 function makeTest( text ){
michael@0 420 var elem = $("<div></div>")
michael@0 421 .attr("id", "test" + makeTest.id++)
michael@0 422 .addClass("box");
michael@0 423
michael@0 424 $("<h4></h4>")
michael@0 425 .text( text )
michael@0 426 .appendTo("#fx-tests")
michael@0 427 .click(function(){
michael@0 428 $(this).next().toggle();
michael@0 429 })
michael@0 430 .after( elem );
michael@0 431
michael@0 432 return elem;
michael@0 433 }
michael@0 434
michael@0 435 makeTest.id = 1;

mercurial