Bug 1303418 Don't allow upgrades that change the addon ID r=mossop

MozReview-Commit-ID: JHINo8ShmeI

--HG--
extra : source : 9a74c400ed6c62d5fc6abe0cd42d27be70f18f02
extra : amend_source : 8776cfb584840bccc817ce1fda00d04b236875eb
extra : intermediate-source : 8490362e38cdaa930985a5adafc581d7bb76fe45
This commit is contained in:
Andrew Swan 2016-09-16 15:00:18 -07:00
Родитель b605dece0c
Коммит 8fbeb75129
19 изменённых файлов: 180 добавлений и 601 удалений

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

@ -3211,6 +3211,8 @@ this.AddonManager = {
["ERROR_SIGNEDSTATE_REQUIRED", -5], ["ERROR_SIGNEDSTATE_REQUIRED", -5],
// The downloaded add-on had a different type than expected. // The downloaded add-on had a different type than expected.
["ERROR_UNEXPECTED_ADDON_TYPE", -6], ["ERROR_UNEXPECTED_ADDON_TYPE", -6],
// The addon did not have the expected ID
["ERROR_INCORRECT_ID", -7],
]), ]),
// These must be kept in sync with AddonUpdateChecker. // These must be kept in sync with AddonUpdateChecker.

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

@ -5818,6 +5818,27 @@ AddonInstall.prototype = {
return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, err]); return Promise.reject([AddonManager.ERROR_CORRUPT_FILE, err]);
} }
if (this.existingAddon) {
// Check various conditions related to upgrades
if (this.addon.id != this.existingAddon.id) {
zipreader.close();
return Promise.reject([AddonManager.ERROR_INCORRECT_ID,
`Refusing to upgrade addon ${this.existingAddon.id} to different ID {this.addon.id}`]);
}
if (this.addon.type == "multipackage") {
zipreader.close();
return Promise.reject([AddonManager.ERROR_UNEXPECTED_ADDON_TYPE,
`Refusing to upgrade addon ${this.existingAddon.id} to a multi-package xpi`]);
}
if (this.existingAddon.type == "webextension" && this.addon.type != "webextension") {
zipreader.close();
return Promise.reject([AddonManager.ERROR_UNEXPECTED_ADDON_TYPE,
"WebExtensions may not be upated to other extension types"]);
}
}
if (mustSign(this.addon.type)) { if (mustSign(this.addon.type)) {
if (this.addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) { if (this.addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) {
// This add-on isn't properly signed by a signature that chains to the // This add-on isn't properly signed by a signature that chains to the
@ -5855,13 +5876,6 @@ AddonInstall.prototype = {
} }
} }
if (this.existingAddon && this.existingAddon.type == "webextension" &&
this.addon.type != "webextension") {
zipreader.close();
return Promise.reject([AddonManager.ERROR_UNEXPECTED_ADDON_TYPE,
"WebExtensions may not be upated to other extension types"]);
}
if (this.addon.type == "multipackage") if (this.addon.type == "multipackage")
return this._loadMultipackageManifests(zipreader); return this._loadMultipackageManifests(zipreader);
@ -6137,6 +6151,7 @@ AddonInstall.prototype = {
}, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); }, AddonManager.UPDATE_WHEN_ADDON_INSTALLED);
} }
}, ([error, message]) => { }, ([error, message]) => {
this.removeTemporaryFile();
this.downloadFailed(error, message); this.downloadFailed(error, message);
}); });
} }

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

@ -0,0 +1,5 @@
function install(data, reason) {}
function startup(data, reason) {}
function shutdown(data, reason) {}
function uninstall(data, reason) {}

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

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>updatemulti@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:updateURL>http://localhost:4444/data/test_update_multi.rdf</em:updateURL>
<em:bootstrap>true</em:bootstrap>
<em:name>Test Addon 1</em:name>
<em:targetApplication><Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description></em:targetApplication>
</Description>
</RDF>

Двоичный файл не отображается.

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

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>updatemulti@tests.mozilla.org</em:id>
<em:type>32</em:type>
<em:version>2.0</em:version>
</Description>
</RDF>

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

@ -0,0 +1,5 @@
function install(data, reason) {}
function startup(data, reason) {}
function shutdown(data, reason) {}
function uninstall(data, reason) {}

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

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon1@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<em:bootstrap>true</em:bootstrap>
<em:name>Test Addon 1</em:name>
<em:targetApplication><Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description></em:targetApplication>
</Description>
</RDF>

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

@ -0,0 +1,5 @@
function install(data, reason) {}
function startup(data, reason) {}
function shutdown(data, reason) {}
function uninstall(data, reason) {}

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

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon1.changed@tests.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<em:bootstrap>true</em:bootstrap>
<em:name>Test Addon 1</em:name>
<em:targetApplication><Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description></em:targetApplication>
</Description>
</RDF>

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

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon2@tests.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<!-- Front End MetaData -->
<em:name>Test 2</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon2@tests.mozilla.org</em:id>
<em:version>5.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<!-- Front End MetaData -->
<em:name>Test 2</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -1,21 +0,0 @@
Components.utils.import("resource://gre/modules/Services.jsm");
function install(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", 3);
Services.prefs.setIntPref("bootstraptest.install_reason", reason);
}
function startup(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 3);
Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
}
function shutdown(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 0);
Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
}
function uninstall(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", 0);
Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
}

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

@ -1,25 +0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon3@tests.mozilla.org</em:id>
<em:version>3.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<em:bootstrap>true</em:bootstrap>
<!-- Front End MetaData -->
<em:name>Test 3</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -1,21 +0,0 @@
Components.utils.import("resource://gre/modules/Services.jsm");
function install(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", 4);
Services.prefs.setIntPref("bootstraptest.install_reason", reason);
}
function startup(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 4);
Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
}
function shutdown(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 0);
Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
}
function uninstall(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", 0);
Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
}

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

@ -1,25 +0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon4@tests.mozilla.org</em:id>
<em:version>4.0</em:version>
<em:updateURL>http://localhost:4444/data/test_updateid.rdf</em:updateURL>
<em:bootstrap>true</em:bootstrap>
<!-- Front End MetaData -->
<em:name>Test 4</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:extension:updatemulti@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_update_multi2.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
</RDF>

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

@ -14,67 +14,7 @@
<em:id>xpcshell@tests.mozilla.org</em:id> <em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion> <em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion> <em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_updateid2_2.xpi</em:updateLink> <em:updateLink>http://localhost:4444/addons/test_updateid2.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:addon2@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>3.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_updateid3_3.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:addon3@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>4.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_updateid4_4.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:addon4@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>5.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_updateid2_5.xpi</em:updateLink>
</Description> </Description>
</em:targetApplication> </em:targetApplication>
</Description> </Description>

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

@ -7,416 +7,80 @@
// The test extension uses an insecure update url. // The test extension uses an insecure update url.
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
Components.utils.import("resource://testing-common/httpd.js");
var testserver;
const profileDir = gProfD.clone(); const profileDir = gProfD.clone();
profileDir.append("extensions"); profileDir.append("extensions");
function resetPrefs() { function promiseInstallUpdate(install) {
Services.prefs.setIntPref("bootstraptest.active_version", -1); return new Promise((resolve, reject) => {
Services.prefs.setIntPref("bootstraptest.installed_version", -1); install.addListener({
Services.prefs.setIntPref("bootstraptest.startup_reason", -1); onDownloadFailed: () => {
Services.prefs.setIntPref("bootstraptest.shutdown_reason", -1); let err = new Error("download error");
Services.prefs.setIntPref("bootstraptest.install_reason", -1); err.code = install.error;
Services.prefs.setIntPref("bootstraptest.uninstall_reason", -1); reject(err);
},
onInstallFailed: () => {
let err = new Error("install error");
err.code = install.error;
reject(err);
},
onInstallEnded: resolve,
});
install.install();
});
} }
function getActiveVersion() { // Create and configure the HTTP server.
return Services.prefs.getIntPref("bootstraptest.active_version"); let testserver = createHttpServer(4444);
} testserver.registerDirectory("/data/", do_get_file("data"));
testserver.registerDirectory("/addons/", do_get_file("addons"));
function getInstalledVersion() {
return Services.prefs.getIntPref("bootstraptest.installed_version");
}
function run_test() { function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
// Create and configure the HTTP server.
testserver = new HttpServer();
testserver.registerDirectory("/data/", do_get_file("data"));
testserver.registerDirectory("/addons/", do_get_file("addons"));
testserver.start(4444);
do_test_pending();
run_test_1();
}
function end_test() {
testserver.stop(do_test_finished);
}
function installUpdate(aInstall, aCallback) {
aInstall.addListener({
onInstallEnded: function(aInstall) {
// give the startup time to run
do_execute_soon(function() {
aCallback(aInstall);
});
}
});
aInstall.install();
}
// Verify that an update to an add-on with a new ID uninstalls the old add-on
function run_test_1() {
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_updateid.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 1",
}, profileDir);
startupManager(); startupManager();
run_next_test();
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
do_check_neq(a1, null);
do_check_eq(a1.version, "1.0");
a1.findUpdates({
onUpdateAvailable: function(addon, install) {
do_check_eq(install.name, addon.name);
do_check_eq(install.version, "2.0");
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
do_check_eq(install.existingAddon, a1);
installUpdate(install, check_test_1);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
} }
function check_test_1(install) { // Verify that an update to an add-on with a new ID fails
AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { add_task(function* test_update_new_id() {
// Existing add-on should have a pending upgrade yield promiseInstallFile(do_get_addon("test_updateid1"));
do_check_neq(a1.pendingUpgrade, null);
do_check_eq(a1.pendingUpgrade.id, "addon2@tests.mozilla.org");
do_check_eq(a1.pendingUpgrade.install.existingAddon, a1);
do_check_neq(a1.syncGUID);
let a1SyncGUID = a1.syncGUID; let addon = yield promiseAddonByID("addon1@tests.mozilla.org");
do_check_neq(addon, null);
do_check_eq(addon.version, "1.0");
restartManager(); let update = yield promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED);
let install = update.updateAvailable;
do_check_eq(install.name, addon.name);
do_check_eq(install.version, "2.0");
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
do_check_eq(install.existingAddon, addon);
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", yield Assert.rejects(promiseInstallUpdate(install),
"addon2@tests.mozilla.org"], function([a1, a2]) { function(err) { return err.code == AddonManager.ERROR_INCORRECT_ID },
// Should have uninstalled the old and installed the new "Upgrade to a different ID fails");
do_check_eq(a1, null);
do_check_neq(a2, null);
do_check_neq(a2.syncGUID, null);
// The Sync GUID should change when the ID changes addon.uninstall();
do_check_neq(a1SyncGUID, a2.syncGUID); });
a2.uninstall(); // Verify that an update to a multi-package xpi fails
add_task(function* test_update_new_id() {
yield promiseInstallFile(do_get_addon("test_update_multi1"));
do_execute_soon(run_test_2); let addon = yield promiseAddonByID("updatemulti@tests.mozilla.org");
}); do_check_neq(addon, null);
})); do_check_eq(addon.version, "1.0");
}
// Test that when the new add-on already exists we just upgrade that let update = yield promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED);
function run_test_2() { let install = update.updateAvailable;
restartManager(); do_check_eq(install.name, addon.name);
shutdownManager(); do_check_eq(install.version, "2.0");
do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
do_check_eq(install.existingAddon, addon);
writeInstallRDFForExtension({ yield Assert.rejects(promiseInstallUpdate(install),
id: "addon1@tests.mozilla.org", function(err) { return err.code == AddonManager.ERROR_UNEXPECTED_ADDON_TYPE },
version: "1.0", "Upgrade to a multipackage xpi fails");
updateURL: "http://localhost:4444/data/test_updateid.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 1",
}, profileDir);
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 2",
}, profileDir);
startupManager(); addon.uninstall();
});
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
do_check_neq(a1, null);
do_check_eq(a1.version, "1.0");
a1.findUpdates({
onUpdateAvailable: function(addon, install) {
installUpdate(install, check_test_2);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
function check_test_2(install) {
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org"],
callback_soon(function([a1, a2]) {
do_check_eq(a1.pendingUpgrade, null);
// Existing add-on should have a pending upgrade
do_check_neq(a2.pendingUpgrade, null);
do_check_eq(a2.pendingUpgrade.id, "addon2@tests.mozilla.org");
do_check_eq(a2.pendingUpgrade.install.existingAddon, a2);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org"], function([a1, a2]) {
// Should have uninstalled the old and installed the new
do_check_neq(a1, null);
do_check_neq(a2, null);
a1.uninstall();
a2.uninstall();
do_execute_soon(run_test_3);
});
}));
}
// Test that we rollback correctly when removing the old add-on fails
function run_test_3() {
restartManager();
shutdownManager();
// This test only works on Windows
if (!("nsIWindowsRegKey" in AM_Ci)) {
run_test_4();
return;
}
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_updateid.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 1",
}, profileDir);
startupManager();
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
do_check_neq(a1, null);
do_check_eq(a1.version, "1.0");
a1.findUpdates({
onUpdateAvailable: function(addon, install) {
installUpdate(install, check_test_3);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
function check_test_3(install) {
AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
// Existing add-on should have a pending upgrade
do_check_neq(a1.pendingUpgrade, null);
do_check_eq(a1.pendingUpgrade.id, "addon2@tests.mozilla.org");
do_check_eq(a1.pendingUpgrade.install.existingAddon, a1);
// Lock the old add-on open so it can't be uninstalled
var file = profileDir.clone();
file.append("addon1@tests.mozilla.org");
if (!file.exists())
file.leafName += ".xpi";
else
file.append("install.rdf");
var fstream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(AM_Ci.nsIFileOutputStream);
fstream.init(file, FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY, FileUtils.PERMS_FILE, 0);
restartManager();
fstream.close();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org"],
callback_soon(function([a1, a2]) {
// Should not have installed the new add-on but it should still be
// pending install
do_check_neq(a1, null);
do_check_eq(a2, null);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org"], function([a1, a2]) {
// Should have installed the new add-on
do_check_eq(a1, null);
do_check_neq(a2, null);
a2.uninstall();
do_execute_soon(run_test_4);
});
}));
}));
}
// Tests that upgrading to a bootstrapped add-on works but requires a restart
function run_test_4() {
restartManager();
shutdownManager();
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "2.0",
updateURL: "http://localhost:4444/data/test_updateid.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 2",
}, profileDir);
startupManager();
resetPrefs();
AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
do_check_neq(a2, null);
do_check_neq(a2.syncGUID, null);
do_check_eq(a2.version, "2.0");
a2.findUpdates({
onUpdateAvailable: function(addon, install) {
installUpdate(install, check_test_4);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
function check_test_4() {
AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org",
"addon3@tests.mozilla.org"],
callback_soon(function([a2, a3]) {
// Should still be pending install even though the new add-on is restartless
do_check_neq(a2, null);
do_check_eq(a3, null);
do_check_neq(a2.pendingUpgrade, null);
do_check_eq(a2.pendingUpgrade.id, "addon3@tests.mozilla.org");
do_check_eq(getInstalledVersion(), -1);
do_check_eq(getActiveVersion(), -1);
restartManager();
AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org",
"addon3@tests.mozilla.org"], function([a2, a3]) {
// Should have updated
do_check_eq(a2, null);
do_check_neq(a3, null);
do_check_eq(getInstalledVersion(), 3);
do_check_eq(getActiveVersion(), 3);
do_execute_soon(run_test_5);
});
}));
}
// Tests that upgrading to another bootstrapped add-on works without a restart
function run_test_5() {
AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
do_check_neq(a3, null);
do_check_eq(a3.version, "3.0");
a3.findUpdates({
onUpdateAvailable: function(addon, install) {
installUpdate(install, check_test_5);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
function check_test_5() {
AddonManager.getAddonsByIDs(["addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"],
callback_soon(function([a3, a4]) {
// Should have updated
do_check_eq(a3, null);
do_check_neq(a4, null);
do_check_eq(getInstalledVersion(), 4);
do_check_eq(getActiveVersion(), 4);
restartManager();
AddonManager.getAddonsByIDs(["addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"], function([a3, a4]) {
// Should still be gone
do_check_eq(a3, null);
do_check_neq(a4, null);
do_check_eq(getInstalledVersion(), 4);
do_check_eq(getActiveVersion(), 4);
run_test_6();
});
}));
}
// Tests that upgrading to a non-bootstrapped add-on works but requires a restart
function run_test_6() {
AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) {
do_check_neq(a4, null);
do_check_eq(a4.version, "4.0");
a4.findUpdates({
onUpdateAvailable: function(addon, install) {
installUpdate(install, check_test_6);
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
function check_test_6() {
AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org",
"addon2@tests.mozilla.org"],
callback_soon(function([a4, a2]) {
// Should still be pending install even though the old add-on is restartless
do_check_neq(a4, null);
do_check_eq(a2, null);
do_check_neq(a4.pendingUpgrade, null);
do_check_eq(a4.pendingUpgrade.id, "addon2@tests.mozilla.org");
do_check_eq(getInstalledVersion(), 4);
do_check_eq(getActiveVersion(), 4);
restartManager();
AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org",
"addon2@tests.mozilla.org"], function([a4, a2]) {
// Should have updated
do_check_eq(a4, null);
do_check_neq(a2, null);
do_check_eq(getInstalledVersion(), 0);
do_check_eq(getActiveVersion(), 0);
end_test();
});
}));
}