summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_addon_events.js
blob: 262a604953e40ba3eec1f4eb753a2e8951b93e3a (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { AddonManager } = ChromeUtils.importESModule(
  "resource://gre/modules/AddonManager.sys.mjs"
);
add_task(async function testReloadExitedAddon() {
  await startupAddonsManager();

  DevToolsServer.init();
  DevToolsServer.registerAllActors();

  const client = new DevToolsClient(DevToolsServer.connectPipe());
  await client.connect();

  // Retrieve the current list of addons to be notified of the next list update.
  // We will also call listAddons every time we receive the event "addonListChanged" for
  // the same reason.
  await client.mainRoot.listAddons();

  info("Install the addon");
  const addonFile = do_get_file("addons/web-extension", false);

  let installedAddon;
  await expectAddonListChanged(client, async () => {
    installedAddon = await AddonManager.installTemporaryAddon(addonFile);
  });
  ok(true, "Received onAddonListChanged when installing addon");

  info("Disable the addon");
  await expectAddonListChanged(client, () => installedAddon.disable());
  ok(true, "Received onAddonListChanged when disabling addon");

  info("Enable the addon");
  await expectAddonListChanged(client, () => installedAddon.enable());
  ok(true, "Received onAddonListChanged when enabling addon");

  info("Put the addon in pending uninstall mode");
  await expectAddonListChanged(client, () => installedAddon.uninstall(true));
  ok(true, "Received onAddonListChanged when addon moves to pending uninstall");

  info("Cancel uninstall for addon");
  await expectAddonListChanged(client, () => installedAddon.cancelUninstall());
  ok(true, "Received onAddonListChanged when addon uninstall is canceled");

  info("Completely uninstall the addon");
  await expectAddonListChanged(client, () => installedAddon.uninstall());
  ok(true, "Received onAddonListChanged when addon is uninstalled");

  await close(client);
});

async function expectAddonListChanged(client, predicate) {
  const onAddonListChanged = client.mainRoot.once("addonListChanged");
  await predicate();
  await onAddonListChanged;
  await client.mainRoot.listAddons();
}