Bug 1303863 - Remove restore_pref and restore_all_prefs methods from Firefox Puppeteer.
MozReview-Commit-ID: 7GdwCK98Rsb
--- a/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py
+++ b/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py
@@ -26,16 +26,18 @@ class TestFaviconInAutocomplete(FirefoxT
self.test_string = 'mozilla'
self.test_favicon = 'mozilla_favicon.ico'
self.autocomplete_results = self.browser.navbar.locationbar.autocomplete_results
def tearDown(self):
try:
self.autocomplete_results.close(force=True)
+ self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES)
+ self.marionette.clear_pref(self.PREF_SUGGEST_BOOKMARK)
finally:
FirefoxTestCase.tearDown(self)
def test_favicon_in_autocomplete(self):
# Open the test page
def load_urls():
with self.marionette.using_context('content'):
self.marionette.navigate(self.test_urls[0])
--- a/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py
+++ b/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py
@@ -34,16 +34,17 @@ class TestStarInAutocomplete(FirefoxTest
try:
if self.bookmark_panel:
self.marionette.execute_script("""
arguments[0].hidePopup();
""", script_args=[self.bookmark_panel])
self.browser.navbar.locationbar.autocomplete_results.close()
self.places.restore_default_bookmarks()
+ self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES)
finally:
FirefoxTestCase.tearDown(self)
def test_star_in_autocomplete(self):
search_string = 'grants'
def visit_urls():
with self.marionette.using_context('content'):
--- a/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
+++ b/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
@@ -15,16 +15,22 @@ class TestAboutPrivateBrowsing(FirefoxTe
FirefoxTestCase.setUp(self)
# Use a fake local support URL
support_url = 'about:blank?'
self.prefs.set_pref('app.support.baseURL', support_url)
self.pb_url = support_url + 'private-browsing'
+ def tearDown(self):
+ try:
+ self.marionette.clear_pref('app.support.baseURL')
+ finally:
+ FirefoxTestCase.tearDown(self)
+
def testCheckAboutPrivateBrowsing(self):
self.assertFalse(self.browser.is_private)
with self.marionette.using_context('content'):
self.marionette.navigate('about:privatebrowsing')
status_node = self.marionette.find_element(By.CSS_SELECTOR, 'p.showNormal')
self.assertEqual(status_node.text,
--- a/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py
+++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py
@@ -48,16 +48,18 @@ class TestSafeBrowsingNotificationBar(Fi
# 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.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
+ self.marionette.clear_pref('browser.safebrowsing.phishing.enabled')
+ self.marionette.clear_pref('browser.safebrowsing.malware.enabled')
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']
report_page, unsafe_page = item['report_page'], item['unsafe_page']
--- 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
@@ -34,16 +34,18 @@ class TestSafeBrowsingWarningPages(Firef
# 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.permissions.remove('https://www.itisatrap.org', 'safe-browsing')
self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
+ self.marionette.clear_pref('browser.safebrowsing.malware.enabled')
+ self.marionette.clear_pref('browser.safebrowsing.phishing.enabled')
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
self.marionette.navigate(unsafe_page)
--- a/testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py
+++ b/testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py
@@ -20,16 +20,23 @@ class TestSSLDisabledErrorPage(FirefoxTe
self.utils.sanitize({"sessions": True})
# Disable SSL 3.0, TLS 1.0 and TLS 1.1 for secure connections
# by forcing the use of TLS 1.2
# see: http://kb.mozillazine.org/Security.tls.version.*#Possible_values_and_their_effects
self.prefs.set_pref('security.tls.version.min', 3)
self.prefs.set_pref('security.tls.version.max', 3)
+ def tearDown(self):
+ try:
+ self.marionette.clear_pref('security.tls.version.min')
+ self.marionette.clear_pref('security.tls.version.max')
+ finally:
+ FirefoxTestCase.tearDown(self)
+
def test_ssl_disabled_error_page(self):
with self.marionette.using_context('content'):
# Open the test page
self.assertRaises(MarionetteException, self.marionette.navigate, self.url)
# Wait for the DOM to receive events
time.sleep(1)
--- a/testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py
+++ b/testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py
@@ -38,16 +38,17 @@ class TestSSLStatusAfterRestart(FirefoxT
self.identity_popup = self.locationbar.identity_popup
def tearDown(self):
try:
self.windows.close_all([self.browser])
self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
self.browser.switch_to()
self.identity_popup.close(force=True)
+ self.marionette.clear_pref('browser.startup.page')
finally:
FirefoxTestCase.tearDown(self)
@skip_if_e10s
def test_ssl_status_after_restart(self):
for item in self.test_data:
with self.marionette.using_context('content'):
self.marionette.navigate(item['url'])
--- a/testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py
+++ b/testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py
@@ -15,16 +15,22 @@ class TestSubmitUnencryptedInfoWarning(F
def setUp(self):
FirefoxTestCase.setUp(self)
self.url = 'https://ssl-dv.mozqa.com/data/firefox/security/unencryptedsearch.html'
self.test_string = 'mozilla'
self.prefs.set_pref('security.warn_submit_insecure', True)
+ def tearDown(self):
+ try:
+ self.marionette.clear_pref('security.warn_submit_insecure')
+ finally:
+ FirefoxTestCase.tearDown(self)
+
def test_submit_unencrypted_info_warning(self):
with self.marionette.using_context('content'):
self.marionette.navigate(self.url)
# Get the page's search box and submit button.
searchbox = self.marionette.find_element(By.ID, 'q')
button = self.marionette.find_element(By.ID, 'submit')
--- a/testing/firefox-ui/tests/puppeteer/test_notifications.py
+++ b/testing/firefox-ui/tests/puppeteer/test_notifications.py
@@ -19,16 +19,19 @@ class TestNotifications(FirefoxTestCase)
self.prefs.set_pref('extensions.install.requireSecureOrigin', False)
self.addons_url = self.marionette.absolute_url('addons/extensions/')
self.utils.permissions.add(self.marionette.baseurl, 'install')
def tearDown(self):
try:
+ self.marionette.clear_pref('extensions.install.requireSecureOrigin')
+ self.marionette.clear_pref('xpinstall.signatures.required')
+
self.utils.permissions.remove(self.addons_url, 'install')
if self.browser.notification:
self.browser.notification.close(force=True)
finally:
FirefoxTestCase.tearDown(self)
def test_open_close_notification(self):
--- a/testing/firefox-ui/tests/puppeteer/test_prefs.py
+++ b/testing/firefox-ui/tests/puppeteer/test_prefs.py
@@ -1,39 +1,38 @@
# 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 marionette_driver.errors import MarionetteException
-
from firefox_ui_harness.testcases import FirefoxTestCase
class testPreferences(FirefoxTestCase):
def setUp(self):
FirefoxTestCase.setUp(self)
self.new_pref = 'marionette.unittest.set_pref'
self.unknown_pref = 'marionette.unittest.unknown'
self.bool_pref = 'browser.tabs.loadBookmarksInBackground'
self.int_pref = 'browser.tabs.maxOpenBeforeWarn'
- self.string_pref = 'browser.newtab.url'
-
- def test_reset_pref(self):
- self.prefs.set_pref(self.new_pref, 'unittest')
- self.assertEqual(self.prefs.get_pref(self.new_pref), 'unittest')
+ # Consider using new test preferences
+ # See Bug 1303863 Comment #32
+ self.string_pref = 'browser.startup.homepage'
- # Preference gets removed
- self.assertTrue(self.prefs.reset_pref(self.new_pref))
- self.assertEqual(self.prefs.get_pref(self.new_pref), None)
-
- # There is no such preference anymore
- self.assertFalse(self.prefs.reset_pref(self.new_pref))
+ def tearDown(self):
+ try:
+ self.marionette.clear_pref('marionette.unittest.set_pref')
+ self.marionette.clear_pref('marionette.unittest.unknown')
+ self.marionette.clear_pref('browser.tabs.loadBookmarksInBackground')
+ self.marionette.clear_pref('browser.tabs.maxOpenBeforeWarn')
+ self.marionette.clear_pref('browser.startup.homepage')
+ finally:
+ FirefoxTestCase.tearDown(self)
def test_get_pref(self):
# check correct types
self.assertTrue(isinstance(self.prefs.get_pref(self.bool_pref),
bool))
self.assertTrue(isinstance(self.prefs.get_pref(self.int_pref),
int))
self.assertTrue(isinstance(self.prefs.get_pref(self.string_pref),
@@ -52,105 +51,96 @@ class testPreferences(FirefoxTestCase):
properties_file = 'chrome://branding/locale/browserconfig.properties'
self.assertEqual(self.prefs.get_pref('browser.startup.homepage'),
properties_file)
value = self.prefs.get_pref('browser.startup.homepage',
interface='nsIPrefLocalizedString')
self.assertNotEqual(value, properties_file)
- def test_restore_pref(self):
- # test with single set_pref call and a new preference
- self.prefs.set_pref(self.new_pref, True)
- self.assertTrue(self.prefs.get_pref(self.new_pref))
- self.prefs.restore_pref(self.new_pref)
-
- orig_value = self.prefs.get_pref(self.string_pref)
-
- # test with single set_pref call
- self.prefs.set_pref(self.string_pref, 'unittest')
- self.assertEqual(self.prefs.get_pref(self.string_pref), 'unittest')
- self.prefs.restore_pref(self.string_pref)
- self.assertEqual(self.prefs.get_pref(self.string_pref), orig_value)
-
- # test with multiple set_pref calls
- self.prefs.set_pref(self.string_pref, 'unittest1')
- self.prefs.set_pref(self.string_pref, 'unittest2')
- self.assertEqual(self.prefs.get_pref(self.string_pref), 'unittest2')
- self.prefs.restore_pref(self.string_pref)
- self.assertEqual(self.prefs.get_pref(self.string_pref), orig_value)
-
- # test with multiple restore_pref calls
- self.prefs.set_pref(self.string_pref, 'unittest3')
- self.prefs.restore_pref(self.string_pref)
- self.assertRaises(MarionetteException,
- self.prefs.restore_pref, self.string_pref)
-
- # test with an unknown pref
- self.assertRaises(MarionetteException,
- self.prefs.restore_pref, self.unknown_pref)
-
- def test_restore_all_prefs(self):
- orig_bool = self.prefs.get_pref(self.bool_pref)
- orig_int = self.prefs.get_pref(self.int_pref)
- orig_string = self.prefs.get_pref(self.string_pref)
-
- self.prefs.set_pref(self.bool_pref, not orig_bool)
- self.prefs.set_pref(self.int_pref, 99999)
- self.prefs.set_pref(self.string_pref, 'unittest')
-
- self.prefs.restore_all_prefs()
- self.assertEqual(self.prefs.get_pref(self.bool_pref), orig_bool)
- self.assertEqual(self.prefs.get_pref(self.int_pref), orig_int)
- self.assertEqual(self.prefs.get_pref(self.string_pref), orig_string)
-
def test_set_pref_casted_values(self):
# basestring as boolean
self.prefs.set_pref(self.bool_pref, '')
self.assertFalse(self.prefs.get_pref(self.bool_pref))
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.bool_pref)
self.prefs.set_pref(self.bool_pref, 'unittest')
self.assertTrue(self.prefs.get_pref(self.bool_pref))
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.bool_pref)
# int as boolean
self.prefs.set_pref(self.bool_pref, 0)
self.assertFalse(self.prefs.get_pref(self.bool_pref))
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.bool_pref)
self.prefs.set_pref(self.bool_pref, 5)
self.assertTrue(self.prefs.get_pref(self.bool_pref))
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.bool_pref)
# boolean as int
self.prefs.set_pref(self.int_pref, False)
self.assertEqual(self.prefs.get_pref(self.int_pref), 0)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.int_pref)
self.prefs.set_pref(self.int_pref, True)
self.assertEqual(self.prefs.get_pref(self.int_pref), 1)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.int_pref)
# int as string
self.prefs.set_pref(self.string_pref, 54)
self.assertEqual(self.prefs.get_pref(self.string_pref), '54')
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.string_pref)
def test_set_pref_invalid(self):
self.assertRaises(AssertionError,
self.prefs.set_pref, self.new_pref, None)
def test_set_pref_new_preference(self):
self.prefs.set_pref(self.new_pref, True)
self.assertTrue(self.prefs.get_pref(self.new_pref))
- self.prefs.restore_pref(self.new_pref)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.new_pref)
self.prefs.set_pref(self.new_pref, 5)
self.assertEqual(self.prefs.get_pref(self.new_pref), 5)
- self.prefs.restore_pref(self.new_pref)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.new_pref)
self.prefs.set_pref(self.new_pref, 'test')
self.assertEqual(self.prefs.get_pref(self.new_pref), 'test')
- self.prefs.restore_pref(self.new_pref)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.new_pref)
def test_set_pref_new_values(self):
self.prefs.set_pref(self.bool_pref, True)
self.assertTrue(self.prefs.get_pref(self.bool_pref))
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.bool_pref)
self.prefs.set_pref(self.int_pref, 99999)
self.assertEqual(self.prefs.get_pref(self.int_pref), 99999)
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.int_pref)
self.prefs.set_pref(self.string_pref, 'test_string')
self.assertEqual(self.prefs.get_pref(self.string_pref), 'test_string')
+ # Remove when all self.marionette methods are implemented
+ # Please see Bug 1293588
+ self.marionette.clear_pref(self.string_pref)
--- a/testing/firefox-ui/tests/puppeteer/test_windows.py
+++ b/testing/firefox-ui/tests/puppeteer/test_windows.py
@@ -24,16 +24,22 @@ class BaseWindowTestCase(FirefoxTestCase
the content process manually, which generates a crash report,
which causes these tests to orange. We side-step this by
setting dom.ipc.tabs.shutdownTimeoutSecs to 0, which disables
the shutdown timer.
"""
FirefoxTestCase.setUp(self)
self.prefs.set_pref('dom.ipc.tabs.shutdownTimeoutSecs', 0)
+ def tearDown(self):
+ try:
+ self.marionette.clear_pref('dom.ipc.tabs.shutdownTimeoutSecs')
+ finally:
+ FirefoxTestCase.tearDown(self)
+
class TestWindows(BaseWindowTestCase):
def tearDown(self):
try:
self.windows.close_all([self.browser])
finally:
BaseWindowTestCase.tearDown(self)
--- a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
@@ -1,14 +1,12 @@
# 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 marionette_driver.errors import MarionetteException
-
from firefox_puppeteer.base import BaseLib
class Preferences(BaseLib):
archive = {}
def get_pref(self, pref_name, default_branch=False, interface=None):
"""Retrieves the value of a preference.
@@ -97,60 +95,24 @@ class Preferences(BaseLib):
prefBranch.clearUserPref(pref_name);
return true;
}
else {
return false;
}
""", script_args=[pref_name])
- def restore_all_prefs(self):
- """Restores all previously modified preferences to their former values.
-
- Please see :func:`~Preferences.restore_pref` for details.
- """
- while len(self.archive):
- self.restore_pref(self.archive.keys()[0])
-
- def restore_pref(self, pref_name):
- """Restores a previously set preference to its former value.
-
- The first time a preference gets modified a backup of its value is
- made. By calling this method, exactly this value will be restored,
- whether how often the preference has been modified again afterward.
-
- If the preference did not exist before and has been newly created, it
- will be reset to its original value. Please see
- :func:`~Preferences.reset_pref` for details.
-
- :param pref_name: The preference to restore
- """
- assert pref_name is not None
-
- try:
- # in case it is a newly set preference, reset it. Otherwise restore
- # its original value.
- if self.archive[pref_name] is None:
- self.reset_pref(pref_name)
- else:
- self.set_pref(pref_name, self.archive[pref_name])
-
- del self.archive[pref_name]
- except KeyError:
- raise MarionetteException('Nothing to restore for preference "%s"',
- pref_name)
-
def set_pref(self, pref_name, value):
"""Sets a preference to a specified value.
To set the value of a preference its name has to be specified.
The first time a new value for a preference is set, its value will be
automatically archived. It allows to restore the original value by
- calling :func:`~Preferences.restore_pref`.
+ calling :func:`self.marionette.clear_pref`.
:param pref_name: The preference to set
:param value: The value to set the preference to
"""
assert pref_name is not None
assert value is not None
with self.marionette.using_context('chrome'):
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
@@ -104,16 +104,14 @@ class BaseFirefoxTestCase(unittest.TestC
with self.marionette.using_context(self.marionette.CONTEXT_CONTENT):
# Ensure that we have a default page opened
self.marionette.navigate(self.prefs.get_pref('browser.newtab.url'))
def tearDown(self, *args, **kwargs):
self.marionette.set_context('chrome')
try:
- self.prefs.restore_all_prefs()
-
# This code should be run after all other tearDown code
# so that in case of a failure, further tests will not run
# in a state that is more inconsistent than necessary.
self._check_and_fix_leaked_handles()
finally:
super(BaseFirefoxTestCase, self).tearDown(*args, **kwargs)