test_addon_events.js (2183B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { AddonManager } = ChromeUtils.importESModule( 7 "resource://gre/modules/AddonManager.sys.mjs" 8 ); 9 add_task(async function testReloadExitedAddon() { 10 await startupAddonsManager(); 11 12 DevToolsServer.init(); 13 DevToolsServer.registerAllActors(); 14 15 const client = new DevToolsClient(DevToolsServer.connectPipe()); 16 await client.connect(); 17 18 // Retrieve the current list of addons to be notified of the next list update. 19 // We will also call listAddons every time we receive the event "addonListChanged" for 20 // the same reason. 21 await client.mainRoot.listAddons(); 22 23 info("Install the addon"); 24 const addonFile = do_get_file("addons/web-extension", false); 25 26 let installedAddon; 27 await expectAddonListChanged(client, async () => { 28 installedAddon = await AddonManager.installTemporaryAddon(addonFile); 29 }); 30 ok(true, "Received onAddonListChanged when installing addon"); 31 32 info("Disable the addon"); 33 await expectAddonListChanged(client, () => installedAddon.disable()); 34 ok(true, "Received onAddonListChanged when disabling addon"); 35 36 info("Enable the addon"); 37 await expectAddonListChanged(client, () => installedAddon.enable()); 38 ok(true, "Received onAddonListChanged when enabling addon"); 39 40 info("Put the addon in pending uninstall mode"); 41 await expectAddonListChanged(client, () => installedAddon.uninstall(true)); 42 ok(true, "Received onAddonListChanged when addon moves to pending uninstall"); 43 44 info("Cancel uninstall for addon"); 45 await expectAddonListChanged(client, () => installedAddon.cancelUninstall()); 46 ok(true, "Received onAddonListChanged when addon uninstall is canceled"); 47 48 info("Completely uninstall the addon"); 49 await expectAddonListChanged(client, () => installedAddon.uninstall()); 50 ok(true, "Received onAddonListChanged when addon is uninstalled"); 51 52 await close(client); 53 }); 54 55 async function expectAddonListChanged(client, predicate) { 56 const onAddonListChanged = client.mainRoot.once("addonListChanged"); 57 await predicate(); 58 await onAddonListChanged; 59 await client.mainRoot.listAddons(); 60 }