tor-browser

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

test_extensions.js (2356B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 const { AddonTestUtils } = ChromeUtils.importESModule(
      6  "resource://testing-common/AddonTestUtils.sys.mjs"
      7 );
      8 const { AddonManager } = ChromeUtils.importESModule(
      9  "resource://gre/modules/AddonManager.sys.mjs"
     10 );
     11 
     12 AddonTestUtils.init(this);
     13 AddonTestUtils.overrideCertDB();
     14 AddonTestUtils.appInfo = getAppInfo();
     15 
     16 const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
     17 const BASE_URL = `http://example.com/data`;
     18 
     19 let addonID = "policytest2@mozilla.com";
     20 
     21 add_task(async function setup() {
     22  await AddonTestUtils.promiseStartupManager();
     23 
     24  let webExtensionFile = AddonTestUtils.createTempWebExtensionFile({
     25    manifest: {
     26      browser_specific_settings: {
     27        gecko: {
     28          id: addonID,
     29        },
     30      },
     31    },
     32  });
     33 
     34  server.registerFile("/data/policy_test.xpi", webExtensionFile);
     35 });
     36 
     37 add_task(async function test_addon_forceinstalled_remote() {
     38  await Promise.all([
     39    AddonTestUtils.promiseInstallEvent("onInstallEnded"),
     40    setupPolicyEngineWithJson({
     41      policies: {
     42        Extensions: {
     43          Install: [BASE_URL + "/policy_test.xpi"],
     44          Locked: [addonID],
     45        },
     46      },
     47    }),
     48  ]);
     49  let addon = await AddonManager.getAddonByID(addonID);
     50  notEqual(addon, null, "Addon should not be null");
     51  equal(addon.appDisabled, false, "Addon should not be disabled");
     52  equal(
     53    addon.permissions & AddonManager.PERM_CAN_UNINSTALL,
     54    0,
     55    "Addon should not be able to be uninstalled."
     56  );
     57  equal(
     58    addon.permissions & AddonManager.PERM_CAN_DISABLE,
     59    0,
     60    "Addon should not be able to be disabled."
     61  );
     62  await assertManagementAPIInstallType(addon.id, "admin");
     63 
     64  await addon.uninstall();
     65 });
     66 
     67 add_task(async function test_addon_forceinstalled_local() {
     68  let addonID2 = "policytest@mozilla.com";
     69 
     70  let file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     71  file.append("policytest_v0.1.xpi");
     72  await Promise.all([
     73    AddonTestUtils.promiseInstallEvent("onInstallEnded"),
     74    setupPolicyEngineWithJson({
     75      policies: {
     76        Extensions: {
     77          Install: [file.path],
     78        },
     79      },
     80    }),
     81  ]);
     82  let addon = await AddonManager.getAddonByID(addonID2);
     83  notEqual(addon, null, "Addon should not be null");
     84  await addon.uninstall();
     85 });