summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_distribution_langpack.js
blob: 0e594d60ecd0d931cb0ecfae514d5a2da74c9839 (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
104
105
106
107
108
109
110
111
112
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// This verifies that add-ons distributed with the application in
// langauge subdirectories correctly get installed

// Allow distributed add-ons to install
Services.prefs.setBoolPref("extensions.installDistroAddons", true);

createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");

const profileDir = gProfD.clone();
profileDir.append("extensions");
const distroDir = gProfD.clone();
distroDir.append("distribution");
distroDir.append("extensions");
registerDirectory("XREAppDist", distroDir.parent);
const enUSDistroDir = distroDir.clone();
enUSDistroDir.append("locale-en-US");
const deDEDistroDir = distroDir.clone();
deDEDistroDir.append("locale-de-DE");
const esESDistroDir = distroDir.clone();
esESDistroDir.append("locale-es-ES");

const enUSID = "addon-en-US@tests.mozilla.org";
const deDEID = "addon-de-DE@tests.mozilla.org";
const esESID = "addon-es-ES@tests.mozilla.org";

async function writeDistroAddons(version) {
  let xpi = await createTempWebExtensionFile({
    manifest: {
      version,
      browser_specific_settings: { gecko: { id: enUSID } },
    },
  });
  xpi.copyTo(enUSDistroDir, `${enUSID}.xpi`);

  xpi = await createTempWebExtensionFile({
    manifest: {
      version,
      browser_specific_settings: { gecko: { id: deDEID } },
    },
  });
  xpi.copyTo(deDEDistroDir, `${deDEID}.xpi`);

  xpi = await createTempWebExtensionFile({
    manifest: {
      version,
      browser_specific_settings: { gecko: { id: esESID } },
    },
  });
  xpi.copyTo(esESDistroDir, `${esESID}.xpi`);
}

add_task(async function setup() {
  await writeDistroAddons("1.0");
});

// Tests that on the first startup the requested locale
// add-on gets installed, and others don't.
add_task(async function run_locale_test() {
  Services.locale.availableLocales = ["de-DE", "en-US"];
  Services.locale.requestedLocales = ["de-DE"];

  Assert.equal(Services.locale.requestedLocale, "de-DE");

  await promiseStartupManager();

  let a1 = await AddonManager.getAddonByID(deDEID);
  Assert.notEqual(a1, null);
  Assert.equal(a1.version, "1.0");
  Assert.ok(a1.isActive);
  Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE);
  Assert.ok(!a1.foreignInstall);

  let a2 = await AddonManager.getAddonByID(enUSID);
  Assert.equal(a2, null);

  let a3 = await AddonManager.getAddonByID(esESID);
  Assert.equal(a3, null);

  await a1.uninstall();
  await promiseShutdownManager();
});

// Tests that on the first startup the correct fallback locale
// add-on gets installed, and others don't.
add_task(async function run_fallback_test() {
  Services.locale.availableLocales = ["es-ES", "en-US"];
  Services.locale.requestedLocales = ["es-UY"];

  Assert.equal(Services.locale.requestedLocale, "es-UY");

  await promiseStartupManager();

  let a1 = await AddonManager.getAddonByID(esESID);
  Assert.notEqual(a1, null);
  Assert.equal(a1.version, "1.0");
  Assert.ok(a1.isActive);
  Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE);
  Assert.ok(!a1.foreignInstall);

  let a2 = await AddonManager.getAddonByID(enUSID);
  Assert.equal(a2, null);

  let a3 = await AddonManager.getAddonByID(deDEID);
  Assert.equal(a3, null);

  await a1.uninstall();
  await promiseShutdownManager();
});