summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/webextensions/browser_permissions_local_file.js
blob: 22dff8cb38d51abd9ccb2c5c94d5dc680916611f (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
"use strict";

async function installFile(filename) {
  const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
    Ci.nsIChromeRegistry
  );
  let chromeUrl = Services.io.newURI(gTestPath);
  let fileUrl = ChromeRegistry.convertChromeURL(chromeUrl);
  let file = fileUrl.QueryInterface(Ci.nsIFileURL).file;
  file.leafName = filename;

  let MockFilePicker = SpecialPowers.MockFilePicker;
  MockFilePicker.init(window.browsingContext);
  MockFilePicker.setFiles([file]);
  MockFilePicker.afterOpenCallback = MockFilePicker.cleanup;

  let { document } = await BrowserOpenAddonsMgr("addons://list/extension");

  // Do the install...
  await waitAboutAddonsViewLoaded(document);
  let installButton = document.querySelector('[action="install-from-file"]');
  installButton.click();
}

add_task(async function test_install_extension_from_local_file() {
  // Listen for the first installId so we can check it later.
  let firstInstallId = null;
  AddonManager.addInstallListener({
    onNewInstall(install) {
      firstInstallId = install.installId;
      AddonManager.removeInstallListener(this);
    },
  });

  await SpecialPowers.pushPrefEnv({
    set: [
      // This test asserts that the extension icon is in the install dialog
      // and so it requires the signature checks to be enabled (otherwise the
      // extension icon is expected to be replaced by a warning icon) and the
      // two test extension used by this test (browser_webext_nopermissions.xpi
      // and browser_webext_permissions.xpi) are signed using AMO stage signatures.
      ["xpinstall.signatures.dev-root", true],
    ],
  });

  // Install the add-ons.
  await testInstallMethod(installFile, "installLocal");

  await SpecialPowers.popPrefEnv();

  // Check we got an installId.
  ok(
    firstInstallId != null && !isNaN(firstInstallId),
    "There was an installId found"
  );
});