Bug 1317270 - Allow to set preference values on the default branch. r=maja_zf, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 14 Nov 2016 14:13:04 +0100
changeset 352695 89a57db73dd99eee7c9dafcc0fe4d24f3cde5339
parent 352694 bb32677bad4c65780153a9a642067d9cae236190
child 352696 fcd21d218a25a784399174da9d72191e89117b51
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1317270
milestone52.0a2
Bug 1317270 - Allow to set preference values on the default branch. r=maja_zf, a=test-only 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