summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_verify_l10n_strings.js
blob: 9442adf31019d2724d849582aef11dbc9a6fb2c8 (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
/* 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/. */

ChromeUtils.defineESModuleGetters(this, {
  BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs",
});

// Maps add-on descriptors to updated Fluent IDs. Keep it in sync
// with the list in XPIDatabase.jsm.
const updatedAddonFluentIds = new Map([
  ["extension-default-theme-name", "extension-default-theme-name-auto"],
]);

add_task(async function test_ensure_bundled_addons_are_localized() {
  let l10nReg = L10nRegistry.getInstance();
  let bundles = l10nReg.generateBundlesSync(
    ["en-US"],
    ["browser/appExtensionFields.ftl"]
  );
  let addons = await AddonManager.getAllAddons();
  let standardBuiltInThemes = addons.filter(
    addon =>
      addon.isBuiltin &&
      addon.type === "theme" &&
      !addon.id.endsWith("colorway@mozilla.org")
  );
  let bundle = bundles.next().value;

  ok(!!standardBuiltInThemes.length, "Standard built-in themes should exist");

  for (let standardTheme of standardBuiltInThemes) {
    let l10nId = standardTheme.id.replace("@mozilla.org", "");
    for (let prop of ["name", "description"]) {
      let defaultFluentId = `extension-${l10nId}-${prop}`;
      let fluentId =
        updatedAddonFluentIds.get(defaultFluentId) || defaultFluentId;
      ok(
        bundle.hasMessage(fluentId),
        `l10n id for ${standardTheme.id} \"${prop}\" attribute should exist`
      );
    }
  }

  let colorwayThemes = Array.from(BuiltInThemes.builtInThemeMap.keys()).filter(
    id => id.endsWith("colorway@mozilla.org")
  );
  ok(!!colorwayThemes.length, "Colorway themes should exist");
  for (let id of colorwayThemes) {
    let l10nId = id.replace("@mozilla.org", "");
    let [, variantName] = l10nId.split("-", 2);
    if (variantName != "colorway") {
      let defaultFluentId = `extension-colorways-${variantName}-name`;
      let fluentId =
        updatedAddonFluentIds.get(defaultFluentId) || defaultFluentId;
      ok(
        bundle.hasMessage(fluentId),
        `l10n id for ${id} \"name\" attribute should exist`
      );
    }
  }
});