Bug 1497549 - Add support for setting locale via policy. r=Felipe,zbraniecki, a=lizzard
authorMichael Kaply <mozilla@kaply.com>
Fri, 09 Nov 2018 16:25:56 -0600
changeset 450458 4983ed48535aeea7058c838fa81633faabab9661
parent 450457 b9c34e2086c23f68fcf76a1e8d969ac3e1832dc3
child 450459 f27badd7938f81b636e922692abdf013543b1887
push id236
push userryanvm@gmail.com
push dateTue, 13 Nov 2018 00:43:03 +0000
treeherdermozilla-esr60@ad2e4899a821 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, zbraniecki, lizzard
bugs1497549
milestone60.3.1
Bug 1497549 - Add support for setting locale via policy. r=Felipe,zbraniecki, a=lizzard
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policy_locale.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -640,16 +640,22 @@ var Policies = {
         manager.disallowFeature("changeProxySettings");
         ProxyPolicies.configureProxySettings(param, setAndLockPref);
       } else {
         ProxyPolicies.configureProxySettings(param, setDefaultPref);
       }
     }
   },
 
+  "RequestedLocales": {
+    onBeforeAddons(manager, param) {
+      Services.locale.setRequestedLocales(param);
+    },
+  },
+
   "SanitizeOnShutdown": {
     onBeforeUIStartup(manager, param) {
       setAndLockPref("privacy.sanitize.sanitizeOnShutdown", param);
       if (param) {
         setAndLockPref("privacy.clearOnShutdown.cache", true);
         setAndLockPref("privacy.clearOnShutdown.cookies", true);
         setAndLockPref("privacy.clearOnShutdown.downloads", true);
         setAndLockPref("privacy.clearOnShutdown.formdata", true);
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -670,16 +670,23 @@
         },
 
         "AutoLogin": {
           "type": "boolean"
         }
       }
     },
 
+    "RequestedLocales": {
+      "type": "array",
+      "items": {
+        "type": "string"
+      }
+    },
+
     "SanitizeOnShutdown": {
       "description": "Clears ALL browser data on shutdown.",
       "first_available": "60.0",
 
       "type": "boolean"
     },
 
     "SearchBar": {
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -41,15 +41,16 @@ support-files =
 [browser_policy_disable_profile_reset.js]
 [browser_policy_disable_profile_import.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_disable_telemetry.js]
 [browser_policy_display_bookmarks.js]
 [browser_policy_display_menu.js]
 [browser_policy_extensions.js]
+[browser_policy_locale.js]
 [browser_policy_override_postupdatepage.js]
 [browser_policy_permissions.js]
 [browser_policy_proxy.js]
 [browser_policy_search_engine.js]
 [browser_policy_searchbar.js]
 [browser_policy_set_homepage.js]
 [browser_policy_websitefilter.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_locale.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const REQ_LOC_CHANGE_EVENT = "intl:requested-locales-changed";
+
+function promiseLocaleChanged() {
+  return new Promise(resolve => {
+    let localeObserver = {
+      observe(aSubject, aTopic, aData) {
+        switch (aTopic) {
+          case REQ_LOC_CHANGE_EVENT:
+            let reqLocs = Services.locale.getRequestedLocales();
+            is(reqLocs[0], "de");
+            Services.obs.removeObserver(localeObserver, REQ_LOC_CHANGE_EVENT);
+            resolve();
+        }
+      },
+    };
+    Services.obs.addObserver(localeObserver, REQ_LOC_CHANGE_EVENT);
+  });
+}
+
+add_task(async function test_requested_locale() {
+  let localePromise = promiseLocaleChanged();
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "RequestedLocales": ["de"],
+    },
+  });
+  await localePromise;
+});