Bug 1314891 - create_window_instance() should not fail with UnknownWindowError but create a BaseWindow. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 03 Nov 2016 10:12:10 +0100
changeset 433223 f50660489a64a4ce6edf456a69f05719189c5a7a
parent 431996 2c773b97167252cedcba0be0c7af9d4cab192ef5
child 535828 f81953f7a2fa2a506e14d1c3c3003189cd7f39a1
push id34511
push userbmo:hskupin@gmail.com
push dateThu, 03 Nov 2016 09:12:37 +0000
bugs1314891
milestone52.0a1
Bug 1314891 - create_window_instance() should not fail with UnknownWindowError but create a BaseWindow. MozReview-Commit-ID: 8UMSB34OkUD
testing/firefox-ui/tests/puppeteer/test_windows.py
testing/puppeteer/firefox/firefox_puppeteer/ui/windows.py
--- a/testing/firefox-ui/tests/puppeteer/test_windows.py
+++ b/testing/firefox-ui/tests/puppeteer/test_windows.py
@@ -33,17 +33,17 @@ class BaseWindowTestCase(FirefoxTestCase
 class TestWindows(BaseWindowTestCase):
 
     def tearDown(self):
         try:
             self.windows.close_all([self.browser])
         finally:
             BaseWindowTestCase.tearDown(self)
 
-    def test_windows(self):
+    def test_switch_to(self):
         url = self.marionette.absolute_url('layout/mozilla.html')
 
         # Open two more windows
         for index in range(0, 2):
             self.marionette.execute_script(""" window.open(); """)
 
         windows = self.windows.all
         self.assertEquals(len(windows), 3)
@@ -76,16 +76,28 @@ class TestWindows(BaseWindowTestCase):
         self.assertRaises(NoSuchWindowException,
                           self.windows.switch_to, lambda win: False)
 
         self.windows.close_all([self.browser])
         self.browser.switch_to()
 
         self.assertEqual(len(self.windows.all), 1)
 
+    def test_switch_to_unknown_window_type(self):
+        def open_by_js(_):
+            with self.marionette.using_context('chrome'):
+                self.marionette.execute_script("""
+                  window.open('chrome://browser/content/safeMode.xul', '_blank',
+                              'chrome,centerscreen,resizable=no');
+                """)
+
+        win = self.browser.open_window(callback=open_by_js, expected_window_class=BaseWindow)
+        win.close()
+        self.browser.switch_to()
+
 
 class TestBaseWindow(BaseWindowTestCase):
 
     def tearDown(self):
         try:
             self.windows.close_all([self.browser])
         finally:
             BaseWindowTestCase.tearDown(self)
--- a/testing/puppeteer/firefox/firefox_puppeteer/ui/windows.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/ui/windows.py
@@ -101,32 +101,26 @@ class Windows(BaseLib):
         current_handle = self.marionette.current_chrome_window_handle
         window = None
 
         with self.marionette.using_context('chrome'):
             try:
                 # Retrieve window type to determine the type of chrome window
                 if handle != self.marionette.current_chrome_window_handle:
                     self.switch_to(handle)
-
-                window_type = Wait(self.marionette).until(
-                    lambda mn: mn.get_window_type(),
-                    message='Cannot get window type for chrome window handle "%s"' % handle
-                )
-
+                window_type = self.marionette.get_window_type()
             finally:
                 # Ensure to switch back to the original window
                 if handle != current_handle:
                     self.switch_to(current_handle)
 
             if window_type in self.windows_map:
                 window = self.windows_map[window_type](lambda: self.marionette, handle)
             else:
-                raise errors.UnknownWindowError('Unknown window type "%s" for handle: "%s"' %
-                                                (window_type, handle))
+                window = BaseWindow(lambda: self.marionette, handle)
 
             if expected_class is not None and type(window) is not expected_class:
                 raise errors.UnexpectedWindowTypeError('Expected window "%s" but got "%s"' %
                                                        (expected_class, type(window)))
 
             # Before continuing ensure the chrome window has been completed loading
             Wait(self.marionette).until(
                 lambda _: self.loaded(handle),