Bug 847867 - Ensure extensions.bootstrappedAddons is updated to reflect live changes. r=Mossop

This commit is contained in:
Blair McBride 2013-04-01 21:58:16 +13:00
Родитель 2d0b4a0736
Коммит 07a55ea47d
2 изменённых файлов: 115 добавлений и 61 удалений

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

@ -1681,8 +1681,6 @@ var XPIProvider = {
// of XPCOM // of XPCOM
Services.obs.addObserver({ Services.obs.addObserver({
observe: function shutdownObserver(aSubject, aTopic, aData) { observe: function shutdownObserver(aSubject, aTopic, aData) {
Services.prefs.setCharPref(PREF_BOOTSTRAP_ADDONS,
JSON.stringify(XPIProvider.bootstrappedAddons));
for (let id in XPIProvider.bootstrappedAddons) { for (let id in XPIProvider.bootstrappedAddons) {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.persistentDescriptor = XPIProvider.bootstrappedAddons[id].descriptor; file.persistentDescriptor = XPIProvider.bootstrappedAddons[id].descriptor;
@ -1789,6 +1787,14 @@ var XPIProvider = {
Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, false); Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, false);
}, },
/**
* Persists changes to XPIProvider.bootstrappedAddons to it's store (a pref).
*/
persistBootstrappedAddons: function XPI_persistBootstrappedAddons() {
Services.prefs.setCharPref(PREF_BOOTSTRAP_ADDONS,
JSON.stringify(this.bootstrappedAddons));
},
/** /**
* Adds a list of currently active add-ons to the next crash report. * Adds a list of currently active add-ons to the next crash report.
*/ */
@ -2939,6 +2945,7 @@ var XPIProvider = {
// Cache the new install location states // Cache the new install location states
let cache = JSON.stringify(this.getInstallLocationStates()); let cache = JSON.stringify(this.getInstallLocationStates());
Services.prefs.setCharPref(PREF_INSTALL_CACHE, cache); Services.prefs.setCharPref(PREF_INSTALL_CACHE, cache);
this.persistBootstrappedAddons();
// Clear out any cached migration data. // Clear out any cached migration data.
XPIDatabase.migrateData = null; XPIDatabase.migrateData = null;
@ -3680,6 +3687,7 @@ var XPIProvider = {
type: aType, type: aType,
descriptor: aFile.persistentDescriptor descriptor: aFile.persistentDescriptor
}; };
this.persistBootstrappedAddons();
this.addAddonsToCrashReporter(); this.addAddonsToCrashReporter();
// Locales only contain chrome and can't have bootstrap scripts // Locales only contain chrome and can't have bootstrap scripts
@ -3747,6 +3755,7 @@ var XPIProvider = {
unloadBootstrapScope: function XPI_unloadBootstrapScope(aId) { unloadBootstrapScope: function XPI_unloadBootstrapScope(aId) {
delete this.bootstrapScopes[aId]; delete this.bootstrapScopes[aId];
delete this.bootstrappedAddons[aId]; delete this.bootstrappedAddons[aId];
this.persistBootstrappedAddons();
this.addAddonsToCrashReporter(); this.addAddonsToCrashReporter();
}, },

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

@ -101,6 +101,39 @@ function getUninstallNewVersion() {
return Services.prefs.getIntPref("bootstraptest.uninstall_newversion"); return Services.prefs.getIntPref("bootstraptest.uninstall_newversion");
} }
function do_check_bootstrappedPref(aCallback) {
let data = "{}";
try {
// This is ok to fail, as the pref won't exist on a fresh profile.
data = Services.prefs.getCharPref("extensions.bootstrappedAddons");
} catch (e) {}
data = JSON.parse(data);
AddonManager.getAddonsByTypes(["extension"], function(aAddons) {
for (let addon of aAddons) {
if (!addon.id.endsWith("@tests.mozilla.org"))
continue;
if (!addon.isActive)
continue;
if (addon.operationsRequiringRestart != AddonManager.OP_NEEDS_RESTART_NONE)
continue;
do_check_true(addon.id in data);
let addonData = data[addon.id];
delete data[addon.id];
do_check_eq(addonData.version, addon.version);
do_check_eq(addonData.type, addon.type);
let file = addon.getResourceURI().QueryInterface(Components.interfaces.nsIFileURL).file;
do_check_eq(addonData.descriptor, file.persistentDescriptor);
}
do_check_eq(Object.keys(data).length, 0);
aCallback();
});
}
function run_test() { function run_test() {
do_test_pending(); do_test_pending();
@ -120,7 +153,7 @@ function run_test() {
file.leafName = "extensions.ini"; file.leafName = "extensions.ini";
do_check_false(file.exists()); do_check_false(file.exists());
run_test_1(); do_check_bootstrappedPref(run_test_1);
} }
// Tests that installing doesn't require a restart // Tests that installing doesn't require a restart
@ -161,8 +194,11 @@ function run_test_1() {
do_check_eq(getActiveVersion(), -1); do_check_eq(getActiveVersion(), -1);
waitForPref("bootstraptest.active_version", function() { waitForPref("bootstraptest.active_version", function() {
check_test_1(addon.syncGUID); do_check_bootstrappedPref(function() {
check_test_1(addon.syncGUID);
});
}); });
}); });
install.install(); install.install();
}); });
@ -243,7 +279,7 @@ function run_test_2() {
do_check_true(newb1.userDisabled); do_check_true(newb1.userDisabled);
do_check_false(newb1.isActive); do_check_false(newb1.isActive);
run_test_3(); do_check_bootstrappedPref(run_test_3);
}); });
}); });
} }
@ -273,7 +309,7 @@ function run_test_3() {
do_check_true(b1.userDisabled); do_check_true(b1.userDisabled);
do_check_false(b1.isActive); do_check_false(b1.isActive);
run_test_4(); do_check_bootstrappedPref(run_test_4);
}); });
} }
@ -310,7 +346,7 @@ function run_test_4() {
do_check_false(newb1.userDisabled); do_check_false(newb1.userDisabled);
do_check_true(newb1.isActive); do_check_true(newb1.isActive);
run_test_5(); do_check_bootstrappedPref(run_test_5);
}); });
}); });
} }
@ -338,7 +374,7 @@ function run_test_5() {
do_check_true(b1.isActive); do_check_true(b1.isActive);
do_check_false(isExtensionInAddonsList(profileDir, b1.id)); do_check_false(isExtensionInAddonsList(profileDir, b1.id));
run_test_6(); do_check_bootstrappedPref(run_test_6);
}); });
} }
@ -390,7 +426,7 @@ function check_test_6() {
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0");
run_test_7(); do_check_bootstrappedPref(run_test_7);
}); });
} }
@ -408,7 +444,7 @@ function run_test_7() {
AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0); AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
b1.uninstall(); b1.uninstall();
check_test_7(); do_check_bootstrappedPref(check_test_7);
}); });
} }
@ -428,7 +464,7 @@ function check_test_7() {
AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(newb1) { AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(newb1) {
do_check_eq(newb1, null); do_check_eq(newb1, null);
run_test_8(); do_check_bootstrappedPref(run_test_8);
}); });
}); });
} }
@ -455,7 +491,7 @@ function run_test_8() {
do_check_eq(getStartupOldVersion(), 0); do_check_eq(getStartupOldVersion(), 0);
do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
run_test_9(); do_check_bootstrappedPref(run_test_9);
}); });
} }
@ -471,7 +507,7 @@ function run_test_9() {
do_check_eq(b1, null); do_check_eq(b1, null);
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
run_test_10(); do_check_bootstrappedPref(run_test_10);
}); });
} }
@ -573,7 +609,7 @@ function check_test_10_pt2() {
do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "2.0");
run_test_11(); do_check_bootstrappedPref(run_test_11);
}); });
} }
@ -609,7 +645,7 @@ function check_test_11() {
do_check_eq(getActiveVersion(), 0); do_check_eq(getActiveVersion(), 0);
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
run_test_12(); do_check_bootstrappedPref(run_test_12);
} }
// Tests that bootstrapped extensions are correctly loaded even if the app is // Tests that bootstrapped extensions are correctly loaded even if the app is
@ -637,7 +673,7 @@ function run_test_12() {
b1.uninstall(); b1.uninstall();
restartManager(); restartManager();
run_test_13(); do_check_bootstrappedPref(run_test_13);
}); });
} }
@ -700,10 +736,12 @@ function check_test_13() {
do_check_eq(getActiveVersion(), 0); // Should not have called startup though do_check_eq(getActiveVersion(), 0); // Should not have called startup though
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0");
b1.uninstall(); do_check_bootstrappedPref(function() {
restartManager(); b1.uninstall();
restartManager();
run_test_14(); run_test_14();
});
}); });
}); });
}); });
@ -729,9 +767,11 @@ function run_test_14() {
do_check_eq(getActiveVersion(), 0); // Should not have called startup though do_check_eq(getActiveVersion(), 0); // Should not have called startup though
do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0"); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0");
b1.uninstall(); do_check_bootstrappedPref(function() {
b1.uninstall();
run_test_15(); run_test_15();
});
}); });
} }
@ -788,20 +828,22 @@ function check_test_15() {
do_check_eq(getInstalledVersion(), 2); do_check_eq(getInstalledVersion(), 2);
do_check_eq(getActiveVersion(), 0); do_check_eq(getActiveVersion(), 0);
restartManager(); do_check_bootstrappedPref(function() {
restartManager();
AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
do_check_neq(b1, null); do_check_neq(b1, null);
do_check_eq(b1.version, "2.0"); do_check_eq(b1.version, "2.0");
do_check_false(b1.appDisabled); do_check_false(b1.appDisabled);
do_check_true(b1.userDisabled); do_check_true(b1.userDisabled);
do_check_false(b1.isActive); do_check_false(b1.isActive);
do_check_eq(getInstalledVersion(), 2); do_check_eq(getInstalledVersion(), 2);
do_check_eq(getActiveVersion(), 0); do_check_eq(getActiveVersion(), 0);
b1.uninstall(); b1.uninstall();
run_test_16(); run_test_16();
});
}); });
}); });
} }
@ -872,7 +914,7 @@ function run_test_17() {
do_check_eq(b1.version, "1.0"); do_check_eq(b1.version, "1.0");
do_check_true(b1.isActive); do_check_true(b1.isActive);
run_test_18(); do_check_bootstrappedPref(run_test_18);
}); });
} }
@ -899,7 +941,7 @@ function run_test_18() {
do_check_eq(getInstallOldVersion(), 1); do_check_eq(getInstallOldVersion(), 1);
do_check_eq(getStartupOldVersion(), 1); do_check_eq(getStartupOldVersion(), 1);
run_test_19(); do_check_bootstrappedPref(run_test_19);
}); });
}); });
} }
@ -942,7 +984,7 @@ function check_test_19() {
do_check_eq(getInstallOldVersion(), 0); do_check_eq(getInstallOldVersion(), 0);
do_check_eq(getStartupOldVersion(), 0); do_check_eq(getStartupOldVersion(), 0);
run_test_20(); do_check_bootstrappedPref(run_test_20);
}); });
} }
@ -1011,11 +1053,12 @@ function run_test_21() {
do_check_eq(getStartupReason(), APP_STARTUP); do_check_eq(getStartupReason(), APP_STARTUP);
do_check_eq(getStartupOldVersion(), 0); do_check_eq(getStartupOldVersion(), 0);
manuallyUninstall(userExtDir, "bootstrap1@tests.mozilla.org"); do_check_bootstrappedPref(function() {
manuallyUninstall(userExtDir, "bootstrap1@tests.mozilla.org");
restartManager(); restartManager();
run_test_22();
run_test_22(); });
}); });
} }
@ -1069,9 +1112,11 @@ function run_test_22() {
do_check_eq(getStartupReason(), APP_STARTUP); do_check_eq(getStartupReason(), APP_STARTUP);
do_check_eq(getStartupOldVersion(), 0); do_check_eq(getStartupOldVersion(), 0);
b1.uninstall(); do_check_bootstrappedPref(function() {
b1.uninstall();
run_test_23(); run_test_23();
});
}); });
}); });
} }
@ -1115,7 +1160,7 @@ function run_test_23() {
"onInstallEnded", "onInstallEnded",
], function() { ], function() {
do_check_true(addon.hasResource("install.rdf")); do_check_true(addon.hasResource("install.rdf"));
check_test_23(); do_check_bootstrappedPref(check_test_23);
}); });
}); });
install.install(); install.install();
@ -1171,35 +1216,35 @@ function run_test_24() {
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
do_check_eq(getInstalledVersion2(), 1); do_check_eq(getInstalledVersion2(), 1);
do_check_eq(getActiveVersion2(), 1); do_check_eq(getActiveVersion2(), 1);
resetPrefs(); resetPrefs();
restartManager(); restartManager();
do_check_eq(getInstalledVersion(), -1); do_check_eq(getInstalledVersion(), -1);
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
do_check_eq(getInstalledVersion2(), -1); do_check_eq(getInstalledVersion2(), -1);
do_check_eq(getActiveVersion2(), 1); do_check_eq(getActiveVersion2(), 1);
shutdownManager(); shutdownManager();
do_check_eq(getInstalledVersion(), -1); do_check_eq(getInstalledVersion(), -1);
do_check_eq(getActiveVersion(), 0); do_check_eq(getActiveVersion(), 0);
do_check_eq(getInstalledVersion2(), -1); do_check_eq(getInstalledVersion2(), -1);
do_check_eq(getActiveVersion2(), 0); do_check_eq(getActiveVersion2(), 0);
// Break the preferece // Break the preferece
let bootstrappedAddons = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons")); let bootstrappedAddons = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
bootstrappedAddons["bootstrap1@tests.mozilla.org"].descriptor += "foo"; bootstrappedAddons["bootstrap1@tests.mozilla.org"].descriptor += "foo";
Services.prefs.setCharPref("extensions.bootstrappedAddons", JSON.stringify(bootstrappedAddons)); Services.prefs.setCharPref("extensions.bootstrappedAddons", JSON.stringify(bootstrappedAddons));
startupManager(false); startupManager(false);
do_check_eq(getInstalledVersion(), -1); do_check_eq(getInstalledVersion(), -1);
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
do_check_eq(getInstalledVersion2(), -1); do_check_eq(getInstalledVersion2(), -1);
do_check_eq(getActiveVersion2(), 1); do_check_eq(getActiveVersion2(), 1);
run_test_25(); run_test_25();
}); });
}); });
@ -1212,32 +1257,32 @@ function run_test_25() {
waitForPref("bootstraptest.active_version", function() { waitForPref("bootstraptest.active_version", function() {
do_check_eq(getInstalledVersion(), 1); do_check_eq(getInstalledVersion(), 1);
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
installAllFiles([do_get_addon("test_bootstrap1_4")], function() { installAllFiles([do_get_addon("test_bootstrap1_4")], function() {
// Needs a restart to complete this so the old version stays running // Needs a restart to complete this so the old version stays running
do_check_eq(getInstalledVersion(), 1); do_check_eq(getInstalledVersion(), 1);
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
do_check_neq(b1, null); do_check_neq(b1, null);
do_check_eq(b1.version, "1.0"); do_check_eq(b1.version, "1.0");
do_check_true(b1.isActive); do_check_true(b1.isActive);
do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
restartManager(); restartManager();
do_check_eq(getInstalledVersion(), 0); do_check_eq(getInstalledVersion(), 0);
do_check_eq(getUninstallReason(), ADDON_UPGRADE); do_check_eq(getUninstallReason(), ADDON_UPGRADE);
do_check_eq(getUninstallNewVersion(), 4); do_check_eq(getUninstallNewVersion(), 4);
do_check_eq(getActiveVersion(), 0); do_check_eq(getActiveVersion(), 0);
AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
do_check_neq(b1, null); do_check_neq(b1, null);
do_check_eq(b1.version, "4.0"); do_check_eq(b1.version, "4.0");
do_check_true(b1.isActive); do_check_true(b1.isActive);
do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
run_test_26(); do_check_bootstrappedPref(run_test_26);
}); });
}); });
}); });
@ -1272,7 +1317,7 @@ function run_test_26() {
do_check_true(b1.isActive); do_check_true(b1.isActive);
do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
run_test_27(); do_check_bootstrappedPref(run_test_27);
}); });
}); });
}); });
@ -1314,7 +1359,7 @@ function run_test_27() {
do_check_false(b1.isActive); do_check_false(b1.isActive);
do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
run_test_28(); do_check_bootstrappedPref(run_test_28);
}); });
}); });
}); });
@ -1351,7 +1396,7 @@ function run_test_28() {
do_check_eq(getInstalledVersion(), 1); do_check_eq(getInstalledVersion(), 1);
do_check_eq(getActiveVersion(), 1); do_check_eq(getActiveVersion(), 1);
do_test_finished(); do_check_bootstrappedPref(do_test_finished);
}); });
}); });
}); });