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

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 5c5ec1f8cb3e3deee794420e35378901fce2ce04
Author: Martin Kimmerle <dev at 256k.de>
Date:   Wed Sep 9 15:34:22 2015 +0200

    [tst][add] Marionette test: open <a> in new window
    
    Convert Mozmill test
    "testLinks/testHTMLAnchorElement/testOpenInNewWindow.js"
    to Marionette.
---
 tests/marionette/rp_puppeteer/ui/tabs.py           | 14 ++++
 .../tests/links/html_anchor_element/manifest.ini   |  1 +
 .../html_anchor_element/test_open_in_new_window.py | 84 ++++++++++++++++++++++
 3 files changed, 99 insertions(+)

diff --git a/tests/marionette/rp_puppeteer/ui/tabs.py b/tests/marionette/rp_puppeteer/ui/tabs.py
new file mode 100644
index 0000000..70385b6
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/ui/tabs.py
@@ -0,0 +1,14 @@
+# 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 marionette_driver.wait import Wait
+
+
+class Tabs(BaseLib):
+    def is_loaded(self, tab):
+        return tab.tab_element.get_attribute("busy") == None
+
+    def wait_until_loaded(self, tab):
+        Wait(self.marionette).until(lambda _: self.is_loaded(tab))
diff --git a/tests/marionette/tests/links/html_anchor_element/manifest.ini b/tests/marionette/tests/links/html_anchor_element/manifest.ini
index 52d59c7..2b35d0e 100644
--- a/tests/marionette/tests/links/html_anchor_element/manifest.ini
+++ b/tests/marionette/tests/links/html_anchor_element/manifest.ini
@@ -1,2 +1,3 @@
 [test_link_click.py]
 [test_open_in_new_tab.py]
+[test_open_in_new_window.py]
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
new file mode 100644
index 0000000..bb2c713
--- /dev/null
+++ b/tests/marionette/tests/links/html_anchor_element/test_open_in_new_window.py
@@ -0,0 +1,84 @@
+# 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
+
+
+TEST_URL = "http://www.maindomain.test/link_1.html";
+PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow"
+
+
+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
+
+
+    def tearDown(self):
+        self.windows.close_all(exceptions=[self.main_window])
+        RequestPolicyTestCase.tearDown(self)
+
+
+    def test_open_in_new_window(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"):
+            self.assertEqual(len(self.windows.all), 1, "There is only one window.")
+
+            # Open the link in a new tab, using all possible methods
+            # sequentially.
+            for _ in self.open_link_multi(link):
+                self.assertEqual(len(self.windows.all), 2,
+                                 "A new window has been opened.")
+
+                new_window_handle = self.windows.focused_chrome_window_handle
+                self.assertNotEqual(new_window_handle, self.main_window.handle,
+                                    "The new window has been focused.")
+                new_window = self.windows.create_window_instance(
+                    new_window_handle
+                )
+                # Switch to the new window.
+                new_window.switch_to()
+
+                # checks in the destination's window
+                tab = new_window.tabbar.selected_tab
+                Tabs(lambda: self.marionette).wait_until_loaded(tab)
+                self.assertEqual(tab.location, link_url,
+                                 "The location in the new window is correct.")
+                self.assertFalse(self.redir.panel_exists(),
+                                 ("Following the link didn't cause a "
+                                  "redirect in the destination window."))
+
+                # Close the new window.
+                self.windows.close_all(exceptions=[self.main_window])
+                # It's necessary to switch back to the main window.
+                self.main_window.switch_to()
+
+                # checks in the origin's window
+                self.assertFalse(self.redir.panel_exists(),
+                                 ("Following the link didn't cause a "
+                                  "redirect in the origin tab."))
+
+
+    def open_link_multi(self, link):
+        """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
+        ]
+
+        for id in context_menu_ids:
+            ContextMenu(lambda: self.marionette).select_entry(id, 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