Bug 1507803 - [marionette] Allow to open a chrome window via the WindowManager mixin class. r=ato
authorHenrik Skupin <mail@hskupin.info>
Fri, 23 Nov 2018 07:55:40 +0000
changeset 504229 0f57247530fd990832fd1e3a50d11c25c21b86ac
parent 504223 ad6143ff142da2f47fe8fcbfd025174a791707bf
child 504230 4afd2f3b8f33bf61287313fdfa609a325386dd06
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1507803
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
testing/marionette/harness/marionette_harness/tests/unit/test_anonymous_content.py
testing/marionette/harness/marionette_harness/tests/unit/test_checkbox_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_click_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_element_state_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_elementsize_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
testing/marionette/harness/marionette_harness/tests/unit/test_findelement_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_get_current_url_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_pagesource_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_screenshot.py
testing/marionette/harness/marionette_harness/tests/unit/test_switch_frame_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_title_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_close_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_close_content.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_management.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_status_content.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_type_chrome.py
--- a/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
+++ b/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
@@ -112,8 +112,58 @@ class WindowManagerMixin(object):
             [new_window] = list(set(self.marionette.chrome_window_handles) - set(current_windows))
 
             # Before continuing ensure the window has been completed loading
             Wait(self.marionette).until(
                 lambda _: loaded(new_window),
                 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 1509380 - Missing focus/activate event when Firefox is not
+                    // the top-most application. As such wait for the next tick, and
+                    // manually focus the newly opened window.
+                    win.setTimeout(() => win.focus(), 0);
+
+                    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)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_anonymous_content.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_anonymous_content.py
@@ -12,23 +12,18 @@ from marionette_harness import Marionett
 
 
 class TestAnonymousNodes(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         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):
         self.close_all_windows()
 
         super(TestAnonymousNodes, self).tearDown()
 
     def test_switch_to_anonymous_frame(self):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_checkbox_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_checkbox_chrome.py
@@ -11,23 +11,17 @@ from marionette_harness import Marionett
 
 class TestSelectedChrome(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(TestSelectedChrome, self).setUp()
 
         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):
         try:
             self.close_all_windows()
         finally:
             super(TestSelectedChrome, self).tearDown()
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_click_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_click_chrome.py
@@ -17,23 +17,17 @@ class TestClickChrome(WindowManagerMixin
         self.marionette.set_context("chrome")
 
     def tearDown(self):
         self.close_all_windows()
 
         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():
             return self.marionette.execute_script(
                 "return arguments[0].checked",
                 script_args=[box])
 
         box = self.marionette.find_element(By.ID, "testBox")
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_element_state_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_element_state_chrome.py
@@ -11,23 +11,17 @@ from marionette_harness import Marionett
 
 class TestElementState(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(TestElementState, 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');
-            """)
-
-        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):
         self.close_all_windows()
 
         super(TestElementState, self).tearDown()
 
     @skip("Switched off in bug 896043, and to be turned on in bug 896046")
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_elementsize_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_elementsize_chrome.py
@@ -11,23 +11,17 @@ from marionette_harness import Marionett
 
 class TestElementSizeChrome(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(TestElementSizeChrome, self).setUp()
 
         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):
         self.close_all_windows()
         super(TestElementSizeChrome, self).tearDown()
 
     def testShouldReturnTheSizeOfAnInput(self):
         shrinko = self.marionette.find_element(By.ID, 'textInput')
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
@@ -370,23 +370,18 @@ class TestExecuteChrome(WindowManagerMix
         super(TestExecuteChrome, self).tearDown()
 
     def test_permission(self):
         self.marionette.execute_script(
             "Components.classes['@mozilla.org/preferences-service;1']")
 
     @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")
             actual = self.marionette.execute_script(
                 "return document.querySelectorAll('textbox')")
             self.assertEqual(expected, actual)
 
         finally:
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_findelement_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_findelement_chrome.py
@@ -13,23 +13,17 @@ from marionette_harness import Marionett
 
 class TestElementsChrome(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(TestElementsChrome, 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');
-            """)
-
-        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):
         self.close_all_windows()
 
         super(TestElementsChrome, self).tearDown()
 
     def test_id(self):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_get_current_url_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_get_current_url_chrome.py
@@ -26,25 +26,17 @@ class TestGetCurrentUrlChrome(WindowMana
             self.marionette.navigate(url)
             self.assertEqual(self.marionette.get_url(), url)
 
         chrome_url = self.marionette.execute_script("return window.location.href;")
         self.assertEqual(self.marionette.get_url(), chrome_url)
 
     @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;")
         self.assertEqual(self.marionette.get_url(), chrome_url)
 
         # With no tabbrowser available an exception will be thrown
         with self.assertRaises(NoSuchWindowException):
             with self.marionette.using_context("content"):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_pagesource_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_pagesource_chrome.py
@@ -8,23 +8,17 @@ from marionette_harness import Marionett
 
 
 class TestPageSourceChrome(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         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):
         self.close_all_windows()
         super(TestPageSourceChrome, self).tearDown()
 
     def testShouldReturnXULDetails(self):
         source = self.marionette.page_source
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_screenshot.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_screenshot.py
@@ -130,32 +130,18 @@ class TestScreenCaptureChrome(WindowMana
     @property
     def window_dimensions(self):
         return tuple(self.marionette.execute_script("""
             let el = document.documentElement;
             let rect = el.getBoundingClientRect();
             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."""
         with self.marionette.using_context("content"):
             screenshot_content = self.marionette.screenshot()
         screenshot_chrome = self.marionette.screenshot()
         self.assertNotEqual(screenshot_content, screenshot_chrome)
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_switch_frame_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_switch_frame_chrome.py
@@ -10,23 +10,17 @@ from marionette_harness import Marionett
 
 
 class TestSwitchFrameChrome(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         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)
 
     def tearDown(self):
         self.close_all_windows()
         super(TestSwitchFrameChrome, self).tearDown()
 
     def test_switch_simple(self):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_title_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_title_chrome.py
@@ -15,21 +15,14 @@ class TestTitleChrome(WindowManagerMixin
         self.marionette.set_context("chrome")
 
     def tearDown(self):
         self.close_all_windows()
 
         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(
             "return window.document.documentElement.getAttribute('title');")
         self.assertEqual(title, self.marionette.title)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_chrome.py
@@ -26,24 +26,17 @@ class TestCloseWindow(WindowManagerMixin
 
         self.assertNotIn(win, self.marionette.window_handles)
         chrome_window_handles = self.marionette.close_chrome_window()
         self.assertNotIn(win, chrome_window_handles)
         self.assertListEqual(self.start_windows, chrome_window_handles)
         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)
         self.assertNotIn(win, self.marionette.window_handles)
         chrome_window_handles = self.marionette.close_chrome_window()
         self.assertNotIn(win, chrome_window_handles)
         self.assertListEqual(self.start_windows, chrome_window_handles)
         self.assertNotIn(win, self.marionette.chrome_window_handles)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_content.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_content.py
@@ -30,25 +30,17 @@ class TestCloseWindow(WindowManagerMixin
         self.assertNotIn(win, self.marionette.window_handles)
         chrome_window_handles = self.marionette.close_chrome_window()
         self.assertNotIn(win, chrome_window_handles)
         self.assertListEqual(self.start_windows, chrome_window_handles)
         self.assertNotIn(win, self.marionette.window_handles)
 
     @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)
         self.assertNotIn(win, self.marionette.window_handles)
         chrome_window_handles = self.marionette.close_chrome_window()
         self.assertNotIn(win, chrome_window_handles)
         self.assertListEqual(self.start_windows, chrome_window_handles)
         self.assertNotIn(win, self.marionette.window_handles)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
@@ -61,23 +61,17 @@ class TestWindowHandles(WindowManagerMix
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.chrome_window_handles,
                              chrome_window_handles_in_chrome_scope)
             self.assertEqual(self.marionette.window_handles,
                              window_handles_in_chrome_scope)
 
     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)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_win)
         self.assert_window_handles()
         self.assertEqual(self.marionette.current_chrome_window_handle, new_win)
@@ -168,23 +162,17 @@ class TestWindowHandles(WindowManagerMix
         self.assert_window_handles()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(self.start_tab)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
     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)
 
         self.marionette.switch_to_window(new_win)
         self.assert_window_handles()
         self.assertEqual(self.marionette.get_url(), xul_dialog)
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_management.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_management.py
@@ -42,25 +42,17 @@ class TestNoSuchWindowContent(WindowMana
 
         self.marionette.switch_to_window(self.start_window)
 
         with self.assertRaises(NoSuchWindowException):
             self.marionette.switch_to_window(win)
 
     @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")
         self.marionette.close_chrome_window()
 
         with self.assertRaises(NoSuchWindowException):
             self.marionette.current_window_handle
         with self.assertRaises(NoSuchWindowException):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_status_content.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_status_content.py
@@ -51,25 +51,17 @@ class TestNoSuchWindowContent(WindowMana
 
         self.marionette.switch_to_window(self.start_window)
 
         with self.assertRaises(NoSuchWindowException):
             self.marionette.switch_to_window(win)
 
     @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")
         self.marionette.close_chrome_window()
 
         with self.assertRaises(NoSuchWindowException):
             self.marionette.current_window_handle
         with self.assertRaises(NoSuchWindowException):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_type_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_type_chrome.py
@@ -15,21 +15,14 @@ class TestWindowTypeChrome(WindowManager
         self.marionette.set_context("chrome")
 
     def tearDown(self):
         self.close_all_windows()
 
         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(
             "return window.document.documentElement.getAttribute('windowtype');")
         self.assertEqual(window_type, self.marionette.get_window_type())