diff --git a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js index dcfb702d9a96..e58e4050529c 100644 --- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js +++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js @@ -1627,10 +1627,12 @@ this.XPIDatabaseReconcile = { // Remove the invalid add-on from the install location if the install // location isn't locked, no restart will be necessary - if (!aInstallLocation.locked) - aInstallLocation.uninstallAddon(aId); - else + if (aInstallLocation.isLinkedAddon(aId)) + logger.warn("Not uninstalling invalid item because it is a proxy file"); + else if (aInstallLocation.locked) logger.warn("Could not uninstall invalid item from locked install location"); + else + aInstallLocation.uninstallAddon(aId); return null; } diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_proxy/bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/data/test_proxy/bootstrap.js new file mode 100644 index 000000000000..1666f2972c37 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_proxy/bootstrap.js @@ -0,0 +1 @@ +Components.utils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this); diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index efd5b4ff7c89..44f1d6775afb 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -2116,3 +2116,36 @@ var promiseConsoleOutput = Task.async(function*(aTask) { Services.console.unregisterListener(listener); } }); + +/** + * Creates an extension proxy file. + * See: https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment#Firefox_extension_proxy_file + * @param aDir + * The directory to add the proxy file to. + * @param aAddon + * An nsIFile for the add-on file that this is a proxy file for. + * @param aId + * A string to use for the add-on ID. + * @return An nsIFile for the proxy file. + */ +function writeProxyFileToDir(aDir, aAddon, aId) { + let dir = aDir.clone(); + + if (!dir.exists()) + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); + + let file = dir.clone(); + file.append(aId); + + let addonPath = aAddon.path; + + let fos = AM_Cc["@mozilla.org/network/file-output-stream;1"]. + createInstance(AM_Ci.nsIFileOutputStream); + fos.init(file, + FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE, + FileUtils.PERMS_FILE, 0); + fos.write(addonPath, addonPath.length); + fos.close(); + + return file; +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_proxy.js b/toolkit/mozapps/extensions/test/xpcshell/test_proxy.js new file mode 100644 index 000000000000..012a8fa5f211 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_proxy.js @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const ID = "proxy1@tests.mozilla.org"; + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42"); +startupManager(); + +BootstrapMonitor.init(); + +// Ensure that a proxy file to an add-on with a valid manifest works. +add_task(function*() { + let tempdir = gTmpD.clone(); + writeInstallRDFToDir({ + id: ID, + version: "1.0", + bootstrap: true, + unpack: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Bootstrap 1 (proxy)", + }, tempdir, ID, "bootstrap.js"); + + let unpackedAddon = tempdir.clone(); + unpackedAddon.append(ID); + do_get_file("data/test_proxy/bootstrap.js") + .copyTo(unpackedAddon, "bootstrap.js"); + + // create proxy file in profile/extensions dir + let extensionsDir = gProfD.clone(); + extensionsDir.append("extensions"); + let proxyFile = writeProxyFileToDir(extensionsDir, unpackedAddon, ID); + + yield promiseRestartManager(); + + BootstrapMonitor.checkAddonInstalled(ID, "1.0"); + BootstrapMonitor.checkAddonStarted(ID, "1.0"); + + let addon = yield promiseAddonByID(ID); + + do_check_neq(addon, null); + do_check_eq(addon.version, "1.0"); + do_check_eq(addon.name, "Test Bootstrap 1 (proxy)"); + do_check_true(addon.isCompatible); + do_check_false(addon.appDisabled); + do_check_true(addon.isActive); + do_check_eq(addon.type, "extension"); + do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_MISSING : AddonManager.SIGNEDSTATE_NOT_REQUIRED); + + do_check_true(proxyFile.exists()); + + addon.uninstall(); + unpackedAddon.remove(true); + + yield promiseRestartManager(); +}); + + +// Ensure that a proxy file to an add-on is not removed even +// if the manifest file is invalid. See bug 1195353. +add_task(function*() { + let tempdir = gTmpD.clone(); + + // use a mismatched ID to make this install.rdf invalid + writeInstallRDFToDir({ + id: "bad-proxy1@tests.mozilla.org", + version: "1.0", + bootstrap: true, + unpack: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Bootstrap 1 (proxy)", + }, tempdir, ID, "bootstrap.js"); + + let unpackedAddon = tempdir.clone(); + unpackedAddon.append(ID); + do_get_file("data/test_proxy/bootstrap.js") + .copyTo(unpackedAddon, "bootstrap.js"); + + // create proxy file in profile/extensions dir + let extensionsDir = gProfD.clone(); + extensionsDir.append("extensions"); + let proxyFile = writeProxyFileToDir(extensionsDir, unpackedAddon, ID); + + yield promiseRestartManager(); + + BootstrapMonitor.checkAddonNotInstalled(ID, "1.0"); + BootstrapMonitor.checkAddonNotStarted(ID, "1.0"); + + let addon = yield promiseAddonByID(ID); + do_check_eq(addon, null); + + do_check_true(proxyFile.exists()); + + unpackedAddon.remove(true); + proxyFile.remove(true); + + yield promiseRestartManager(); +}); diff --git a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini index b47c1125cf28..c713e8f27bb0 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini +++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini @@ -30,6 +30,7 @@ skip-if = appname != "firefox" [test_XPIcancel.js] [test_XPIStates.js] [test_temporary.js] +[test_proxy.js] [include:xpcshell-shared.ini]