summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/enterprisepolicies/tests/xpcshell/test_requestedlocales.js
blob: 6c298cee5afe452738eb983d8729401653f5b2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* 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(requestedLocale) {
  return new Promise(resolve => {
    let localeObserver = {
      observe(aSubject, aTopic, aData) {
        switch (aTopic) {
          case REQ_LOC_CHANGE_EVENT:
            let reqLocs = Services.locale.requestedLocales;
            equal(reqLocs[0], requestedLocale);
            Services.obs.removeObserver(localeObserver, REQ_LOC_CHANGE_EVENT);
            resolve();
        }
      },
    };
    Services.obs.addObserver(localeObserver, REQ_LOC_CHANGE_EVENT);
  });
}

add_task(async function test_requested_locale_array() {
  let originalLocales = Services.locale.requestedLocales;
  let localePromise = promiseLocaleChanged("de");
  await setupPolicyEngineWithJson({
    policies: {
      RequestedLocales: ["de"],
    },
  });
  await localePromise;
  Services.locale.requestedLocales = originalLocales;
});

add_task(async function test_requested_locale_string() {
  let originalLocales = Services.locale.requestedLocales;
  let localePromise = promiseLocaleChanged("fr");
  await setupPolicyEngineWithJson({
    policies: {
      RequestedLocales: "fr",
    },
  });
  await localePromise;
  Services.locale.requestedLocales = originalLocales;
});