summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/head_compat.js
blob: 79ddb8dd3fdd2fcae6a343b52a6ebbb05d181ab9 (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
//
// This file provides helpers for tests of addons that use strictCompatibility.
// Since WebExtensions cannot opt out of strictCompatibility, we add a
// simple extension loader that lets tests directly set AddonInternal
// properties (including strictCompatibility)
//

/* import-globals-from head_addons.js */

const { XPIExports } = ChromeUtils.importESModule(
  "resource://gre/modules/addons/XPIExports.sys.mjs"
);

const MANIFEST = "compat_manifest.json";

AddonManager.addExternalExtensionLoader({
  name: "compat-test",
  manifestFile: MANIFEST,
  async loadManifest(pkg) {
    let addon = new XPIExports.AddonInternal();
    let manifest = JSON.parse(await pkg.readString(MANIFEST));
    Object.assign(addon, manifest);
    return addon;
  },
  loadScope(addon, file) {
    return {
      install() {},
      uninstall() {},
      startup() {},
      shutdonw() {},
    };
  },
});

const DEFAULTS = {
  defaultLocale: {},
  locales: [],
  targetPlatforms: [],
  type: "extension",
  version: "1.0",
};

function createAddon(manifest) {
  return AddonTestUtils.createTempXPIFile({
    [MANIFEST]: Object.assign({}, DEFAULTS, manifest),
  });
}