Bug 664833: Having a pending install for an existing add-on when a schema migration occurs will break the extension manager. r=robstrong

This commit is contained in:
Dave Townsend 2011-06-20 09:56:00 -07:00
Родитель 854ce884b6
Коммит 6f9a0d0cea
4 изменённых файлов: 316 добавлений и 2 удалений

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

@ -1976,8 +1976,9 @@ var XPIProvider = {
try {
fis.init(jsonfile, -1, 0, 0);
aManifests[aLocation.name][id] = json.decodeFromStream(fis,
jsonfile.fileSize);
let addonObj = json.decodeFromStream(fis, jsonfile.fileSize);
aManifests[aLocation.name][id] = new AddonInternal();
aManifests[aLocation.name][id].fromJSON(addonObj);
existingAddonID = aManifests[aLocation.name][id].existingAddonID || id;
}
catch (e) {
@ -2540,6 +2541,7 @@ var XPIProvider = {
// If there is migration data then apply it.
if (aMigrateData) {
LOG("Migrating data from old database");
// A theme's disabled state is determined by the selected theme
// preference which is read in loadManifestFromRDF
if (newAddon.type != "theme")
@ -2553,6 +2555,7 @@ var XPIProvider = {
// The version property isn't a perfect check for this but covers the
// vast majority of cases.
if (aMigrateData.version == newAddon.version) {
LOG("Migrating compatibility info");
if ("targetApplications" in aMigrateData)
newAddon.applyCompatibilityUpdate(aMigrateData, true);
}
@ -6771,6 +6774,18 @@ AddonInternal.prototype = {
}
return obj;
},
/**
* fromJSON should be called to set the properties of this AddonInternal to
* those from the passed in object. It is essentially the inverse of toJSON.
*
* @param aObj
* A JS object containing properties to be set on this AddonInternal
*/
fromJSON: function(aObj) {
for (let prop in aObj)
this[prop] = aObj[prop];
}
};

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

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!-- An extension that is compatible with the XPCShell test suite -->
<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>2.0</em:version>
<!-- Front End MetaData -->
<em:name>Test 1</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>2</em:minVersion>
<em:maxVersion>2</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

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

@ -0,0 +1,274 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that a pending upgrade during a schema update doesn't break things
var addon1 = {
id: "addon1@tests.mozilla.org",
version: "2.0",
name: "Test 1",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
var addon2 = {
id: "addon2@tests.mozilla.org",
version: "2.0",
name: "Test 2",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "2"
}]
};
var addon3 = {
id: "addon3@tests.mozilla.org",
version: "2.0",
name: "Test 3",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}]
};
var addon4 = {
id: "addon4@tests.mozilla.org",
version: "2.0",
name: "Test 4",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "2",
maxVersion: "2"
}]
};
const profileDir = gProfD.clone();
profileDir.append("extensions");
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
run_test_1();
}
// Tests whether a schema migration without app version change works
function run_test_1() {
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
startupManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"],
function([a1, a2, a3, a4]) {
do_check_neq(a1, null);
do_check_eq(a1.version, "2.0");
do_check_false(a1.appDisabled);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
do_check_neq(a2, null);
do_check_eq(a2.version, "2.0");
do_check_false(a2.appDisabled);
do_check_false(a2.userDisabled);
do_check_true(a2.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
do_check_neq(a3, null);
do_check_eq(a3.version, "2.0");
do_check_false(a3.appDisabled);
do_check_false(a3.userDisabled);
do_check_true(a3.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
do_check_neq(a4, null);
do_check_eq(a4.version, "2.0");
do_check_true(a4.appDisabled);
do_check_false(a4.userDisabled);
do_check_false(a4.isActive);
do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
// Prepare the add-on update
installAllFiles([do_get_addon("test_bug659772")], function() {
shutdownManager();
// Make it look like the next time the app is started it has a new DB schema
let dbfile = gProfD.clone();
dbfile.append("extensions.sqlite");
let db = AM_Cc["@mozilla.org/storage/service;1"].
getService(AM_Ci.mozIStorageService).
openDatabase(dbfile);
db.schemaVersion = 1;
Services.prefs.setIntPref("extensions.databaseSchema", 1);
db.close();
startupManager(false);
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"],
function([a1, a2, a3, a4]) {
do_check_neq(a1, null);
do_check_eq(a1.version, "2.0");
do_check_false(a1.appDisabled);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
do_check_neq(a2, null);
do_check_eq(a2.version, "2.0");
do_check_false(a2.appDisabled);
do_check_false(a2.userDisabled);
do_check_true(a2.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
// Should stay enabled because we migrate the compat info from
// the previous version of the DB
do_check_neq(a3, null);
do_check_eq(a3.version, "2.0");
do_check_false(a3.appDisabled);
do_check_false(a3.userDisabled);
do_check_true(a3.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
do_check_neq(a4, null);
do_check_eq(a4.version, "2.0");
do_check_true(a4.appDisabled);
do_check_false(a4.userDisabled);
do_check_false(a4.isActive);
do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
a1.uninstall();
a2.uninstall();
a3.uninstall();
a4.uninstall();
restartManager();
shutdownManager();
run_test_2();
});
});
});
}
// Tests whether a schema migration with app version change works
function run_test_2() {
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
startupManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"],
function([a1, a2, a3, a4]) {
do_check_neq(a1, null);
do_check_eq(a1.version, "2.0");
do_check_false(a1.appDisabled);
do_check_false(a1.userDisabled);
do_check_true(a1.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
do_check_neq(a2, null);
do_check_eq(a2.version, "2.0");
do_check_false(a2.appDisabled);
do_check_false(a2.userDisabled);
do_check_true(a2.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
do_check_neq(a3, null);
do_check_eq(a3.version, "2.0");
do_check_false(a3.appDisabled);
do_check_false(a3.userDisabled);
do_check_true(a3.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
do_check_neq(a4, null);
do_check_eq(a4.version, "2.0");
do_check_true(a4.appDisabled);
do_check_false(a4.userDisabled);
do_check_false(a4.isActive);
do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
// Prepare the add-on update
installAllFiles([do_get_addon("test_bug659772")], function() {
shutdownManager();
// Make it look like the next time the app is started it has a new DB schema
let dbfile = gProfD.clone();
dbfile.append("extensions.sqlite");
let db = AM_Cc["@mozilla.org/storage/service;1"].
getService(AM_Ci.mozIStorageService).
openDatabase(dbfile);
db.schemaVersion = 1;
Services.prefs.setIntPref("extensions.databaseSchema", 1);
db.close();
gAppInfo.version = "2";
startupManager(true);
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
"addon2@tests.mozilla.org",
"addon3@tests.mozilla.org",
"addon4@tests.mozilla.org"],
function([a1, a2, a3, a4]) {
do_check_neq(a1, null);
do_check_eq(a1.version, "2.0");
do_check_true(a1.appDisabled);
do_check_false(a1.userDisabled);
do_check_false(a1.isActive);
do_check_false(isExtensionInAddonsList(profileDir, addon1.id));
do_check_neq(a2, null);
do_check_eq(a2.version, "2.0");
do_check_false(a2.appDisabled);
do_check_false(a2.userDisabled);
do_check_true(a2.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
// Should become appDisabled because we migrate the compat info from
// the previous version of the DB
do_check_neq(a3, null);
do_check_eq(a3.version, "2.0");
do_check_true(a3.appDisabled);
do_check_false(a3.userDisabled);
do_check_false(a3.isActive);
do_check_false(isExtensionInAddonsList(profileDir, addon3.id));
do_check_neq(a4, null);
do_check_eq(a4.version, "2.0");
do_check_false(a4.appDisabled);
do_check_false(a4.userDisabled);
do_check_true(a4.isActive);
do_check_true(isExtensionInAddonsList(profileDir, addon4.id));
a1.uninstall();
a2.uninstall();
a3.uninstall();
a4.uninstall();
restartManager();
shutdownManager();
do_test_finished();
});
});
});
}

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

@ -55,6 +55,7 @@ tail =
[test_bug619730.js]
[test_bug620837.js]
[test_bug655254.js]
[test_bug659772.js]
[test_cacheflush.js]
[test_checkcompatibility.js]
[test_corrupt.js]