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

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 module("offset");
     3 // opens a new window to run the tests against
     4 var testwin = function(name, fn) {
     5 	testwin[name] = load_offset_fixture(name);
     6 	var interval = setInterval(function() {
     7 		if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) {
     8 			clearInterval(interval);
     9 			test(name, fn);
    10 		}
    11 	}, 0);
    13 	function load_offset_fixture(name) {
    14 		var win = window.open( "./data/offset/" + name + ".html?num"+parseInt(Math.random()*1000), name, 'left=0,top=0,width=500,height=500,toolbar=1,resizable=0' );
    15 		if ( !win ) { 
    16 			alert("Please disable your popup blocker for the offset test suite");
    17 			throw "Please disable your popup blocker for the offset test suite";
    18 		}
    19 		return win;
    20 	}
    21 };
    23 testwin("absolute", function() {
    24 	var $w = testwin["absolute"].$;
    26 	equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" );
    27 	equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" );
    29 	equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" );
    30 	equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" );
    32 	equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" );
    33 	equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" );
    35 	equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" );
    36 	equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" );
    39 	equals( $w('#absolute-1').position().top, 0, "$('#absolute-1').position().top" );
    40 	equals( $w('#absolute-1').position().left, 0, "$('#absolute-1').position().left" );
    42 	equals( $w('#absolute-1-1').position().top, 1, "$('#absolute-1-1').position().top" );
    43 	equals( $w('#absolute-1-1').position().left, 1, "$('#absolute-1-1').position().left" );
    45 	equals( $w('#absolute-1-1-1').position().top, 1, "$('#absolute-1-1-1').position().top" );
    46 	equals( $w('#absolute-1-1-1').position().left, 1, "$('#absolute-1-1-1').position().left" );
    48 	equals( $w('#absolute-2').position().top, 19, "$('#absolute-2').position().top" );
    49 	equals( $w('#absolute-2').position().left, 19, "$('#absolute-2').position().left" );
    51 	testwin["absolute"].close();
    52 });
    54 testwin("relative", function() {
    55 	var $w = testwin["relative"].$;
    57 	// IE is collapsing the top margin of 1px
    58 	equals( $w('#relative-1').offset().top, $.browser.msie ? 6 : 7, "$('#relative-1').offset().top" );
    59 	equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" );
    61 	// IE is collapsing the top margin of 1px
    62 	equals( $w('#relative-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#relative-1-1').offset().top" );
    63 	equals( $w('#relative-1-1').offset().left, 15, "$('#relative-1-1').offset().left" );
    65 	// IE is collapsing the top margin of 1px
    66 	equals( $w('#relative-2').offset().top, $.browser.msie ? 141 : 142, "$('#relative-2').offset().top" );
    67 	equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" );
    70 	// IE is collapsing the top margin of 1px
    71 	equals( $w('#relative-1').position().top, $.browser.msie ? 5 : 6, "$('#relative-1').position().top" );
    72 	equals( $w('#relative-1').position().left, 6, "$('#relative-1').position().left" );
    74 	// IE is collapsing the top margin of 1px
    75 	equals( $w('#relative-1-1').position().top, $.browser.msie ? 4 : 5, "$('#relative-1-1').position().top" );
    76 	equals( $w('#relative-1-1').position().left, 5, "$('#relative-1-1').position().left" );
    78 	// IE is collapsing the top margin of 1px
    79 	equals( $w('#relative-2').position().top, $.browser.msie ? 140 : 141, "$('#relative-2').position().top" );
    80 	equals( $w('#relative-2').position().left, 26, "$('#relative-2').position().left" );
    82 	testwin["relative"].close();
    83 });
    85 testwin("static", function() {
    86 	var $w = testwin["static"].$;
    88 	// IE is collapsing the top margin of 1px
    89 	equals( $w('#static-1').offset().top, $.browser.msie ? 6 : 7, "$('#static-1').offset().top" );
    90 	equals( $w('#static-1').offset().left, 7, "$('#static-1').offset().left" );
    92 	// IE is collapsing the top margin of 1px
    93 	equals( $w('#static-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#static-1-1').offset().top" );
    94 	equals( $w('#static-1-1').offset().left, 15, "$('#static-1-1').offset().left" );
    96 	// IE is collapsing the top margin of 1px
    97 	equals( $w('#static-1-1-1').offset().top, $.browser.msie ? 20 : 23, "$('#static-1-1-1').offset().top" );
    98 	equals( $w('#static-1-1-1').offset().left, 23, "$('#static-1-1-1').offset().left" );
   100 	// IE is collapsing the top margin of 1px
   101 	equals( $w('#static-2').offset().top, $.browser.msie ? 121 : 122, "$('#static-2').offset().top" );
   102 	equals( $w('#static-2').offset().left, 7, "$('#static-2').offset().left" );
   105 	// IE is collapsing the top margin of 1px
   106 	equals( $w('#static-1').position().top, $.browser.msie ? 5 : 6, "$('#static-1').position().top" );
   107 	equals( $w('#static-1').position().left, 6, "$('#static-1').position().left" );
   109 	// IE is collapsing the top margin of 1px
   110 	equals( $w('#static-1-1').position().top, $.browser.msie ? 12 : 14, "$('#static-1-1').position().top" );
   111 	equals( $w('#static-1-1').position().left, 14, "$('#static-1-1').position().left" );
   113 	// IE is collapsing the top margin of 1px
   114 	equals( $w('#static-1-1-1').position().top, $.browser.msie ? 19 : 22, "$('#static-1-1-1').position().top" );
   115 	equals( $w('#static-1-1-1').position().left, 22, "$('#static-1-1-1').position().left" );
   117 	// IE is collapsing the top margin of 1px
   118 	equals( $w('#static-2').position().top, $.browser.msie ? 120 : 121, "$('#static-2').position().top" );
   119 	equals( $w('#static-2').position().left, 6, "$('#static-2').position().left" );
   121 	testwin["static"].close();
   122 });
   124 if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) )
   125 	testwin("fixed", function() {
   126 		var $w = testwin["fixed"].$;
   128 		equals( $w('#fixed-1').offset().top, 1001, "$('#fixed-1').offset().top" );
   129 		equals( $w('#fixed-1').offset().left, $.browser.msie ? 994 : 1001, "$('#fixed-1').offset().left" );
   131 		equals( $w('#fixed-2').offset().top, 1021, "$('#fixed-2').offset().top" );
   132 		equals( $w('#fixed-2').offset().left, $.browser.msie ? 1014 : 1021, "$('#fixed-2').offset().left" );
   134 		testwin["fixed"].close();
   135 	});
   137 testwin("table", function() {
   138 	var $w = testwin["table"].$;
   140 	equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" );
   141 	equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" );
   143 	equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" );
   144 	equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" );
   146 	equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" );
   147 	equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" );
   149 	testwin["table"].close();
   150 });
   152 testwin("scroll", function() {
   153 	var $w = testwin["scroll"].$;
   155 	// IE is collapsing the top margin of 1px
   156 	equals( $w('#scroll-1').offset().top, $.browser.msie ? 6 : 7, "$('#scroll-1').offset().top" );
   157 	equals( $w('#scroll-1').offset().left, 7, "$('#scroll-1').offset().left" );
   159 	// IE is collapsing the top margin of 1px
   160 	equals( $w('#scroll-1-1').offset().top, $.browser.msie ? 9 : 11, "$('#scroll-1-1').offset().top" );
   161 	equals( $w('#scroll-1-1').offset().left, 11, "$('#scroll-1-1').offset().left" );
   163 	testwin["scroll"].close();
   164 });

mercurial