Bug 1255041 - Implement uninstall() on DOM Addon objects. r=rhelmer

MozReview-Commit-ID: Ad3r78Y9IKb

--HG--
extra : rebase_source : 6a5f0d85b5c13138d6df57c9d5f6233aa10868bb
This commit is contained in:
Andrew Swan 2016-04-21 09:59:14 -07:00
Родитель b6755044e2
Коммит 87981b40e1
6 изменённых файлов: 87 добавлений и 11 удалений

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

@ -314,10 +314,12 @@ function webAPIForAddon(addon) {
let result = {}; let result = {};
// By default just pass through any plain property, the webidl will control // By default just pass through any plain property, the webidl will
// access. // control access. Also filter out private properties, regular Addon
// objects are okay but MockAddon used in tests has non-serializable
// private properties.
for (let prop in addon) { for (let prop in addon) {
if (typeof(addon[prop]) != "function") { if (prop[0] != "_" && typeof(addon[prop]) != "function") {
result[prop] = addon[prop]; result[prop] = addon[prop];
} }
} }
@ -2859,6 +2861,24 @@ var AddonManagerInternal = {
}); });
}, },
addonUninstall(target, id) {
return new Promise(resolve => {
AddonManager.getAddonByID(id, addon => {
if (!addon) {
resolve(false);
}
try {
addon.uninstall();
resolve(true);
} catch (err) {
Cu.reportError(err);
resolve(false);
}
});
});
},
addonInstallDoInstall(target, id) { addonInstallDoInstall(target, id) {
let state = this.installs.get(id); let state = this.installs.get(id);
if (!state) { if (!state) {

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

@ -76,16 +76,13 @@ const APIBroker = {
APIBroker.init(); APIBroker.init();
function Addon(win, properties) { function Addon(window, properties) {
this.window = window;
// We trust the webidl binding to broker access to our properties. // We trust the webidl binding to broker access to our properties.
for (let key of Object.keys(properties)) { for (let key of Object.keys(properties)) {
this[key] = properties[key]; this[key] = properties[key];
} }
this.uninstall = function() {
let err = new win.Error("not yet implemented");
return win.Promise.reject(err);
};
} }
function AddonInstall(window, properties) { function AddonInstall(window, properties) {
@ -128,6 +125,12 @@ function WebAPITask(generator) {
} }
} }
Addon.prototype = {
uninstall: WebAPITask(function*() {
return yield APIBroker.sendRequest("addonUninstall", this.id);
}),
};
const INSTALL_EVENTS = [ const INSTALL_EVENTS = [
"onDownloadStarted", "onDownloadStarted",
"onDownloadProgress", "onDownloadProgress",

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

@ -67,5 +67,6 @@ skip-if = require_signing
[browser_webapi.js] [browser_webapi.js]
[browser_webapi_access.js] [browser_webapi_access.js]
[browser_webapi_install.js] [browser_webapi_install.js]
[browser_webapi_uninstall.js]
[include:browser-common.ini] [include:browser-common.ini]

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

@ -232,7 +232,7 @@ add_task(makeInstallTest(function* (browser) {
} }
]; ];
yield testInstall(browser, XPI_URL + "bogus", steps, "a basic install works"); yield testInstall(browser, XPI_URL + "bogus", steps, "install of a bad url fails");
let addons = yield promiseAddonsByIDs([ID]); let addons = yield promiseAddonsByIDs([ID]);
is(addons[0], null, "The addon was not installed"); is(addons[0], null, "The addon was not installed");

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

@ -0,0 +1,51 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const TESTPAGE = `${SECURE_TESTROOT}webapi_checkavailable.html`;
Services.prefs.setBoolPref("extensions.webapi.testing", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("extensions.webapi.testing");
});
function testWithAPI(task) {
return function*() {
yield BrowserTestUtils.withNewTab(TESTPAGE, task);
}
}
function API_uninstallByID(browser, id) {
return ContentTask.spawn(browser, id, function*(id) {
let addon = yield content.navigator.mozAddonManager.getAddonByID(id);
let result = yield addon.uninstall();
return result;
});
}
add_task(testWithAPI(function*(browser) {
const ID1 = "addon1@tests.mozilla.org";
const ID2 = "addon2@tests.mozilla.org";
let provider = new MockProvider();
provider.addAddon(new MockAddon(ID1, "Test add-on 1", "extension", 0));
provider.addAddon(new MockAddon(ID2, "Test add-on 2", "extension", 0));
let [a1, a2] = yield promiseAddonsByIDs([ID1, ID2]);
isnot(a1, null, "addon1 is installed");
isnot(a2, null, "addon2 is installed");
let result = yield API_uninstallByID(browser, ID1);
is(result, true, "uninstall of addon1 succeeded");
[a1, a2] = yield promiseAddonsByIDs([ID1, ID2]);
is(a1, null, "addon1 is uninstalled");
isnot(a2, null, "addon2 is still installed");
result = yield API_uninstallByID(browser, ID2);
is(result, true, "uninstall of addon2 succeeded");
[a2] = yield promiseAddonsByIDs([ID2]);
is(a2, null, "addon2 is uninstalled");
}));

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

@ -1129,7 +1129,8 @@ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) {
AddonManager.PERM_CAN_ENABLE | AddonManager.PERM_CAN_ENABLE |
AddonManager.PERM_CAN_DISABLE | AddonManager.PERM_CAN_DISABLE |
AddonManager.PERM_CAN_UPGRADE; AddonManager.PERM_CAN_UPGRADE;
this.operationsRequiringRestart = aOperationsRequiringRestart || this.operationsRequiringRestart = (aOperationsRequiringRestart != undefined) ?
aOperationsRequiringRestart :
(AddonManager.OP_NEEDS_RESTART_INSTALL | (AddonManager.OP_NEEDS_RESTART_INSTALL |
AddonManager.OP_NEEDS_RESTART_UNINSTALL | AddonManager.OP_NEEDS_RESTART_UNINSTALL |
AddonManager.OP_NEEDS_RESTART_ENABLE | AddonManager.OP_NEEDS_RESTART_ENABLE |