|
3 | 3 | import json
|
4 | 4 | import os
|
5 | 5 | import threading
|
6 |
| -import time |
7 | 6 | import traceback
|
8 | 7 | import uuid
|
9 | 8 |
|
@@ -103,6 +102,9 @@ def set_timeout(self, timeout):
|
103 | 102 | self.marionette.timeout.script = timeout
|
104 | 103 | self.timeout = timeout
|
105 | 104 |
|
| 105 | + def create_window(self, type="tab", **kwargs): |
| 106 | + return self.marionette.open(type=type, focus=True)["handle"] |
| 107 | + |
106 | 108 | @property
|
107 | 109 | def current_window(self):
|
108 | 110 | return self.marionette.current_window_handle
|
@@ -233,57 +235,6 @@ def dismiss_alert(self, f):
|
233 | 235 | else:
|
234 | 236 | break
|
235 | 237 |
|
236 |
| - def get_test_window(self, window_id, parent, timeout=5): |
237 |
| - """Find the test window amongst all the open windows. |
238 |
| - This is assumed to be either the named window or the one after the parent in the list of |
239 |
| - window handles |
240 |
| -
|
241 |
| - :param window_id: The DOM name of the Window |
242 |
| - :param parent: The handle of the runner window |
243 |
| - :param timeout: The time in seconds to wait for the window to appear. This is because in |
244 |
| - some implementations there's a race between calling window.open and the |
245 |
| - window being added to the list of WebDriver accessible windows.""" |
246 |
| - test_window = None |
247 |
| - end_time = time.time() + timeout |
248 |
| - while time.time() < end_time: |
249 |
| - if window_id: |
250 |
| - try: |
251 |
| - # Try this, it's in Level 1 but nothing supports it yet |
252 |
| - win_s = self.parent.base.execute_script("return window['%s'];" % self.window_id) |
253 |
| - win_obj = json.loads(win_s) |
254 |
| - test_window = win_obj["window-fcc6-11e5-b4f8-330a88ab9d7f"] |
255 |
| - except Exception: |
256 |
| - pass |
257 |
| - |
258 |
| - if test_window is None: |
259 |
| - handles = self.marionette.window_handles |
260 |
| - if len(handles) == 2: |
261 |
| - test_window = next(iter(set(handles) - {parent})) |
262 |
| - elif len(handles) > 2 and handles[0] == parent: |
263 |
| - # Hope the first one here is the test window |
264 |
| - test_window = handles[1] |
265 |
| - |
266 |
| - if test_window is not None: |
267 |
| - assert test_window != parent |
268 |
| - return test_window |
269 |
| - |
270 |
| - time.sleep(0.1) |
271 |
| - |
272 |
| - raise Exception("unable to find test window") |
273 |
| - |
274 |
| - def test_window_loaded(self): |
275 |
| - """Wait until the page in the new window has been loaded. |
276 |
| -
|
277 |
| - Hereby ignore Javascript execptions that are thrown when |
278 |
| - the document has been unloaded due to a process change. |
279 |
| - """ |
280 |
| - while True: |
281 |
| - try: |
282 |
| - self.parent.base.execute_script(self.window_loaded_script, asynchronous=True) |
283 |
| - break |
284 |
| - except errors.JavascriptException: |
285 |
| - pass |
286 |
| - |
287 | 238 |
|
288 | 239 | class MarionettePrefsProtocolPart(PrefsProtocolPart):
|
289 | 240 | def setup(self):
|
@@ -496,7 +447,8 @@ def minimize(self):
|
496 | 447 | return self.marionette.minimize_window()
|
497 | 448 |
|
498 | 449 | def set_rect(self, rect):
|
499 |
| - self.marionette.set_window_rect(rect["x"], rect["y"], rect["height"], rect["width"]) |
| 450 | + self.marionette.set_window_rect( |
| 451 | + rect.get("x"), rect.get("y"), rect.get("height"), rect.get("width")) |
500 | 452 |
|
501 | 453 | def get_rect(self):
|
502 | 454 | return self.marionette.window_rect
|
@@ -986,16 +938,13 @@ def do_test(self, test):
|
986 | 938 | return (test.make_result(extra=extra, *data), [])
|
987 | 939 |
|
988 | 940 | def do_testharness(self, protocol, url, timeout):
|
989 |
| - parent_window = protocol.testharness.close_old_windows(self.last_environment["protocol"]) |
| 941 | + protocol.testharness.close_old_windows(self.last_environment["protocol"]) |
990 | 942 |
|
991 | 943 | if self.protocol.coverage.is_enabled:
|
992 | 944 | self.protocol.coverage.reset()
|
993 | 945 |
|
994 |
| - protocol.base.execute_script("window.open('about:blank', '%s', 'noopener')" % self.window_id) |
995 |
| - test_window = protocol.testharness.get_test_window(self.window_id, parent_window, |
996 |
| - timeout=10 * self.timeout_multiplier) |
| 946 | + test_window = protocol.base.create_window() |
997 | 947 | self.protocol.base.set_window(test_window)
|
998 |
| - protocol.testharness.test_window_loaded() |
999 | 948 |
|
1000 | 949 | if self.debug_test and self.browser.supports_devtools:
|
1001 | 950 | self.protocol.debug.load_devtools()
|
@@ -1059,8 +1008,6 @@ def __init__(self, logger, browser, server_config, timeout_multiplier=1,
|
1059 | 1008 |
|
1060 | 1009 | self.install_extensions = browser.extensions
|
1061 | 1010 |
|
1062 |
| - with open(os.path.join(here, "reftest.js")) as f: |
1063 |
| - self.script = f.read() |
1064 | 1011 | with open(os.path.join(here, "test-wait.js")) as f:
|
1065 | 1012 | self.wait_script = f.read() % {"classname": "reftest-wait"}
|
1066 | 1013 |
|
@@ -1108,10 +1055,19 @@ def do_test(self, test):
|
1108 | 1055 | self.has_window = False
|
1109 | 1056 |
|
1110 | 1057 | if not self.has_window:
|
1111 |
| - self.protocol.base.execute_script(self.script) |
1112 |
| - self.protocol.base.set_window(self.protocol.marionette.window_handles[-1]) |
| 1058 | + self.protocol.base.create_window(type="window") |
| 1059 | + # Resize the browser window so that its inner dimensions have |
| 1060 | + # exactly a size of 800x600 pixels, which means ignoring all |
| 1061 | + # visible toolbars and sidebars. |
| 1062 | + offsets = self.protocol.marionette.execute_script(""" |
| 1063 | + return { |
| 1064 | + width: window.outerWidth - window.innerWidth, |
| 1065 | + height: window.outerHeight - window.innerHeight, |
| 1066 | + }; |
| 1067 | + """) |
| 1068 | + self.protocol.marionette.set_window_rect( |
| 1069 | + x=0, y=0, width=800 + offsets["width"], height=600 + offsets["height"]) |
1113 | 1070 | self.has_window = True
|
1114 |
| - self.protocol.testharness.test_window_loaded() |
1115 | 1071 |
|
1116 | 1072 | if self.protocol.coverage.is_enabled:
|
1117 | 1073 | self.protocol.coverage.reset()
|
|
0 commit comments