Bug 1408099 - Fix ExtensionPreferencesManager.getLevelOfControl to deal with undefined settings, r=aswan
authorBob Silverberg <bsilverberg@mozilla.com>
Thu, 12 Oct 2017 17:31:27 -0400
changeset 386212 247bb54b615fd5a73353f7f8b186672fcbaf8fee
parent 386211 1199e3c98d9fd8bc3e545f0e8cbf4c6fd05be28a
child 386213 c844b986015b481d36b717bbf4d959898c74ec10
push id32678
push userarchaeopteryx@coole-files.de
push dateSat, 14 Oct 2017 09:40:07 +0000
treeherdermozilla-central@0dd64d5842e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1408099
milestone58.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 1408099 - Fix ExtensionPreferencesManager.getLevelOfControl to deal with undefined settings, r=aswan Prior to this, if getLevelOfControl was called before the setting was defined to the EPM, an exception was thrown. This fixes it by returning a level of control of "not_controllable" if the setting has not yet been defined. MozReview-Commit-ID: 96jXLoJlUI
toolkit/components/extensions/ExtensionPreferencesManager.jsm
toolkit/components/extensions/test/xpcshell/test_ext_browserSettings_homepage.js
toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
--- a/toolkit/components/extensions/ExtensionPreferencesManager.jsm
+++ b/toolkit/components/extensions/ExtensionPreferencesManager.jsm
@@ -337,17 +337,21 @@ this.ExtensionPreferencesManager = {
    *
    * @returns {Promise}
    *          Resolves to the level of control of the extension over the setting.
    */
   async getLevelOfControl(extension, name, storeType = STORE_TYPE) {
     // This could be called for a setting that isn't defined to the PreferencesManager,
     // in which case we simply defer to the SettingsStore.
     if (storeType === STORE_TYPE) {
-      for (let prefName of settingsMap.get(name).prefNames) {
+      let setting = settingsMap.get(name);
+      if (!setting) {
+        return "not_controllable";
+      }
+      for (let prefName of setting.prefNames) {
         if (Preferences.locked(prefName)) {
           return "not_controllable";
         }
       }
     }
     await ExtensionSettingsStore.initialize();
     return ExtensionSettingsStore.getLevelOfControl(extension, storeType, name);
   },
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings_homepage.js
@@ -0,0 +1,29 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(async function test_homepage_get_without_set() {
+  async function background() {
+    let homepage = await browser.browserSettings.homepageOverride.get({});
+    browser.test.sendMessage("homepage", homepage);
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    background,
+    manifest: {
+      permissions: ["browserSettings"],
+    },
+  });
+
+  let defaultHomepage = Services.prefs.getComplexValue(
+    "browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
+
+  await extension.startup();
+  let homepage = await extension.awaitMessage("homepage");
+  equal(homepage.value, defaultHomepage,
+        "The homepageOverride setting has the expected value.");
+  equal(homepage.levelOfControl, "not_controllable",
+        "The homepageOverride setting has the expected levelOfControl.");
+
+  await extension.unload();
+});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -9,16 +9,18 @@
 skip-if = os == "android" # Android does not use Places for history.
 [test_ext_background_private_browsing.js]
 [test_ext_background_runtime_connect_params.js]
 [test_ext_background_sub_windows.js]
 [test_ext_background_telemetry.js]
 [test_ext_background_window_properties.js]
 skip-if = os == "android"
 [test_ext_browserSettings.js]
+[test_ext_browserSettings_homepage.js]
+skip-if = os == "android"
 [test_ext_contextual_identities.js]
 skip-if = os == "android" # Containers are not exposed to android.
 [test_ext_debugging_utils.js]
 [test_ext_downloads.js]
 [test_ext_downloads_download.js]
 skip-if = os == "android"
 [test_ext_downloads_misc.js]
 skip-if = os == "android" || (os=='linux' && bits==32) # linux32: bug 1324870