|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=565541 |
|
6 --> |
|
7 <window title="Mozilla Bug 565541" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=565541" |
|
14 target="_blank">Mozilla Bug 565541</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 |
|
21 /** Test for Bug 565541 **/ |
|
22 var previousX, previousY, previousWidth, previousHeight; |
|
23 |
|
24 function backValues() |
|
25 { |
|
26 previousX = window.top.screenX; |
|
27 previousY = window.top.screenY; |
|
28 previousWidth = window.top.innerWidth; |
|
29 previousHeight = window.top.innerHeight; |
|
30 } |
|
31 |
|
32 function restoreValues() |
|
33 { |
|
34 window.top.screenX = previousX; |
|
35 window.top.screenY = previousY; |
|
36 window.top.innerWidth = previousWidth; |
|
37 window.top.innerHeight = previousHeight; |
|
38 } |
|
39 |
|
40 function getNewWidth(aWindow) |
|
41 { |
|
42 return (aWindow.innerWidth > (screen.width / 2)) ? 100 : screen.width; |
|
43 } |
|
44 |
|
45 function getNewHeight(aWindow) |
|
46 { |
|
47 return (aWindow.innerHeight > (screen.height / 2)) ? 100 : screen.height; |
|
48 } |
|
49 |
|
50 function getNewX(aWindow) |
|
51 { |
|
52 return (aWindow.screenX > ((screen.width - aWindow.outerWidth) / 2)) |
|
53 ? 0 : screen.width - aWindow.outerWidth; |
|
54 } |
|
55 |
|
56 function getNewY(aWindow) |
|
57 { |
|
58 return (aWindow.screenY > ((screen.height - aWindow.outerHeight) / 2)) |
|
59 ? 0 : screen.height - aWindow.outerHeight; |
|
60 } |
|
61 |
|
62 /** |
|
63 * hitEventLoop is called when we want to check something but we can't rely on |
|
64 * an event or a specific number of event loop hiting. |
|
65 * This method can be called by specifying a condition, a test (using SimpleTest |
|
66 * API), how many times the event loop has to be hitten and what to call next. |
|
67 * If times < 0, the event loop will be hitten as long as the condition isn't |
|
68 * true or the test doesn't time out. |
|
69 */ |
|
70 function hitEventLoop(condition, test, times, next) { |
|
71 if (condition() || times == 0) { |
|
72 test(); |
|
73 next(); |
|
74 return; |
|
75 } |
|
76 |
|
77 setTimeout(hitEventLoop, 0, condition, test, times - 1, next); |
|
78 } |
|
79 |
|
80 function checkChangeIsEnabled(aWindow, aNext) |
|
81 { |
|
82 // Something should happen. We are not going to go to the next test until |
|
83 // it does. |
|
84 var hits = -1; |
|
85 |
|
86 var prevWidth; |
|
87 var prevHeight; |
|
88 |
|
89 var prevX; |
|
90 var prevY; |
|
91 |
|
92 var oWidth; |
|
93 var oHeight; |
|
94 |
|
95 function sizeChangeCondition() { |
|
96 return aWindow.innerWidth != prevWidth && aWindow.innerHeight != prevHeight; |
|
97 } |
|
98 |
|
99 function sizeChangeTest() { |
|
100 isnot(aWindow.innerWidth, prevWidth, "Window width should have changed"); |
|
101 isnot(aWindow.innerHeight, prevHeight, "Window height should have changed"); |
|
102 |
|
103 prevWidth = aWindow.innerWidth; |
|
104 prevHeight = aWindow.innerHeight; |
|
105 } |
|
106 |
|
107 function posChangeCondition() { |
|
108 // With GTK, sometimes, only one dimension changes. |
|
109 if (navigator.platform.indexOf('Linux') != -1) { |
|
110 return aWindow.screenX != prevX || aWindow.screenY != prevY; |
|
111 } |
|
112 return aWindow.screenX != prevX && aWindow.screenY != prevY; |
|
113 } |
|
114 |
|
115 function posChangeConditionIgnoreLinux() { |
|
116 if (posChangeCondition()) { |
|
117 return true; |
|
118 } |
|
119 |
|
120 if (navigator.platform.indexOf('Linux') != -1) { |
|
121 return true; |
|
122 } |
|
123 } |
|
124 |
|
125 function posChangeTest() { |
|
126 // With GTK, sometimes, only one dimension changes. |
|
127 if (navigator.platform.indexOf('Linux') != -1) { |
|
128 // With GTK, sometimes, aWindow.screenX changes during two calls. |
|
129 // So we call it once and save the returned value. |
|
130 var x = aWindow.screenX; |
|
131 var y = aWindow.screenY; |
|
132 if (x != prevX) { |
|
133 isnot(x, prevX, "Window x position should have changed"); |
|
134 } |
|
135 if (y != prevY) { |
|
136 isnot(y, prevY, "Window y position should have changed"); |
|
137 } |
|
138 } else { |
|
139 isnot(aWindow.screenX, prevX, "Window x position should have changed"); |
|
140 isnot(aWindow.screenY, prevY, "Window y position should have changed"); |
|
141 } |
|
142 |
|
143 prevX = aWindow.screenX; |
|
144 prevY = aWindow.screenY; |
|
145 } |
|
146 |
|
147 function outerChangeCondition() { |
|
148 return aWindow.outerWidth != oWidth && aWindow.outerHeight != oHeight; |
|
149 } |
|
150 |
|
151 function outerChangeTest() { |
|
152 isnot(aWindow.outerWidth, oWidth, "Window outerWidth should have changed"); |
|
153 isnot(aWindow.outerHeight, oHeight, "Window outerHeight should have changed"); |
|
154 |
|
155 aWindow.outerWidth = oWidth; |
|
156 aWindow.outerHeight = oHeight; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Size checks. |
|
161 */ |
|
162 prevWidth = aWindow.innerWidth; |
|
163 prevHeight = aWindow.innerHeight; |
|
164 |
|
165 aWindow.innerWidth = getNewWidth(aWindow); |
|
166 aWindow.innerHeight = getNewHeight(aWindow); |
|
167 |
|
168 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
169 aWindow.resizeTo(getNewWidth(aWindow), getNewHeight(aWindow)); |
|
170 |
|
171 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
172 aWindow.resizeBy(getNewWidth(aWindow) - aWindow.innerWidth, |
|
173 getNewHeight(aWindow) - aWindow.innerHeight); |
|
174 |
|
175 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
176 prevWidth = aWindow.innerWidth = getNewWidth(aWindow); |
|
177 prevHeight = aWindow.innerHeight = getNewHeight(aWindow); |
|
178 aWindow.sizeToContent(); |
|
179 |
|
180 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
181 /** |
|
182 * Position checks. |
|
183 */ |
|
184 prevX = aWindow.screenX; |
|
185 prevY = aWindow.screenY; |
|
186 |
|
187 aWindow.screenX = getNewX(aWindow); |
|
188 aWindow.screenY = getNewY(aWindow); |
|
189 |
|
190 hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
|
191 aWindow.moveTo(getNewX(aWindow), getNewY(aWindow)); |
|
192 |
|
193 hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
|
194 aWindow.moveBy(getNewX(aWindow) - aWindow.screenX, |
|
195 getNewY(aWindow) - aWindow.screenY); |
|
196 |
|
197 hitEventLoop(posChangeConditionIgnoreLinux, posChangeTest, hits, function () { |
|
198 /** |
|
199 * Outer width/height checks. |
|
200 */ |
|
201 oWidth = aWindow.outerWidth; |
|
202 oHeight = aWindow.outerHeight; |
|
203 |
|
204 aWindow.outerWidth = oWidth * 2; |
|
205 aWindow.outerHeight = oHeight * 2; |
|
206 |
|
207 hitEventLoop(outerChangeCondition, outerChangeTest, hits, aNext); |
|
208 }); |
|
209 }); |
|
210 }); |
|
211 }); |
|
212 }); |
|
213 }); |
|
214 }); |
|
215 } |
|
216 |
|
217 SimpleTest.waitForExplicitFinish(); |
|
218 SimpleTest.waitForFocus(function() { |
|
219 if (screen.width <= 200 || screen.height <= 200) { |
|
220 todo(false, "The screen is too small to run this test."); |
|
221 SimpleTest.finish(); |
|
222 } |
|
223 |
|
224 backValues(); |
|
225 |
|
226 // We are in a chrome context, we can change the size and position. |
|
227 checkChangeIsEnabled(window.top, function() { |
|
228 // We create a window and check that the size and position can be set with |
|
229 // window.open parameters and can be changed by the created window. |
|
230 var w = window.open("data:text/html,<script>" + |
|
231 "function check(next) {" + |
|
232 " var is_range = function(aTest, aValue, aRange, aMsg) {" + |
|
233 " ok(aTest < aValue + aRange && aTest > aValue - aRange, aMsg);" + |
|
234 " };" + |
|
235 " is_range(window.innerWidth, 170, 5, 'parameter width should be taken into account');" + |
|
236 " is_range(window.innerHeight, 170, 5, 'parameter height should be taken into account');" + |
|
237 " is_range(window.screenX, 25, 5, 'parameter screenX should be taken into account');" + |
|
238 " is_range(window.screenY, 25, 5, 'parameter screenY should be taken into account');" + |
|
239 " checkChangeIsEnabled(window, next);" + |
|
240 "} <\/script>", '', |
|
241 'width=170,height=170,screenX=25,screenY=25'); |
|
242 |
|
243 SimpleTest.waitForFocus(function() { |
|
244 w.wrappedJSObject.ok = SimpleTest.ok; |
|
245 w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; |
|
246 w.wrappedJSObject.check(function() { |
|
247 // The current window can change the size and position of the created one. |
|
248 checkChangeIsEnabled(w, function() { |
|
249 w.close(); |
|
250 |
|
251 // If we call window.open with an empty string as a third parameter, |
|
252 // by default, it will create a new tab instead of a new window. |
|
253 // In a chrome context, the size and position can change. |
|
254 w = window.open("data:text/html,<script>" + |
|
255 "function check(next) {" + |
|
256 " checkChangeIsEnabled(window, next);" + |
|
257 "} <\/script>", '', ''); |
|
258 |
|
259 SimpleTest.waitForFocus(function() { |
|
260 w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; |
|
261 w.wrappedJSObject.check(function() { |
|
262 // The current window can change the size and position of the new tab. |
|
263 // Because we are in a chrome context. |
|
264 checkChangeIsEnabled(w, function() { |
|
265 w.close(); |
|
266 |
|
267 restoreValues(); |
|
268 SimpleTest.finish(); |
|
269 }); |
|
270 }); |
|
271 }, w, false); |
|
272 }); |
|
273 }); |
|
274 }, w, false); |
|
275 }); |
|
276 }); |
|
277 ]]> |
|
278 </script> |
|
279 </window> |