[Pkg-mozext-commits] [requestpolicy] 59/257: [tst][add] introduce RequestPolicyPuppeteer
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:19:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 2807efefe7b9916cf68c9cc89e6831b060c9fc73
Author: Martin Kimmerle <dev at 256k.de>
Date: Sat Sep 26 19:48:29 2015 +0200
[tst][add] introduce RequestPolicyPuppeteer
The `RequestPolicyPuppeteer` class is used to expose libraries
to test cases. That way e.g. the `Rules` class can be accessed
via `self.rules`.
---
tests/marionette/rp_puppeteer/__init__.py | 32 ++++++++++++++++++++
tests/marionette/rp_puppeteer/decorators.py | 35 ++++++++++++++++++++++
tests/marionette/rp_puppeteer/tests/test_rules.py | 3 --
tests/marionette/rp_ui_harness/testcases.py | 7 ++++-
.../links/html_anchor_element/test_link_click.py | 2 --
.../html_anchor_element/test_open_in_new_tab.py | 7 -----
.../html_anchor_element/test_open_in_new_window.py | 12 +++-----
.../text_selection/test_open_in_current_tab.py | 9 ------
.../links/text_selection/test_open_in_new_tab.py | 9 ------
.../text_selection/test_open_in_new_window.py | 13 ++------
10 files changed, 79 insertions(+), 50 deletions(-)
diff --git a/tests/marionette/rp_puppeteer/__init__.py b/tests/marionette/rp_puppeteer/__init__.py
index 8b13789..c7f32b4 100644
--- a/tests/marionette/rp_puppeteer/__init__.py
+++ b/tests/marionette/rp_puppeteer/__init__.py
@@ -1 +1,33 @@
+# 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 .decorators import use_class_as_property
+
+
+class RequestPolicyPuppeteer(object):
+ """The puppeteer class is used to expose libraries to test cases.
+
+ Each library can be referenced by its puppeteer name as a member of a
+ RequestPolicyTestCase instance.
+ """
+
+ @use_class_as_property('api.rules.Rules')
+ def rules(self):
+ pass
+
+ @use_class_as_property('ui.context_menu.ContextMenu')
+ def ctx_menu(self):
+ pass
+
+ @use_class_as_property('ui.redirect_notification.RedirectNotification')
+ def redir(self):
+ pass
+
+ @use_class_as_property('ui.tabs.Tabs')
+ def tabs(self):
+ pass
+
+ @use_class_as_property('ui.web_utils.WebUtils')
+ def web_utils(self):
+ pass
diff --git a/tests/marionette/rp_puppeteer/decorators.py b/tests/marionette/rp_puppeteer/decorators.py
new file mode 100644
index 0000000..ab2a4e1
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/decorators.py
@@ -0,0 +1,35 @@
+# 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 functools import wraps
+from importlib import import_module
+
+
+class use_class_as_property(object):
+ """
+ This decorator imports a library module and sets an instance
+ of the associated class as an attribute on the Puppeteer
+ object and returns it.
+
+ Note: return value of the wrapped function is ignored.
+ """
+ def __init__(self, lib):
+ self.lib = lib
+ self.mod_name, self.cls_name = self.lib.rsplit('.', 1)
+
+ def __call__(self, func):
+ @property
+ @wraps(func)
+ def _(cls, *args, **kwargs):
+ tag = '_rp_{}_{}'.format(self.mod_name, self.cls_name)
+ prop = getattr(cls, tag, None)
+
+ if not prop:
+ module = import_module('.{}'.format(self.mod_name),
+ 'rp_puppeteer')
+ prop = getattr(module, self.cls_name)(cls.get_marionette)
+ setattr(cls, tag, prop)
+ func(cls, *args, **kwargs)
+ return prop
+ return _
diff --git a/tests/marionette/rp_puppeteer/tests/test_rules.py b/tests/marionette/rp_puppeteer/tests/test_rules.py
index bade8f8..9a36163 100644
--- a/tests/marionette/rp_puppeteer/tests/test_rules.py
+++ b/tests/marionette/rp_puppeteer/tests/test_rules.py
@@ -3,7 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.api.rules import Rules
from marionette import SkipTest
@@ -13,8 +12,6 @@ class RulesTestCase(RequestPolicyTestCase):
def setUp(self):
super(RulesTestCase, self).setUp()
- self.rules = Rules(lambda: self.marionette)
-
cr = self.rules.create_rule
self.rules_1248 = [
diff --git a/tests/marionette/rp_ui_harness/testcases.py b/tests/marionette/rp_ui_harness/testcases.py
index 9bd4d1d..c202a2c 100644
--- a/tests/marionette/rp_ui_harness/testcases.py
+++ b/tests/marionette/rp_ui_harness/testcases.py
@@ -3,13 +3,18 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from firefox_ui_harness import FirefoxTestCase
+from rp_puppeteer import RequestPolicyPuppeteer
from rp_puppeteer.api.error_detection import (LoggingErrorDetection,
ConsoleErrorDetection)
-class RequestPolicyTestCase(FirefoxTestCase):
+class RequestPolicyTestCase(RequestPolicyPuppeteer, FirefoxTestCase):
"""Base testcase class for RequestPolicy Marionette tests.
+
+ Note: RequestPolicyPuppeteer must be the first base class
+ in order to allow overriding the attributes of the `Puppeteer`
+ class.
"""
def __init__(self, *args, **kwargs):
diff --git a/tests/marionette/tests/links/html_anchor_element/test_link_click.py b/tests/marionette/tests/links/html_anchor_element/test_link_click.py
index feacbe3..759a6b3 100644
--- a/tests/marionette/tests/links/html_anchor_element/test_link_click.py
+++ b/tests/marionette/tests/links/html_anchor_element/test_link_click.py
@@ -3,7 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -14,7 +13,6 @@ class TestLinkClick(RequestPolicyTestCase):
def setUp(self):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
def test_link_click(self):
diff --git a/tests/marionette/tests/links/html_anchor_element/test_open_in_new_tab.py b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_tab.py
index 46d2134..b34f8c1 100644
--- a/tests/marionette/tests/links/html_anchor_element/test_open_in_new_tab.py
+++ b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_tab.py
@@ -4,9 +4,6 @@
from rp_ui_harness import RequestPolicyTestCase
from marionette_driver.marionette import Actions
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
-from rp_puppeteer.ui.context_menu import ContextMenu
-from rp_puppeteer.ui.tabs import Tabs
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -18,10 +15,6 @@ class TestOpenInNewTab(RequestPolicyTestCase):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
- self.tabs = Tabs(lambda: self.marionette)
- self.ctx_menu = ContextMenu(lambda: self.marionette)
-
def test_open_in_new_tab(self):
with self.marionette.using_context("content"):
diff --git a/tests/marionette/tests/links/html_anchor_element/test_open_in_new_window.py b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_window.py
index bb2c713..9f14bbb 100644
--- a/tests/marionette/tests/links/html_anchor_element/test_open_in_new_window.py
+++ b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_window.py
@@ -3,9 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
-from rp_puppeteer.ui.context_menu import ContextMenu
-from rp_puppeteer.ui.tabs import Tabs
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -16,7 +13,6 @@ class TestOpenInNewWindow(RequestPolicyTestCase):
def setUp(self):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
self.main_window = self.windows.current
@@ -53,7 +49,7 @@ class TestOpenInNewWindow(RequestPolicyTestCase):
# checks in the destination's window
tab = new_window.tabbar.selected_tab
- Tabs(lambda: self.marionette).wait_until_loaded(tab)
+ self.tabs.wait_until_loaded(tab)
self.assertEqual(tab.location, link_url,
"The location in the new window is correct.")
self.assertFalse(self.redir.panel_exists(),
@@ -75,10 +71,10 @@ class TestOpenInNewWindow(RequestPolicyTestCase):
"""Open a link in new window using different methods."""
context_menu_ids = [
- "context-openlink", # Open Link in New Window
- "context-openlinkprivate" # Open Link in New Private Window
+ "context-openlink", # Open Link in New Window
+ "context-openlinkprivate" # Open Link in New Private Window
]
for id in context_menu_ids:
- ContextMenu(lambda: self.marionette).select_entry(id, link)
+ self.ctx_menu.select_entry(id, link)
yield
diff --git a/tests/marionette/tests/links/text_selection/test_open_in_current_tab.py b/tests/marionette/tests/links/text_selection/test_open_in_current_tab.py
index 1cfffaa..fa57417 100644
--- a/tests/marionette/tests/links/text_selection/test_open_in_current_tab.py
+++ b/tests/marionette/tests/links/text_selection/test_open_in_current_tab.py
@@ -3,10 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
-from rp_puppeteer.ui.context_menu import ContextMenu
-from rp_puppeteer.ui.tabs import Tabs
-from rp_puppeteer.ui.web_utils import WebUtils
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -19,11 +15,6 @@ class TestOpenInCurrentTab(RequestPolicyTestCase):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
- self.web_utils = WebUtils(lambda: self.marionette)
- self.tabs = Tabs(lambda: self.marionette)
- self.ctx_menu = ContextMenu(lambda: self.marionette)
-
def test_open_in_current_tab(self):
with self.marionette.using_context("content"):
diff --git a/tests/marionette/tests/links/text_selection/test_open_in_new_tab.py b/tests/marionette/tests/links/text_selection/test_open_in_new_tab.py
index 8449b6e..2bca14b 100644
--- a/tests/marionette/tests/links/text_selection/test_open_in_new_tab.py
+++ b/tests/marionette/tests/links/text_selection/test_open_in_new_tab.py
@@ -3,10 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
-from rp_puppeteer.ui.context_menu import ContextMenu
-from rp_puppeteer.ui.tabs import Tabs
-from rp_puppeteer.ui.web_utils import WebUtils
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -19,11 +15,6 @@ class TestOpenInNewTab(RequestPolicyTestCase):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
- self.web_utils = WebUtils(lambda: self.marionette)
- self.tabs = Tabs(lambda: self.marionette)
- self.ctx_menu = ContextMenu(lambda: self.marionette)
-
def test_open_in_new_tab(self):
with self.marionette.using_context("content"):
diff --git a/tests/marionette/tests/links/text_selection/test_open_in_new_window.py b/tests/marionette/tests/links/text_selection/test_open_in_new_window.py
index 814e911..0abe687 100644
--- a/tests/marionette/tests/links/text_selection/test_open_in_new_window.py
+++ b/tests/marionette/tests/links/text_selection/test_open_in_new_window.py
@@ -3,10 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from rp_ui_harness import RequestPolicyTestCase
-from rp_puppeteer.ui.redirect_notification import RedirectNotification
-from rp_puppeteer.ui.context_menu import ContextMenu
-from rp_puppeteer.ui.tabs import Tabs
-from rp_puppeteer.ui.web_utils import WebUtils
TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -19,11 +15,6 @@ class TestOpenInNewWindow(RequestPolicyTestCase):
RequestPolicyTestCase.setUp(self)
self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
- self.redir = RedirectNotification(lambda: self.marionette)
- self.web_utils = WebUtils(lambda: self.marionette)
- self.tabs = Tabs(lambda: self.marionette)
- self.ctx_menu = ContextMenu(lambda: self.marionette)
-
self.origin_window = self.windows.current
def tearDown(self):
@@ -79,8 +70,8 @@ class TestOpenInNewWindow(RequestPolicyTestCase):
"""Open a selected URL in new window using different methods."""
context_menu_ids = [
- "context-openlink", # Open Link in New Window
- "context-openlinkprivate" # Open Link in New Private Window
+ "context-openlink", # Open Link in New Window
+ "context-openlinkprivate" # Open Link in New Private Window
]
for id in context_menu_ids:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list