[Pkg-mozext-commits] [requestpolicy] 81/257: [tst][fix] ctx_menu: `select_entry()`, `_close()`
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:19:59 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 b7c2ddab1898879b509ed1a99c8406d1eb91a31d
Author: Martin Kimmerle <dev at 256k.de>
Date: Wed Oct 14 21:52:17 2015 +0200
[tst][fix] ctx_menu: `select_entry()`, `_close()`
* `select_entry()` should always close the context menu in the
end.
* `select_entry()` should raise `ElementNotDisplayedException`.
* `self.state` must be compared using "==", not "is"!
---
tests/marionette/rp_puppeteer/errors.py | 3 ++
tests/marionette/rp_puppeteer/tests/manifest.ini | 1 +
.../rp_puppeteer/tests/test_context_menu.py | 45 ++++++++++++++++++++++
tests/marionette/rp_puppeteer/ui/context_menu.py | 19 +++++++--
4 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/tests/marionette/rp_puppeteer/errors.py b/tests/marionette/rp_puppeteer/errors.py
index 4b8231f..3edcabd 100644
--- a/tests/marionette/rp_puppeteer/errors.py
+++ b/tests/marionette/rp_puppeteer/errors.py
@@ -5,5 +5,8 @@
from marionette_driver.errors import MarionetteException
+class ElementNotDisplayedException(MarionetteException):
+ pass
+
class RadioButtonException(MarionetteException):
pass
diff --git a/tests/marionette/rp_puppeteer/tests/manifest.ini b/tests/marionette/rp_puppeteer/tests/manifest.ini
index 290d1a2..1315bf2 100644
--- a/tests/marionette/rp_puppeteer/tests/manifest.ini
+++ b/tests/marionette/rp_puppeteer/tests/manifest.ini
@@ -1,4 +1,5 @@
[test_addons.py]
+[test_context_menu.py]
[test_error_detection.py]
[test_l10n.py]
[test_prefs.py]
diff --git a/tests/marionette/rp_puppeteer/tests/test_context_menu.py b/tests/marionette/rp_puppeteer/tests/test_context_menu.py
new file mode 100644
index 0000000..88b768d
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/tests/test_context_menu.py
@@ -0,0 +1,45 @@
+# 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.testcases import RequestPolicyTestCase
+from rp_puppeteer.errors import ElementNotDisplayedException
+from marionette_driver.errors import NoSuchElementException
+
+
+class TestLinkClickRedirectInNewTab(RequestPolicyTestCase):
+
+ def setUp(self):
+ super(TestLinkClickRedirectInNewTab, self).setUp()
+
+ # A page with a link to the domain's root.
+ self.test_url = "http://www.maindomain.test/link.html?/"
+ with self.marionette.using_context("content"):
+ self.marionette.navigate(self.test_url)
+ self.link = self.marionette.find_element("tag name", "a")
+ self.origin_tab = self.browser.tabbar.selected_tab
+
+ def tearDown(self):
+ try:
+ self.browser.tabbar.close_all_tabs(exceptions=[self.origin_tab])
+ finally:
+ super(TestLinkClickRedirectInNewTab, self).tearDown()
+
+ def test_select_entry__normal(self):
+ # Open Link in New Tab.
+ self.ctx_menu.select_entry("context-openlinkintab", self.link)
+ self.assertEqual(self.browser.tabbar.selected_tab, self.origin_tab,
+ "The tab has not changed.")
+ self.assertEqual(self.ctx_menu.state, "closed")
+
+ def test_select_entry__nonexistant(self):
+ with self.assertRaises(NoSuchElementException):
+ self.ctx_menu.select_entry("foo-bar-nonexistant", self.link)
+ self.assertEqual(self.ctx_menu.state, "closed")
+
+ def test_select_entry__invisible(self):
+ with self.assertRaises(ElementNotDisplayedException):
+ # Select the "Copy" entry, which exists but is not shown when
+ # right-clicking on a link.
+ self.ctx_menu.select_entry("context-copy", self.link)
+ self.assertEqual(self.ctx_menu.state, "closed")
diff --git a/tests/marionette/rp_puppeteer/ui/context_menu.py b/tests/marionette/rp_puppeteer/ui/context_menu.py
index fde30fc..839a61c 100644
--- a/tests/marionette/rp_puppeteer/ui/context_menu.py
+++ b/tests/marionette/rp_puppeteer/ui/context_menu.py
@@ -6,6 +6,7 @@ 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
+from rp_puppeteer.errors import ElementNotDisplayedException
class ContextMenu(BaseLib):
@@ -26,8 +27,11 @@ class ContextMenu(BaseLib):
"""Select a specific entry in the context menu of an HTMLElement."""
self._open(context_element)
- self._click(entry_id)
- self._close()
+ try:
+ self._click(entry_id)
+ finally:
+ # The context menu should always be closed.
+ self._close()
##################################
# Private Properties and Methods #
@@ -50,8 +54,15 @@ class ContextMenu(BaseLib):
def _click(self, entry_id):
"""Click on an entry in the menu."""
+ def is_displayed(entry):
+ rect = entry.rect
+ return rect["width"] > 0 and rect["height"] > 0
+
entry = self.element.find_element("id", entry_id)
- entry.click()
+ if is_displayed(entry):
+ entry.click()
+ else:
+ raise ElementNotDisplayedException
def _close(self):
"""Close the context menu."""
@@ -59,7 +70,7 @@ class ContextMenu(BaseLib):
# 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 self.state is "open":
+ if self.state == "open":
self.element.send_keys(Keys.ESCAPE)
self._wait_for_state("closed")
--
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