зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1507803 - [marionette] Allow to open a chrome window via the WindowManager mixin class. r=ato
The current implemenation for opening new chrome windows via the WindowManager mixin class is racy because it doesn't wait for the newly opened window to have focus and being activated first. The patch adds a new method to the WindowManager class, which is waits for those events. It can then be used across all existent Marionette unit tests. Differential Revision: https://phabricator.services.mozilla.com/D12180 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
82956adc4f
Коммит
4e3732636a
|
@ -117,3 +117,52 @@ class WindowManagerMixin(object):
|
|||
message="Window with handle '{}'' did not finish loading".format(new_window))
|
||||
|
||||
return new_window
|
||||
|
||||
def open_chrome_window(self, url):
|
||||
"""Open a new chrome window with the specified chrome URL.
|
||||
|
||||
Can be replaced with "WebDriver:NewWindow" once the command
|
||||
supports opening generic chrome windows beside browsers (bug 1507771).
|
||||
"""
|
||||
def open_with_js():
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.execute_async_script("""
|
||||
let [url, resolve] = arguments;
|
||||
|
||||
function waitForEvent(target, type, args) {
|
||||
return new Promise(resolve => {
|
||||
let params = Object.assign({once: true}, args);
|
||||
target.addEventListener(type, event => {
|
||||
dump(`** Received DOM event ${event.type} for ${event.target}\n`);
|
||||
resolve();
|
||||
}, params);
|
||||
});
|
||||
}
|
||||
|
||||
function waitForFocus(win) {
|
||||
return Promise.all([
|
||||
waitForEvent(win, "activate"),
|
||||
waitForEvent(win, "focus", {capture: true}),
|
||||
]);
|
||||
}
|
||||
|
||||
(async function() {
|
||||
// Open a window, wait for it to receive focus
|
||||
let win = window.openDialog(url, null, "chrome,centerscreen");
|
||||
|
||||
// Bug 1507803 - Missing focus/activate event when tests are
|
||||
// run in the background.
|
||||
win.focus();
|
||||
|
||||
await waitForFocus(win);
|
||||
|
||||
// Now refocus our original window and wait for that to happen.
|
||||
let focused = waitForFocus(window);
|
||||
window.focus();
|
||||
await focused;
|
||||
|
||||
resolve();
|
||||
})();
|
||||
""", script_args=(url,))
|
||||
|
||||
return self.open_window(trigger=open_with_js)
|
||||
|
|
|
@ -17,13 +17,8 @@ class TestAnonymousNodes(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestAnonymousNodes, self).setUp()
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test_anonymous_content.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
new_window = self.open_window(trigger=open_window_with_js)
|
||||
url = "chrome://marionette/content/test_anonymous_content.xul"
|
||||
new_window = self.open_chrome_window(url)
|
||||
self.marionette.switch_to_window(new_window)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -16,13 +16,7 @@ class TestSelectedChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'_blank', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
new_window = self.open_window(trigger=open_window_with_js)
|
||||
new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(new_window)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -22,13 +22,7 @@ class TestClickChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestClickChrome, self).tearDown()
|
||||
|
||||
def test_click(self):
|
||||
|
||||
def open_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen'); """)
|
||||
|
||||
win = self.open_window(open_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
def checked():
|
||||
|
|
|
@ -16,13 +16,7 @@ class TestElementState(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
self.win = self.open_window(open_window_with_js)
|
||||
self.win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(self.win)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -16,13 +16,7 @@ class TestElementSizeChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test2.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
new_window = self.open_window(trigger=open_window_with_js)
|
||||
new_window = self.open_chrome_window("chrome://marionette/content/test2.xul")
|
||||
self.marionette.switch_to_window(new_window)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -375,13 +375,8 @@ class TestExecuteChrome(WindowManagerMixin, TestExecuteContent):
|
|||
|
||||
@skip_if_mobile("New windows not supported in Fennec")
|
||||
def test_unmarshal_element_collection(self):
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script(
|
||||
"window.open('chrome://marionette/content/test.xul', 'xul', 'chrome');")
|
||||
|
||||
try:
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
expected = self.marionette.find_elements(By.TAG_NAME, "textbox")
|
||||
|
|
|
@ -18,13 +18,7 @@ class TestElementsChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -31,15 +31,7 @@ class TestGetCurrentUrlChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
@skip_if_mobile("Fennec doesn't support other chrome windows")
|
||||
def test_no_browser_window(self):
|
||||
|
||||
def open_window_with_js():
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
chrome_url = self.marionette.execute_script("return window.location.href;")
|
||||
|
|
|
@ -13,13 +13,7 @@ class TestPageSourceChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestPageSourceChrome, self).setUp()
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
new_window = self.open_window(open_with_js)
|
||||
new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(new_window)
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -135,22 +135,8 @@ class TestScreenCaptureChrome(WindowManagerMixin, ScreenCaptureTestCase):
|
|||
return [rect.width, rect.height];
|
||||
"""))
|
||||
|
||||
def open_dialog(self, url=None, width=None, height=None):
|
||||
if url is None:
|
||||
url = "chrome://marionette/content/test_dialog.xul"
|
||||
|
||||
def opener():
|
||||
features = "chrome"
|
||||
if height is not None:
|
||||
features += ",height={}".format(height)
|
||||
if width is not None:
|
||||
features += ",width={}".format(width)
|
||||
|
||||
self.marionette.execute_script("""
|
||||
window.openDialog(arguments[0], "", arguments[1]);
|
||||
""", script_args=[url, features])
|
||||
|
||||
return self.open_window(opener)
|
||||
def open_dialog(self):
|
||||
return self.open_chrome_window("chrome://marionette/content/test_dialog.xul")
|
||||
|
||||
def test_capture_different_context(self):
|
||||
"""Check that screenshots in content and chrome are different."""
|
||||
|
|
|
@ -15,13 +15,7 @@ class TestSwitchFrameChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestSwitchFrameChrome, self).setUp()
|
||||
self.marionette.set_context("chrome")
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
new_window = self.open_window(trigger=open_window_with_js)
|
||||
new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(new_window)
|
||||
self.assertNotEqual(self.start_window, self.marionette.current_chrome_window_handle)
|
||||
|
||||
|
|
|
@ -20,14 +20,7 @@ class TestTitleChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestTitleChrome, self).tearDown()
|
||||
|
||||
def test_get_chrome_title(self):
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
title = self.marionette.execute_script(
|
||||
|
|
|
@ -31,14 +31,7 @@ class TestCloseWindow(WindowManagerMixin, MarionetteTestCase):
|
|||
self.assertNotIn(win, self.marionette.window_handles)
|
||||
|
||||
def test_close_chrome_window_for_non_browser_window(self):
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
self.assertIn(win, self.marionette.chrome_window_handles)
|
||||
|
|
|
@ -35,15 +35,7 @@ class TestCloseWindow(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
@skip_if_mobile("Interacting with chrome windows not available for Fennec")
|
||||
def test_close_chrome_window_for_non_browser_window(self):
|
||||
|
||||
def open_window_with_js():
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
self.assertIn(win, self.marionette.chrome_window_handles)
|
||||
|
|
|
@ -66,13 +66,7 @@ class TestWindowHandles(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
def test_chrome_window_handles_after_opening_new_dialog(self):
|
||||
xul_dialog = "chrome://marionette/content/test_dialog.xul"
|
||||
|
||||
def open_via_js():
|
||||
self.marionette.execute_script("""
|
||||
window.openDialog(arguments[0]);
|
||||
""", script_args=(xul_dialog,))
|
||||
|
||||
new_win = self.open_window(trigger=open_via_js)
|
||||
new_win = self.open_chrome_window(xul_dialog)
|
||||
self.assert_window_handles()
|
||||
self.assertEqual(len(self.marionette.chrome_window_handles), len(self.start_windows) + 1)
|
||||
self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
|
||||
|
@ -173,13 +167,7 @@ class TestWindowHandles(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
def test_window_handles_after_opening_new_dialog(self):
|
||||
xul_dialog = "chrome://marionette/content/test_dialog.xul"
|
||||
|
||||
def open_via_js():
|
||||
self.marionette.execute_script("""
|
||||
window.openDialog(arguments[0]);
|
||||
""", script_args=(xul_dialog,))
|
||||
|
||||
new_win = self.open_window(trigger=open_via_js)
|
||||
new_win = self.open_chrome_window(xul_dialog)
|
||||
self.assert_window_handles()
|
||||
self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
|
||||
self.assertEqual(self.marionette.current_window_handle, self.start_tab)
|
||||
|
|
|
@ -47,15 +47,7 @@ class TestNoSuchWindowContent(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
@skip_if_mobile("Fennec doesn't support other chrome windows")
|
||||
def test_closed_chrome_window_while_in_frame(self):
|
||||
|
||||
def open_window_with_js():
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.switch_to_frame("iframe")
|
||||
|
|
|
@ -56,15 +56,7 @@ class TestNoSuchWindowContent(WindowManagerMixin, MarionetteTestCase):
|
|||
|
||||
@skip_if_mobile("Fennec doesn't support other chrome windows")
|
||||
def test_closed_chrome_window_while_in_frame(self):
|
||||
|
||||
def open_window_with_js():
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(trigger=open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
with self.marionette.using_context("chrome"):
|
||||
self.marionette.switch_to_frame("iframe")
|
||||
|
|
|
@ -20,14 +20,7 @@ class TestWindowTypeChrome(WindowManagerMixin, MarionetteTestCase):
|
|||
super(TestWindowTypeChrome, self).tearDown()
|
||||
|
||||
def test_get_window_type(self):
|
||||
|
||||
def open_window_with_js():
|
||||
self.marionette.execute_script("""
|
||||
window.open('chrome://marionette/content/test.xul',
|
||||
'foo', 'chrome,centerscreen');
|
||||
""")
|
||||
|
||||
win = self.open_window(open_window_with_js)
|
||||
win = self.open_chrome_window("chrome://marionette/content/test.xul")
|
||||
self.marionette.switch_to_window(win)
|
||||
|
||||
window_type = self.marionette.execute_script(
|
||||
|
|
Загрузка…
Ссылка в новой задаче