tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fx.js (11742B)


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