Bug 1354590 - Add 'temporary' flag to runtime.onInstalled details. r=aswan,zombie

MozReview-Commit-ID: IbQno1ZL7KV

--HG--
extra : rebase_source : 4229cf4bef0ddb2d17180fb7159111694af4018e
This commit is contained in:
Tushar Saini (:shatur) 2017-05-14 10:54:11 +05:30
parent 17f07e92b9
commit 8bde0a472a
4 changed files with 54 additions and 4 deletions

View File

@ -33,18 +33,24 @@ this.runtime = class extends ExtensionAPI {
}).api(),
onInstalled: new SingletonEventManager(context, "runtime.onInstalled", fire => {
let temporary = !!extension.addonData.temporarilyInstalled;
let listener = () => {
switch (extension.startupReason) {
case "APP_STARTUP":
if (AddonManagerPrivate.browserUpdated) {
fire.sync({reason: "browser_update"});
fire.sync({reason: "browser_update", temporary});
}
break;
case "ADDON_INSTALL":
fire.sync({reason: "install"});
fire.sync({reason: "install", temporary});
break;
case "ADDON_UPGRADE":
fire.sync({reason: "update", previousVersion: extension.addonData.oldVersion});
fire.sync({
reason: "update",
previousVersion: extension.addonData.oldVersion,
temporary,
});
break;
}
};

View File

@ -475,6 +475,10 @@
"optional": true,
"description": "Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is 'update'."
},
"temporary": {
"type": "boolean",
"description": "Indicates whether the addon is installed as a temporary extension."
},
"id": {
"type": "string",
"optional": true,

View File

@ -57,11 +57,12 @@ function background() {
});
}
async function expectEvents(extension, {onStartupFired, onInstalledFired, onInstalledReason, onInstalledPrevious}) {
async function expectEvents(extension, {onStartupFired, onInstalledFired, onInstalledReason, onInstalledTemporary, onInstalledPrevious}) {
extension.sendMessage("get-on-installed-details");
let details = await extension.awaitMessage("on-installed-details");
if (onInstalledFired) {
equal(details.reason, onInstalledReason, "runtime.onInstalled fired with the correct reason");
equal(details.temporary, onInstalledTemporary, "runtime.onInstalled fired with the correct temporary flag");
if (onInstalledPrevious) {
equal(details.previousVersion, onInstalledPrevious, "runtime.onInstalled after update with correct previousVersion");
}
@ -137,6 +138,7 @@ add_task(async function test_should_fire_on_addon_update() {
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "install",
});
@ -159,6 +161,7 @@ add_task(async function test_should_fire_on_addon_update() {
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "update",
onInstalledPrevious: "1.0",
});
@ -191,6 +194,7 @@ add_task(async function test_should_fire_on_browser_update() {
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "install",
});
@ -210,6 +214,7 @@ add_task(async function test_should_fire_on_browser_update() {
await expectEvents(extension, {
onStartupFired: true,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "browser_update",
});
@ -229,6 +234,7 @@ add_task(async function test_should_fire_on_browser_update() {
await expectEvents(extension, {
onStartupFired: true,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "browser_update",
});
@ -260,6 +266,7 @@ add_task(async function test_should_not_fire_on_reload() {
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "install",
});
@ -299,6 +306,7 @@ add_task(async function test_should_not_fire_on_restart() {
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledTemporary: false,
onInstalledReason: "install",
});
@ -316,3 +324,34 @@ add_task(async function test_should_not_fire_on_restart() {
await extension.markUnloaded();
await promiseShutdownManager();
});
add_task(async function test_temporary_installation() {
const EXTENSION_ID = "test_runtime_on_installed_addon_temporary@tests.mozilla.org";
await promiseStartupManager();
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "temporary",
manifest: {
"version": "1.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
},
background,
});
await extension.startup();
await expectEvents(extension, {
onStartupFired: false,
onInstalledFired: true,
onInstalledReason: "install",
onInstalledTemporary: true,
});
await extension.unload();
await promiseShutdownManager();
});

View File

@ -4468,6 +4468,7 @@ this.XPIProvider = {
resolve => XPIDatabase.getVisibleAddonForID(addon.id, resolve));
let extraParams = {};
extraParams.temporarilyInstalled = aInstallLocation === TemporaryInstallLocation;
if (oldAddon) {
if (!oldAddon.bootstrap) {
logger.warn("Non-restartless Add-on is already installed", addon.id);