Bug 1195353 - leave extension proxy files that point to invalid manifests r=mossop

This commit is contained in:
Robert Helmer 2015-11-25 23:28:30 -08:00
parent 54a14586fa
commit d64a5b230f
5 changed files with 146 additions and 3 deletions

View File

@ -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;
}

View File

@ -0,0 +1 @@
Components.utils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this);

View File

@ -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;
}

View File

@ -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();
});

View File

@ -30,6 +30,7 @@ skip-if = appname != "firefox"
[test_XPIcancel.js]
[test_XPIStates.js]
[test_temporary.js]
[test_proxy.js]
[include:xpcshell-shared.ini]