summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_locale.js
blob: 2824c489b41bc4587c476f4c5b6901fc1cbed3e3 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */
add_task(async function setup() {
  // Setup for test
  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
  await promiseStartupManager();
});

// Tests that the localized properties are visible before installation
add_task(async function test_1() {
  await restartWithLocales(["fr-FR"]);

  let xpi = AddonTestUtils.createTempWebExtensionFile({
    manifest: {
      name: "__MSG_name__",
      description: "__MSG_description__",
      default_locale: "en",

      browser_specific_settings: {
        gecko: {
          id: "addon1@tests.mozilla.org",
        },
      },
    },

    files: {
      "_locales/en/messages.json": {
        name: {
          message: "Fallback Name",
          description: "name",
        },
        description: {
          message: "Fallback Description",
          description: "description",
        },
      },
      "_locales/fr_FR/messages.json": {
        name: {
          message: "fr-FR Name",
          description: "name",
        },
        description: {
          message: "fr-FR Description",
          description: "description",
        },
      },
      "_locales/de-DE/messages.json": {
        name: {
          message: "de-DE Name",
          description: "name",
        },
      },
    },
  });

  let install = await AddonManager.getInstallForFile(xpi);
  Assert.equal(install.addon.name, "fr-FR Name");
  Assert.equal(install.addon.description, "fr-FR Description");
  await install.install();
});

// Tests that the localized properties are visible after installation
add_task(async function test_2() {
  let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
  Assert.notEqual(addon, null);

  Assert.equal(addon.name, "fr-FR Name");
  Assert.equal(addon.description, "fr-FR Description");

  await addon.disable();
});

// Test that the localized properties are still there when disabled.
add_task(async function test_3() {
  let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
  Assert.notEqual(addon, null);
  Assert.equal(addon.name, "fr-FR Name");
});

// Test that changing locale works
add_task(async function test_5() {
  await restartWithLocales(["de-DE"]);

  let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
  Assert.notEqual(addon, null);

  Assert.equal(addon.name, "de-DE Name");
  Assert.equal(addon.description, "Fallback Description");
});

// Test that missing locales use the fallbacks
add_task(async function test_6() {
  await restartWithLocales(["nl-NL"]);

  let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
  Assert.notEqual(addon, null);

  Assert.equal(addon.name, "Fallback Name");
  Assert.equal(addon.description, "Fallback Description");

  await addon.enable();
});