2010-04-29 13:11:23 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
const AM_Cc = Components.classes;
|
|
|
|
const AM_Ci = Components.interfaces;
|
|
|
|
|
|
|
|
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
|
|
|
|
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
2010-08-23 18:04:06 -07:00
|
|
|
Components.utils.import("resource://gre/modules/AddonRepository.jsm");
|
2010-04-29 13:11:23 -07:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2010-08-23 18:04:06 -07:00
|
|
|
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
2010-04-29 13:11:23 -07:00
|
|
|
|
|
|
|
var gInternalManager = null;
|
|
|
|
var gAppInfo = null;
|
|
|
|
var gAddonsList;
|
|
|
|
|
|
|
|
function createAppInfo(id, name, version, platformVersion) {
|
|
|
|
gAppInfo = {
|
|
|
|
// nsIXULAppInfo
|
|
|
|
vendor: "Mozilla",
|
|
|
|
name: name,
|
|
|
|
ID: id,
|
|
|
|
version: version,
|
|
|
|
appBuildID: "2007010101",
|
|
|
|
platformVersion: platformVersion,
|
|
|
|
platformBuildID: "2007010101",
|
|
|
|
|
|
|
|
// nsIXULRuntime
|
|
|
|
inSafeMode: false,
|
|
|
|
logConsoleErrors: true,
|
|
|
|
OS: "XPCShell",
|
|
|
|
XPCOMABI: "noarch-spidermonkey",
|
|
|
|
invalidateCachesOnRestart: function invalidateCachesOnRestart() {
|
|
|
|
// Do nothing
|
|
|
|
},
|
|
|
|
|
2010-04-07 11:05:03 -07:00
|
|
|
// nsICrashReporter
|
|
|
|
annotations: {},
|
|
|
|
|
|
|
|
annotateCrashReport: function(key, data) {
|
|
|
|
this.annotations[key] = data;
|
|
|
|
},
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIXULAppInfo,
|
|
|
|
AM_Ci.nsIXULRuntime,
|
2010-04-07 11:05:03 -07:00
|
|
|
AM_Ci.nsICrashReporter,
|
2010-04-29 13:11:23 -07:00
|
|
|
AM_Ci.nsISupports])
|
|
|
|
};
|
2010-04-08 12:28:10 -07:00
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
var XULAppInfoFactory = {
|
|
|
|
createInstance: function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return gAppInfo.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
|
|
|
|
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
|
|
|
|
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
|
|
|
|
}
|
|
|
|
|
2010-04-07 11:05:03 -07:00
|
|
|
/**
|
|
|
|
* Tests that an add-on does appear in the crash report annotations, if
|
|
|
|
* crash reporting is enabled. The test will fail if the add-on is not in the
|
|
|
|
* annotation.
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aId
|
|
|
|
* The ID of the add-on
|
|
|
|
* @param aVersion
|
|
|
|
* The version of the add-on
|
2010-04-07 11:05:03 -07:00
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function do_check_in_crash_annotation(aId, aVersion) {
|
2010-04-07 11:05:03 -07:00
|
|
|
if (!("nsICrashReporter" in AM_Ci))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!("Add-ons" in gAppInfo.annotations)) {
|
|
|
|
do_check_false(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let addons = gAppInfo.annotations["Add-ons"].split(",");
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_false(addons.indexOf(aId + ":" + aVersion) < 0);
|
2010-04-07 11:05:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that an add-on does not appear in the crash report annotations, if
|
|
|
|
* crash reporting is enabled. The test will fail if the add-on is in the
|
|
|
|
* annotation.
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aId
|
|
|
|
* The ID of the add-on
|
|
|
|
* @param aVersion
|
|
|
|
* The version of the add-on
|
2010-04-07 11:05:03 -07:00
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function do_check_not_in_crash_annotation(aId, aVersion) {
|
2010-04-07 11:05:03 -07:00
|
|
|
if (!("nsICrashReporter" in AM_Ci))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!("Add-ons" in gAppInfo.annotations)) {
|
|
|
|
do_check_true(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let addons = gAppInfo.annotations["Add-ons"].split(",");
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_true(addons.indexOf(aId + ":" + aVersion) < 0);
|
2010-04-07 11:05:03 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
/**
|
|
|
|
* Returns a testcase xpi
|
|
|
|
*
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aName
|
|
|
|
* The name of the testcase (without extension)
|
|
|
|
* @return an nsILocalFile pointing to the testcase xpi
|
2010-04-29 13:11:23 -07:00
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function do_get_addon(aName) {
|
|
|
|
return do_get_file("addons/" + aName + ".xpi");
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-11-09 18:52:06 -08:00
|
|
|
function do_get_addon_hash(aName, aAlgorithm) {
|
|
|
|
if (!aAlgorithm)
|
|
|
|
aAlgorithm = "sha1";
|
|
|
|
|
|
|
|
let file = do_get_addon(aName);
|
|
|
|
|
|
|
|
let crypto = AM_Cc["@mozilla.org/security/hash;1"].
|
|
|
|
createInstance(AM_Ci.nsICryptoHash);
|
|
|
|
crypto.initWithString(aAlgorithm);
|
|
|
|
let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(AM_Ci.nsIFileInputStream);
|
|
|
|
fis.init(file, -1, -1, false);
|
|
|
|
crypto.updateFromStream(fis, file.fileSize);
|
|
|
|
|
|
|
|
// return the two-digit hexadecimal code for a byte
|
|
|
|
function toHexString(charCode)
|
|
|
|
("0" + charCode.toString(16)).slice(-2);
|
|
|
|
|
|
|
|
let binary = crypto.finish(false);
|
|
|
|
return aAlgorithm + ":" + [toHexString(binary.charCodeAt(i)) for (i in binary)].join("")
|
|
|
|
}
|
|
|
|
|
2010-09-10 15:54:37 -07:00
|
|
|
/**
|
|
|
|
* Returns an extension uri spec
|
|
|
|
*
|
|
|
|
* @param aProfileDir
|
|
|
|
* The extension install directory
|
|
|
|
* @return a uri spec pointing to the root of the extension
|
|
|
|
*/
|
|
|
|
function do_get_addon_root_uri(aProfileDir, aId) {
|
|
|
|
let path = aProfileDir.clone();
|
|
|
|
path.append(aId);
|
|
|
|
if (!path.exists()) {
|
|
|
|
path.leafName += ".xpi";
|
|
|
|
return "jar:" + Services.io.newFileURI(path).spec + "!/";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Services.io.newFileURI(path).spec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_get_expected_addon_name(aId) {
|
|
|
|
if (Services.prefs.getBoolPref("extensions.alwaysUnpack"))
|
|
|
|
return aId;
|
|
|
|
return aId + ".xpi";
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:04:06 -07:00
|
|
|
/**
|
|
|
|
* Check that an array of actual add-ons is the same as an array of
|
|
|
|
* expected add-ons.
|
|
|
|
*
|
|
|
|
* @param aActualAddons
|
|
|
|
* The array of actual add-ons to check.
|
|
|
|
* @param aExpectedAddons
|
|
|
|
* The array of expected add-ons to check against.
|
|
|
|
* @param aProperties
|
|
|
|
* An array of properties to check.
|
|
|
|
*/
|
|
|
|
function do_check_addons(aActualAddons, aExpectedAddons, aProperties) {
|
|
|
|
do_check_neq(aActualAddons, null);
|
|
|
|
do_check_eq(aActualAddons.length, aExpectedAddons.length);
|
|
|
|
for (let i = 0; i < aActualAddons.length; i++)
|
|
|
|
do_check_addon(aActualAddons[i], aExpectedAddons[i], aProperties);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the actual add-on is the same as the expected add-on.
|
|
|
|
*
|
|
|
|
* @param aActualAddon
|
|
|
|
* The actual add-on to check.
|
|
|
|
* @param aExpectedAddon
|
|
|
|
* The expected add-on to check against.
|
|
|
|
* @param aProperties
|
|
|
|
* An array of properties to check.
|
|
|
|
*/
|
|
|
|
function do_check_addon(aActualAddon, aExpectedAddon, aProperties) {
|
|
|
|
do_check_neq(aActualAddon, null);
|
|
|
|
|
|
|
|
aProperties.forEach(function(aProperty) {
|
|
|
|
let actualValue = aActualAddon[aProperty];
|
|
|
|
let expectedValue = aExpectedAddon[aProperty];
|
|
|
|
|
|
|
|
// Check that all undefined expected properties are null on actual add-on
|
|
|
|
if (!(aProperty in aExpectedAddon)) {
|
|
|
|
if (actualValue !== undefined && actualValue !== null)
|
|
|
|
do_throw("Unexpected defined/non-null property for add-on " +
|
|
|
|
aExpectedAddon.id + " (addon[" + aProperty + "] = " + actualValue);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aProperty) {
|
|
|
|
case "creator":
|
|
|
|
do_check_author(actualValue, expectedValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "developers":
|
|
|
|
case "translators":
|
|
|
|
case "contributors":
|
|
|
|
do_check_eq(actualValue.length, expectedValue.length);
|
|
|
|
for (let i = 0; i < actualValue.length; i++)
|
|
|
|
do_check_author(actualValue[i], expectedValue[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "screenshots":
|
|
|
|
do_check_eq(actualValue.length, expectedValue.length);
|
|
|
|
for (let i = 0; i < actualValue.length; i++)
|
|
|
|
do_check_screenshot(actualValue[i], expectedValue[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "sourceURI":
|
|
|
|
do_check_eq(actualValue.spec, expectedValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "updateDate":
|
|
|
|
do_check_eq(actualValue.getTime(), expectedValue.getTime());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (actualValue !== expectedValue)
|
|
|
|
do_throw("Failed for " + aProperty + " for add-on " + aExpectedAddon.id +
|
|
|
|
" (" + actualValue + " === " + expectedValue + ")");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the actual author is the same as the expected author.
|
|
|
|
*
|
|
|
|
* @param aActual
|
|
|
|
* The actual author to check.
|
|
|
|
* @param aExpected
|
|
|
|
* The expected author to check against.
|
|
|
|
*/
|
|
|
|
function do_check_author(aActual, aExpected) {
|
|
|
|
do_check_eq(aActual.toString(), aExpected.name);
|
|
|
|
do_check_eq(aActual.name, aExpected.name);
|
|
|
|
do_check_eq(aActual.url, aExpected.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the actual screenshot is the same as the expected screenshot.
|
|
|
|
*
|
|
|
|
* @param aActual
|
|
|
|
* The actual screenshot to check.
|
|
|
|
* @param aExpected
|
|
|
|
* The expected screenshot to check against.
|
|
|
|
*/
|
|
|
|
function do_check_screenshot(aActual, aExpected) {
|
|
|
|
do_check_eq(aActual.toString(), aExpected.url);
|
|
|
|
do_check_eq(aActual.url, aExpected.url);
|
|
|
|
do_check_eq(aActual.thumbnailURL, aExpected.thumbnailURL);
|
|
|
|
do_check_eq(aActual.caption, aExpected.caption);
|
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
/**
|
2010-07-14 10:13:26 -07:00
|
|
|
* Starts up the add-on manager as if it was started by the application.
|
2010-04-29 13:11:23 -07:00
|
|
|
*
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aAppChanged
|
|
|
|
* An optional boolean parameter to simulate the case where the
|
|
|
|
* application has changed version since the last run. If not passed it
|
|
|
|
* defaults to true
|
2010-04-29 13:11:23 -07:00
|
|
|
*/
|
2010-07-14 10:13:26 -07:00
|
|
|
function startupManager(aAppChanged) {
|
2010-04-29 13:11:23 -07:00
|
|
|
if (gInternalManager)
|
|
|
|
do_throw("Test attempt to startup manager that was already started.");
|
|
|
|
|
2010-07-14 10:13:26 -07:00
|
|
|
if (aAppChanged || aAppChanged === undefined) {
|
|
|
|
var file = gProfD.clone();
|
|
|
|
file.append("extensions.ini");
|
|
|
|
if (file.exists())
|
|
|
|
file.remove(true);
|
|
|
|
}
|
2010-04-29 13:11:23 -07:00
|
|
|
|
|
|
|
gInternalManager = AM_Cc["@mozilla.org/addons/integration;1"].
|
|
|
|
getService(AM_Ci.nsIObserver).
|
|
|
|
QueryInterface(AM_Ci.nsITimerCallback);
|
|
|
|
|
2010-06-11 12:02:44 -07:00
|
|
|
gInternalManager.observe(null, "addons-startup", null);
|
2010-04-29 13:11:23 -07:00
|
|
|
|
2010-07-14 10:13:26 -07:00
|
|
|
// Load the add-ons list as it was after extension registration
|
|
|
|
loadAddonsList();
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-14 10:13:26 -07:00
|
|
|
* Restarts the add-on manager as if the host application was restarted.
|
2010-04-29 13:11:23 -07:00
|
|
|
*
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aNewVersion
|
|
|
|
* An optional new version to use for the application. Passing this
|
|
|
|
* will change nsIXULAppInfo.version and make the startup appear as if
|
|
|
|
* the application version has changed.
|
2010-04-29 13:11:23 -07:00
|
|
|
*/
|
2010-07-14 10:13:26 -07:00
|
|
|
function restartManager(aNewVersion) {
|
2010-04-29 13:11:23 -07:00
|
|
|
shutdownManager();
|
2010-04-28 09:42:07 -07:00
|
|
|
if (aNewVersion) {
|
|
|
|
gAppInfo.version = aNewVersion;
|
2010-07-14 10:13:26 -07:00
|
|
|
startupManager(true);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-07-14 10:13:26 -07:00
|
|
|
startupManager(false);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function shutdownManager() {
|
|
|
|
if (!gInternalManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let obs = AM_Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(AM_Ci.nsIObserverService);
|
2010-08-23 18:04:06 -07:00
|
|
|
|
|
|
|
let xpiShutdown = false;
|
|
|
|
obs.addObserver({
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
xpiShutdown = true;
|
|
|
|
obs.removeObserver(this, "xpi-provider-shutdown");
|
|
|
|
}
|
|
|
|
}, "xpi-provider-shutdown", false);
|
|
|
|
|
|
|
|
let repositoryShutdown = false;
|
|
|
|
obs.addObserver({
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
repositoryShutdown = true;
|
|
|
|
obs.removeObserver(this, "addon-repository-shutdown");
|
|
|
|
}
|
|
|
|
}, "addon-repository-shutdown", false);
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
obs.notifyObservers(null, "quit-application-granted", null);
|
|
|
|
gInternalManager.observe(null, "xpcom-shutdown", null);
|
|
|
|
gInternalManager = null;
|
2010-04-07 11:05:03 -07:00
|
|
|
|
2010-08-23 18:04:06 -07:00
|
|
|
AddonRepository.shutdown();
|
|
|
|
|
2010-05-27 15:09:26 -07:00
|
|
|
// Load the add-ons list as it was after application shutdown
|
2010-07-14 10:13:26 -07:00
|
|
|
loadAddonsList();
|
2010-05-27 15:09:26 -07:00
|
|
|
|
2010-04-07 11:05:03 -07:00
|
|
|
// Clear any crash report annotations
|
|
|
|
gAppInfo.annotations = {};
|
2010-05-27 15:10:09 -07:00
|
|
|
|
|
|
|
let thr = AM_Cc["@mozilla.org/thread-manager;1"].
|
|
|
|
getService(AM_Ci.nsIThreadManager).
|
|
|
|
mainThread;
|
|
|
|
|
2010-08-23 18:04:06 -07:00
|
|
|
// Wait until we observe the shutdown notifications
|
|
|
|
while (!repositoryShutdown || !xpiShutdown) {
|
|
|
|
if (thr.hasPendingEvents())
|
|
|
|
thr.processNextEvent(false);
|
2010-05-27 15:10:09 -07:00
|
|
|
}
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 10:13:26 -07:00
|
|
|
function loadAddonsList() {
|
2010-04-28 09:42:07 -07:00
|
|
|
function readDirectories(aSection) {
|
2010-04-29 13:11:23 -07:00
|
|
|
var dirs = [];
|
2010-04-28 09:42:07 -07:00
|
|
|
var keys = parser.getKeys(aSection);
|
2010-04-29 13:11:23 -07:00
|
|
|
while (keys.hasMore()) {
|
2010-04-28 09:42:07 -07:00
|
|
|
let descriptor = parser.getString(aSection, keys.getNext());
|
2010-04-29 13:11:23 -07:00
|
|
|
try {
|
|
|
|
let file = AM_Cc["@mozilla.org/file/local;1"].
|
|
|
|
createInstance(AM_Ci.nsILocalFile);
|
|
|
|
file.persistentDescriptor = descriptor;
|
|
|
|
dirs.push(file);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// Throws if the directory doesn't exist, we can ignore this since the
|
|
|
|
// platform will too.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
|
|
|
|
gAddonsList = {
|
|
|
|
extensions: [],
|
|
|
|
themes: []
|
|
|
|
};
|
|
|
|
|
|
|
|
var file = gProfD.clone();
|
|
|
|
file.append("extensions.ini");
|
|
|
|
if (!file.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var factory = AM_Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
|
|
|
|
getService(AM_Ci.nsIINIParserFactory);
|
|
|
|
var parser = factory.createINIParser(file);
|
|
|
|
gAddonsList.extensions = readDirectories("ExtensionDirs");
|
|
|
|
gAddonsList.themes = readDirectories("ThemeDirs");
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function isItemInAddonsList(aType, aDir, aId) {
|
|
|
|
var path = aDir.clone();
|
|
|
|
path.append(aId);
|
2010-09-10 15:54:37 -07:00
|
|
|
var xpiPath = aDir.clone();
|
|
|
|
xpiPath.append(aId + ".xpi");
|
2010-04-28 09:42:07 -07:00
|
|
|
for (var i = 0; i < gAddonsList[aType].length; i++) {
|
2010-09-10 15:54:37 -07:00
|
|
|
let file = gAddonsList[aType][i];
|
|
|
|
if (file.isDirectory() && file.equals(path))
|
|
|
|
return true;
|
|
|
|
if (file.isFile() && file.equals(xpiPath))
|
2010-04-29 13:11:23 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function isThemeInAddonsList(aDir, aId) {
|
|
|
|
return isItemInAddonsList("themes", aDir, aId);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function isExtensionInAddonsList(aDir, aId) {
|
|
|
|
return isItemInAddonsList("extensions", aDir, aId);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-28 11:49:56 -07:00
|
|
|
/**
|
|
|
|
* Escapes any occurances of &, ", < or > with XML entities.
|
|
|
|
*
|
|
|
|
* @param str
|
|
|
|
* The string to escape
|
|
|
|
* @return The escaped string
|
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function escapeXML(aStr) {
|
|
|
|
return aStr.toString()
|
|
|
|
.replace(/&/g, "&")
|
|
|
|
.replace(/"/g, """)
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">");
|
2010-04-28 11:49:56 -07:00
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function writeLocaleStrings(aData) {
|
2010-04-29 13:11:23 -07:00
|
|
|
let rdf = "";
|
2010-04-28 09:42:07 -07:00
|
|
|
["name", "description", "creator", "homepageURL"].forEach(function(aProp) {
|
|
|
|
if (aProp in aData)
|
|
|
|
rdf += "<em:" + aProp + ">" + escapeXML(aData[aProp]) + "</em:" + aProp + ">\n";
|
2010-04-29 13:11:23 -07:00
|
|
|
});
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
["developer", "translator", "contributor"].forEach(function(aProp) {
|
|
|
|
if (aProp in aData) {
|
|
|
|
aData[aProp].forEach(function(aValue) {
|
|
|
|
rdf += "<em:" + aProp + ">" + escapeXML(aValue) + "</em:" + aProp + ">\n";
|
2010-04-29 13:11:23 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return rdf;
|
|
|
|
}
|
|
|
|
|
2010-09-10 15:54:37 -07:00
|
|
|
function createInstallRDF(aData) {
|
2010-04-29 13:11:23 -07:00
|
|
|
var rdf = '<?xml version="1.0"?>\n';
|
|
|
|
rdf += '<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' +
|
|
|
|
' xmlns:em="http://www.mozilla.org/2004/em-rdf#">\n';
|
|
|
|
rdf += '<Description about="urn:mozilla:install-manifest">\n';
|
|
|
|
|
|
|
|
["id", "version", "type", "internalName", "updateURL", "updateKey",
|
2010-09-01 11:10:03 -07:00
|
|
|
"optionsURL", "aboutURL", "iconURL", "icon64URL",
|
2010-11-09 09:25:39 -08:00
|
|
|
"skinnable", "bootstrap"].forEach(function(aProp) {
|
2010-04-28 09:42:07 -07:00
|
|
|
if (aProp in aData)
|
|
|
|
rdf += "<em:" + aProp + ">" + escapeXML(aData[aProp]) + "</em:" + aProp + ">\n";
|
2010-04-29 13:11:23 -07:00
|
|
|
});
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
rdf += writeLocaleStrings(aData);
|
2010-04-29 13:11:23 -07:00
|
|
|
|
2010-07-01 11:37:32 -07:00
|
|
|
if ("targetPlatforms" in aData) {
|
|
|
|
aData.targetPlatforms.forEach(function(aPlatform) {
|
|
|
|
rdf += "<em:targetPlatform>" + escapeXML(aPlatform) + "</em:targetPlatform>\n";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
if ("targetApplications" in aData) {
|
|
|
|
aData.targetApplications.forEach(function(aApp) {
|
2010-04-29 13:11:23 -07:00
|
|
|
rdf += "<em:targetApplication><Description>\n";
|
2010-04-28 09:42:07 -07:00
|
|
|
["id", "minVersion", "maxVersion"].forEach(function(aProp) {
|
|
|
|
if (aProp in aApp)
|
|
|
|
rdf += "<em:" + aProp + ">" + escapeXML(aApp[aProp]) + "</em:" + aProp + ">\n";
|
2010-04-29 13:11:23 -07:00
|
|
|
});
|
|
|
|
rdf += "</Description></em:targetApplication>\n";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-24 16:41:46 -07:00
|
|
|
if ("localized" in aData) {
|
|
|
|
aData.localized.forEach(function(aLocalized) {
|
|
|
|
rdf += "<em:localized><Description>\n";
|
|
|
|
if ("locale" in aLocalized) {
|
|
|
|
aLocalized.locale.forEach(function(aLocaleName) {
|
|
|
|
rdf += "<em:locale>" + escapeXML(aLocaleName) + "</em:locale>\n";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
rdf += writeLocaleStrings(aLocalized);
|
|
|
|
rdf += "</Description></em:localized>\n";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
rdf += "</Description>\n</RDF>\n";
|
2010-09-10 15:54:37 -07:00
|
|
|
return rdf;
|
|
|
|
}
|
2010-04-29 13:11:23 -07:00
|
|
|
|
2010-09-10 15:54:37 -07:00
|
|
|
/**
|
|
|
|
* Writes an install.rdf manifest into a directory using the properties passed
|
|
|
|
* in a JS object. The objects should contain a property for each property to
|
|
|
|
* appear in the RDFThe object may contain an array of objects with id,
|
|
|
|
* minVersion and maxVersion in the targetApplications property to give target
|
|
|
|
* application compatibility.
|
|
|
|
*
|
|
|
|
* @param aData
|
|
|
|
* The object holding data about the add-on
|
|
|
|
* @param aDir
|
|
|
|
* The directory to add the install.rdf to
|
|
|
|
* @param aExtraFile
|
|
|
|
* An optional dummy file to create in the directory
|
|
|
|
*/
|
|
|
|
function writeInstallRDFToDir(aData, aDir, aExtraFile) {
|
|
|
|
var rdf = createInstallRDF(aData);
|
2010-04-28 09:42:07 -07:00
|
|
|
if (!aDir.exists())
|
|
|
|
aDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
|
|
|
|
var file = aDir.clone();
|
2010-04-29 13:11:23 -07:00
|
|
|
file.append("install.rdf");
|
2010-04-29 13:11:24 -07:00
|
|
|
if (file.exists())
|
|
|
|
file.remove(true);
|
2010-04-29 13:11:23 -07:00
|
|
|
var 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(rdf, rdf.length);
|
|
|
|
fos.close();
|
2010-09-10 15:54:37 -07:00
|
|
|
|
|
|
|
if (!aExtraFile)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file = aDir.clone();
|
|
|
|
file.append(aExtraFile);
|
|
|
|
file.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes an install.rdf manifest into an extension using the properties passed
|
|
|
|
* in a JS object. The objects should contain a property for each property to
|
|
|
|
* appear in the RDFThe object may contain an array of objects with id,
|
|
|
|
* minVersion and maxVersion in the targetApplications property to give target
|
|
|
|
* application compatibility.
|
|
|
|
*
|
|
|
|
* @param aData
|
|
|
|
* The object holding data about the add-on
|
|
|
|
* @param aDir
|
|
|
|
* The install directory to add the extension to
|
|
|
|
* @param aId
|
|
|
|
* An optional string to override the default installation aId
|
|
|
|
* @param aExtraFile
|
|
|
|
* An optional dummy file to create in the extension
|
|
|
|
* @return A file pointing to where the extension was installed
|
|
|
|
*/
|
|
|
|
function writeInstallRDFForExtension(aData, aDir, aId, aExtraFile) {
|
|
|
|
var id = aId ? aId : aData.id
|
|
|
|
|
|
|
|
var dir = aDir.clone();
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) {
|
|
|
|
dir.append(id);
|
|
|
|
writeInstallRDFToDir(aData, dir, aExtraFile);
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dir.exists())
|
|
|
|
dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
|
|
|
|
dir.append(id + ".xpi");
|
|
|
|
var rdf = createInstallRDF(aData);
|
|
|
|
var stream = AM_Cc["@mozilla.org/io/string-input-stream;1"].
|
|
|
|
createInstance(AM_Ci.nsIStringInputStream);
|
|
|
|
stream.setData(rdf, -1);
|
|
|
|
var zipW = AM_Cc["@mozilla.org/zipwriter;1"].
|
|
|
|
createInstance(AM_Ci.nsIZipWriter);
|
|
|
|
zipW.open(dir, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE);
|
|
|
|
zipW.addEntryStream("install.rdf", 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
|
|
|
|
stream, false);
|
|
|
|
if (aExtraFile)
|
|
|
|
zipW.addEntryStream(aExtraFile, 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
|
|
|
|
stream, false);
|
|
|
|
zipW.close();
|
|
|
|
return dir;
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-09-14 17:39:07 -07:00
|
|
|
/**
|
|
|
|
* Sets the last modified time of the extension, usually to trigger an update
|
|
|
|
* of its metadata. If the extension is unpacked, this function assumes that
|
|
|
|
* the extension contains only the install.rdf file.
|
|
|
|
*
|
|
|
|
* @param aExt a file pointing to either the packed extension or its unpacked directory.
|
|
|
|
* @param aTime the time to which we set the lastModifiedTime of the extension
|
|
|
|
*/
|
|
|
|
function setExtensionModifiedTime(aExt, aTime) {
|
|
|
|
aExt.lastModifiedTime = aTime;
|
|
|
|
if (aExt.isDirectory()) {
|
|
|
|
aExt = aExt.clone();
|
|
|
|
aExt.append("install.rdf");
|
|
|
|
aExt.lastModifiedTime = aTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function registerDirectory(aKey, aDir) {
|
2010-04-29 13:11:23 -07:00
|
|
|
var dirProvider = {
|
2010-04-28 09:42:07 -07:00
|
|
|
getFile: function(aProp, aPersistent) {
|
|
|
|
aPersistent.value = true;
|
|
|
|
if (aProp == aKey)
|
|
|
|
return aDir.clone();
|
2010-04-29 13:11:23 -07:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIDirectoryServiceProvider,
|
|
|
|
AM_Ci.nsISupports])
|
|
|
|
};
|
|
|
|
Services.dirsvc.registerProvider(dirProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
var gExpectedEvents = {};
|
|
|
|
var gExpectedInstalls = [];
|
|
|
|
var gNext = null;
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function getExpectedEvent(aId) {
|
|
|
|
if (!(aId in gExpectedEvents))
|
|
|
|
do_throw("Wasn't expecting events for " + aId);
|
|
|
|
if (gExpectedEvents[aId].length == 0)
|
|
|
|
do_throw("Too many events for " + aId);
|
|
|
|
let event = gExpectedEvents[aId].shift();
|
2010-04-29 13:11:23 -07:00
|
|
|
if (event instanceof Array)
|
|
|
|
return event;
|
|
|
|
return [event, true];
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:07:49 -07:00
|
|
|
function getExpectedInstall(aAddon) {
|
|
|
|
if (gExpectedInstalls instanceof Array)
|
|
|
|
return gExpectedInstalls.shift();
|
|
|
|
if (!aAddon || !aAddon.id)
|
|
|
|
return gExpectedInstalls["NO_ID"].shift();
|
|
|
|
let id = aAddon.id;
|
|
|
|
if (!(id in gExpectedInstalls) || !(gExpectedInstalls[id] instanceof Array))
|
|
|
|
do_throw("Wasn't expecting events for " + id);
|
|
|
|
if (gExpectedInstalls[id].length == 0)
|
|
|
|
do_throw("Too many events for " + id);
|
|
|
|
return gExpectedInstalls[id].shift();
|
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
const AddonListener = {
|
2010-07-13 09:55:08 -07:00
|
|
|
onPropertyChanged: function(aAddon, aProperties) {
|
|
|
|
let [event, properties] = getExpectedEvent(aAddon.id);
|
|
|
|
do_check_eq("onPropertyChanged", event);
|
|
|
|
do_check_eq(aProperties.length, properties.length);
|
|
|
|
properties.forEach(function(aProperty) {
|
|
|
|
// Only test that the expected properties are listed, having additional
|
|
|
|
// properties listed is not necessary a problem
|
2010-09-13 23:56:54 -07:00
|
|
|
if (aProperties.indexOf(aProperty) == -1)
|
|
|
|
do_throw("Did not see property change for " + aProperty);
|
2010-07-13 09:55:08 -07:00
|
|
|
});
|
|
|
|
return check_test_completed(arguments);
|
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onEnabling: function(aAddon, aRequiresRestart) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onEnabling", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_eq(aRequiresRestart, expectedRestart);
|
2010-04-29 13:11:23 -07:00
|
|
|
if (expectedRestart)
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE));
|
|
|
|
do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onEnabled: function(aAddon) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onEnabled", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onDisabling: function(aAddon, aRequiresRestart) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onDisabling", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_eq(aRequiresRestart, expectedRestart);
|
2010-04-29 13:11:23 -07:00
|
|
|
if (expectedRestart)
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_DISABLE));
|
|
|
|
do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onDisabled: function(aAddon) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onDisabled", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onInstalling: function(aAddon, aRequiresRestart) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onInstalling", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_eq(aRequiresRestart, expectedRestart);
|
2010-04-29 13:11:23 -07:00
|
|
|
if (expectedRestart)
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_INSTALL));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onInstalled: function(aAddon) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onInstalled", event);
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onUninstalling: function(aAddon, aRequiresRestart) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onUninstalling", event);
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_eq(aRequiresRestart, expectedRestart);
|
2010-04-29 13:11:23 -07:00
|
|
|
if (expectedRestart)
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_UNINSTALL));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onUninstalled: function(aAddon) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onUninstalled", event);
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onOperationCancelled: function(aAddon) {
|
|
|
|
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq("onOperationCancelled", event);
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const InstallListener = {
|
|
|
|
onNewInstall: function(install) {
|
|
|
|
if (install.state != AddonManager.STATE_DOWNLOADED &&
|
|
|
|
install.state != AddonManager.STATE_AVAILABLE)
|
|
|
|
do_throw("Bad install state " + install.state);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onNewInstall", getExpectedInstall());
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadStarted: function(install) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_DOWNLOADING);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onDownloadStarted", getExpectedInstall());
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadEnded: function(install) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onDownloadEnded", getExpectedInstall());
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-06-10 16:39:47 -07:00
|
|
|
onDownloadFailed: function(install) {
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onDownloadFailed", getExpectedInstall());
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-04-07 11:16:10 -07:00
|
|
|
onDownloadCancelled: function(install) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_CANCELLED);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onDownloadCancelled", getExpectedInstall());
|
2010-04-07 11:16:10 -07:00
|
|
|
return check_test_completed(arguments);
|
|
|
|
},
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
onInstallStarted: function(install) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_INSTALLING);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onInstallStarted", getExpectedInstall(install.addon));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onInstallEnded: function(install, newAddon) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_INSTALLED);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onInstallEnded", getExpectedInstall(install.addon));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
},
|
|
|
|
|
2010-06-10 16:39:47 -07:00
|
|
|
onInstallFailed: function(install) {
|
2010-04-29 13:11:23 -07:00
|
|
|
do_check_eq(install.state, AddonManager.STATE_INSTALL_FAILED);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onInstallFailed", getExpectedInstall(install.addon));
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-28 11:46:00 -07:00
|
|
|
},
|
|
|
|
|
2010-04-07 11:16:10 -07:00
|
|
|
onInstallCancelled: function(install) {
|
|
|
|
do_check_eq(install.state, AddonManager.STATE_CANCELLED);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(install.error, 0);
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onInstallCancelled", getExpectedInstall(install.addon));
|
2010-04-07 11:16:10 -07:00
|
|
|
return check_test_completed(arguments);
|
|
|
|
},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
onExternalInstall: function(aAddon, existingAddon, aRequiresRestart) {
|
2010-09-07 15:07:49 -07:00
|
|
|
do_check_eq("onExternalInstall", getExpectedInstall(aAddon));
|
2010-04-28 09:42:07 -07:00
|
|
|
do_check_false(aRequiresRestart);
|
2010-04-05 10:25:23 -07:00
|
|
|
return check_test_completed(arguments);
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function hasFlag(aBits, aFlag) {
|
|
|
|
return (aBits & aFlag) != 0;
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Just a wrapper around setting the expected events
|
2010-04-28 09:42:07 -07:00
|
|
|
function prepare_test(aExpectedEvents, aExpectedInstalls, aNext) {
|
2010-04-29 13:11:23 -07:00
|
|
|
AddonManager.addAddonListener(AddonListener);
|
|
|
|
AddonManager.addInstallListener(InstallListener);
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
gExpectedInstalls = aExpectedInstalls;
|
|
|
|
gExpectedEvents = aExpectedEvents;
|
|
|
|
gNext = aNext;
|
2010-04-29 13:11:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 10:25:23 -07:00
|
|
|
// Checks if all expected events have been seen and if so calls the callback
|
2010-04-28 09:42:07 -07:00
|
|
|
function check_test_completed(aArgs) {
|
2010-04-05 10:25:23 -07:00
|
|
|
if (!gNext)
|
|
|
|
return;
|
|
|
|
|
2010-09-07 15:07:49 -07:00
|
|
|
if (gExpectedInstalls instanceof Array &&
|
|
|
|
gExpectedInstalls.length > 0)
|
2010-04-05 10:25:23 -07:00
|
|
|
return;
|
2010-09-07 15:07:49 -07:00
|
|
|
else for each (let installList in gExpectedInstalls) {
|
|
|
|
if (installList.length > 0)
|
|
|
|
return;
|
|
|
|
}
|
2010-04-05 10:25:23 -07:00
|
|
|
|
|
|
|
for (let id in gExpectedEvents) {
|
|
|
|
if (gExpectedEvents[id].length > 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
return gNext.apply(null, aArgs);
|
2010-04-05 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
// Verifies that all the expected events for all add-ons were seen
|
|
|
|
function ensure_test_completed() {
|
|
|
|
for (let i in gExpectedEvents) {
|
|
|
|
if (gExpectedEvents[i].length > 0)
|
|
|
|
do_throw("Didn't see all the expected events for " + i);
|
|
|
|
}
|
|
|
|
gExpectedEvents = {};
|
|
|
|
if (gExpectedInstalls)
|
|
|
|
do_check_eq(gExpectedInstalls.length, 0);
|
|
|
|
}
|
2010-04-08 12:28:10 -07:00
|
|
|
|
2010-04-28 11:49:56 -07:00
|
|
|
/**
|
|
|
|
* A helper method to install an array of AddonInstall to completion and then
|
|
|
|
* call a provided callback.
|
|
|
|
*
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aInstalls
|
2010-04-28 11:49:56 -07:00
|
|
|
* The array of AddonInstalls to install
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aCallback
|
2010-04-28 11:49:56 -07:00
|
|
|
* The callback to call when all installs have finished
|
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function completeAllInstalls(aInstalls, aCallback) {
|
|
|
|
let count = aInstalls.length;
|
|
|
|
|
2010-04-28 11:49:56 -07:00
|
|
|
if (count == 0) {
|
2010-04-28 09:42:07 -07:00
|
|
|
aCallback();
|
2010-04-28 11:49:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
function installCompleted(aInstall) {
|
|
|
|
aInstall.removeListener(listener);
|
2010-04-28 11:49:56 -07:00
|
|
|
|
|
|
|
if (--count == 0)
|
2010-04-28 09:42:07 -07:00
|
|
|
aCallback();
|
2010-04-28 11:49:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let listener = {
|
|
|
|
onDownloadFailed: installCompleted,
|
|
|
|
onDownloadCancelled: installCompleted,
|
|
|
|
onInstallFailed: installCompleted,
|
|
|
|
onInstallCancelled: installCompleted,
|
|
|
|
onInstallEnded: installCompleted
|
|
|
|
};
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
aInstalls.forEach(function(aInstall) {
|
|
|
|
aInstall.addListener(listener);
|
|
|
|
aInstall.install();
|
2010-04-28 11:49:56 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper method to install an array of files and call a callback after the
|
|
|
|
* installs are completed.
|
|
|
|
*
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aFiles
|
2010-04-28 11:49:56 -07:00
|
|
|
* The array of files to install
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aCallback
|
2010-04-28 11:49:56 -07:00
|
|
|
* The callback to call when all installs have finished
|
2010-04-28 09:42:07 -07:00
|
|
|
* @param aIgnoreIncompatible
|
2010-04-28 11:49:56 -07:00
|
|
|
* Optional parameter to ignore add-ons that are incompatible in
|
|
|
|
* aome way with the application
|
|
|
|
*/
|
2010-04-28 09:42:07 -07:00
|
|
|
function installAllFiles(aFiles, aCallback, aIgnoreIncompatible) {
|
|
|
|
let count = aFiles.length;
|
2010-04-28 11:49:56 -07:00
|
|
|
let installs = [];
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
aFiles.forEach(function(aFile) {
|
|
|
|
AddonManager.getInstallForFile(aFile, function(aInstall) {
|
|
|
|
if (!aInstall)
|
|
|
|
do_throw("No AddonInstall created for " + aFile.path);
|
2010-06-10 16:39:47 -07:00
|
|
|
do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED);
|
2010-04-28 11:49:56 -07:00
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
if (!aIgnoreIncompatible || !aInstall.addon.appDisabled)
|
|
|
|
installs.push(aInstall);
|
2010-04-28 11:49:56 -07:00
|
|
|
|
|
|
|
if (--count == 0)
|
2010-04-28 09:42:07 -07:00
|
|
|
completeAllInstalls(installs, aCallback);
|
2010-04-28 11:49:56 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-04-08 12:28:10 -07:00
|
|
|
if ("nsIWindowsRegKey" in AM_Ci) {
|
|
|
|
var MockRegistry = {
|
|
|
|
LOCAL_MACHINE: {},
|
|
|
|
CURRENT_USER: {},
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
setValue: function(aRoot, aPath, aName, aValue) {
|
|
|
|
switch (aRoot) {
|
2010-04-08 12:28:10 -07:00
|
|
|
case AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE:
|
|
|
|
var rootKey = MockRegistry.LOCAL_MACHINE;
|
|
|
|
break
|
|
|
|
case AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER:
|
|
|
|
rootKey = MockRegistry.CURRENT_USER;
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
if (!(aPath in rootKey)) {
|
|
|
|
rootKey[aPath] = [];
|
2010-04-08 12:28:10 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-04-28 09:42:07 -07:00
|
|
|
for (let i = 0; i < rootKey[aPath].length; i++) {
|
|
|
|
if (rootKey[aPath][i].name == aName) {
|
|
|
|
if (aValue === null)
|
|
|
|
rootKey[aPath].splice(i, 1);
|
2010-04-08 12:28:10 -07:00
|
|
|
else
|
2010-04-28 09:42:07 -07:00
|
|
|
rootKey[aPath][i].value = aValue;
|
2010-04-08 12:28:10 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
if (aValue === null)
|
2010-04-08 12:28:10 -07:00
|
|
|
return;
|
|
|
|
|
2010-04-28 09:42:07 -07:00
|
|
|
rootKey[aPath].push({
|
|
|
|
name: aName,
|
|
|
|
value: aValue
|
2010-04-08 12:28:10 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a mock nsIWindowsRegistry implementation. It only implements the
|
|
|
|
* methods that the extension manager requires.
|
|
|
|
*/
|
|
|
|
function MockWindowsRegKey() {
|
|
|
|
}
|
|
|
|
|
|
|
|
MockWindowsRegKey.prototype = {
|
|
|
|
values: null,
|
|
|
|
|
|
|
|
// --- Overridden nsISupports interface functions ---
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIWindowsRegKey]),
|
|
|
|
|
|
|
|
// --- Overridden nsIWindowsRegKey interface functions ---
|
|
|
|
open: function(aRootKey, aRelPath, aMode) {
|
|
|
|
switch (aRootKey) {
|
|
|
|
case AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE:
|
|
|
|
var rootKey = MockRegistry.LOCAL_MACHINE;
|
|
|
|
break
|
|
|
|
case AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER:
|
|
|
|
rootKey = MockRegistry.CURRENT_USER;
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(aRelPath in rootKey))
|
|
|
|
rootKey[aRelPath] = [];
|
|
|
|
this.values = rootKey[aRelPath];
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
this.values = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get valueCount() {
|
|
|
|
if (!this.values)
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
return this.values.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
getValueName: function(aIndex) {
|
|
|
|
if (!this.values || aIndex >= this.values.length)
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
return this.values[aIndex].name;
|
|
|
|
},
|
|
|
|
|
|
|
|
readStringValue: function(aName) {
|
|
|
|
for (let i = 0; i < this.values.length; i++) {
|
|
|
|
if (this.values[i].name == aName)
|
|
|
|
return this.values[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var WinRegFactory = {
|
|
|
|
createInstance: function(aOuter, aIid) {
|
|
|
|
if (aOuter != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
var key = new MockWindowsRegKey();
|
|
|
|
return key.QueryInterface(aIid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
|
|
|
|
registrar.registerFactory(Components.ID("{0478de5b-0f38-4edb-851d-4c99f1ed8eba}"),
|
|
|
|
"Mock Windows Registry Implementation",
|
|
|
|
"@mozilla.org/windows-registry-key;1", WinRegFactory);
|
|
|
|
}
|
|
|
|
|
2010-04-29 13:11:23 -07:00
|
|
|
// Get the profile directory for tests to use.
|
|
|
|
const gProfD = do_get_profile().QueryInterface(AM_Ci.nsILocalFile);
|
|
|
|
|
|
|
|
// Enable more extensive EM logging
|
|
|
|
Services.prefs.setBoolPref("extensions.logging.enabled", true);
|
|
|
|
|
2010-04-07 11:08:32 -07:00
|
|
|
// By default only load extensions from the profile install location
|
|
|
|
Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_PROFILE);
|
|
|
|
|
2010-08-23 18:04:06 -07:00
|
|
|
// By default, don't cache add-ons in AddonRepository.jsm
|
|
|
|
Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
|
|
|
|
|
2010-08-17 12:08:33 -07:00
|
|
|
// Disable the compatibility updates window by default
|
|
|
|
Services.prefs.setBoolPref("extensions.showMismatchUI", false);
|
|
|
|
|
2010-09-22 14:12:28 -07:00
|
|
|
// Point update checks to the local machine for fast failures
|
|
|
|
Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL");
|
|
|
|
Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL");
|
|
|
|
|
2011-01-19 14:37:24 -08:00
|
|
|
// By default ignore bundled add-ons
|
|
|
|
Services.prefs.setBoolPref("extensions.installDistroAddons", false);
|
|
|
|
|
2010-08-01 10:52:24 -07:00
|
|
|
// Register a temporary directory for the tests.
|
|
|
|
const gTmpD = gProfD.clone();
|
|
|
|
gTmpD.append("temp");
|
|
|
|
gTmpD.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
|
|
|
registerDirectory("TmpD", gTmpD);
|
|
|
|
|
|
|
|
do_register_cleanup(function() {
|
|
|
|
// Check that the temporary directory is empty
|
|
|
|
var dirEntries = gTmpD.directoryEntries
|
|
|
|
.QueryInterface(AM_Ci.nsIDirectoryEnumerator);
|
|
|
|
var entry;
|
|
|
|
while (entry = dirEntries.nextFile) {
|
|
|
|
do_throw("Found unexpected file in temporary directory: " + entry.leafName);
|
|
|
|
}
|
|
|
|
|
2010-10-20 11:03:27 -07:00
|
|
|
var testDir = gProfD.clone();
|
|
|
|
testDir.append("extensions");
|
|
|
|
testDir.append("trash");
|
|
|
|
do_check_false(testDir.exists());
|
|
|
|
|
|
|
|
testDir.leafName = "staged";
|
|
|
|
do_check_false(testDir.exists());
|
|
|
|
|
|
|
|
testDir.leafName = "staged-xpis";
|
|
|
|
do_check_false(testDir.exists());
|
|
|
|
|
2010-08-01 10:52:24 -07:00
|
|
|
shutdownManager();
|
|
|
|
});
|