Bug 1506581 - Listen to all possible AddonManager events in BrowserAddonList;r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D11644

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2018-11-13 14:26:39 +00:00
Родитель 6c78bc8bfd
Коммит c1bc33b0e9
3 изменённых файлов: 101 добавлений и 3 удалений

Просмотреть файл

@ -713,13 +713,50 @@ Object.defineProperty(BrowserAddonList.prototype, "onListChanged", {
},
});
BrowserAddonList.prototype.onInstalled = function(addon) {
this._notifyListChanged();
this._adjustListener();
/**
* AddonManager listener must implement onDisabled.
*/
BrowserAddonList.prototype.onDisabled = function(addon) {
this._onAddonManagerUpdated();
};
/**
* AddonManager listener must implement onEnabled.
*/
BrowserAddonList.prototype.onEnabled = function(addon) {
this._onAddonManagerUpdated();
};
/**
* AddonManager listener must implement onInstalled.
*/
BrowserAddonList.prototype.onInstalled = function(addon) {
this._onAddonManagerUpdated();
};
/**
* AddonManager listener must implement onOperationCancelled.
*/
BrowserAddonList.prototype.onOperationCancelled = function(addon) {
this._onAddonManagerUpdated();
};
/**
* AddonManager listener must implement onUninstalling.
*/
BrowserAddonList.prototype.onUninstalling = function(addon) {
this._onAddonManagerUpdated();
};
/**
* AddonManager listener must implement onUninstalled.
*/
BrowserAddonList.prototype.onUninstalled = function(addon) {
this._actorByAddonId.delete(addon.id);
this._onAddonManagerUpdated();
};
BrowserAddonList.prototype._onAddonManagerUpdated = function(addon) {
this._notifyListChanged();
this._adjustListener();
};

Просмотреть файл

@ -0,0 +1,60 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable no-shadow */
"use strict";
const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
startupAddonsManager();
add_task(async function testReloadExitedAddon() {
DebuggerServer.init();
DebuggerServer.registerAllActors();
const client = new DebuggerClient(DebuggerServer.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.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.listAddons();
}

Просмотреть файл

@ -33,6 +33,7 @@ support-files =
addons/web-extension-upgrade/manifest.json
addons/web-extension2/manifest.json
[test_addon_events.js]
[test_addon_reload.js]
skip-if = verify # verify mode causes AddonRepository shutdown errors
[test_addons_actor.js]