summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/xpcshell/test_signed_multi.js
blob: 01de29088e57ec5232778d4050ddc3ce6d725e7c (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
// Enable signature checks for these tests
gUseRealCertChecks = true;
// Disable update security
Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);

const DATA = "data/signing_checks/";

// Each multi-package XPI contains one valid theme and one other add-on that
// has the following error state:
const ADDONS = {
  "multi_signed.xpi": 0,
  "multi_badid.xpi": AddonManager.ERROR_CORRUPT_FILE,
  "multi_broken.xpi": AddonManager.ERROR_CORRUPT_FILE,
  "multi_unsigned.xpi": AddonManager.ERROR_SIGNEDSTATE_REQUIRED,
};

function createInstall(filename) {
  return new Promise(resolve => {
    AddonManager.getInstallForFile(do_get_file(DATA + filename), resolve, "application/x-xpinstall");
  });
}

function run_test() {
  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "4", "4");
  startupManager();

  run_next_test();
}

function* test_addon(filename) {
  do_print("Testing " + filename);

  let install = yield createInstall(filename);
  do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
  do_check_eq(install.error, 0);

  do_check_neq(install.linkedInstalls, null);
  do_check_eq(install.linkedInstalls.length, 1);

  let linked = install.linkedInstalls[0];
  do_print(linked.state);
  do_check_eq(linked.error, ADDONS[filename]);
  if (linked.error == 0) {
    do_check_eq(linked.state, AddonManager.STATE_DOWNLOADED);
    linked.cancel();
  }
  else {
    do_check_eq(linked.state, AddonManager.STATE_DOWNLOAD_FAILED);
  }

  install.cancel();
}

for (let filename of Object.keys(ADDONS))
  add_task(test_addon.bind(null, filename));