Bug 1410736 - Replace remaining uses of general.useragent.locale with LocaleService API. r=jfkthame draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Fri, 03 Nov 2017 17:08:34 -0700
changeset 693054 420c65111dc5066eb00ef86ddf375db533008bbf
parent 693006 66f496680fae6e7d8f02bc17ff58b9234ee07c70
child 738933 1c86e115e91426a40b718b31bad4e58471812f6d
push id87690
push userbmo:gandalf@aviary.pl
push dateSat, 04 Nov 2017 00:08:45 +0000
reviewersjfkthame
bugs1410736
milestone58.0a1
Bug 1410736 - Replace remaining uses of general.useragent.locale with LocaleService API. r=jfkthame MozReview-Commit-ID: F0Ofe2lHHEo
browser/components/search/test/browser_google_codes.js
browser/components/search/test/browser_google_nocodes.js
chrome/test/unit/test_bug848297.js
dom/animation/test/chrome/test_animation_performance_warning.html
toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js
toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js
toolkit/components/reputationservice/test/unit/test_app_rep_windows.js
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
toolkit/mozapps/extensions/test/xpcshell/test_locale.js
toolkit/mozapps/extensions/test/xpcshell/test_update.js
toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
--- a/browser/components/search/test/browser_google_codes.js
+++ b/browser/components/search/test/browser_google_codes.js
@@ -50,24 +50,22 @@ function asyncInit() {
     Services.search.init(function() {
       ok(Services.search.isInitialized, "search service should be initialized");
       resolve();
     });
   });
 }
 
 function asyncReInit() {
-  const kLocalePref = "general.useragent.locale";
-
   let promise = new Promise(resolve => {
     waitForSearchNotification("reinit-complete", resolve);
   });
 
   Services.search.QueryInterface(Ci.nsIObserver)
-          .observe(null, "nsPref:changed", kLocalePref);
+          .observe(null, "intl:requested-locales-changed", null);
 
   return promise;
 }
 
 let gEngineCount;
 
 add_task(async function preparation() {
   // ContentSearch is interferring with our async re-initializations of the
--- a/browser/components/search/test/browser_google_nocodes.js
+++ b/browser/components/search/test/browser_google_nocodes.js
@@ -50,24 +50,22 @@ function asyncInit() {
     Services.search.init(function() {
       ok(Services.search.isInitialized, "search service should be initialized");
       resolve();
     });
   });
 }
 
 function asyncReInit() {
-  const kLocalePref = "general.useragent.locale";
-
   let promise = new Promise(resolve => {
     waitForSearchNotification("reinit-complete", resolve);
   });
 
   Services.search.QueryInterface(Ci.nsIObserver)
-          .observe(null, "nsPref:changed", kLocalePref);
+          .observe(null, "intl:requested-locales-changed", null);
 
   return promise;
 }
 
 let gEngineCount;
 
 add_task(async function preparation() {
   // ContentSearch is interferring with our async re-initializations of the
--- a/chrome/test/unit/test_bug848297.js
+++ b/chrome/test/unit/test_bug848297.js
@@ -4,16 +4,17 @@
  */
 
 var MANIFESTS = [
   do_get_file("data/test_bug848297.manifest")
 ];
 
 // Stub in the locale service so we can control what gets returned as the OS locale setting
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 registerManifests(MANIFESTS);
 
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                 .getService(Ci.nsIXULChromeRegistry)
                 .QueryInterface(Ci.nsIToolkitChromeRegistry);
 chromeReg.checkForNewChrome();
 
@@ -28,17 +29,17 @@ function enum_to_array(strings) {
   }
   rv.sort();
   return rv;
 }
 
 function run_test() {
 
   // without override
-  prefService.setCharPref("general.useragent.locale", "de");
+  Services.locale.setRequestedLocales(["de"]);
   do_check_eq(chromeReg.getSelectedLocale("basepack"), "en-US");
   do_check_eq(chromeReg.getSelectedLocale("overpack"), "de");
   do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")),
                    ["en-US", "fr"]);
 
   // with override
   prefService.setCharPref("chrome.override_package.basepack", "overpack");
   do_check_eq(chromeReg.getSelectedLocale("basepack"), "de");
--- a/dom/animation/test/chrome/test_animation_performance_warning.html
+++ b/dom/animation/test/chrome/test_animation_performance_warning.html
@@ -26,18 +26,20 @@
 <script>
 'use strict';
 
 // This is used for obtaining localized strings.
 var gStringBundle;
 
 W3CTest.runner.requestLongerTimeout(2);
 
+const { Services } = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm");
+Services.locale.setRequestedLocales(["en-US"]);
+
 SpecialPowers.pushPrefEnv({ "set": [
-                            ["general.useragent.locale", "en-US"],
                             // Need to set devPixelsPerPx explicitly to gain
                             // consistent pixel values in warning messages
                             // regardless of platform DPIs.
                             ["layout.css.devPixelsPerPx", 1],
                           ] },
                           start);
 
 function compare_property_state(a, b) {
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
@@ -6,20 +6,21 @@ Cu.import("resource://gre/modules/Prefer
 // to use the right timeout for content scripts executed at document_idle.
 ExtensionTestUtils.mockAppInfo();
 
 const server = createHttpServer();
 server.registerDirectory("/data/", do_get_file("data"));
 
 const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
 
+var originalReqLocales = Services.locale.getRequestedLocales();
+
 do_register_cleanup(() => {
   Preferences.reset("intl.accept_languages");
-  Preferences.reset("intl.locale.matchOS");
-  Preferences.reset("general.useragent.locale");
+  Services.locale.setRequestedLocales(originalReqLocales);
 });
 
 
 add_task(async function test_i18n() {
   function runTests(assertEq) {
     let _ = browser.i18n.getMessage.bind(browser.i18n);
 
     let url = browser.runtime.getURL("/");
@@ -213,31 +214,30 @@ add_task(async function test_i18n_negoti
       });
     } + `(${runTests})`,
   };
 
   Components.manager.addBootstrappedManifestLocation(do_get_file("data/locales/"));
 
   let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
 
-  Preferences.set("intl.locale.matchOS", false);
   for (let [lang, msg] of [["en-US", "English."], ["jp", "\u65e5\u672c\u8a9e"]]) {
-    Preferences.set("general.useragent.locale", lang);
+    Services.locale.setRequestedLocales([lang]);
 
     let extension = ExtensionTestUtils.loadExtension(extensionData);
     await extension.startup();
     await extension.awaitMessage("content-ready");
 
     extension.sendMessage(msg);
     await extension.awaitMessage("background-script-finished");
     await extension.awaitMessage("content-script-finished");
 
     await extension.unload();
   }
-  Preferences.reset("general.useragent.locale");
+  Services.locale.setRequestedLocales(originalReqLocales);
 
   await contentPage.close();
 });
 
 
 add_task(async function test_get_accept_languages() {
   function checkResults(source, results, expected) {
     browser.test.assertEq(
@@ -372,17 +372,17 @@ add_task(async function test_get_ui_lang
 
   extension.sendMessage(["expect-results", "en-US"]);
 
   await extension.awaitMessage("background-done");
   await extension.awaitMessage("content-done");
 
   // We don't currently have a good way to mock this.
   if (false) {
-    Preferences.set("general.useragent.locale", "he");
+    Services.locale.setRequestedLocales(["he"]);
 
     extension.sendMessage(["expect-results", "he"]);
 
     await extension.awaitMessage("background-done");
     await extension.awaitMessage("content-done");
   }
 
   await contentPage.close();
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
@@ -117,33 +117,30 @@ async function test_i18n_css(options = {
 
   cssURL = cssURL.replace(/foo.css$/, "locale.css");
 
   css = await fetch(cssURL);
   equal(css, '* { content: "en-US ltr rtl left right" }', "CSS file localized in mochitest scope");
 
   // We don't currently have a good way to mock this.
   if (false) {
-    const LOCALE = "general.useragent.locale";
     const DIR = "intl.uidirection";
-    const DIR_LEGACY = "intl.uidirection.en"; // Needed for Android until bug 1215247 is resolved
 
     // We don't wind up actually switching the chrome registry locale, since we
     // don't have a chrome package for Hebrew. So just override it, and force
     // RTL directionality.
-    Preferences.set(LOCALE, "he");
+    const origReqLocales = Services.locale.getRequestedLocales();
+    Services.locale.setRequestedLocales(["he"]);
     Preferences.set(DIR, 1);
-    Preferences.set(DIR_LEGACY, "rtl");
 
     css = await fetch(cssURL);
     equal(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope");
 
-    Preferences.reset(LOCALE);
+    Services.locale.setRequestedLocales(origReqLocales);
     Preferences.reset(DIR);
-    Preferences.reset(DIR_LEGACY);
   }
 
   await extension.awaitFinish("i18n-css");
   await extension.unload();
 }
 
 add_task(async function startup() {
   await promiseStartupManager();
--- a/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js
@@ -75,18 +75,17 @@ add_task(async function() {
   await extension.awaitStartup();
 
   equal(extension.version, "1.0", "Expected extension version");
   manifest = await getManifest();
   equal(manifest.name, "en-US 1.0", "Got expected manifest name");
 
 
   do_print("Change locale to 'fr' and restart");
-  Preferences.set("intl.locale.matchOS", false);
-  Preferences.set("general.useragent.locale", "fr");
+  Services.locale.setRequestedLocales(["fr"]);
   await AddonTestUtils.promiseRestartManager();
   await extension.awaitStartup();
 
   equal(extension.version, "1.0", "Expected extension version");
   manifest = await getManifest();
   equal(manifest.name, "fr 1.0", "Got expected manifest name");
 
 
@@ -94,17 +93,17 @@ add_task(async function() {
   await extension.upgrade(makeExtension({version: "1.1"}));
 
   equal(extension.version, "1.1", "Expected extension version");
   manifest = await getManifest();
   equal(manifest.name, "fr 1.1", "Got expected manifest name");
 
 
   do_print("Change locale to 'en-US' and restart");
-  Preferences.set("general.useragent.locale", "en-US");
+  Services.locale.setRequestedLocales(["en-US"]);
   await AddonTestUtils.promiseRestartManager();
   await extension.awaitStartup();
 
   equal(extension.version, "1.1", "Expected extension version");
   manifest = await getManifest();
   equal(manifest.name, "en-US 1.1", "Got expected manifest name");
 
 
--- a/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js
+++ b/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js
@@ -69,24 +69,24 @@ add_task(function test_setup() {
   // Ensure safebrowsing is enabled for this test, even if the app
   // doesn't have it enabled.
   Services.prefs.setBoolPref("browser.safebrowsing.malware.enabled", true);
   Services.prefs.setBoolPref("browser.safebrowsing.downloads.enabled", true);
   // Set block table explicitly, no need for the allow table though
   Services.prefs.setCharPref("urlclassifier.downloadBlockTable",
                              "goog-badbinurl-shavar");
   // SendRemoteQueryInternal needs locale preference.
-  let locale = Services.prefs.getCharPref("general.useragent.locale");
-  Services.prefs.setCharPref("general.useragent.locale", "en-US");
+  let originalReqLocales = Services.locale.getRequestedLocales();
+  Services.locale.setRequestedLocales(["en-US"]);
 
   do_register_cleanup(function() {
     Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled");
     Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled");
     Services.prefs.clearUserPref("urlclassifier.downloadBlockTable");
-    Services.prefs.setCharPref("general.useragent.locale", locale);
+    Services.locale.setRequestedLocales(originalReqLocales);
   });
 
   gHttpServer = new HttpServer();
   gHttpServer.registerDirectory("/", do_get_cwd());
 
   function createVerdict(aShouldBlock) {
     // We can't programmatically create a protocol buffer here, so just
     // hardcode some already serialized ones.
--- a/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js
+++ b/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js
@@ -158,25 +158,25 @@ add_task(async function test_setup() {
   Services.prefs.setBoolPref("browser.safebrowsing.downloads.enabled", true);
   // Set block and allow tables explicitly, since the allowlist is normally
   // disabled on comm-central.
   Services.prefs.setCharPref("urlclassifier.downloadBlockTable",
                              "goog-badbinurl-shavar");
   Services.prefs.setCharPref("urlclassifier.downloadAllowTable",
                              "goog-downloadwhite-digest256");
   // SendRemoteQueryInternal needs locale preference.
-  let locale = Services.prefs.getCharPref("general.useragent.locale");
-  Services.prefs.setCharPref("general.useragent.locale", "en-US");
+  let originalReqLocales = Services.locale.getRequestedLocales();
+  Services.locale.setRequestedLocales(["en-US"]);
 
   do_register_cleanup(function() {
     Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled");
     Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled");
     Services.prefs.clearUserPref("urlclassifier.downloadBlockTable");
     Services.prefs.clearUserPref("urlclassifier.downloadAllowTable");
-    Services.prefs.setCharPref("general.useragent.locale", locale);
+    Services.locale.setRequestedLocales(originalReqLocales);
   });
 
   gHttpServer = new HttpServer();
   gHttpServer.registerDirectory("/", do_get_cwd());
 
   function createVerdict(aShouldBlock) {
     // We can't programmatically create a protocol buffer here, so just
     // hardcode some already serialized ones.
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -62,16 +62,17 @@ const NS_APP_USER_PROFILE_50_DIR = "Prof
 
 // Loading plugins from NS_APP_SEARCH_DIR is no longer supported.
 // Instead, we now load plugins from APP_SEARCH_PREFIX, where a
 // list.txt file needs to exist to list available engines.
 const APP_SEARCH_PREFIX = "resource://search-plugins/";
 
 // See documentation in nsIBrowserSearchService.idl.
 const SEARCH_ENGINE_TOPIC        = "browser-search-engine-modified";
+const REQ_LOCALES_CHANGED_TOPIC  = "intl:requested-locales-changed";
 const QUIT_APPLICATION_TOPIC     = "quit-application";
 
 const SEARCH_ENGINE_REMOVED      = "engine-removed";
 const SEARCH_ENGINE_ADDED        = "engine-added";
 const SEARCH_ENGINE_CHANGED      = "engine-changed";
 const SEARCH_ENGINE_LOADED       = "engine-loaded";
 const SEARCH_ENGINE_CURRENT      = "engine-current";
 const SEARCH_ENGINE_DEFAULT      = "engine-default";
@@ -132,17 +133,16 @@ const OPENSEARCH_LOCALNAME = "OpenSearch
 const MOZSEARCH_NS_10     = "http://www.mozilla.org/2006/browser/search/";
 const MOZSEARCH_LOCALNAME = "SearchPlugin";
 
 const URLTYPE_SUGGEST_JSON = "application/x-suggestions+json";
 const URLTYPE_SEARCH_HTML  = "text/html";
 const URLTYPE_OPENSEARCH   = "application/opensearchdescription+xml";
 
 const BROWSER_SEARCH_PREF = "browser.search.";
-const LOCALE_PREF = "general.useragent.locale";
 
 const USER_DEFINED = "searchTerms";
 
 // Custom search parameters
 const MOZ_PARAM_LOCALE         = "moz:locale";
 const MOZ_PARAM_DIST_ID        = "moz:distributionID";
 const MOZ_PARAM_OFFICIAL       = "moz:official";
 
@@ -2285,17 +2285,17 @@ Engine.prototype = {
     // or distribution directory.
     if (/^(?:jar:)?(?:\[app\]|\[distribution\])/.test(this._loadPath))
       return true;
 
     // If we are using a non-default locale or in the xpcshell test case,
     // we'll accept as a 'default' engine anything that has been registered at
     // resource://search-plugins/ even if the file doesn't come from the
     // application folder.  If not, skip costly additional checks.
-    if (!Services.prefs.prefHasUserValue(LOCALE_PREF) &&
+    if (Services.locale.defaultLocale !== Services.locale.getRequestedLocale() &&
         !gEnvironment.get("XPCSHELL_TEST_PROFILE_DIR"))
       return false;
 
     // Some xpcshell tests use the search service without registering
     // resource://search-plugins/.
     if (!Services.io.getProtocolHandler("resource")
                  .QueryInterface(Ci.nsIResProtocolHandler)
                  .hasSubstitution("search-plugins"))
@@ -4661,23 +4661,21 @@ SearchService.prototype = {
             break;
         }
         break;
 
       case QUIT_APPLICATION_TOPIC:
         this._removeObservers();
         break;
 
-      case "nsPref:changed":
-        if (aVerb == LOCALE_PREF) {
-          // Locale changed. Re-init. We rely on observers, because we can't
-          // return this promise to anyone.
-          this._asyncReInit();
-          break;
-        }
+      case REQ_LOCALES_CHANGED_TOPIC:
+        // Locale changed. Re-init. We rely on observers, because we can't
+        // return this promise to anyone.
+        this._asyncReInit();
+        break;
     }
   },
 
   // nsITimerCallback
   notify: function SRCH_SVC_notify(aTimer) {
     LOG("_notify: checking for updates");
 
     if (!getBoolPref(BROWSER_SEARCH_PREF + "update", true))
@@ -4722,17 +4720,17 @@ SearchService.prototype = {
       return;
     }
     this._observersAdded = true;
 
     Services.obs.addObserver(this, SEARCH_ENGINE_TOPIC);
     Services.obs.addObserver(this, QUIT_APPLICATION_TOPIC);
 
     if (AppConstants.MOZ_BUILD_APP == "mobile/android") {
-      Services.prefs.addObserver(LOCALE_PREF, this);
+      Services.obs.addObserver(this, REQ_LOCALES_CHANGED_TOPIC);
     }
 
     // The current stage of shutdown. Used to help analyze crash
     // signatures in case of shutdown timeout.
     let shutdownState = {
       step: "Not started",
       latestError: {
         message: undefined,
@@ -4767,17 +4765,17 @@ SearchService.prototype = {
   },
   _observersAdded: false,
 
   _removeObservers: function SRCH_SVC_removeObservers() {
     Services.obs.removeObserver(this, SEARCH_ENGINE_TOPIC);
     Services.obs.removeObserver(this, QUIT_APPLICATION_TOPIC);
 
     if (AppConstants.MOZ_BUILD_APP == "mobile/android") {
-      Services.prefs.removeObserver(LOCALE_PREF, this);
+      Services.obs.removeObserver(this, REQ_LOCALES_CHANGED_TOPIC);
     }
   },
 
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsIBrowserSearchService,
     Ci.nsIObserver,
     Ci.nsITimerCallback
   ])
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -249,24 +249,24 @@ function isUSTimezone() {
   // Hawaii-Aleutian Standard Time (http://www.timeanddate.com/time/zones/hast)
 
   let UTCOffset = (new Date()).getTimezoneOffset();
   return UTCOffset >= 150 && UTCOffset <= 600;
 }
 
 const kDefaultenginenamePref = "browser.search.defaultenginename";
 const kTestEngineName = "Test search engine";
-const kLocalePref = "general.useragent.locale";
+const REQ_LOCALES_CHANGED_TOPIC = "intl:requested-locales-changed";
 
 function getDefaultEngineName(isUS) {
   const nsIPLS = Ci.nsIPrefLocalizedString;
   // Copy the logic from nsSearchService
   let pref = kDefaultenginenamePref;
   if (isUS === undefined)
-    isUS = Services.prefs.getCharPref(kLocalePref) == "en-US" && isUSTimezone();
+    isUS = Services.locale.getRequestedLocale() == "en-US" && isUSTimezone();
   if (isUS) {
     pref += ".US";
   }
   return Services.prefs.getComplexValue(pref, nsIPLS).data;
 }
 
 /**
  * Waits for the cache file to be saved.
@@ -504,17 +504,17 @@ function asyncInit() {
     });
   });
 }
 
 function asyncReInit() {
   let promise = waitForSearchNotification("reinit-complete");
 
   Services.search.QueryInterface(Ci.nsIObserver)
-          .observe(null, "nsPref:changed", kLocalePref);
+          .observe(null, REQ_LOCALES_CHANGED_TOPIC, null);
 
   return promise;
 }
 
 // This "enum" from nsSearchService.js
 const TELEMETRY_RESULT_ENUM = {
   SUCCESS: 0,
   SUCCESS_WITHOUT_DATA: 1,
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
@@ -1,16 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
-
 // Disables security checking our updates which haven't been signed
 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
 
 var Ci = Components.interfaces;
 var Cu = Components.utils;
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://testing-common/MockRegistrar.jsm");
@@ -155,18 +152,17 @@ function run_test() {
 
   server = new HttpServer();
   server.registerPathHandler("/0", requestHandler);
   server.registerPathHandler("/1", requestHandler);
   server.registerPathHandler("/2", requestHandler);
   server.registerPathHandler("/3", requestHandler);
   server.start(4444);
 
-  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US");
+  Services.locale.setRequestedLocales(["en-US"]);
 
   startupManager();
   installAllFiles(ADDONS.map(a => do_get_addon(a.addon)), function() {
 
     restartManager();
     AddonManager.getAddonByID(ADDONS[1].id, callback_soon(function(addon) {
       do_check_true(!(!addon));
       addon.userDisabled = true;
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
@@ -1,25 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
-
 const ADDON = "test_bug397778";
 const ID = "bug397778@tests.mozilla.org";
 
 function run_test() {
   // Setup for test
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1");
-  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
 
   // Install test add-on
   startupManager();
   installAllFiles([do_get_addon(ADDON)], function() {
     restartManager();
 
     run_test_1();
   });
@@ -41,74 +37,74 @@ function run_test_1() {
 
       do_execute_soon(run_test_2);
     });
   }));
 }
 
 function run_test_2() {
   // Change locale. The more specific de-DE is the best match
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de");
+  Services.locale.setRequestedLocales(["de"]);
   restartManager();
 
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     do_check_eq(addon.name, "de-DE Name");
     do_check_eq(addon.description, null);
 
     do_execute_soon(run_test_3);
   });
 }
 
 function run_test_3() {
   // Change locale. Locale case should have no effect
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "DE-de");
+  Services.locale.setRequestedLocales(["DE-de"]);
   restartManager();
 
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     do_check_eq(addon.name, "de-DE Name");
     do_check_eq(addon.description, null);
 
     do_execute_soon(run_test_4);
   });
 }
 
 function run_test_4() {
   // Change locale. es-ES should closely match
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "es-AR");
+  Services.locale.setRequestedLocales(["es-AR"]);
   restartManager();
 
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     do_check_eq(addon.name, "es-ES Name");
     do_check_eq(addon.description, "es-ES Description");
 
     do_execute_soon(run_test_5);
   });
 }
 
 function run_test_5() {
   // Change locale. Either zh-CN or zh-TW could match
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "zh");
+  Services.locale.setRequestedLocales(["zh"]);
   restartManager();
 
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     if (addon.name != "zh-TW Name" && addon.name != "zh-CN Name")
       do_throw("zh matched to " + addon.name);
 
     do_execute_soon(run_test_6);
   });
 }
 
 function run_test_6() {
   // Unknown locale should try to match against en-US as well. Of en,en-GB
   // en should match as being less specific
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
+  Services.locale.setRequestedLocales(["nl-NL"]);
   restartManager();
 
   AddonManager.getAddonByID(ID, function(addon) {
     do_check_neq(addon, null);
     do_check_eq(addon.name, "en Name");
     do_check_eq(addon.description, "en Description");
 
     do_execute_soon(do_test_finished);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js
@@ -4,17 +4,16 @@
  */
 
 const BLOCKLIST_TIMER                 = "blocklist-background-update-timer";
 const PREF_BLOCKLIST_URL              = "extensions.blocklist.url";
 const PREF_BLOCKLIST_ENABLED          = "extensions.blocklist.enabled";
 const PREF_APP_DISTRIBUTION           = "distribution.id";
 const PREF_APP_DISTRIBUTION_VERSION   = "distribution.version";
 const PREF_APP_UPDATE_CHANNEL         = "app.update.channel";
-const PREF_GENERAL_USERAGENT_LOCALE   = "general.useragent.locale";
 const CATEGORY_UPDATE_TIMER           = "update-timer";
 
 // Get the HTTP server.
 Components.utils.import("resource://testing-common/httpd.js");
 Components.utils.import("resource://testing-common/MockRegistrar.jsm");
 var testserver;
 var gOSVersion;
 var gBlocklist;
@@ -116,17 +115,17 @@ function run_test() {
   timerService.fireTimer(BLOCKLIST_TIMER);
 
   // Some values have to be on the default branch to work
   var defaults = Services.prefs.QueryInterface(Components.interfaces.nsIPrefService)
                        .getDefaultBranch(null);
   defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "updatechannel");
   defaults.setCharPref(PREF_APP_DISTRIBUTION, "distribution");
   defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "distribution-version");
-  defaults.setCharPref(PREF_GENERAL_USERAGENT_LOCALE, "locale");
+  Services.locale.setRequestedLocales(["locale"]);
 
   // This should correctly escape everything
   Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/2?" +
                      "%APP_ID%&%APP_VERSION%&%PRODUCT%&%VERSION%&%BUILD_ID%&" +
                      "%BUILD_TARGET%&%LOCALE%&%CHANNEL%&" +
                      "%OS_VERSION%&%PLATFORM_VERSION%&%DISTRIBUTION%&%DISTRIBUTION_VERSION%");
   Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, true);
   timerService.fireTimer(BLOCKLIST_TIMER);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_locale.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_locale.js
@@ -1,25 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-// This verifies that localized properties work as expected
-
-const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
-
-
 function run_test() {
   do_test_pending();
 
   // Setup for test
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
-  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
 
   startupManager();
 
   run_test_1();
 }
 
 // Tests that the localized properties are visible before installation
 function run_test_1() {
@@ -83,32 +76,32 @@ function run_test_4() {
     do_check_eq(contributors[2], "Fr Contributor 3");
 
     do_execute_soon(run_test_5);
   });
 }
 
 // Test that changing locale works
 function run_test_5() {
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE");
+  Services.locale.setRequestedLocales(["de-DE"]);
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
     do_check_neq(addon, null);
 
     do_check_eq(addon.name, "de-DE Name");
     do_check_eq(addon.description, null);
 
     do_execute_soon(run_test_6);
   });
 }
 
 // Test that missing locales use the fallbacks
 function run_test_6() {
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
+  Services.locale.setRequestedLocales(["nl-NL"]);
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) {
     do_check_neq(addon, null);
 
     do_check_eq(addon.name, "Fallback Name");
     do_check_eq(addon.description, "Fallback Description");
 
@@ -127,17 +120,17 @@ function run_test_7() {
     do_check_eq(addon.name, "Name from prefs");
 
     do_execute_soon(run_test_8);
   });
 }
 
 // Test that the prefs will override localized values from the manifest
 function run_test_8() {
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
   restartManager();
 
   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
     do_check_neq(addon, null);
 
     do_check_eq(addon.name, "Name from prefs");
     let contributors = addon.contributors;
     do_check_eq(contributors.length, 2);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update.js
@@ -1,16 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This verifies that add-on update checks work
 
-const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
 // This test requires lightweight themes update to be enabled even if the app
 // doesn't support lightweight themes.
 Services.prefs.setBoolPref("lightweightThemes.update.enabled", true);
@@ -33,18 +31,17 @@ testserver.registerDirectory("/addons/",
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 var originalSyncGUID;
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
-  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
 
   run_next_test();
 }
 
 let testParams = [
   { updateFile: "test_update.rdf",
     appId: "xpcshell@tests.mozilla.org" },
   { updateFile: "test_update.json",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js
@@ -1,16 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // This verifies that add-on update checks work
 
-const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
 // This test requires lightweight themes update to be enabled even if the app
 // doesn't support lightweight themes.
 Services.prefs.setBoolPref("lightweightThemes.update.enabled", true);
@@ -31,18 +29,17 @@ mapFile("/data/test_update.xml", testser
 testserver.registerDirectory("/addons/", do_get_file("addons"));
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
-  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
 
   run_next_test();
 }
 
 let testParams = [
   { updateFile: "test_update.rdf",
     appId: "xpcshell@tests.mozilla.org" },
   { updateFile: "test_update.json",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
@@ -1,18 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 Components.utils.import("resource://gre/modules/AppConstants.jsm");
 
 const ID = "webextension1@tests.mozilla.org";
 
-const PREF_SELECTED_LOCALE = "general.useragent.locale";
-
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 startupManager();
 
 const { GlobalManager } = Components.utils.import("resource://gre/modules/Extension.jsm", {});
 
@@ -143,25 +141,25 @@ add_task(async function test_manifest_lo
   await promiseWebExtensionStartup();
 
   let addon = await promiseAddonByID(extensionId);
   addon.userDisabled = true;
 
   equal(addon.name, "Web Extensiøn foo ☹");
   equal(addon.description, "Descriptïon bar ☹ of add-on");
 
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  Services.locale.setRequestedLocales(["fr-FR"]);
   await promiseRestartManager();
 
   addon = await promiseAddonByID(extensionId);
 
   equal(addon.name, "Web Extensiøn le foo ☺");
   equal(addon.description, "Descriptïon le bar ☺ of add-on");
 
-  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de");
+  Services.locale.setRequestedLocales(["de"]);
   await promiseRestartManager();
 
   addon = await promiseAddonByID(extensionId);
 
   equal(addon.name, "Web Extensiøn foo ☹");
   equal(addon.description, "Descriptïon bar ☹ of add-on");
 
   addon.uninstall();