summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_test_wrapper.js
blob: b4b1b87ee5c7de85e574fcaaa637bb6cb88c4113 (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
"use strict";

Services.prefs.setBoolPref("extensions.blocklist.enabled", false);

ChromeUtils.defineESModuleGetters(this, {
  AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
});

AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo(
  "xpcshell@tests.mozilla.org",
  "XPCShell",
  "1",
  "43"
);

const TEST_ADDON_ID = "@some-permanent-test-addon";

// Load a permanent extension that eventually unloads the extension immediately
// after add-on startup, to set the stage as a regression test for bug 1575190.
add_task(async function setup_wrapper() {
  let extension = ExtensionTestUtils.loadExtension({
    useAddonManager: "permanent",
    manifest: {
      browser_specific_settings: { gecko: { id: TEST_ADDON_ID } },
    },
    background() {
      browser.test.sendMessage("started_up");
    },
  });

  await AddonTestUtils.promiseStartupManager();
  await extension.startup();
  await extension.awaitBackgroundStarted();
  await AddonTestUtils.promiseShutdownManager();

  // Check message because it is expected to be received while `startup()` was
  // pending resolution.
  info("Awaiting expected started_up message 1");
  await extension.awaitMessage("started_up");

  // Load AddonManager, and unload the extension as soon as it has started.
  await AddonTestUtils.promiseStartupManager();
  await extension.awaitBackgroundStarted();
  await extension.unload();
  await AddonTestUtils.promiseShutdownManager();

  // Confirm that the extension has started when promiseStartupManager returned.
  info("Awaiting expected started_up message 2");
  await extension.awaitMessage("started_up");
});

// Check that the add-on from the previous test has indeed been uninstalled.
add_task(async function restart_addon_manager_after_extension_unload() {
  await AddonTestUtils.promiseStartupManager();
  let addon = await AddonManager.getAddonByID(TEST_ADDON_ID);
  equal(addon, null, "Test add-on should have been removed");
  await AddonTestUtils.promiseShutdownManager();
});