Bug 1271911 - Enhance utils module for permissions. r?maja_zf
MozReview-Commit-ID: GfpvGV2uhFx
--- a/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py
+++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py
@@ -46,17 +46,17 @@ class TestSafeBrowsingNotificationBar(Fi
time.sleep(3)
# TODO: Bug 1139544: While we don't have a reliable way to close the safe browsing
# notification bar when a test fails, run this test in a new tab.
self.browser.tabbar.open_tab()
def tearDown(self):
try:
- self.utils.remove_perms('https://www.itisatrap.org', 'safe-browsing')
+ self.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
finally:
FirefoxTestCase.tearDown(self)
def test_notification_bar(self):
with self.marionette.using_context('content'):
for item in self.test_data:
button_property = item['button_property']
@@ -92,17 +92,17 @@ class TestSafeBrowsingNotificationBar(Fi
button = self.marionette.find_element(By.ID, 'ignoreWarningButton')
button.click()
Wait(self.marionette, timeout=self.browser.timeout_page_load).until(
expected.element_present(By.ID, 'main-feature'))
self.assertEquals(self.marionette.get_url(), self.browser.get_final_url(unsafe_page))
# Clean up here since the permission gets set in this function
- self.utils.remove_perms('https://www.itisatrap.org', 'safe-browsing')
+ self.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
# Check the not a forgery or attack button in the notification bar
def check_not_badware_button(self, button_property, report_page):
with self.marionette.using_context('chrome'):
# TODO: update to use safe browsing notification bar class when bug 1139544 lands
label = self.browser.get_property(button_property)
button = (self.marionette.find_element(By.ID, 'content')
.find_element('anon attribute', {'label': label}))
--- a/testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py
+++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py
@@ -32,17 +32,17 @@ class TestSafeBrowsingWarningPages(Firef
time.sleep(3)
# TODO: Bug 1139544: While we don't have a reliable way to close the safe browsing
# notification bar when a test fails, run this test in a new tab.
self.browser.tabbar.open_tab()
def tearDown(self):
try:
- self.utils.remove_perms('https://www.itisatrap.org', 'safe-browsing')
+ self.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
finally:
FirefoxTestCase.tearDown(self)
def test_warning_pages(self):
with self.marionette.using_context("content"):
for unsafe_page in self.urls:
# Load a test page, then test the get me out button
@@ -101,9 +101,9 @@ class TestSafeBrowsingWarningPages(Firef
button = self.marionette.find_element(By.ID, 'ignoreWarningButton')
button.click()
Wait(self.marionette, timeout=self.browser.timeout_page_load).until(
expected.element_present(By.ID, 'main-feature'))
self.assertEquals(self.marionette.get_url(), self.browser.get_final_url(unsafe_page))
# Clean up by removing safe browsing permission for unsafe page
- self.utils.remove_perms('https://www.itisatrap.org', 'safe-browsing')
+ self.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
--- a/testing/puppeteer/firefox/firefox_puppeteer/api/utils.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/api/utils.py
@@ -5,46 +5,42 @@
from marionette_driver.errors import MarionetteException
from firefox_puppeteer.base import BaseLib
class Utils(BaseLib):
"""Low-level access to utility actions."""
+ def __init__(self, *args, **kwargs):
+ BaseLib.__init__(self, *args, **kwargs)
+
+ self._permissions = Permissions(lambda: self.marionette)
+
+ @property
+ def permissions(self):
+ """Handling of various permissions for hosts.
+
+ :returns: Instance of the Permissions class.
+ """
+ return self._permissions
+
def compare_version(self, a, b):
"""Compare two version strings.
:param a: The first version.
:param b: The second version.
:returns: -1 if a is smaller than b, 0 if equal, and 1 if larger.
"""
return self.marionette.execute_script("""
Components.utils.import("resource://gre/modules/Services.jsm");
return Services.vc.compare(arguments[0], arguments[1]);
""", script_args=[a, b])
- def remove_perms(self, host, permission):
- """Remove permission for web host.
-
- Permissions include safe-browsing, install, geolocation, and others described here:
- https://dxr.mozilla.org/mozilla-central/source/browser/modules/SitePermissions.jsm#144
- and elsewhere.
-
- :param host: The web host whose permission will be removed.
- :param permission: The type of permission to be removed.
- """
- with self.marionette.using_context('chrome'):
- self.marionette.execute_script("""
- Components.utils.import("resource://gre/modules/Services.jsm");
- let uri = Services.io.newURI(arguments[0], null, null);
- Services.perms.remove(uri, arguments[1]);
- """, script_args=[host, permission])
-
def sanitize(self, data_type):
"""Sanitize user data, including cache, cookies, offlineApps, history, formdata,
downloads, passwords, sessions, siteSettings.
Usage:
sanitize(): Clears all user data.
sanitize({ "sessions": True }): Clears only session user data.
@@ -99,8 +95,46 @@ class Utils(BaseLib):
itemPrefs.clearUserPref(pref);
};
marionetteScriptFinished(false);
});
""", script_args=[data_type])
if not result:
raise MarionetteException('Sanitizing of profile data failed.')
+
+
+class Permissions(BaseLib):
+
+ def add(self, host, permission):
+ """Add a permission for web host.
+
+ Permissions include safe-browsing, install, geolocation, and others described here:
+ https://dxr.mozilla.org/mozilla-central/source/browser/modules/SitePermissions.jsm#144
+ and elsewhere.
+
+ :param host: The web host whose permission will be added.
+ :param permission: The type of permission to be added.
+ """
+ with self.marionette.using_context('chrome'):
+ self.marionette.execute_script("""
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ let uri = Services.io.newURI(arguments[0], null, null);
+ Services.perms.add(uri, arguments[1],
+ Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
+ """, script_args=[host, permission])
+
+ def remove(self, host, permission):
+ """Remove a permission for web host.
+
+ Permissions include safe-browsing, install, geolocation, and others described here:
+ https://dxr.mozilla.org/mozilla-central/source/browser/modules/SitePermissions.jsm#144
+ and elsewhere.
+
+ :param host: The web host whose permission will be removed.
+ :param permission: The type of permission to be removed.
+ """
+ with self.marionette.using_context('chrome'):
+ self.marionette.execute_script("""
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ let uri = Services.io.newURI(arguments[0], null, null);
+ Services.perms.remove(uri, arguments[1]);
+ """, script_args=[host, permission])