tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_permissions_local_file.js (1910B)


      1 "use strict";
      2 
      3 async function installFile(filename) {
      4  const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
      5    Ci.nsIChromeRegistry
      6  );
      7  let chromeUrl = Services.io.newURI(gTestPath);
      8  let fileUrl = ChromeRegistry.convertChromeURL(chromeUrl);
      9  let file = fileUrl.QueryInterface(Ci.nsIFileURL).file;
     10  file.leafName = filename;
     11 
     12  let MockFilePicker = SpecialPowers.MockFilePicker;
     13  MockFilePicker.init(window.browsingContext);
     14  MockFilePicker.setFiles([file]);
     15  MockFilePicker.afterOpenCallback = MockFilePicker.cleanup;
     16 
     17  let { document } = await BrowserAddonUI.openAddonsMgr(
     18    "addons://list/extension"
     19  );
     20 
     21  // Do the install...
     22  await waitAboutAddonsViewLoaded(document);
     23  let installButton = document.querySelector('[action="install-from-file"]');
     24  installButton.click();
     25 }
     26 
     27 add_task(async function test_install_extension_from_local_file() {
     28  // Listen for the first installId so we can check it later.
     29  let firstInstallId = null;
     30  AddonManager.addInstallListener({
     31    onNewInstall(install) {
     32      firstInstallId = install.installId;
     33      AddonManager.removeInstallListener(this);
     34    },
     35  });
     36 
     37  await SpecialPowers.pushPrefEnv({
     38    set: [
     39      // This test asserts that the extension icon is in the install dialog
     40      // and so it requires the signature checks to be enabled (otherwise the
     41      // extension icon is expected to be replaced by a warning icon) and the
     42      // two test extension used by this test (browser_webext_nopermissions.xpi
     43      // and browser_webext_permissions.xpi) are signed using AMO stage signatures.
     44      ["xpinstall.signatures.dev-root", true],
     45    ],
     46  });
     47 
     48  // Install the add-ons.
     49  await testInstallMethod(installFile, "installLocal");
     50 
     51  await SpecialPowers.popPrefEnv();
     52 
     53  // Check we got an installId.
     54  ok(
     55    firstInstallId != null && !isNaN(firstInstallId),
     56    "There was an installId found"
     57  );
     58 });