[Pkg-mozext-commits] [requestpolicy] 54/257: [tst][add] Marionette test: open selURL in current tab

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 df608fd9bf463bb2133b954dd5cb7d2b67ecf741
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu Sep 10 11:32:45 2015 +0200

    [tst][add] Marionette test: open selURL in current tab
    
    Convert Mozmill test
    "testLinks/testTextSelection/testOpenInCurrentTab.js"
    to Marionette.
---
 tests/marionette/rp_puppeteer/ui/context_menu.py   |  6 ++-
 tests/marionette/rp_puppeteer/ui/web_utils.py      | 21 +++++++++
 tests/marionette/tests/links/manifest.ini          |  1 +
 .../tests/links/text_selection/manifest.ini        |  1 +
 .../text_selection/test_open_in_current_tab.py     | 50 ++++++++++++++++++++++
 5 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/tests/marionette/rp_puppeteer/ui/context_menu.py b/tests/marionette/rp_puppeteer/ui/context_menu.py
index a347283..2b1067e 100644
--- a/tests/marionette/rp_puppeteer/ui/context_menu.py
+++ b/tests/marionette/rp_puppeteer/ui/context_menu.py
@@ -45,7 +45,11 @@ class ContextMenu(BaseLib):
     def _close(self, menu):
         """Close the context menu."""
 
-        menu.send_keys(Keys.ESCAPE)
+        # Only close if the menu is open. The menu for example closes itself
+        # in case the URL in the current tab changes. Sending ESC to a menu
+        # which is _not_ open anymore will cause the page load to stop.
+        if menu.get_attribute("state") is "open":
+            menu.send_keys(Keys.ESCAPE)
         self._wait_for_state(menu, "closed")
 
 
diff --git a/tests/marionette/rp_puppeteer/ui/web_utils.py b/tests/marionette/rp_puppeteer/ui/web_utils.py
new file mode 100644
index 0000000..20d0a6a
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/ui/web_utils.py
@@ -0,0 +1,21 @@
+# 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
+
+
+class WebUtils(BaseLib):
+    """Utils for the Web API."""
+
+    def select_element_text(self, element):
+        """Select the text content of an HTML Element."""
+
+        self.marionette.execute_script("""
+          var element = arguments[0];
+          var selection = element.ownerDocument.defaultView.getSelection();
+          var range = element.ownerDocument.createRange();
+          range.selectNodeContents(element);
+          selection.removeAllRanges();
+          selection.addRange(range);
+        """, script_args=[element])
diff --git a/tests/marionette/tests/links/manifest.ini b/tests/marionette/tests/links/manifest.ini
index 49e9c81..4453c04 100644
--- a/tests/marionette/tests/links/manifest.ini
+++ b/tests/marionette/tests/links/manifest.ini
@@ -1 +1,2 @@
 [include:html_anchor_element/manifest.ini]
+[include:text_selection/manifest.ini]
diff --git a/tests/marionette/tests/links/text_selection/manifest.ini b/tests/marionette/tests/links/text_selection/manifest.ini
new file mode 100644
index 0000000..518987f
--- /dev/null
+++ b/tests/marionette/tests/links/text_selection/manifest.ini
@@ -0,0 +1 @@
+[test_open_in_current_tab.py]
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
new file mode 100644
index 0000000..1cfffaa
--- /dev/null
+++ b/tests/marionette/tests/links/text_selection/test_open_in_current_tab.py
@@ -0,0 +1,50 @@
+# 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 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";
+PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow"
+
+
+class TestOpenInCurrentTab(RequestPolicyTestCase):
+
+    def setUp(self):
+        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"):
+            # load the test url
+            self.marionette.navigate(TEST_URL)
+
+            # find the URL string and its wrapping element
+            url_wrapper = self.marionette.find_element("id", "text_url_1")
+            url = url_wrapper.get_attribute("textContent")
+
+            # select the URL
+            self.web_utils.select_element_text(url_wrapper)
+
+        with self.marionette.using_context("chrome"):
+            # perform right-click and entry selection
+            self.ctx_menu.select_entry("context-openlinkincurrent", url_wrapper)
+
+            tab = self.browser.tabbar.selected_tab
+            self.tabs.wait_until_loaded(tab)
+
+            self.assertFalse(self.redir.panel_exists(),
+                             "Following the URL didn't cause a redirect.")
+            self.assertEqual(tab.location, url,
+                             "The location is correct.")

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