[Pkg-mozext-commits] [requestpolicy] 51/257: [tst][add] Marionette test: open <a> in new tab

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:19:55 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 1a06eb417d243e80f5e6906878a52dbc54742698
Author: Martin Kimmerle <dev at 256k.de>
Date:   Wed Sep 9 15:33:35 2015 +0200

    [tst][add] Marionette test: open <a> in new tab
    
    Convert Mozmill test
    "testLinks/testHTMLAnchorElement/testOpenInNewTab.js"
    to Marionette.
---
 tests/marionette/rp_puppeteer/ui/context_menu.py   | 55 ++++++++++++++++
 .../tests/links/html_anchor_element/manifest.ini   |  1 +
 .../html_anchor_element/test_open_in_new_tab.py    | 73 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/tests/marionette/rp_puppeteer/ui/context_menu.py b/tests/marionette/rp_puppeteer/ui/context_menu.py
new file mode 100644
index 0000000..a347283
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/ui/context_menu.py
@@ -0,0 +1,55 @@
+# 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.base import BaseLib
+from firefox_puppeteer.api.keys import Keys
+from marionette_driver.marionette import Actions
+from marionette_driver.wait import Wait
+
+
+class ContextMenu(BaseLib):
+    def select_entry(self, entry_id, context_element):
+        """Select a specific entry in the context menu of an HTMLElement.
+        """
+
+        menu = self.marionette.find_element("id", "contentAreaContextMenu")
+
+        self._open(menu, context_element)
+        self._click(menu, entry_id)
+        self._close(menu)
+
+
+    def _open(self, menu, context_element):
+        """Open the context menu."""
+
+        with self.marionette.using_context("content"):
+            # right click on the HTML element
+            Actions(self.marionette).click(context_element, 2).perform()
+
+        self._wait_for_state(menu, "open")
+
+        # FIXME: Sub-menus aren't currently supported. To support those,
+        #        implement the Mozmill Controller's `_buildMenu()` function.
+        #        It populates all submenus of the context menu recursively.
+        #        Right now only top-level menu entries can be selected.
+
+
+    def _click(self, menu, entry_id):
+        """Click on an entry in the menu."""
+
+        entry = menu.find_element("id", entry_id)
+        Actions(self.marionette).click(entry).perform()
+
+
+    def _close(self, menu):
+        """Close the context menu."""
+
+        menu.send_keys(Keys.ESCAPE)
+        self._wait_for_state(menu, "closed")
+
+
+    def _wait_for_state(self, menu, state):
+        Wait(self.marionette).until(
+            lambda m: menu.get_attribute("state") == state,
+            message="The menu's state is now '" + state + "'.")
diff --git a/tests/marionette/tests/links/html_anchor_element/manifest.ini b/tests/marionette/tests/links/html_anchor_element/manifest.ini
index 89bd789..52d59c7 100644
--- a/tests/marionette/tests/links/html_anchor_element/manifest.ini
+++ b/tests/marionette/tests/links/html_anchor_element/manifest.ini
@@ -1 +1,2 @@
 [test_link_click.py]
+[test_open_in_new_tab.py]
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
new file mode 100644
index 0000000..f51f09d
--- /dev/null
+++ b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_tab.py
@@ -0,0 +1,73 @@
+# 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 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
+
+
+TEST_URL = "http://www.maindomain.test/link_1.html";
+PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow"
+
+
+class TestOpenInNewTab(RequestPolicyTestCase):
+    def setUp(self):
+        RequestPolicyTestCase.setUp(self)
+        self.prefs.set_pref(PREF_DEFAULT_ALLOW, False);
+        self.redir = RedirectNotification(lambda: self.marionette)
+
+
+    def test_open_in_new_tab(self):
+        with self.marionette.using_context("content"):
+            # load the test url
+            self.marionette.navigate(TEST_URL)
+            # get the link and its url
+            link = self.marionette.find_element("tag name", "a")
+            link_url = link.get_attribute("href")
+
+        with self.marionette.using_context("chrome"):
+            # Open the link in a new tab, using all possible methods
+            # sequentially.
+            for _ in self.open_link_multi(link):
+                self.assertEqual(len(self.browser.tabbar.tabs), 2,
+                                 "A new tab has been opened.")
+
+                # checks in the origin's tab
+                self.assertFalse(self.redir.panel_exists(),
+                                 ("Following the link didn't cause a "
+                                  "redirect in the origin tab."))
+
+                # the destination's tab
+                tab = self.browser.tabbar.tabs[-1]
+                tab.switch_to()
+                # checks in the destination's tab
+                self.assertEqual(tab.location, link_url,
+                                 "The location in the new tab is correct.")
+                self.assertFalse(self.redir.panel_exists(),
+                                 ("Following the link didn't cause a "
+                                  "redirect in the destination tab."))
+                tab.close()
+
+
+    def open_link_multi(self, link):
+        """Open a link in new tabs using different methods."""
+
+        # METHOD #1: middle click
+        with self.marionette.using_context("content"):
+            Actions(self.marionette).click(link, 1).perform()
+        yield
+
+        # METHOD #2: context menu
+        (
+            ContextMenu(lambda: self.marionette)
+            .select_entry("context-openlinkintab", link)
+        )
+        # TODO: Use the "tabs" library as soon as it has been ported
+        #       to Marionette, see Mozilla Bug 1121725.
+        #       The mozmill code to open the link in a new tab was:
+        #       ```
+        #       tabBrowser.openTab({method: "contextMenu", target: link});
+        #       ```
+        yield

-- 
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