Bug 1254268 - Distribution should use default prefs, regression from 1252466; r=mconnor a=ritu
authorWes Kocher <wkocher@mozilla.com>
Mon, 14 Mar 2016 11:39:55 -0700
changeset 323426 c3bcee5d608ccc8c95e01b7eeef49e869f928966
parent 323425 60b56259a4301ad174e4f9d1bd77a1a1feed386e
child 323427 aa6c02ad1e3a93d81846685911b12fe2de7a6da8
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconnor, ritu
bugs1254268, 1252466
milestone47.0a2
Bug 1254268 - Distribution should use default prefs, regression from 1252466; r=mconnor a=ritu
browser/components/distribution.js
browser/components/tests/unit/test_distribution.js
--- a/browser/components/distribution.js
+++ b/browser/components/distribution.js
@@ -348,49 +348,49 @@ DistributionCustomizer.prototype = {
 
     var usedPreferences = [];
 
     if (sections["Preferences-" + this._locale]) {
       for (let key of enumerate(this._ini.getKeys("Preferences-" + this._locale))) {
         try {
           let value = this._ini.getString("Preferences-" + this._locale, key);
           if (value) {
-            Preferences.set(key, parseValue(value));
+            defaults.set(key, parseValue(value));
           }
           usedPreferences.push(key);
         } catch (e) { /* ignore bad prefs and move on */ }
       }
     }
 
     if (sections["Preferences-" + this._language]) {
       for (let key of enumerate(this._ini.getKeys("Preferences-" + this._language))) {
         if (usedPreferences.indexOf(key) > -1) {
           continue;
         }
         try {
           let value = this._ini.getString("Preferences-" + this._language, key);
           if (value) {
-            Preferences.set(key, parseValue(value));
+            defaults.set(key, parseValue(value));
           }
           usedPreferences.push(key);
         } catch (e) { /* ignore bad prefs and move on */ }
       }
     }
 
     if (sections["Preferences"]) {
       for (let key of enumerate(this._ini.getKeys("Preferences"))) {
         if (usedPreferences.indexOf(key) > -1) {
           continue;
         }
         try {
           let value = this._ini.getString("Preferences", key);
           if (value) {
             value = value.replace(/%LOCALE%/g, this._locale);
             value = value.replace(/%LANGUAGE%/g, this._language);
-            Preferences.set(key, parseValue(value));
+            defaults.set(key, parseValue(value));
           }
         } catch (e) { /* ignore bad prefs and move on */ }
       }
     }
 
     let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].
       createInstance(Ci.nsIPrefLocalizedString);
 
--- a/browser/components/tests/unit/test_distribution.js
+++ b/browser/components/tests/unit/test_distribution.js
@@ -57,52 +57,54 @@ do_register_cleanup(function () {
   Assert.ok(!iniFile.exists());
 });
 
 add_task(function* () {
   // Force distribution.
   let glue = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver)
   glue.observe(null, TOPIC_BROWSERGLUE_TEST, TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
 
-  Assert.equal(Services.prefs.getCharPref("distribution.id"), "disttest");
-  Assert.equal(Services.prefs.getCharPref("distribution.version"), "1.0");
-  Assert.equal(Services.prefs.getComplexValue("distribution.about", Ci.nsISupportsString).data, "Tèƨƭ δïƨƭřïβúƭïôñ ƒïℓè");
+  var defaultBranch = Services.prefs.getDefaultBranch(null);
+
+  Assert.equal(defaultBranch.getCharPref("distribution.id"), "disttest");
+  Assert.equal(defaultBranch.getCharPref("distribution.version"), "1.0");
+  Assert.equal(defaultBranch.getComplexValue("distribution.about", Ci.nsISupportsString).data, "Tèƨƭ δïƨƭřïβúƭïôñ ƒïℓè");
 
-  Assert.equal(Services.prefs.getCharPref("distribution.test.string"), "Test String");
-  Assert.equal(Services.prefs.getCharPref("distribution.test.string.noquotes"), "Test String");
-  Assert.equal(Services.prefs.getIntPref("distribution.test.int"), 777);
-  Assert.equal(Services.prefs.getBoolPref("distribution.test.bool.true"), true);
-  Assert.equal(Services.prefs.getBoolPref("distribution.test.bool.false"), false);
+  Assert.equal(defaultBranch.getCharPref("distribution.test.string"), "Test String");
+  Assert.equal(defaultBranch.getCharPref("distribution.test.string.noquotes"), "Test String");
+  Assert.equal(defaultBranch.getIntPref("distribution.test.int"), 777);
+  Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.true"), true);
+  Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.false"), false);
 
-  Assert.throws(() => Services.prefs.getCharPref("distribution.test.empty"));
-  Assert.throws(() => Services.prefs.getIntPref("distribution.test.empty"));
-  Assert.throws(() => Services.prefs.getBoolPref("distribution.test.empty"));
+  Assert.throws(() => defaultBranch.getCharPref("distribution.test.empty"));
+  Assert.throws(() => defaultBranch.getIntPref("distribution.test.empty"));
+  Assert.throws(() => defaultBranch.getBoolPref("distribution.test.empty"));
 
-  Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale"), "en-US");
-  Assert.equal(Services.prefs.getCharPref("distribution.test.pref.language.en"), "en");
-  Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale.en-US"), "en-US");
-  Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.language.de"));
-  // This value was never set because of the empty language specific pref
-  Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.language.reset"));
-  // This value was never set because of the empty locale specific pref
-  Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.locale.reset"));
-  // This value was overridden by a locale specific setting
-  Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale.set"), "Locale Set");
-  // This value was overridden by a language specific setting
-  Assert.equal(Services.prefs.getCharPref("distribution.test.pref.language.set"), "Language Set");
-  // Language should not override locale
-  Assert.notEqual(Services.prefs.getCharPref("distribution.test.pref.locale.set"), "Language Set");
+  Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale"), "en-US");
+  Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.en"), "en");
+  Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.en-US"), "en-US");
+  Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.de"));
+    // This value was never set because of the empty language specific pref
+  Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.reset"));
+    // This value was never set because of the empty locale specific pref
+  Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.locale.reset"));
+    // This value was overridden by a locale specific setting
+  Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Locale Set");
+    // This value was overridden by a language specific setting
+  Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.set"), "Language Set");
+    // Language should not override locale
+  Assert.notEqual(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Language Set");
 
-  Assert.equal(Services.prefs.getComplexValue("distribution.test.locale", Ci.nsIPrefLocalizedString).data, "en-US");
-  Assert.equal(Services.prefs.getComplexValue("distribution.test.language.en", Ci.nsIPrefLocalizedString).data, "en");
-  Assert.equal(Services.prefs.getComplexValue("distribution.test.locale.en-US", Ci.nsIPrefLocalizedString).data, "en-US");
-  Assert.throws(() => Services.prefs.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString));
-  // This value was never set because of the empty language specific pref
-  Assert.throws(() => Services.prefs.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString));
-  // This value was never set because of the empty locale specific pref
-  Assert.throws(() => Services.prefs.getComplexValue("distribution.test.locale.reset", Ci.nsIPrefLocalizedString));
-  // This value was overridden by a locale specific setting
-  Assert.equal(Services.prefs.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Locale Set");
-  // This value was overridden by a language specific setting
-  Assert.equal(Services.prefs.getComplexValue("distribution.test.language.set", Ci.nsIPrefLocalizedString).data, "Language Set");
-  // Language should not override locale
-  Assert.notEqual(Services.prefs.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Language Set");
+  Assert.equal(defaultBranch.getComplexValue("distribution.test.locale", Ci.nsIPrefLocalizedString).data, "en-US");
+  Assert.equal(defaultBranch.getComplexValue("distribution.test.language.en", Ci.nsIPrefLocalizedString).data, "en");
+  Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.en-US", Ci.nsIPrefLocalizedString).data, "en-US");
+  Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString));
+    // This value was never set because of the empty language specific pref
+  Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString));
+    // This value was never set because of the empty locale specific pref
+  Assert.throws(() => defaultBranch.getComplexValue("distribution.test.locale.reset", Ci.nsIPrefLocalizedString));
+    // This value was overridden by a locale specific setting
+  Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Locale Set");
+    // This value was overridden by a language specific setting
+  Assert.equal(defaultBranch.getComplexValue("distribution.test.language.set", Ci.nsIPrefLocalizedString).data, "Language Set");
+    // Language should not override locale
+  Assert.notEqual(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Language Set");
 });