1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/ajax/jquery/test/unit/offset.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +module("offset"); 1.5 + 1.6 +// opens a new window to run the tests against 1.7 +var testwin = function(name, fn) { 1.8 + testwin[name] = load_offset_fixture(name); 1.9 + var interval = setInterval(function() { 1.10 + if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) { 1.11 + clearInterval(interval); 1.12 + test(name, fn); 1.13 + } 1.14 + }, 0); 1.15 + 1.16 + function load_offset_fixture(name) { 1.17 + 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' ); 1.18 + if ( !win ) { 1.19 + alert("Please disable your popup blocker for the offset test suite"); 1.20 + throw "Please disable your popup blocker for the offset test suite"; 1.21 + } 1.22 + return win; 1.23 + } 1.24 +}; 1.25 + 1.26 +testwin("absolute", function() { 1.27 + var $w = testwin["absolute"].$; 1.28 + 1.29 + equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" ); 1.30 + equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" ); 1.31 + 1.32 + equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" ); 1.33 + equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" ); 1.34 + 1.35 + equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" ); 1.36 + equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" ); 1.37 + 1.38 + equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" ); 1.39 + equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" ); 1.40 + 1.41 + 1.42 + equals( $w('#absolute-1').position().top, 0, "$('#absolute-1').position().top" ); 1.43 + equals( $w('#absolute-1').position().left, 0, "$('#absolute-1').position().left" ); 1.44 + 1.45 + equals( $w('#absolute-1-1').position().top, 1, "$('#absolute-1-1').position().top" ); 1.46 + equals( $w('#absolute-1-1').position().left, 1, "$('#absolute-1-1').position().left" ); 1.47 + 1.48 + equals( $w('#absolute-1-1-1').position().top, 1, "$('#absolute-1-1-1').position().top" ); 1.49 + equals( $w('#absolute-1-1-1').position().left, 1, "$('#absolute-1-1-1').position().left" ); 1.50 + 1.51 + equals( $w('#absolute-2').position().top, 19, "$('#absolute-2').position().top" ); 1.52 + equals( $w('#absolute-2').position().left, 19, "$('#absolute-2').position().left" ); 1.53 + 1.54 + testwin["absolute"].close(); 1.55 +}); 1.56 + 1.57 +testwin("relative", function() { 1.58 + var $w = testwin["relative"].$; 1.59 + 1.60 + // IE is collapsing the top margin of 1px 1.61 + equals( $w('#relative-1').offset().top, $.browser.msie ? 6 : 7, "$('#relative-1').offset().top" ); 1.62 + equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" ); 1.63 + 1.64 + // IE is collapsing the top margin of 1px 1.65 + equals( $w('#relative-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#relative-1-1').offset().top" ); 1.66 + equals( $w('#relative-1-1').offset().left, 15, "$('#relative-1-1').offset().left" ); 1.67 + 1.68 + // IE is collapsing the top margin of 1px 1.69 + equals( $w('#relative-2').offset().top, $.browser.msie ? 141 : 142, "$('#relative-2').offset().top" ); 1.70 + equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" ); 1.71 + 1.72 + 1.73 + // IE is collapsing the top margin of 1px 1.74 + equals( $w('#relative-1').position().top, $.browser.msie ? 5 : 6, "$('#relative-1').position().top" ); 1.75 + equals( $w('#relative-1').position().left, 6, "$('#relative-1').position().left" ); 1.76 + 1.77 + // IE is collapsing the top margin of 1px 1.78 + equals( $w('#relative-1-1').position().top, $.browser.msie ? 4 : 5, "$('#relative-1-1').position().top" ); 1.79 + equals( $w('#relative-1-1').position().left, 5, "$('#relative-1-1').position().left" ); 1.80 + 1.81 + // IE is collapsing the top margin of 1px 1.82 + equals( $w('#relative-2').position().top, $.browser.msie ? 140 : 141, "$('#relative-2').position().top" ); 1.83 + equals( $w('#relative-2').position().left, 26, "$('#relative-2').position().left" ); 1.84 + 1.85 + testwin["relative"].close(); 1.86 +}); 1.87 + 1.88 +testwin("static", function() { 1.89 + var $w = testwin["static"].$; 1.90 + 1.91 + // IE is collapsing the top margin of 1px 1.92 + equals( $w('#static-1').offset().top, $.browser.msie ? 6 : 7, "$('#static-1').offset().top" ); 1.93 + equals( $w('#static-1').offset().left, 7, "$('#static-1').offset().left" ); 1.94 + 1.95 + // IE is collapsing the top margin of 1px 1.96 + equals( $w('#static-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#static-1-1').offset().top" ); 1.97 + equals( $w('#static-1-1').offset().left, 15, "$('#static-1-1').offset().left" ); 1.98 + 1.99 + // IE is collapsing the top margin of 1px 1.100 + equals( $w('#static-1-1-1').offset().top, $.browser.msie ? 20 : 23, "$('#static-1-1-1').offset().top" ); 1.101 + equals( $w('#static-1-1-1').offset().left, 23, "$('#static-1-1-1').offset().left" ); 1.102 + 1.103 + // IE is collapsing the top margin of 1px 1.104 + equals( $w('#static-2').offset().top, $.browser.msie ? 121 : 122, "$('#static-2').offset().top" ); 1.105 + equals( $w('#static-2').offset().left, 7, "$('#static-2').offset().left" ); 1.106 + 1.107 + 1.108 + // IE is collapsing the top margin of 1px 1.109 + equals( $w('#static-1').position().top, $.browser.msie ? 5 : 6, "$('#static-1').position().top" ); 1.110 + equals( $w('#static-1').position().left, 6, "$('#static-1').position().left" ); 1.111 + 1.112 + // IE is collapsing the top margin of 1px 1.113 + equals( $w('#static-1-1').position().top, $.browser.msie ? 12 : 14, "$('#static-1-1').position().top" ); 1.114 + equals( $w('#static-1-1').position().left, 14, "$('#static-1-1').position().left" ); 1.115 + 1.116 + // IE is collapsing the top margin of 1px 1.117 + equals( $w('#static-1-1-1').position().top, $.browser.msie ? 19 : 22, "$('#static-1-1-1').position().top" ); 1.118 + equals( $w('#static-1-1-1').position().left, 22, "$('#static-1-1-1').position().left" ); 1.119 + 1.120 + // IE is collapsing the top margin of 1px 1.121 + equals( $w('#static-2').position().top, $.browser.msie ? 120 : 121, "$('#static-2').position().top" ); 1.122 + equals( $w('#static-2').position().left, 6, "$('#static-2').position().left" ); 1.123 + 1.124 + testwin["static"].close(); 1.125 +}); 1.126 + 1.127 +if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) ) 1.128 + testwin("fixed", function() { 1.129 + var $w = testwin["fixed"].$; 1.130 + 1.131 + equals( $w('#fixed-1').offset().top, 1001, "$('#fixed-1').offset().top" ); 1.132 + equals( $w('#fixed-1').offset().left, $.browser.msie ? 994 : 1001, "$('#fixed-1').offset().left" ); 1.133 + 1.134 + equals( $w('#fixed-2').offset().top, 1021, "$('#fixed-2').offset().top" ); 1.135 + equals( $w('#fixed-2').offset().left, $.browser.msie ? 1014 : 1021, "$('#fixed-2').offset().left" ); 1.136 + 1.137 + testwin["fixed"].close(); 1.138 + }); 1.139 + 1.140 +testwin("table", function() { 1.141 + var $w = testwin["table"].$; 1.142 + 1.143 + equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" ); 1.144 + equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" ); 1.145 + 1.146 + equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" ); 1.147 + equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" ); 1.148 + 1.149 + equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" ); 1.150 + equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" ); 1.151 + 1.152 + testwin["table"].close(); 1.153 +}); 1.154 + 1.155 +testwin("scroll", function() { 1.156 + var $w = testwin["scroll"].$; 1.157 + 1.158 + // IE is collapsing the top margin of 1px 1.159 + equals( $w('#scroll-1').offset().top, $.browser.msie ? 6 : 7, "$('#scroll-1').offset().top" ); 1.160 + equals( $w('#scroll-1').offset().left, 7, "$('#scroll-1').offset().left" ); 1.161 + 1.162 + // IE is collapsing the top margin of 1px 1.163 + equals( $w('#scroll-1-1').offset().top, $.browser.msie ? 9 : 11, "$('#scroll-1-1').offset().top" ); 1.164 + equals( $w('#scroll-1-1').offset().left, 11, "$('#scroll-1-1').offset().left" ); 1.165 + 1.166 + testwin["scroll"].close(); 1.167 +}); 1.168 \ No newline at end of file