summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_webapi_install_disabled.js
blob: 5bc291fe7a75b014ac9b340aed3f67dc16f6e2f7 (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
const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
const XPI_URL = `${SECURE_TESTROOT}../xpinstall/amosigned.xpi`;

function waitForClear() {
  const MSG = "WebAPICleanup";
  return new Promise(resolve => {
    let listener = {
      receiveMessage(msg) {
        if (msg.name == MSG) {
          Services.mm.removeMessageListener(MSG, listener);
          resolve();
        }
      },
    };

    Services.mm.addMessageListener(MSG, listener, true);
  });
}

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.webapi.testing", true],
      ["xpinstall.enabled", false],
      ["extensions.install.requireBuiltInCerts", false],
    ],
  });
  info("added preferences");
});

async function testInstall(browser, args) {
  let success = await SpecialPowers.spawn(
    browser,
    [{ args }],
    async function (opts) {
      let { args } = opts;
      let install;
      try {
        install = await content.navigator.mozAddonManager.createInstall(args);
      } catch (e) {}
      return !!install;
    }
  );
  is(success, false, "Install was blocked");
}

add_task(async function () {
  // withNewTab() will close the test tab before returning, at which point
  // the cleanup event will come from the content process.  We need to see
  // that event but don't want to race to install a listener for it after
  // the tab is closed.  So set up the listener now but don't yield the
  // listening promise until below.
  let clearPromise = waitForClear();

  await BrowserTestUtils.withNewTab(TESTPAGE, async function (browser) {
    await testInstall(browser, { url: XPI_URL });
  });

  await clearPromise;
});