[Pkg-mozext-commits] [requestpolicy] 50/80: Marionette: create a `prefs` module

David Prévot taffit at moszumanska.debian.org
Sun Jul 5 15:02:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit e34820391295606ea2ed76b427ca1d74cf8d0a0d
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu Jun 18 03:20:37 2015 +0200

    Marionette: create a `prefs` module
---
 tests/marionette/rp_puppeteer/api/prefs.py        | 20 +++++++++++++++++
 tests/marionette/rp_puppeteer/tests/manifest.ini  |  2 +-
 tests/marionette/rp_puppeteer/tests/test_prefs.py | 26 +++++++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/tests/marionette/rp_puppeteer/api/prefs.py b/tests/marionette/rp_puppeteer/api/prefs.py
new file mode 100644
index 0000000..d58af37
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/api/prefs.py
@@ -0,0 +1,20 @@
+# 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 contextlib import contextmanager
+
+ at contextmanager
+def using_pref(prefs, pref_name, pref_value):
+    """Context manager for setting a pref temporarily.
+
+    :param prefs: The Preferences() object.
+    :param pref_name: The preference to set.
+    :param pref_value: The value to set the preference to.
+    """
+
+    prefs.set_pref(pref_name, pref_value)
+    try:
+        yield
+    finally:
+        prefs.reset_pref(pref_name)
diff --git a/tests/marionette/rp_puppeteer/tests/manifest.ini b/tests/marionette/rp_puppeteer/tests/manifest.ini
index 8b13789..c8c9167 100644
--- a/tests/marionette/rp_puppeteer/tests/manifest.ini
+++ b/tests/marionette/rp_puppeteer/tests/manifest.ini
@@ -1 +1 @@
-
+[test_prefs.py]
diff --git a/tests/marionette/rp_puppeteer/tests/test_prefs.py b/tests/marionette/rp_puppeteer/tests/test_prefs.py
new file mode 100644
index 0000000..e128474
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/tests/test_prefs.py
@@ -0,0 +1,26 @@
+# 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_ui_harness import FirefoxTestCase
+
+from rp_puppeteer.api.prefs import using_pref
+
+
+class TestPrefs(FirefoxTestCase):
+
+    def setUp(self):
+        FirefoxTestCase.setUp(self)
+
+        self.new_pref = 'marionette.unittest.using_pref'
+
+    def test_using_pref(self):
+        self.assertEqual(self.prefs.get_pref(self.new_pref), None,
+                         msg="The pref initially doesn't exist.")
+
+        with using_pref(self.prefs, self.new_pref, 'unittest'):
+            self.assertEqual(self.prefs.get_pref(self.new_pref), 'unittest',
+                             msg="The pref has been set.")
+
+        self.assertEqual(self.prefs.get_pref(self.new_pref), None,
+                         msg="The pref has been removed.")

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