Bug 1313312 - Move FirefoxPuppeteerMixin from testcases to mixins.py. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 27 Oct 2016 11:16:22 +0200
changeset 432239 3bd5300066d349b4309e3819825d0d2cb77f7494
parent 432238 ba1276ec3308a8f34e18db786ecfaaac2f9d22f6
child 432240 20b77e4b4545a99d3203511312163a83f27ead20
push id34239
push userbmo:hskupin@gmail.com
push dateTue, 01 Nov 2016 14:19:19 +0000
bugs1313312
milestone52.0a1
Bug 1313312 - Move FirefoxPuppeteerMixin from testcases to mixins.py. MozReview-Commit-ID: 6wvVoMSvEOb
testing/puppeteer/firefox/firefox_puppeteer/__init__.py
testing/puppeteer/firefox/firefox_puppeteer/mixins.py
testing/puppeteer/firefox/firefox_puppeteer/testcases/__init__.py
testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
--- a/testing/puppeteer/firefox/firefox_puppeteer/__init__.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/__init__.py
@@ -1,8 +1,8 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-from firefox_puppeteer.testcases.base import FirefoxPuppeteerMixin
+from firefox_puppeteer.mixins import FirefoxPuppeteerMixin
 
 
 __version__ = '52.0.0'
deleted file mode 100644
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-from firefox_puppeteer.testcases.base import FirefoxPuppeteerMixin
deleted file mode 100644
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
+++ /dev/null
@@ -1,156 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-import unittest
-
-from firefox_puppeteer.decorators import use_class_as_property
-from firefox_puppeteer.ui.browser.window import BrowserWindow
-
-
-class FirefoxPuppeteerMixin(unittest.TestCase):
-    """The puppeteer mixin class is used to expose additional ui and api libraries
-    to test cases.
-
-    example:
-    `class MyTestCase(BaseFirefoxTestCase, FirefoxPuppeteerMixin)`
-
-    Each library can be referenced by its puppeteer name as a member of a
-    the TestCase instance. For example, from within a test method, the
-    "current_window" member of the "Browser" class can be accessed via
-    "self.browser.current_window".
-    """
-
-    def _check_and_fix_leaked_handles(self):
-        handle_count = len(self.marionette.window_handles)
-        url = []
-
-        try:
-            # Verify the existence of leaked tabs and print their URLs.
-            if self._start_handle_count < handle_count:
-                message = ('A test must not leak window handles. This test started with '
-                           '%s open top level browsing contexts, but ended with %s.'
-                           ' Remaining Tabs URLs:') % (self._start_handle_count, handle_count)
-                with self.marionette.using_context('content'):
-                    for tab in self.marionette.window_handles:
-                        if tab not in self._init_tab_handles:
-                            url.append(' %s' % self.marionette.get_url())
-                self.assertListEqual(self._init_tab_handles, self.marionette.window_handles,
-                                     message + ','.join(url))
-        finally:
-            # For clean-up make sure we work on a proper browser window
-            if not self.browser or self.browser.closed:
-                # Find a proper replacement browser window
-                # TODO: We have to make this less error prone in case no browser is open.
-                self.browser = self.windows.switch_to(lambda win: type(win) is BrowserWindow)
-
-            # Ensure to close all the remaining chrome windows to give following
-            # tests a proper start condition and make them not fail.
-            self.windows.close_all([self.browser])
-            self.browser.focus()
-
-            # Also close all remaining tabs
-            self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
-            self.browser.tabbar.tabs[0].switch_to()
-
-    def restart(self, **kwargs):
-        """Restart Firefox and re-initialize data.
-
-        :param flags: Specific restart flags for Firefox
-        """
-        if kwargs.get('clean'):
-            self.marionette.restart(clean=True)
-        else:
-            self.marionette.restart(in_app=True)
-
-        # Ensure that we always have a valid browser instance available
-        self.browser = self.windows.switch_to(lambda win: type(win) is BrowserWindow)
-
-    def setUp(self, *args, **kwargs):
-        super(FirefoxPuppeteerMixin, self).setUp(*args, **kwargs)
-
-        self._start_handle_count = len(self.marionette.window_handles)
-        self._init_tab_handles = self.marionette.window_handles
-        self.marionette.set_context('chrome')
-
-        self.browser = self.windows.current
-        self.browser.focus()
-        with self.marionette.using_context(self.marionette.CONTEXT_CONTENT):
-            # Ensure that we have a default page opened
-            self.marionette.navigate(self.prefs.get_pref('browser.newtab.url'))
-
-    def tearDown(self, *args, **kwargs):
-        self.marionette.set_context('chrome')
-
-        try:
-            self.prefs.restore_all_prefs()
-
-            # This code should be run after all other tearDown code
-            # so that in case of a failure, further tests will not run
-            # in a state that is more inconsistent than necessary.
-            self._check_and_fix_leaked_handles()
-        finally:
-            super(FirefoxPuppeteerMixin, self).tearDown(*args, **kwargs)
-
-    @use_class_as_property('api.appinfo.AppInfo')
-    def appinfo(self):
-        """
-        Provides access to members of the appinfo  api.
-
-        See the :class:`~api.appinfo.AppInfo` reference.
-        """
-
-    @use_class_as_property('api.keys.Keys')
-    def keys(self):
-        """
-        Provides a definition of control keys to use with keyboard shortcuts.
-        For example, keys.CONTROL or keys.ALT.
-        See the :class:`~api.keys.Keys` reference.
-        """
-
-    @use_class_as_property('api.places.Places')
-    def places(self):
-        """Provides low-level access to several bookmark and history related actions.
-
-        See the :class:`~api.places.Places` reference.
-        """
-
-    @use_class_as_property('api.utils.Utils')
-    def utils(self):
-        """Provides an api for interacting with utility actions.
-
-        See the :class:`~api.utils.Utils` reference.
-        """
-
-    @property
-    def platform(self):
-        """Returns the lowercased platform name.
-
-        :returns: Platform name
-        """
-        return self.marionette.session_capabilities['platformName']
-
-    @use_class_as_property('api.prefs.Preferences')
-    def prefs(self):
-        """
-        Provides an api for setting and inspecting preferences, as see in
-        about:config.
-
-        See the :class:`~api.prefs.Preferences` reference.
-        """
-
-    @use_class_as_property('api.security.Security')
-    def security(self):
-        """
-        Provides an api for accessing security related properties and helpers.
-
-        See the :class:`~api.security.Security` reference.
-        """
-
-    @use_class_as_property('ui.windows.Windows')
-    def windows(self):
-        """
-        Provides shortcuts to the top-level windows.
-
-        See the :class:`~ui.window.Windows` reference.
-        """