dom/tests/mochitest/ajax/jquery/test/unit/offset.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("offset");
michael@0 2
michael@0 3 // opens a new window to run the tests against
michael@0 4 var testwin = function(name, fn) {
michael@0 5 testwin[name] = load_offset_fixture(name);
michael@0 6 var interval = setInterval(function() {
michael@0 7 if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) {
michael@0 8 clearInterval(interval);
michael@0 9 test(name, fn);
michael@0 10 }
michael@0 11 }, 0);
michael@0 12
michael@0 13 function load_offset_fixture(name) {
michael@0 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' );
michael@0 15 if ( !win ) {
michael@0 16 alert("Please disable your popup blocker for the offset test suite");
michael@0 17 throw "Please disable your popup blocker for the offset test suite";
michael@0 18 }
michael@0 19 return win;
michael@0 20 }
michael@0 21 };
michael@0 22
michael@0 23 testwin("absolute", function() {
michael@0 24 var $w = testwin["absolute"].$;
michael@0 25
michael@0 26 equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" );
michael@0 27 equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" );
michael@0 28
michael@0 29 equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" );
michael@0 30 equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" );
michael@0 31
michael@0 32 equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" );
michael@0 33 equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" );
michael@0 34
michael@0 35 equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" );
michael@0 36 equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" );
michael@0 37
michael@0 38
michael@0 39 equals( $w('#absolute-1').position().top, 0, "$('#absolute-1').position().top" );
michael@0 40 equals( $w('#absolute-1').position().left, 0, "$('#absolute-1').position().left" );
michael@0 41
michael@0 42 equals( $w('#absolute-1-1').position().top, 1, "$('#absolute-1-1').position().top" );
michael@0 43 equals( $w('#absolute-1-1').position().left, 1, "$('#absolute-1-1').position().left" );
michael@0 44
michael@0 45 equals( $w('#absolute-1-1-1').position().top, 1, "$('#absolute-1-1-1').position().top" );
michael@0 46 equals( $w('#absolute-1-1-1').position().left, 1, "$('#absolute-1-1-1').position().left" );
michael@0 47
michael@0 48 equals( $w('#absolute-2').position().top, 19, "$('#absolute-2').position().top" );
michael@0 49 equals( $w('#absolute-2').position().left, 19, "$('#absolute-2').position().left" );
michael@0 50
michael@0 51 testwin["absolute"].close();
michael@0 52 });
michael@0 53
michael@0 54 testwin("relative", function() {
michael@0 55 var $w = testwin["relative"].$;
michael@0 56
michael@0 57 // IE is collapsing the top margin of 1px
michael@0 58 equals( $w('#relative-1').offset().top, $.browser.msie ? 6 : 7, "$('#relative-1').offset().top" );
michael@0 59 equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" );
michael@0 60
michael@0 61 // IE is collapsing the top margin of 1px
michael@0 62 equals( $w('#relative-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#relative-1-1').offset().top" );
michael@0 63 equals( $w('#relative-1-1').offset().left, 15, "$('#relative-1-1').offset().left" );
michael@0 64
michael@0 65 // IE is collapsing the top margin of 1px
michael@0 66 equals( $w('#relative-2').offset().top, $.browser.msie ? 141 : 142, "$('#relative-2').offset().top" );
michael@0 67 equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" );
michael@0 68
michael@0 69
michael@0 70 // IE is collapsing the top margin of 1px
michael@0 71 equals( $w('#relative-1').position().top, $.browser.msie ? 5 : 6, "$('#relative-1').position().top" );
michael@0 72 equals( $w('#relative-1').position().left, 6, "$('#relative-1').position().left" );
michael@0 73
michael@0 74 // IE is collapsing the top margin of 1px
michael@0 75 equals( $w('#relative-1-1').position().top, $.browser.msie ? 4 : 5, "$('#relative-1-1').position().top" );
michael@0 76 equals( $w('#relative-1-1').position().left, 5, "$('#relative-1-1').position().left" );
michael@0 77
michael@0 78 // IE is collapsing the top margin of 1px
michael@0 79 equals( $w('#relative-2').position().top, $.browser.msie ? 140 : 141, "$('#relative-2').position().top" );
michael@0 80 equals( $w('#relative-2').position().left, 26, "$('#relative-2').position().left" );
michael@0 81
michael@0 82 testwin["relative"].close();
michael@0 83 });
michael@0 84
michael@0 85 testwin("static", function() {
michael@0 86 var $w = testwin["static"].$;
michael@0 87
michael@0 88 // IE is collapsing the top margin of 1px
michael@0 89 equals( $w('#static-1').offset().top, $.browser.msie ? 6 : 7, "$('#static-1').offset().top" );
michael@0 90 equals( $w('#static-1').offset().left, 7, "$('#static-1').offset().left" );
michael@0 91
michael@0 92 // IE is collapsing the top margin of 1px
michael@0 93 equals( $w('#static-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#static-1-1').offset().top" );
michael@0 94 equals( $w('#static-1-1').offset().left, 15, "$('#static-1-1').offset().left" );
michael@0 95
michael@0 96 // IE is collapsing the top margin of 1px
michael@0 97 equals( $w('#static-1-1-1').offset().top, $.browser.msie ? 20 : 23, "$('#static-1-1-1').offset().top" );
michael@0 98 equals( $w('#static-1-1-1').offset().left, 23, "$('#static-1-1-1').offset().left" );
michael@0 99
michael@0 100 // IE is collapsing the top margin of 1px
michael@0 101 equals( $w('#static-2').offset().top, $.browser.msie ? 121 : 122, "$('#static-2').offset().top" );
michael@0 102 equals( $w('#static-2').offset().left, 7, "$('#static-2').offset().left" );
michael@0 103
michael@0 104
michael@0 105 // IE is collapsing the top margin of 1px
michael@0 106 equals( $w('#static-1').position().top, $.browser.msie ? 5 : 6, "$('#static-1').position().top" );
michael@0 107 equals( $w('#static-1').position().left, 6, "$('#static-1').position().left" );
michael@0 108
michael@0 109 // IE is collapsing the top margin of 1px
michael@0 110 equals( $w('#static-1-1').position().top, $.browser.msie ? 12 : 14, "$('#static-1-1').position().top" );
michael@0 111 equals( $w('#static-1-1').position().left, 14, "$('#static-1-1').position().left" );
michael@0 112
michael@0 113 // IE is collapsing the top margin of 1px
michael@0 114 equals( $w('#static-1-1-1').position().top, $.browser.msie ? 19 : 22, "$('#static-1-1-1').position().top" );
michael@0 115 equals( $w('#static-1-1-1').position().left, 22, "$('#static-1-1-1').position().left" );
michael@0 116
michael@0 117 // IE is collapsing the top margin of 1px
michael@0 118 equals( $w('#static-2').position().top, $.browser.msie ? 120 : 121, "$('#static-2').position().top" );
michael@0 119 equals( $w('#static-2').position().left, 6, "$('#static-2').position().left" );
michael@0 120
michael@0 121 testwin["static"].close();
michael@0 122 });
michael@0 123
michael@0 124 if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) )
michael@0 125 testwin("fixed", function() {
michael@0 126 var $w = testwin["fixed"].$;
michael@0 127
michael@0 128 equals( $w('#fixed-1').offset().top, 1001, "$('#fixed-1').offset().top" );
michael@0 129 equals( $w('#fixed-1').offset().left, $.browser.msie ? 994 : 1001, "$('#fixed-1').offset().left" );
michael@0 130
michael@0 131 equals( $w('#fixed-2').offset().top, 1021, "$('#fixed-2').offset().top" );
michael@0 132 equals( $w('#fixed-2').offset().left, $.browser.msie ? 1014 : 1021, "$('#fixed-2').offset().left" );
michael@0 133
michael@0 134 testwin["fixed"].close();
michael@0 135 });
michael@0 136
michael@0 137 testwin("table", function() {
michael@0 138 var $w = testwin["table"].$;
michael@0 139
michael@0 140 equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" );
michael@0 141 equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" );
michael@0 142
michael@0 143 equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" );
michael@0 144 equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" );
michael@0 145
michael@0 146 equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" );
michael@0 147 equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" );
michael@0 148
michael@0 149 testwin["table"].close();
michael@0 150 });
michael@0 151
michael@0 152 testwin("scroll", function() {
michael@0 153 var $w = testwin["scroll"].$;
michael@0 154
michael@0 155 // IE is collapsing the top margin of 1px
michael@0 156 equals( $w('#scroll-1').offset().top, $.browser.msie ? 6 : 7, "$('#scroll-1').offset().top" );
michael@0 157 equals( $w('#scroll-1').offset().left, 7, "$('#scroll-1').offset().left" );
michael@0 158
michael@0 159 // IE is collapsing the top margin of 1px
michael@0 160 equals( $w('#scroll-1-1').offset().top, $.browser.msie ? 9 : 11, "$('#scroll-1-1').offset().top" );
michael@0 161 equals( $w('#scroll-1-1').offset().left, 11, "$('#scroll-1-1').offset().left" );
michael@0 162
michael@0 163 testwin["scroll"].close();
michael@0 164 });

mercurial