Bug 1429157 - Change PoliciesPrefTracker.restoreDefaultValues to delete prefs that were previously non-existant r=Felipe a=jcristau
authorKirk Steuber <ksteuber@mozilla.com>
Tue, 03 Apr 2018 13:58:04 -0700
changeset 463080 733b9c627ffb6c0ccfd173199071b03e762ed1d8
parent 463079 fe973bfe84fed734c21bad646ba0a4cf88ed78f8
child 463081 6d2939595bbc9a7d4c8b4956c52fe4b8f871b228
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, jcristau
bugs1429157
milestone60.0
Bug 1429157 - Change PoliciesPrefTracker.restoreDefaultValues to delete prefs that were previously non-existant r=Felipe a=jcristau
browser/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
--- a/browser/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
+++ b/browser/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
@@ -102,16 +102,18 @@ var PoliciesPrefTracker = {
     // If this pref is seen multiple times, the very first
     // value seen is the one that is actually the default.
     if (!this._originalValues.has(prefName)) {
       let defaults = new Preferences({defaultBranch: true});
       let stored = {};
 
       if (defaults.has(prefName)) {
         stored.originalDefaultValue = defaults.get(prefName);
+      } else {
+        stored.originalDefaultValue = undefined;
       }
 
       if (Preferences.isSet(prefName) &&
           Preferences.get(prefName) == prefValue) {
         // If a user value exists, and we're changing the default
         // value to be th same as the user value, that will cause
         // the user value to be dropped. In that case, let's also
         // store it to ensure that we restore everything correctly.
@@ -132,16 +134,18 @@ var PoliciesPrefTracker = {
     for (let [prefName, stored] of this._originalValues) {
       // If a pref was used through setDefaultPref instead
       // of setAndLockPref, it wasn't locked, but calling
       // unlockPref is harmless
       Preferences.unlock(prefName);
 
       if (stored.originalDefaultValue !== undefined) {
         defaults.set(prefName, stored.originalDefaultValue);
+      } else {
+        Services.prefs.getDefaultBranch("").deleteBranch(prefName);
       }
 
       if (stored.originalUserValue !== undefined) {
         Preferences.set(prefName, stored.originalUserValue);
       }
     }
 
     this._originalValues.clear();
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
@@ -117,22 +117,26 @@ add_task(async function test_pref_tracke
   let defaults = Services.prefs.getDefaultBranch("");
 
   // Test prefs that had a default value and got changed to another
   defaults.setIntPref("test1.pref1", 10);
   defaults.setStringPref("test1.pref2", "test");
 
   setAndLockPref("test1.pref1", 20);
   setDefaultPref("test1.pref2", "NEW VALUE");
+  setAndLockPref("test1.pref3", "NEW VALUE");
+  setDefaultPref("test1.pref4", 20);
 
   PoliciesPrefTracker.restoreDefaultValues();
 
   is(Services.prefs.getIntPref("test1.pref1"), 10, "Expected value for test1.pref1");
   is(Services.prefs.getStringPref("test1.pref2"), "test", "Expected value for test1.pref2");
   is(Services.prefs.prefIsLocked("test1.pref1"), false, "test1.pref1 got unlocked");
+  is(Services.prefs.getStringPref("test1.pref3", undefined), undefined, "test1.pref3 should have had its value unset");
+  is(Services.prefs.getIntPref("test1.pref4", -1), -1, "test1.pref4 should have had its value unset");
 
   // Test a pref that had a default value and a user value
   defaults.setIntPref("test2.pref1", 10);
   Services.prefs.setIntPref("test2.pref1", 20);
 
   setAndLockPref("test2.pref1", 20);
 
   PoliciesPrefTracker.restoreDefaultValues();