Bug 1279046 Expose onOperationCancelled to a.m.o r=rhelmer

MozReview-Commit-ID: 2QTjGi8tnjT

--HG--
extra : rebase_source : c01c7649105a47e83339186bfc4d4a0b8b74a2dc
This commit is contained in:
Andrew Swan 2016-06-24 10:16:50 -07:00
Родитель b4ecd2ac77
Коммит 6528b7ae63
3 изменённых файлов: 29 добавлений и 0 удалений

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

@ -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);

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

@ -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");
});
});

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

@ -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};