Bug 1317270 - Allow to set preference values on the default branch. r=maja_zf
authorHenrik Skupin <mail@hskupin.info>
Mon, 14 Nov 2016 14:13:04 +0100
changeset 322421 6a2be354a0dde2ec69df3936712f2eaa4cd2f0ab
parent 322420 8314e332761363771cefaff1b37e92b142e6370c
child 322422 7d49f7476aa90a6be5a3808c7fd0f78a8b14fac4
push id30951
push usercbook@mozilla.com
push dateTue, 15 Nov 2016 11:25:40 +0000
treeherdermozilla-central@85a9d908e91a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1317270
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1317270 - Allow to set preference values on the default branch. r=maja_zf MozReview-Commit-ID: BOUMMmmGwrX
testing/firefox-ui/tests/puppeteer/test_prefs.py
testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
--- 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