diff --git a/toolkit/mozapps/extensions/addonManager.js b/toolkit/mozapps/extensions/addonManager.js index 02a1f98e7ee9..942652d8a815 100644 --- a/toolkit/mozapps/extensions/addonManager.js +++ b/toolkit/mozapps/extensions/addonManager.js @@ -243,6 +243,7 @@ amManager.prototype = { onInstalled: (addon) => handler("onInstalled", addon.id, false), onUninstalling: (addon, needsRestart) => handler("onUninstalling", addon.id, needsRestart), onUninstalled: (addon) => handler("onUninstalled", addon.id, false), + onOperationCancelled: (addon) => handler("onOperationCancelled", addon.id, false), }; } AddonManager.addAddonListener(this.addonListener); diff --git a/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js b/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js index 2bf9406c76c8..b8049f13cde1 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js +++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_addon_listener.js @@ -18,6 +18,7 @@ const RESTART_ID = "restart@tests.mozilla.org"; const RESTART_DISABLED_ID = "restart_disabled@tests.mozilla.org"; const RESTARTLESS_ID = "restartless@tests.mozilla.org"; const INSTALL_ID = "install@tests.mozilla.org"; +const CANCEL_ID = "cancel@tests.mozilla.org"; let provider = new MockProvider(false); provider.createAddons([ @@ -35,6 +36,10 @@ provider.createAddons([ name: "Restartless add-on", operationsRequiringRestart: AddonManager.OP_NEED_RESTART_NONE, }, + { + id: CANCEL_ID, + name: "Add-on for uninstall cancel", + }, ]); // Test disable of add-on requiring restart @@ -145,3 +150,25 @@ add_task(function* test_uninstall() { Assert.deepEqual(events, expected, "Got expected uninstall events"); }); }); + +// Test cancel of uninstall. +add_task(function* test_cancel() { + yield BrowserTestUtils.withNewTab(TESTPAGE, function*(browser) { + let addon = yield promiseAddonByID(CANCEL_ID); + isnot(addon, null, "Found add-on for cancelling uninstall"); + + addon.uninstall(); + + let events = yield getListenerEvents(browser); + let expected = [ + {id: CANCEL_ID, needsRestart: true, event: "onUninstalling"}, + ]; + Assert.deepEqual(events, expected, "Got expected uninstalling event"); + + addon.cancelUninstall(); + events = yield getListenerEvents(browser); + expected.push({id: CANCEL_ID, needsRestart: false, event: "onOperationCancelled"}); + Assert.deepEqual(events, expected, "Got expected cancel event"); + }); +}); + diff --git a/toolkit/mozapps/extensions/test/browser/webapi_addon_listener.html b/toolkit/mozapps/extensions/test/browser/webapi_addon_listener.html index 05da5fb8c142..241779bda79c 100644 --- a/toolkit/mozapps/extensions/test/browser/webapi_addon_listener.html +++ b/toolkit/mozapps/extensions/test/browser/webapi_addon_listener.html @@ -14,6 +14,7 @@ let resultEl = document.getElementById("result"); "onInstalled", "onUninstalling", "onUninstalled", + "onOperationCancelled", ].forEach(event => { navigator.mozAddonManager.addEventListener(event, data => { let obj = {event, id: data.id, needsRestart: data.needsRestart};