diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index 58728a60646..796d60dc9f3 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -2396,6 +2396,12 @@ var XPIProvider = { if (aOldAddon.visible) { visibleAddons[aOldAddon.id] = aOldAddon; + if (aOldAddon.bootstrap) { + let bootstrap = oldBootstrappedAddons[aOldAddon.id]; + bootstrap.descriptor = aAddonState.descriptor; + XPIProvider.bootstrappedAddons[aOldAddon.id] = bootstrap; + } + return true; } diff --git a/toolkit/mozapps/extensions/test/addons/test_bug655254_2/bootstrap.js b/toolkit/mozapps/extensions/test/addons/test_bug655254_2/bootstrap.js new file mode 100644 index 00000000000..b79648e893d --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bug655254_2/bootstrap.js @@ -0,0 +1,9 @@ +Components.utils.import("resource://gre/modules/Services.jsm"); + +function startup(data, reason) { + Services.prefs.setIntPref("bootstraptest.active_version", 1); +} + +function shutdown(data, reason) { + Services.prefs.setIntPref("bootstraptest.active_version", 0); +} diff --git a/toolkit/mozapps/extensions/test/addons/test_bug655254_2/install.rdf b/toolkit/mozapps/extensions/test/addons/test_bug655254_2/install.rdf new file mode 100644 index 00000000000..71827885f74 --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bug655254_2/install.rdf @@ -0,0 +1,19 @@ + + + + + + addon2@tests.mozilla.org + 1.0 + Test 2 + true + + + xpcshell@tests.mozilla.org + 2 + 2 + + + + diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index d988358dad8..66d07b3b95d 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -664,6 +664,67 @@ function setExtensionModifiedTime(aExt, aTime) { } } +/** + * Manually installs an XPI file into an install location by either copying the + * XPI there or extracting it depending on whether unpacking is being tested + * or not. + * + * @param aXPIFile + * The XPI file to install. + * @param aInstallLocation + * The install location (an nsIFile) to install into. + * @param aID + * The ID to install as. + */ +function manuallyInstall(aXPIFile, aInstallLocation, aID) { + if (TEST_UNPACKED) { + let dir = aInstallLocation.clone(); + dir.append(aID); + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); + let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. + createInstance(AM_Ci.nsIZipReader); + zip.open(aXPIFile); + let entries = zip.findEntries(null); + while (entries.hasMore()) { + let entry = entries.getNext(); + let target = dir.clone(); + entry.split("/").forEach(function(aPart) { + target.append(aPart); + }); + zip.extract(entry, target); + } + zip.close(); + + return dir; + } + else { + let target = aInstallLocation.clone(); + target.append(aID + ".xpi"); + aXPIFile.copyTo(target.parent, target.leafName); + return target; + } +} + +/** + * Manually uninstalls an add-on by removing its files from the install + * location. + * + * @param aInstallLocation + * The nsIFile of the install location to remove from. + * @param aID + * The ID of the add-on to remove. + */ +function manuallyUninstall(aInstallLocation, aID) { + let file = getFileForAddon(aInstallLocation, aID); + + // In reality because the app is restarted a flush isn't necessary for XPIs + // removed outside the app, but for testing we must flush manually. + if (file.isFile()) + Services.obs.notifyObservers(file, "flush-cache-entry", null); + + file.remove(true); +} + /** * Gets the nsIFile for where an add-on is installed. It may point to a file or * a directory depending on whether add-ons are being installed unpacked or not. diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index 449b720a25e..346c92e578d 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -81,46 +81,6 @@ function getUninstallReason() { return Services.prefs.getIntPref("bootstraptest.uninstall_reason"); } -function manuallyInstall(aXPIFile, aInstallLocation, aID) { - if (TEST_UNPACKED) { - let dir = aInstallLocation.clone(); - dir.append(aID); - dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); - let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. - createInstance(AM_Ci.nsIZipReader); - zip.open(aXPIFile); - let entries = zip.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); - let target = dir.clone(); - entry.split("/").forEach(function(aPart) { - target.append(aPart); - }); - zip.extract(entry, target); - } - zip.close(); - - return dir; - } - else { - let target = aInstallLocation.clone(); - target.append(aID + ".xpi"); - aXPIFile.copyTo(target.parent, target.leafName); - return target; - } -} - -function manuallyUninstall(aInstallLocation, aID) { - let file = getFileForAddon(aInstallLocation, aID); - - // In reality because the app is restarted a flush isn't necessary for XPIs - // removed outside the app, but for testing we must flush manually. - if (file.isFile()) - Services.obs.notifyObservers(file, "flush-cache-entry", null); - - file.remove(true); -} - function run_test() { do_test_pending(); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js index 7da81be7e12..d67e2218cc6 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js @@ -58,14 +58,23 @@ function run_test() { var dir = writeInstallRDFForExtension(addon1, userDir); setExtensionModifiedTime(dir, time); + manuallyInstall(do_get_addon("test_bug655254_2"), userDir, "addon2@tests.mozilla.org"); + startupManager(); - AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", + "addon2@tests.mozilla.org"], function([a1, a2]) { do_check_neq(a1, null); do_check_true(a1.appDisabled); do_check_false(a1.isActive); do_check_false(isExtensionInAddonsList(userDir, a1.id)); + do_check_neq(a2, null); + do_check_false(a2.appDisabled); + do_check_true(a2.isActive); + do_check_false(isExtensionInAddonsList(userDir, a2.id)); + do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 1); + a1.findUpdates({ onUpdateFinished: function() { restartManager(); @@ -78,6 +87,8 @@ function run_test() { shutdownManager(); + do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 0); + userDir.parent.moveTo(gProfD, "extensions3"); userDir = gProfD.clone(); userDir.append("extensions3"); @@ -86,12 +97,19 @@ function run_test() { startupManager(false); - AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", + "addon2@tests.mozilla.org"], function([a1, a2]) { do_check_neq(a1, null); do_check_false(a1.appDisabled); do_check_true(a1.isActive); do_check_true(isExtensionInAddonsList(userDir, a1.id)); + do_check_neq(a2, null); + do_check_false(a2.appDisabled); + do_check_true(a2.isActive); + do_check_false(isExtensionInAddonsList(userDir, a2.id)); + do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 1); + testserver.stop(do_test_finished); }); }); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug740612.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug740612.js index 294c8f216f3..e85976751b9 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug740612.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug740612.js @@ -17,35 +17,6 @@ function getInstalledVersion() { return Services.prefs.getIntPref("bootstraptest.installed_version"); } -function manuallyInstall(aXPIFile, aInstallLocation, aID) { - if (TEST_UNPACKED) { - let dir = aInstallLocation.clone(); - dir.append(aID); - dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); - let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. - createInstance(AM_Ci.nsIZipReader); - zip.open(aXPIFile); - let entries = zip.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); - let target = dir.clone(); - entry.split("/").forEach(function(aPart) { - target.append(aPart); - }); - zip.extract(entry, target); - } - zip.close(); - - return dir; - } - else { - let target = aInstallLocation.clone(); - target.append(aID + ".xpi"); - aXPIFile.copyTo(target.parent, target.leafName); - return target; - } -} - function run_test() { do_test_pending();