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

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:64511a1d0fed
1 module("offset");
2
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);
12
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 };
22
23 testwin("absolute", function() {
24 var $w = testwin["absolute"].$;
25
26 equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" );
27 equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" );
28
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" );
31
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" );
34
35 equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" );
36 equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" );
37
38
39 equals( $w('#absolute-1').position().top, 0, "$('#absolute-1').position().top" );
40 equals( $w('#absolute-1').position().left, 0, "$('#absolute-1').position().left" );
41
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" );
44
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" );
47
48 equals( $w('#absolute-2').position().top, 19, "$('#absolute-2').position().top" );
49 equals( $w('#absolute-2').position().left, 19, "$('#absolute-2').position().left" );
50
51 testwin["absolute"].close();
52 });
53
54 testwin("relative", function() {
55 var $w = testwin["relative"].$;
56
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" );
60
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" );
64
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" );
68
69
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" );
73
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" );
77
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" );
81
82 testwin["relative"].close();
83 });
84
85 testwin("static", function() {
86 var $w = testwin["static"].$;
87
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" );
91
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" );
95
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" );
99
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" );
103
104
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" );
108
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" );
112
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" );
116
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" );
120
121 testwin["static"].close();
122 });
123
124 if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) )
125 testwin("fixed", function() {
126 var $w = testwin["fixed"].$;
127
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" );
130
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" );
133
134 testwin["fixed"].close();
135 });
136
137 testwin("table", function() {
138 var $w = testwin["table"].$;
139
140 equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" );
141 equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" );
142
143 equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" );
144 equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" );
145
146 equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" );
147 equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" );
148
149 testwin["table"].close();
150 });
151
152 testwin("scroll", function() {
153 var $w = testwin["scroll"].$;
154
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" );
158
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" );
162
163 testwin["scroll"].close();
164 });

mercurial