Bug 1322383 - Update Puppeteer and firefox-ui tests for valid window checks. draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 07 Feb 2017 11:16:55 +0100
changeset 502994 d09912f549afa69c85904ff7f1c3a23b6d0e6e16
parent 502993 76d829952d2954cde9df91e19d187fd509d0782a
child 550301 ae2f6761079c37b347e6142d234d8638e1ed64e0
push id50441
push userbmo:hskupin@gmail.com
push dateWed, 22 Mar 2017 15:51:36 +0000
bugs1322383
milestone55.0a1
Bug 1322383 - Update Puppeteer and firefox-ui tests for valid window checks. We have to ensure to switch to the current browser window after closing all the windows in tearDown. MozReview-Commit-ID: 3sYwmbew43d
testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
testing/firefox-ui/tests/puppeteer/test_windows.py
testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/windows.py
--- a/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
+++ b/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
@@ -16,16 +16,19 @@ class TestAboutPrivateBrowsing(Puppeteer
         # Use a fake local support URL
         support_url = 'about:blank?'
         self.marionette.set_pref('app.support.baseURL', support_url)
 
         self.pb_url = support_url + 'private-browsing'
 
     def tearDown(self):
         try:
+            self.puppeteer.windows.close_all([self.browser])
+            self.browser.switch_to()
+
             self.marionette.clear_pref('app.support.baseURL')
         finally:
             super(TestAboutPrivateBrowsing, self).tearDown()
 
     def testCheckAboutPrivateBrowsing(self):
         self.assertFalse(self.browser.is_private)
 
         with self.marionette.using_context('content'):
--- a/testing/firefox-ui/tests/puppeteer/test_windows.py
+++ b/testing/firefox-ui/tests/puppeteer/test_windows.py
@@ -38,16 +38,17 @@ class BaseWindowTestCase(PuppeteerMixin,
             super(BaseWindowTestCase, self).tearDown()
 
 
 class TestWindows(BaseWindowTestCase):
 
     def tearDown(self):
         try:
             self.puppeteer.windows.close_all([self.browser])
+            self.browser.switch_to()
         finally:
             super(TestWindows, self).tearDown()
 
     def test_switch_to(self):
         url = self.marionette.absolute_url('layout/mozilla.html')
 
         # Open two more windows
         for index in range(0, 2):
@@ -102,18 +103,19 @@ class TestWindows(BaseWindowTestCase):
         self.browser.switch_to()
 
 
 class TestBaseWindow(BaseWindowTestCase):
 
     def tearDown(self):
         try:
             self.puppeteer.windows.close_all([self.browser])
+            self.browser.switch_to()
         finally:
-            BaseWindowTestCase.tearDown(self)
+            super(TestBaseWindow, self).tearDown()
 
     def test_basics(self):
         # force BaseWindow instance
         win1 = BaseWindow(self.marionette, self.browser.handle)
 
         self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle)
         self.assertEquals(win1.window_element,
                           self.marionette.find_element(By.CSS_SELECTOR, ':root'))
@@ -142,17 +144,18 @@ class TestBaseWindow(BaseWindowTestCase)
         self.assertEquals(len(self.marionette.chrome_window_handles), 2)
         self.assertNotEquals(win1.handle, win2.handle)
         self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle)
 
         win2.close()
 
         self.assertTrue(win2.closed)
         self.assertEquals(len(self.marionette.chrome_window_handles), 1)
-        self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle)
+        with self.assertRaises(NoSuchWindowException):
+            self.marionette.current_chrome_window_handle
         Wait(self.marionette).until(lambda _: win1.focused)  # catch the no focused window
 
         win1.focus()
 
         # Open and close a new window by a custom callback
         def opener(window):
             window.marionette.execute_script(""" window.open(); """)
 
@@ -210,18 +213,19 @@ class TestBaseWindow(BaseWindowTestCase)
         win1.switch_to()
 
 
 class TestBrowserWindow(BaseWindowTestCase):
 
     def tearDown(self):
         try:
             self.puppeteer.windows.close_all([self.browser])
+            self.browser.switch_to()
         finally:
-            BaseWindowTestCase.tearDown(self)
+            super(TestBrowserWindow, self).tearDown()
 
     def test_basic(self):
         self.assertNotEqual(self.browser.dtds, [])
         self.assertNotEqual(self.browser.properties, [])
 
         self.assertFalse(self.browser.is_private)
 
         self.assertIsNotNone(self.browser.menubar)
--- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/windows.py
+++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/windows.py
@@ -183,19 +183,17 @@ class Windows(BaseLib):
             # if no handle has been found switch back to original window
             if not target_handle:
                 self.marionette.switch_to_window(current_handle)
 
         if target_handle is None:
             raise NoSuchWindowException("No window found for '{}'"
                                         .format(target))
 
-        # only switch if necessary
-        if target_handle != self.marionette.current_chrome_window_handle:
-            self.marionette.switch_to_window(target_handle)
+        self.marionette.switch_to_window(target_handle)
 
         return self.create_window_instance(target_handle)
 
     @classmethod
     def register_window(cls, window_type, window_class):
         """Registers a chrome window with this class so that this class may in
         turn create the appropriate window instance later on.
 
@@ -410,17 +408,19 @@ class BaseWindow(BaseLib):
 
             if kwargs[modifier] is True:
                 keys.append(keymap[modifier])
 
         # Bug 1125209 - Only lower-case command keys should be sent
         keys.append(command_key.lower())
 
         self.switch_to()
-        self.window_element.send_keys(*keys)
+
+        with self.marionette.using_context("chrome"):
+            self.window_element.send_keys(*keys)
 
     def switch_to(self, focus=False):
         """Switches the context to this chrome window.
 
         By default it will not focus the window. If that behavior is wanted, the
         `focus` parameter can be used.
 
         :param focus: If `True`, the chrome window will be focused.