@@ -104,6 +104,9 @@ def set_timeout(self, timeout):
104
104
self .marionette .timeout .script = timeout
105
105
self .timeout = timeout
106
106
107
+ def create_window (self , type = "tab" , ** kwargs ):
108
+ return self .marionette .open (type = type , focus = True )["handle" ]
109
+
107
110
@property
108
111
def current_window (self ):
109
112
return self .marionette .current_window_handle
@@ -234,57 +237,6 @@ def dismiss_alert(self, f):
234
237
else :
235
238
break
236
239
237
- def get_test_window (self , window_id , parent , timeout = 5 ):
238
- """Find the test window amongst all the open windows.
239
- This is assumed to be either the named window or the one after the parent in the list of
240
- window handles
241
-
242
- :param window_id: The DOM name of the Window
243
- :param parent: The handle of the runner window
244
- :param timeout: The time in seconds to wait for the window to appear. This is because in
245
- some implementations there's a race between calling window.open and the
246
- window being added to the list of WebDriver accessible windows."""
247
- test_window = None
248
- end_time = time .time () + timeout
249
- while time .time () < end_time :
250
- if window_id :
251
- try :
252
- # Try this, it's in Level 1 but nothing supports it yet
253
- win_s = self .parent .base .execute_script ("return window['%s'];" % self .window_id )
254
- win_obj = json .loads (win_s )
255
- test_window = win_obj ["window-fcc6-11e5-b4f8-330a88ab9d7f" ]
256
- except Exception :
257
- pass
258
-
259
- if test_window is None :
260
- handles = self .marionette .window_handles
261
- if len (handles ) == 2 :
262
- test_window = next (iter (set (handles ) - {parent }))
263
- elif len (handles ) > 2 and handles [0 ] == parent :
264
- # Hope the first one here is the test window
265
- test_window = handles [1 ]
266
-
267
- if test_window is not None :
268
- assert test_window != parent
269
- return test_window
270
-
271
- time .sleep (0.1 )
272
-
273
- raise Exception ("unable to find test window" )
274
-
275
- def test_window_loaded (self ):
276
- """Wait until the page in the new window has been loaded.
277
-
278
- Hereby ignore Javascript execptions that are thrown when
279
- the document has been unloaded due to a process change.
280
- """
281
- while True :
282
- try :
283
- self .parent .base .execute_script (self .window_loaded_script , asynchronous = True )
284
- break
285
- except errors .JavascriptException :
286
- pass
287
-
288
240
289
241
class MarionettePrefsProtocolPart (PrefsProtocolPart ):
290
242
def setup (self ):
@@ -999,16 +951,13 @@ def do_test(self, test):
999
951
return (test .make_result (extra = extra , * data ), [])
1000
952
1001
953
def do_testharness (self , protocol , url , timeout ):
1002
- parent_window = protocol .testharness .close_old_windows (self .last_environment ["protocol" ])
954
+ protocol .testharness .close_old_windows (self .last_environment ["protocol" ])
1003
955
1004
956
if self .protocol .coverage .is_enabled :
1005
957
self .protocol .coverage .reset ()
1006
958
1007
- protocol .base .execute_script ("window.open('about:blank', '%s', 'noopener')" % self .window_id )
1008
- test_window = protocol .testharness .get_test_window (self .window_id , parent_window ,
1009
- timeout = 10 * self .timeout_multiplier )
959
+ test_window = protocol .base .create_window ()
1010
960
self .protocol .base .set_window (test_window )
1011
- protocol .testharness .test_window_loaded ()
1012
961
1013
962
if self .debug_test and self .browser .supports_devtools :
1014
963
self .protocol .debug .load_devtools ()
@@ -1072,8 +1021,6 @@ def __init__(self, logger, browser, server_config, timeout_multiplier=1,
1072
1021
1073
1022
self .install_extensions = browser .extensions
1074
1023
1075
- with open (os .path .join (here , "reftest.js" )) as f :
1076
- self .script = f .read ()
1077
1024
with open (os .path .join (here , "test-wait.js" )) as f :
1078
1025
self .wait_script = f .read () % {"classname" : "reftest-wait" }
1079
1026
@@ -1121,10 +1068,19 @@ def do_test(self, test):
1121
1068
self .has_window = False
1122
1069
1123
1070
if not self .has_window :
1124
- self .protocol .base .execute_script (self .script )
1125
- self .protocol .base .set_window (self .protocol .marionette .window_handles [- 1 ])
1071
+ self .protocol .base .create_window (type = "window" )
1072
+ # Resize the browser window so that its inner dimensions have
1073
+ # exactly a size of 800x600 pixels, which means ignoring all
1074
+ # visible toolbars and sidebars.
1075
+ offsets = self .protocol .marionette .execute_script ("""
1076
+ return {
1077
+ width: window.outerWidth - window.innerWidth,
1078
+ height: window.outerHeight - window.innerHeight,
1079
+ };
1080
+ """ )
1081
+ self .protocol .marionette .set_window_rect (
1082
+ x = 0 , y = 0 , width = 800 + offsets ["width" ], height = 600 + offsets ["height" ])
1126
1083
self .has_window = True
1127
- self .protocol .testharness .test_window_loaded ()
1128
1084
1129
1085
if self .protocol .coverage .is_enabled :
1130
1086
self .protocol .coverage .reset ()
0 commit comments