Bug 1317270 - Allow to set preference values on the default branch.
MozReview-Commit-ID: BOUMMmmGwrX
--- a/testing/firefox-ui/tests/puppeteer/test_prefs.py
+++ b/testing/firefox-ui/tests/puppeteer/test_prefs.py
@@ -140,8 +140,26 @@ class testPreferences(PuppeteerMixin, Ma
# Please see Bug 1293588
self.marionette.clear_pref(self.int_pref)
self.puppeteer.prefs.set_pref(self.string_pref, 'test_string')
self.assertEqual(self.puppeteer.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)
+
+ def test_set_pref_default_branch(self):
+ orig_value = self.puppeteer.prefs.get_pref(self.string_pref, default_branch=True)
+
+ try:
+ self.puppeteer.prefs.set_pref(self.string_pref, 'default', default_branch=True)
+ self.assertEqual(self.puppeteer.prefs.get_pref(self.string_pref), 'default')
+
+ self.puppeteer.prefs.set_pref(self.string_pref, 'user')
+ self.assertEqual(self.puppeteer.prefs.get_pref(self.string_pref), 'user')
+ self.assertEqual(self.puppeteer.prefs.get_pref(self.string_pref, default_branch=True),
+ 'default')
+
+ self.marionette.clear_pref(self.string_pref)
+ self.assertEqual(self.puppeteer.prefs.get_pref(self.string_pref), 'default')
+
+ finally:
+ self.puppeteer.prefs.set_pref(self.string_pref, orig_value, default_branch=True)
--- a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
@@ -95,42 +95,51 @@ class Preferences(BaseLib):
prefBranch.clearUserPref(pref_name);
return true;
}
else {
return false;
}
""", script_args=[pref_name])
- def set_pref(self, pref_name, value):
+ def set_pref(self, pref_name, value, default_branch=False):
"""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:`self.marionette.clear_pref`.
:param pref_name: The preference to set
:param value: The value to set the preference to
+ :param default_branch: Optional, flag to use the default branch,
+ default to `False`
+
"""
assert pref_name is not None
assert value is not None
with self.marionette.using_context('chrome'):
# Backup original value only once
if pref_name not in self.archive:
self.archive[pref_name] = self.get_pref(pref_name)
retval = self.marionette.execute_script("""
Components.utils.import("resource://gre/modules/Services.jsm");
- let prefBranch = Services.prefs;
+
+ let [pref_name, value, default_branch] = arguments;
- let pref_name = arguments[0];
- let value = arguments[1];
+ let prefBranch;
+ if (default_branch) {
+ prefBranch = Services.prefs.getDefaultBranch("");
+ }
+ else {
+ prefBranch = Services.prefs;
+ }
let type = prefBranch.getPrefType(pref_name);
// If the pref does not exist yet, get the type from the value
if (type == prefBranch.PREF_INVALID) {
switch (typeof value) {
case "boolean":
type = prefBranch.PREF_BOOL;
@@ -156,11 +165,11 @@ class Preferences(BaseLib):
case prefBranch.PREF_INT:
prefBranch.setIntPref(pref_name, value);
break;
default:
return false;
}
return true;
- """, script_args=[pref_name, value])
+ """, script_args=[pref_name, value, default_branch])
assert retval