|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=565541 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 565541</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=565541">Mozilla Bug 565541</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript"> |
|
19 |
|
20 /** Test for Bug 565541 **/ |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 var previousX, previousY, previousWidth, previousHeight; |
|
25 |
|
26 |
|
27 function backValues() |
|
28 { |
|
29 previousX = window.screenX; |
|
30 previousY = window.screenY; |
|
31 previousWidth = window.innerWidth; |
|
32 previousHeight = window.innerHeight; |
|
33 } |
|
34 |
|
35 function restoreValues() |
|
36 { |
|
37 window.screenX = previousX; |
|
38 window.screenY = previousY; |
|
39 window.innerWidth = previousWidth; |
|
40 window.innerHeight = previousHeight; |
|
41 } |
|
42 |
|
43 function getNewWidth(aWindow) |
|
44 { |
|
45 return (aWindow.innerWidth > (screen.width / 2)) ? 100 : screen.width; |
|
46 } |
|
47 |
|
48 function getNewHeight(aWindow) |
|
49 { |
|
50 return (aWindow.innerHeight > (screen.height / 2)) ? 100 : screen.height; |
|
51 } |
|
52 |
|
53 function getNewX(aWindow) |
|
54 { |
|
55 return (aWindow.screenX > ((screen.width - aWindow.outerWidth) / 2)) |
|
56 ? 0 : screen.width - aWindow.outerWidth; |
|
57 } |
|
58 |
|
59 function getNewY(aWindow) |
|
60 { |
|
61 return (aWindow.screenY > ((screen.height - aWindow.outerHeight) / 2)) |
|
62 ? 0 : screen.height - aWindow.outerHeight; |
|
63 } |
|
64 |
|
65 /** |
|
66 * hitEventLoop is called when we want to check something but we can't rely on |
|
67 * an event or a specific number of event loop hiting. |
|
68 * This method can be called by specifying a condition, a test (using SimpleTest |
|
69 * API), how many times the event loop has to be hitten and what to call next. |
|
70 * If times < 0, the event loop will be hitten as long as the condition isn't |
|
71 * true or the test doesn't time out. |
|
72 */ |
|
73 function hitEventLoop(condition, test, times, next) { |
|
74 if (condition() || times == 0) { |
|
75 test(); |
|
76 next(); |
|
77 return; |
|
78 } |
|
79 |
|
80 setTimeout(hitEventLoop, 0, condition, test, times - 1, next); |
|
81 } |
|
82 |
|
83 function checkChangeIsDisabled(aWindow, aNext) |
|
84 { |
|
85 // We want to check that nothing has changed. Having a high value would take |
|
86 // too much time. Worse thing that could happen is random green. |
|
87 var hits = 5; |
|
88 |
|
89 var originalWidth = aWindow.innerWidth; |
|
90 var originalHeight = aWindow.innerHeight; |
|
91 |
|
92 var originalX = aWindow.screenX; |
|
93 var originalY = aWindow.screenY; |
|
94 |
|
95 var oWidth = aWindow.outerWidth; |
|
96 var oHeight = aWindow.outerHeight; |
|
97 |
|
98 function changeCondition() { |
|
99 return aWindow.innerWidth != originalWidth || |
|
100 aWindow.innerHeight != originalHeight || |
|
101 aWindow.screenX != originalX || aWindow.screenY != originalY || |
|
102 aWindow.outerWidth != oWidth || aWindow.outerHeight != oHeight; |
|
103 } |
|
104 |
|
105 function changeTest() { |
|
106 is(aWindow.innerWidth, originalWidth, "Window width shouldn't have changed"); |
|
107 is(aWindow.innerHeight, originalHeight, "Window height shouldn't have changed"); |
|
108 is(aWindow.screenX, originalX, "Window x position shouldn't have changed"); |
|
109 is(aWindow.screenY, originalY, "Window y position shouldn't have changed"); |
|
110 is(aWindow.outerWidth, oWidth, "Window outerWidth shouldn't have changed"); |
|
111 is(aWindow.outerHeight, oHeight, "Window outerHeight shouldn't have changed"); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Size changes. |
|
116 */ |
|
117 var newWidth = getNewWidth(aWindow); |
|
118 var newHeight = getNewHeight(aWindow); |
|
119 |
|
120 aWindow.innerWidth = newWidth; |
|
121 aWindow.innerHeight = newHeight; |
|
122 |
|
123 aWindow.resizeTo(newWidth, newHeight); |
|
124 |
|
125 aWindow.resizeBy(newWidth - aWindow.innerWidth, |
|
126 newHeight - aWindow.innerHeight); |
|
127 |
|
128 aWindow.sizeToContent(); |
|
129 |
|
130 /** |
|
131 * Position checks. |
|
132 */ |
|
133 var newX = getNewX(aWindow); |
|
134 var newY = getNewY(aWindow); |
|
135 |
|
136 aWindow.screenX = newX; |
|
137 aWindow.screenY = newY; |
|
138 |
|
139 aWindow.moveTo(newX, newY); |
|
140 |
|
141 aWindow.moveBy(newX - aWindow.screenX, |
|
142 newY - aWindow.screenY); |
|
143 |
|
144 /** |
|
145 * Outer width/height checks. |
|
146 */ |
|
147 aWindow.outerWidth *= 2; |
|
148 aWindow.outerHeight *= 2; |
|
149 |
|
150 // We did a lot of changes. Now, we are going to wait and see if something |
|
151 // happens. |
|
152 // NOTE: if this happens to fail, you will have to check manually which |
|
153 // operation has been accepted. |
|
154 hitEventLoop(changeCondition, changeTest, hits, aNext); |
|
155 } |
|
156 |
|
157 function checkChangeIsEnabled(aWindow, aNext) |
|
158 { |
|
159 // Something should happen. We are not going to go to the next test until |
|
160 // it does. |
|
161 var hits = -1; |
|
162 |
|
163 var prevWidth; |
|
164 var prevHeight; |
|
165 |
|
166 var prevX; |
|
167 var prevY; |
|
168 |
|
169 var oWidth; |
|
170 var oHeight; |
|
171 |
|
172 function sizeChangeCondition() { |
|
173 return aWindow.innerWidth != prevWidth && aWindow.innerHeight != prevHeight; |
|
174 } |
|
175 |
|
176 function sizeChangeTest() { |
|
177 isnot(aWindow.innerWidth, prevWidth, "Window width should have changed"); |
|
178 isnot(aWindow.innerHeight, prevHeight, "Window height should have changed"); |
|
179 |
|
180 prevWidth = aWindow.innerWidth; |
|
181 prevHeight = aWindow.innerHeight; |
|
182 } |
|
183 |
|
184 function posChangeCondition() { |
|
185 // With GTK, sometimes, only one dimension changes. |
|
186 if (navigator.platform.indexOf('Linux') != -1) { |
|
187 return aWindow.screenX != prevX || aWindow.screenY != prevY; |
|
188 } |
|
189 return aWindow.screenX != prevX && aWindow.screenY != prevY; |
|
190 } |
|
191 |
|
192 function posChangeTest() { |
|
193 // With GTK, sometimes, only one dimension changes. |
|
194 if (navigator.platform.indexOf('Linux') != -1) { |
|
195 // With GTK, sometimes, aWindow.screenX changes during two calls. |
|
196 // So we call it once and save the returned value. |
|
197 var x = aWindow.screenX; |
|
198 var y = aWindow.screenY; |
|
199 if (x != prevX) { |
|
200 isnot(x, prevX, "Window x position should have changed"); |
|
201 } |
|
202 if (y != prevY) { |
|
203 isnot(y, prevY, "Window y position should have changed"); |
|
204 } |
|
205 } else { |
|
206 isnot(aWindow.screenX, prevX, "Window x position should have changed"); |
|
207 isnot(aWindow.screenY, prevY, "Window y position should have changed"); |
|
208 } |
|
209 |
|
210 prevX = aWindow.screenX; |
|
211 prevY = aWindow.screenY; |
|
212 } |
|
213 |
|
214 function outerChangeCondition() { |
|
215 return aWindow.outerWidth != oWidth && aWindow.outerHeight != oHeight; |
|
216 } |
|
217 |
|
218 function outerChangeTest() { |
|
219 isnot(aWindow.outerWidth, oWidth, "Window outerWidth should have changed"); |
|
220 isnot(aWindow.outerHeight, oHeight, "Window outerHeight should have changed"); |
|
221 |
|
222 aWindow.outerWidth = oWidth; |
|
223 aWindow.outerHeight = oHeight; |
|
224 } |
|
225 |
|
226 /** |
|
227 * Size checks. |
|
228 */ |
|
229 prevWidth = aWindow.innerWidth; |
|
230 prevHeight = aWindow.innerHeight; |
|
231 |
|
232 aWindow.innerWidth = getNewWidth(aWindow); |
|
233 aWindow.innerHeight = getNewHeight(aWindow); |
|
234 |
|
235 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
236 aWindow.resizeTo(getNewWidth(aWindow), getNewHeight(aWindow)); |
|
237 |
|
238 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
239 aWindow.resizeBy(getNewWidth(aWindow) - aWindow.innerWidth, |
|
240 getNewHeight(aWindow) - aWindow.innerHeight); |
|
241 |
|
242 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
243 prevWidth = aWindow.innerWidth = getNewWidth(aWindow); |
|
244 prevHeight = aWindow.innerHeight = getNewHeight(aWindow); |
|
245 aWindow.sizeToContent(); |
|
246 |
|
247 hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
|
248 /** |
|
249 * Position checks. |
|
250 */ |
|
251 prevX = aWindow.screenX; |
|
252 prevY = aWindow.screenY; |
|
253 |
|
254 aWindow.screenX = getNewX(aWindow); |
|
255 aWindow.screenY = getNewY(aWindow); |
|
256 |
|
257 hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
|
258 prevX = aWindow.screenX; |
|
259 prevY = aWindow.screenY; |
|
260 |
|
261 aWindow.moveTo(getNewX(aWindow), getNewY(aWindow)); |
|
262 |
|
263 hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
|
264 prevX = aWindow.screenX; |
|
265 prevY = aWindow.screenY; |
|
266 |
|
267 aWindow.moveBy(getNewX(aWindow) - aWindow.screenX, |
|
268 getNewY(aWindow) - aWindow.screenY); |
|
269 |
|
270 hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
|
271 /** |
|
272 * Outer width/height checks. |
|
273 */ |
|
274 oWidth = aWindow.outerWidth; |
|
275 oHeight = aWindow.outerHeight; |
|
276 |
|
277 aWindow.outerWidth = oWidth * 2; |
|
278 aWindow.outerHeight = oHeight * 2; |
|
279 |
|
280 hitEventLoop(outerChangeCondition, outerChangeTest, hits, aNext); |
|
281 }); |
|
282 }); |
|
283 }); |
|
284 }); |
|
285 }); |
|
286 }); |
|
287 }); |
|
288 } |
|
289 |
|
290 SpecialPowers.pushPrefEnv({"set": [["dom.disable_window_move_resize", false]]}, function() { |
|
291 SimpleTest.waitForFocus(function() { |
|
292 if (screen.width <= 200 || screen.height <= 200) { |
|
293 todo(false, "The screen needs to be bigger than 200px*200px to run this test."); |
|
294 SimpleTest.finish(); |
|
295 return; |
|
296 } |
|
297 |
|
298 backValues(); |
|
299 |
|
300 // The current window can't change it's own size and position. |
|
301 checkChangeIsDisabled(window, function() { |
|
302 // We create a window and check that it can change its own size and position. |
|
303 // However, passing size/position parameters to window.open should work. |
|
304 var w = window.open("data:text/html,<script>" + |
|
305 "function check(next) {" + |
|
306 " var is_range = function(aTest, aValue, aRange, aMsg) {" + |
|
307 " window.opener.ok(aTest < aValue + aRange && aTest > aValue - aRange, aMsg);" + |
|
308 " };" + |
|
309 " is_range(window.innerWidth, 170, 5, 'parameter width should be taken into account');" + |
|
310 " is_range(window.innerHeight, 170, 5, 'parameter height should be taken into account');" + |
|
311 " is_range(window.screenX, 65, 5, 'parameter screenX should be taken into account');" + |
|
312 " is_range(window.screenY, 65, 5, 'parameter screenY should be taken into account');" + |
|
313 " window.opener.checkChangeIsEnabled(window, next);" + |
|
314 "} <\/script>", '', |
|
315 'width=170,height=170,screenX=65,screenY=65'); |
|
316 |
|
317 SimpleTest.waitForFocus(function() { |
|
318 w.check(function() { |
|
319 // The current window can change the size and position of the created one. |
|
320 checkChangeIsEnabled(w, function() { |
|
321 w.close(); |
|
322 |
|
323 // If we call window.open with an empty string as a third parameter, |
|
324 // by default, it will create a new tab instead of a new window. |
|
325 // In that case, we shouldn't allow the caller to change the size/position. |
|
326 w = window.open("data:text/html,<script>" + |
|
327 "function check(next) {" + |
|
328 " window.opener.checkChangeIsDisabled(window, next);" + |
|
329 "} <\/script>", '', ''); |
|
330 |
|
331 SimpleTest.waitForFocus(function() { |
|
332 w.check(function() { |
|
333 |
|
334 // The current window can't change the size and position of the new tab. |
|
335 checkChangeIsDisabled(w, function() { |
|
336 w.close(); |
|
337 |
|
338 restoreValues(); |
|
339 SimpleTest.finish(); |
|
340 }); |
|
341 }); |
|
342 }, w, false); |
|
343 }); |
|
344 }) |
|
345 }, w, false); |
|
346 }); |
|
347 }); |
|
348 }); // SpecialPowers.pushPrefEnv() |
|
349 |
|
350 </script> |
|
351 </pre> |
|
352 </body> |
|
353 </html> |