Bug 533038 - 7. Extensions should not be extracted into the profile directory, but installed/stored as XPI file, r=Mossop a=blocking-beta6

This commit is contained in:
Michael Wu 2010-09-10 15:54:37 -07:00
Родитель c5329c4084
Коммит 4c1f25099c
38 изменённых файлов: 553 добавлений и 600 удалений

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

@ -3236,6 +3236,7 @@ pref("browser.history.maxStateObjectSize", 655360);
// XPInstall prefs
pref("xpinstall.whitelist.required", true);
pref("extensions.alwaysUnpack", false);
pref("network.buffer.cache.count", 24);
pref("network.buffer.cache.size", 32768);

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

@ -71,6 +71,7 @@ const PREF_XPI_ENABLED = "xpinstall.enabled";
const PREF_XPI_WHITELIST_REQUIRED = "xpinstall.whitelist.required";
const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
const PREF_XPI_UNPACK = "extensions.alwaysUnpack";
const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts";
const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul";
@ -113,7 +114,7 @@ const REQ_VERSION = 2;
// Properties that exist in the install manifest
const PROP_METADATA = ["id", "version", "type", "internalName", "updateURL",
"updateKey", "optionsURL", "aboutURL", "iconURL",
"icon64URL"]
"icon64URL"];
const PROP_LOCALE_SINGLE = ["name", "description", "creator", "homepageURL"];
const PROP_LOCALE_MULTI = ["developers", "translators", "contributors"];
const PROP_TARGETAPP = ["id", "minVersion", "maxVersion"];
@ -163,7 +164,7 @@ var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\
* @return the selected locale or "en-US" if none is selected
*/
function getLocale() {
if (Prefs.getBoolPref(PREF_MATCH_OS_LOCALE), false)
if (Prefs.getBoolPref(PREF_MATCH_OS_LOCALE, false))
return Services.locale.getLocaleComponentForUserAgent();
return Prefs.getCharPref(PREF_SELECTED_LOCALE, "en-US");
}
@ -414,6 +415,7 @@ function loadManifestFromRDF(aUri, aStream) {
PROP_METADATA.forEach(function(aProp) {
addon[aProp] = getRDFProperty(ds, root, aProp);
});
addon.unpack = getRDFProperty(ds, root, "unpack") == "true";
if (!addon.type) {
addon.type = addon.internalName ? "theme" : "extension";
@ -1155,9 +1157,9 @@ var XPIProvider = {
}
for (let id in this.bootstrappedAddons) {
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dir.persistentDescriptor = this.bootstrappedAddons[id].descriptor;
this.callBootstrapMethod(id, this.bootstrappedAddons[id].version, dir,
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.persistentDescriptor = this.bootstrappedAddons[id].descriptor;
this.callBootstrapMethod(id, this.bootstrappedAddons[id].version, file,
"startup", BOOTSTRAP_REASONS.APP_STARTUP);
}
@ -1168,10 +1170,10 @@ var XPIProvider = {
Services.prefs.setCharPref(PREF_BOOTSTRAP_ADDONS,
JSON.stringify(XPIProvider.bootstrappedAddons));
for (let id in XPIProvider.bootstrappedAddons) {
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dir.persistentDescriptor = XPIProvider.bootstrappedAddons[id].descriptor;
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.persistentDescriptor = XPIProvider.bootstrappedAddons[id].descriptor;
XPIProvider.callBootstrapMethod(id, XPIProvider.bootstrappedAddons[id].version,
dir, "shutdown",
file, "shutdown",
BOOTSTRAP_REASONS.APP_SHUTDOWN);
}
Services.obs.removeObserver(this, "quit-application-granted");
@ -1287,17 +1289,17 @@ var XPIProvider = {
* @param location
* The install location to retrieve the add-on states for
* @return a dictionary mapping add-on IDs to objects with a descriptor
* property which contains the add-ons directory descriptor and an
* property which contains the add-ons dir/file descriptor and an
* mtime property which contains the add-on's last modified time as
* the number of milliseconds since the epoch.
*/
getAddonStates: function XPI_getAddonStates(aLocation) {
let addonStates = {};
aLocation.addonLocations.forEach(function(dir) {
let id = aLocation.getIDForLocation(dir);
aLocation.addonLocations.forEach(function(file) {
let id = aLocation.getIDForLocation(file);
addonStates[id] = {
descriptor: dir.persistentDescriptor,
mtime: dir.lastModifiedTime
descriptor: file.persistentDescriptor,
mtime: file.lastModifiedTime
};
});
@ -1356,37 +1358,44 @@ var XPIProvider = {
while (entries.hasMoreElements()) {
let stageDirEntry = entries.getNext().QueryInterface(Ci.nsILocalFile);
// Only directories are important. Files may be updated manifests.
let id = stageDirEntry.leafName;
if (!stageDirEntry.isDirectory()) {
WARN("Ignoring file: " + stageDirEntry.path);
continue;
if (id.substring(id.length - 4).toLowerCase() == ".xpi") {
id = id.substring(0, id.length - 4);
}
else {
if (id.substring(id.length - 5).toLowerCase() != ".json")
WARN("Ignoring file: " + stageDirEntry.path);
continue;
}
}
// Check that the directory's name is a valid ID.
let id = stageDirEntry.leafName;
if (!gIDTest.test(id)) {
WARN("Ignoring directory whose name is not a valid add-on ID: " +
stageDirEntry.path);
continue;
}
// Check if the directory contains an install manifest.
let manifest = stageDirEntry.clone();
manifest.append(FILE_INSTALL_MANIFEST);
if (stageDirEntry.isDirectory()) {
// Check if the directory contains an install manifest.
let manifest = stageDirEntry.clone();
manifest.append(FILE_INSTALL_MANIFEST);
// If the install manifest doesn't exist uninstall this add-on in this
// install location.
if (!manifest.exists()) {
LOG("Processing uninstall of " + id + " in " + aLocation.name);
aLocation.uninstallAddon(id);
// The file check later will spot the removal and cleanup the database
changed = true;
continue;
// If the install manifest doesn't exist uninstall this add-on in this
// install location.
if (!manifest.exists()) {
LOG("Processing uninstall of " + id + " in " + aLocation.name);
aLocation.uninstallAddon(id);
// The file check later will spot the removal and cleanup the database
changed = true;
continue;
}
}
LOG("Processing install of " + id + " in " + aLocation.name);
try {
var addonInstallDir = aLocation.installAddon(id, stageDirEntry);
var addonInstallLocation = aLocation.installAddon(id, stageDirEntry);
}
catch (e) {
ERROR("Failed to install staged add-on " + id + " in " + aLocation.name +
@ -1412,7 +1421,7 @@ var XPIProvider = {
fis.init(jsonfile, -1, 0, 0);
aManifests[aLocation.name][id] = json.decodeFromStream(fis,
jsonfile.fileSize);
aManifests[aLocation.name][id]._sourceBundle = addonInstallDir;
aManifests[aLocation.name][id]._sourceBundle = addonInstallLocation;
}
catch (e) {
ERROR("Unable to read add-on manifest for " + id + " in " +
@ -1477,10 +1486,13 @@ var XPIProvider = {
let newAddon = aManifests[aInstallLocation.name][aOldAddon.id];
try {
// If not load it from the directory
// If not load it
if (!newAddon) {
let dir = aInstallLocation.getLocationForID(aOldAddon.id);
newAddon = loadManifestFromDir(dir);
let file = aInstallLocation.getLocationForID(aOldAddon.id);
if (file.isFile())
newAddon = loadManifestFromZipFile(file);
else
newAddon = loadManifestFromDir(file);
}
// The ID in the manifest that was loaded must match the ID of the old
@ -1678,9 +1690,14 @@ var XPIProvider = {
let newAddon = aManifests[aInstallLocation.name][aId];
try {
// Otherwise load the manifest from the add-on's directory.
if (!newAddon)
newAddon = loadManifestFromDir(aInstallLocation.getLocationForID(aId));
// Otherwise load the manifest from the add-on
if (!newAddon) {
let file = aInstallLocation.getLocationForID(aId);
if (file.isFile())
newAddon = loadManifestFromZipFile(file);
else
newAddon = loadManifestFromDir(file);
}
// The add-on in the manifest should match the add-on ID.
if (newAddon.id != aId)
throw new Error("Incorrect id in install manifest");
@ -1744,9 +1761,9 @@ var XPIProvider = {
return true;
// Visible bootstrapped add-ons need to have their install method called
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dir.persistentDescriptor = aAddonState.descriptor;
XPIProvider.callBootstrapMethod(newAddon.id, newAddon.version, dir,
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.persistentDescriptor = aAddonState.descriptor;
XPIProvider.callBootstrapMethod(newAddon.id, newAddon.version, file,
"install",
BOOTSTRAP_REASONS.ADDON_INSTALL);
if (!newAddon.active)
@ -2393,18 +2410,18 @@ var XPIProvider = {
*
* @param aId
* The add-on's ID
* @param aDir
* The nsILocalFile for the directory containing the add-on
* @param aFile
* The nsILocalFile for the add-on
* @param aVersion
* The add-on's version
* @return a JavaScript scope
*/
loadBootstrapScope: function XPI_loadBootstrapScope(aId, aDir, aVersion) {
LOG("Loading bootstrap scope from " + aDir.path);
loadBootstrapScope: function XPI_loadBootstrapScope(aId, aFile, aVersion) {
LOG("Loading bootstrap scope from " + aFile.path);
// Mark the add-on as active for the crash reporter before loading
this.bootstrappedAddons[aId] = {
version: aVersion,
descriptor: aDir.persistentDescriptor
descriptor: aFile.persistentDescriptor
};
this.addAddonsToCrashReporter();
@ -2412,15 +2429,23 @@ var XPIProvider = {
createInstance(Ci.nsIPrincipal);
this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal);
let bootstrap = aDir.clone();
bootstrap.append("bootstrap.js");
if (bootstrap.exists()) {
let bootstrap = aFile.clone();
let name = aFile.leafName;
let spec;
if (bootstrap.isDirectory()) {
bootstrap.append("bootstrap.js");
let uri = Services.io.newFileURI(bootstrap);
spec = uri.spec;
} else {
spec = buildJarURI(bootstrap, "bootstrap.js").spec;
}
if (bootstrap.exists()) {
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
createInstance(Ci.mozIJSSubScriptLoader);
try {
loader.loadSubScript(uri.spec, this.bootstrapScopes[aId]);
loader.loadSubScript(spec, this.bootstrapScopes[aId]);
}
catch (e) {
WARN("Error loading bootstrap.js for " + aId + ": " + e);
@ -2455,18 +2480,18 @@ var XPIProvider = {
* The ID of the add-on
* @param aVersion
* The version of the add-on
* @param aDir
* The nsILocalFile for the directory containing the add-on
* @param aFile
* The nsILocalFile for the add-on
* @param aMethod
* The name of the bootstrap method to call
* @param aReason
* The reason flag to pass to the bootstrap's startup method
*/
callBootstrapMethod: function XPI_callBootstrapMethod(aId, aVersion, aDir,
callBootstrapMethod: function XPI_callBootstrapMethod(aId, aVersion, aFile,
aMethod, aReason) {
// Load the scope if it hasn't already been loaded
if (!(aId in this.bootstrapScopes))
this.loadBootstrapScope(aId, aDir, aVersion);
this.loadBootstrapScope(aId, aFile, aVersion);
if (!(aMethod in this.bootstrapScopes[aId])) {
WARN("Add-on " + aId + " is missing bootstrap method " + aMethod);
@ -2476,7 +2501,7 @@ var XPIProvider = {
let params = {
id: aId,
version: aVersion,
installPath: aDir.clone()
installPath: aFile.clone()
};
LOG("Calling bootstrap method " + aMethod + " on " + aId + " version " +
@ -2565,8 +2590,8 @@ var XPIProvider = {
XPIDatabase.updateAddonActive(aAddon);
if (isDisabled) {
if (aAddon.bootstrap) {
let dir = aAddon._installLocation.getLocationForID(aAddon.id);
this.callBootstrapMethod(aAddon.id, aAddon.version, dir, "shutdown",
let file = aAddon._installLocation.getLocationForID(aAddon.id);
this.callBootstrapMethod(aAddon.id, aAddon.version, file, "shutdown",
BOOTSTRAP_REASONS.ADDON_DISABLE);
this.unloadBootstrapScope(aAddon.id);
}
@ -2574,8 +2599,8 @@ var XPIProvider = {
}
else {
if (aAddon.bootstrap) {
let dir = aAddon._installLocation.getLocationForID(aAddon.id);
this.callBootstrapMethod(aAddon.id, aAddon.version, dir, "startup",
let file = aAddon._installLocation.getLocationForID(aAddon.id);
this.callBootstrapMethod(aAddon.id, aAddon.version, file, "startup",
BOOTSTRAP_REASONS.ADDON_ENABLE);
}
AddonManagerPrivate.callAddonListeners("onEnabled", wrapper);
@ -2631,12 +2656,12 @@ var XPIProvider = {
if (!requiresRestart) {
if (aAddon.bootstrap) {
let dir = aAddon._installLocation.getLocationForID(aAddon.id);
let file = aAddon._installLocation.getLocationForID(aAddon.id);
if (aAddon.active) {
this.callBootstrapMethod(aAddon.id, aAddon.version, dir, "shutdown",
this.callBootstrapMethod(aAddon.id, aAddon.version, file, "shutdown",
BOOTSTRAP_REASONS.ADDON_UNINSTALL);
}
this.callBootstrapMethod(aAddon.id, aAddon.version, dir, "uninstall",
this.callBootstrapMethod(aAddon.id, aAddon.version, file, "uninstall",
BOOTSTRAP_REASONS.ADDON_UNINSTALL);
this.unloadBootstrapScope(aAddon.id);
}
@ -3718,7 +3743,7 @@ var XPIDatabase = {
* @param aAddon
* AddonInternal to add
* @param aDescriptor
* The file descriptor of the add-on's directory
* The file descriptor of the add-on
*/
addAddonMetadata: function XPIDB_addAddonMetadata(aAddon, aDescriptor) {
this.beginTransaction();
@ -3813,7 +3838,7 @@ var XPIDatabase = {
* @param aNewAddon
* The new AddonInternal to add
* @param aDescriptor
* The file descriptor of the add-on's directory
* The file descriptor of the add-on
*/
updateAddonMetadata: function XPIDB_updateAddonMetadata(aOldAddon, aNewAddon,
aDescriptor) {
@ -4780,11 +4805,24 @@ AddonInstall.prototype = {
try {
// First stage the file regardless of whether restarting is necessary
let stagedJSON = stagedAddon.clone();
stagedAddon.append(this.addon.id);
if (stagedAddon.exists())
stagedAddon.remove(true);
stagedAddon.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
extractFiles(this.file, stagedAddon);
if (this.addon.unpack || Prefs.getBoolPref(PREF_XPI_UNPACK, false)) {
LOG("Addon " + this.addon.id + " will be installed as " +
"an unpacked directory");
stagedAddon.append(this.addon.id);
if (stagedAddon.exists())
stagedAddon.remove(true);
stagedAddon.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
extractFiles(this.file, stagedAddon);
}
else {
LOG("Addon " + this.addon.id + " will be installed as " +
"a packed xpi");
stagedAddon.append(this.addon.id + ".xpi");
if (stagedAddon.exists())
stagedAddon.remove(true);
this.file.copyTo(this.installLocation.getStagingDir(),
this.addon.id + ".xpi");
}
if (requiresRestart) {
// Point the add-on to its extracted files as the xpi may get deleted
@ -4838,16 +4876,16 @@ AddonInstall.prototype = {
reason = BOOTSTRAP_REASONS.ADDON_DOWNGRADE;
if (this.existingAddon.bootstrap) {
let dir = this.existingAddon._installLocation
.getLocationForID(this.existingAddon.id);
let file = this.existingAddon._installLocation
.getLocationForID(this.existingAddon.id);
if (this.existingAddon.active) {
XPIProvider.callBootstrapMethod(this.existingAddon.id,
this.existingAddon.version,
dir, "shutdown", reason);
file, "shutdown", reason);
}
XPIProvider.callBootstrapMethod(this.existingAddon.id,
this.existingAddon.version,
dir, "uninstall", reason);
file, "uninstall", reason);
XPIProvider.unloadBootstrapScope(this.existingAddon.id);
}
@ -4860,20 +4898,20 @@ AddonInstall.prototype = {
}
}
// Install the new add-on into its final directory
let dir = this.installLocation.installAddon(this.addon.id, stagedAddon);
// Install the new add-on into its final location
let file = this.installLocation.installAddon(this.addon.id, stagedAddon);
// Update the metadata in the database
this.addon._installLocation = this.installLocation;
this.addon.updateDate = dir.lastModifiedTime;
this.addon.updateDate = file.lastModifiedTime;
this.addon.visible = true;
if (isUpgrade) {
XPIDatabase.updateAddonMetadata(this.existingAddon, this.addon,
dir.persistentDescriptor);
file.persistentDescriptor);
}
else {
this.addon.installDate = this.addon.updateDate;
XPIDatabase.addAddonMetadata(this.addon, dir.persistentDescriptor);
XPIDatabase.addAddonMetadata(this.addon, file.persistentDescriptor);
}
// Retrieve the new DBAddonInternal for the add-on we just added
@ -4883,10 +4921,10 @@ AddonInstall.prototype = {
self.addon = a;
if (self.addon.bootstrap) {
XPIProvider.callBootstrapMethod(self.addon.id, self.addon.version,
dir, "install", reason);
file, "install", reason);
if (self.addon.active) {
XPIProvider.callBootstrapMethod(self.addon.id, self.addon.version,
dir, "startup", reason);
file, "startup", reason);
}
else {
XPIProvider.unloadBootstrapScope(self.addon.id);
@ -5792,8 +5830,8 @@ function DirectoryInstallLocation(aName, aDirectory, aScope, aLocked) {
this.locked = aLocked;
this._directory = aDirectory;
this._scope = aScope
this._IDToDirMap = {};
this._DirToIDMap = {};
this._IDToFileMap = {};
this._FileToIDMap = {};
if (!aDirectory.exists())
return;
@ -5806,8 +5844,8 @@ function DirectoryInstallLocation(aName, aDirectory, aScope, aLocked) {
DirectoryInstallLocation.prototype = {
_name : "",
_directory : null,
_IDToDirMap : null, // mapping from add-on ID to nsIFile directory
_DirToIDMap : null, // mapping from directory path to add-on ID
_IDToFileMap : null, // mapping from add-on ID to nsIFile
_FileToIDMap : null, // mapping from add-on path to add-on ID
/**
* Reads a directory linked to in a file.
@ -5877,22 +5915,20 @@ DirectoryInstallLocation.prototype = {
continue;
}
// XXX Bug 530188 requires us to clone this entry
entry = this._directory.clone().QueryInterface(Ci.nsILocalFile);
entry.append(id);
if (entry.isFile()) {
newEntry = this._readDirectoryFromFile(entry);
if (!newEntry)
continue;
entry = newEntry;
}
else if (!entry.isDirectory()) {
LOG("Ignoring entry which isn't a directory: " + entry.path);
continue;
if (id.substring(id.length - 4).toLowerCase() == ".xpi") {
id = id.substring(0, id.length - 4);
}
else {
newEntry = this._readDirectoryFromFile(entry);
if (!newEntry)
continue;
entry = newEntry;
}
}
this._IDToDirMap[id] = entry;
this._DirToIDMap[entry.path] = id;
this._IDToFileMap[id] = entry;
this._FileToIDMap[entry.path] = id;
}
entries.close();
},
@ -5916,8 +5952,8 @@ DirectoryInstallLocation.prototype = {
*/
get addonLocations() {
let locations = [];
for (let id in this._IDToDirMap) {
locations.push(this._IDToDirMap[id].clone()
for (let id in this._IDToFileMap) {
locations.push(this._IDToFileMap[id].clone()
.QueryInterface(Ci.nsILocalFile));
}
return locations;
@ -5936,26 +5972,36 @@ DirectoryInstallLocation.prototype = {
},
/**
* Installs an add-on from a directory into the install location.
* Installs an add-on into the install location.
*
* @param aId
* The ID of the add-on to install
* @param aSource
* The directory to install from
* The source nsIFile to install from
* @return an nsIFile indicating where the add-on was installed to
*/
installAddon: function DirInstallLocation_installAddon(aId, aSource) {
let dir = this._directory.clone().QueryInterface(Ci.nsILocalFile);
dir.append(aId);
if (dir.exists())
dir.remove(true);
let file = this._directory.clone().QueryInterface(Ci.nsILocalFile);
file.append(aId);
if (file.exists())
file.remove(true);
aSource = aSource.clone();
aSource.moveTo(this._directory, aId);
this._DirToIDMap[dir.path] = aId;
this._IDToDirMap[aId] = dir;
file = this._directory.clone().QueryInterface(Ci.nsILocalFile);
file.append(aId + ".xpi");
if (file.exists()) {
Services.obs.notifyObservers(file, "flush-cache-entry", null);
file.remove(true);
}
return dir;
aSource = aSource.clone().QueryInterface(Ci.nsILocalFile);
if (aSource.isFile())
Services.obs.notifyObservers(aSource, "flush-cache-entry", null);
aSource.moveTo(this._directory, aSource.leafName);
aSource.lastModifiedTime = Date.now();
this._FileToIDMap[aSource.path] = aId;
this._IDToFileMap[aId] = aSource;
return aSource;
},
/**
@ -5966,33 +6012,39 @@ DirectoryInstallLocation.prototype = {
* @throws if the ID does not match any of the add-ons installed
*/
uninstallAddon: function DirInstallLocation_uninstallAddon(aId) {
let dir = this._directory.clone();
dir.append(aId);
delete this._DirToIDMap[dir.path];
delete this._IDToDirMap[aId];
if (!dir.exists()) {
WARN("Attempted to remove the directory for " + aId + " from " +
let file = this._IDToFileMap[aId];
if (!file) {
WARN("Attempted to remove " + aId + " from " +
this._name + " but it was already gone");
return;
}
dir.remove(true);
delete this._FileToIDMap[file.path];
delete this._IDToFileMap[aId];
if (!file.exists()) {
WARN("Attempted to remove " + aId + " from " +
this._name + " but it was already gone");
return;
}
if (file.isFile())
Services.obs.notifyObservers(file, "flush-cache-entry", null);
file.remove(true);
},
/**
* Gets the ID of the add-on installed in the given directory.
* Gets the ID of the add-on installed in the given nsIFile.
*
* @param aDir
* The nsIFile directory to look in
* @param aFile
* The nsIFile to look in
* @return the ID
* @throws if the directory does not represent an installed add-on
* @throws if the file does not represent an installed add-on
*/
getIDForLocation: function DirInstallLocation_getIDForLocation(aDir) {
if (aDir.path in this._DirToIDMap)
return this._DirToIDMap[aDir.path];
throw new Error("Unknown add-on location " + aDir.path);
getIDForLocation: function DirInstallLocation_getIDForLocation(aFile) {
if (aFile.path in this._FileToIDMap)
return this._FileToIDMap[aFile.path];
throw new Error("Unknown add-on location " + aFile.path);
},
/**
@ -6000,12 +6052,12 @@ DirectoryInstallLocation.prototype = {
*
* @param aId
* The ID of the add-on
* @return the directory
* @return the nsILocalFile
* @throws if the ID does not match any of the add-ons installed
*/
getLocationForID: function DirInstallLocation_getLocationForID(aId) {
if (aId in this._IDToDirMap)
return this._IDToDirMap[aId].clone().QueryInterface(Ci.nsILocalFile);
if (aId in this._IDToFileMap)
return this._IDToFileMap[aId].clone().QueryInterface(Ci.nsILocalFile);
throw new Error("Unknown add-on ID " + aId);
}
};
@ -6014,7 +6066,7 @@ DirectoryInstallLocation.prototype = {
/**
* An object that identifies a registry install location for add-ons. The location
* consists of a registry key which contains string values mapping ID to the
* directory where an add-on is installed
* path where an add-on is installed
*
* @param aName
* The string identifier of this Install Location.
@ -6028,8 +6080,8 @@ function WinRegInstallLocation(aName, aRootKey, aScope) {
this._name = aName;
this._rootKey = aRootKey;
this._scope = aScope;
this._IDToDirMap = {};
this._DirToIDMap = {};
this._IDToFileMap = {};
this._FileToIDMap = {};
let path = this._appKeyPath + "\\Extensions";
let key = Cc["@mozilla.org/windows-registry-key;1"].
@ -6052,8 +6104,8 @@ WinRegInstallLocation.prototype = {
_name : "",
_rootKey : null,
_scope : null,
_IDToDirMap : null, // mapping from ID to directory object
_DirToIDMap : null, // mapping from directory path to ID
_IDToFileMap : null, // mapping from ID to nsIFile
_FileToIDMap : null, // mapping from path to ID
/**
* Retrieves the path of this Application's data key in the registry.
@ -6076,7 +6128,7 @@ WinRegInstallLocation.prototype = {
},
/**
* Read the registry and build a mapping between ID and directory for each
* Read the registry and build a mapping between ID and path for each
* installed add-on.
*
* @param key
@ -6087,17 +6139,15 @@ WinRegInstallLocation.prototype = {
for (let i = 0; i < count; ++i) {
let id = aKey.getValueName(i);
let dir = Cc["@mozilla.org/file/local;1"].
let file = Cc["@mozilla.org/file/local;1"].
createInstance(Ci.nsILocalFile);
dir.initWithPath(aKey.readStringValue(id));
file.initWithPath(aKey.readStringValue(id));
if (dir.exists() && dir.isDirectory()) {
this._IDToDirMap[id] = dir;
this._DirToIDMap[dir.path] = id;
}
else {
WARN("Ignoring missing add-on in " + dir.path);
}
if (!file.exists())
WARN("Ignoring missing add-on in " + file.path);
this._IDToFileMap[id] = file;
this._FileToIDMap[file.path] = id;
}
},
@ -6120,37 +6170,37 @@ WinRegInstallLocation.prototype = {
*/
get addonLocations() {
let locations = [];
for (let id in this._IDToDirMap) {
locations.push(this._IDToDirMap[id].clone()
for (let id in this._IDToFileMap) {
locations.push(this._IDToFileMap[id].clone()
.QueryInterface(Ci.nsILocalFile));
}
return locations;
},
/**
* Gets the ID of the add-on installed in the given directory.
* Gets the ID of the add-on installed in the given nsIFile.
*
* @param aFile
* The directory to look in
* The nsIFile to look in
* @return the ID
* @throws if the directory does not represent an installed add-on
* @throws if the file does not represent an installed add-on
*/
getIDForLocation: function RegInstallLocation_getIDForLocation(aFile) {
if (aFile.path in this._DirToIDMap)
return this._DirToIDMap[aFile.path];
if (aFile.path in this._FileToIDMap)
return this._FileToIDMap[aFile.path];
throw new Error("Unknown add-on location");
},
/**
* Gets the directory that the add-on with the given ID is installed in.
* Gets the nsIFile that the add-on with the given ID is installed in.
*
* @param aId
* The ID of the add-on
* @return the directory
* @return the nsIFile
*/
getLocationForID: function RegInstallLocation_getLocationForID(aId) {
if (aId in this._IDToDirMap)
return this._IDToDirMap[aId].clone().QueryInterface(Ci.nsILocalFile);
if (aId in this._IDToFileMap)
return this._IDToFileMap[aId].clone().QueryInterface(Ci.nsILocalFile);
throw new Error("Unknown add-on ID");
}
};

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

@ -58,6 +58,7 @@ endif
XPCSHELL_TESTS = \
xpcshell \
xpcshell-unpack \
$(NULL)
include $(topsrcdir)/config/rules.mk
@ -72,3 +73,5 @@ libs::
(cd $$dir && zip -r $(TESTXPI)/$$base.xpi *) \
done \
fi
cp -pPR $(TESTROOT)/xpcshell/. $(TESTROOT)/xpcshell-unpack

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

@ -0,0 +1 @@
Services.prefs.setBoolPref("extensions.alwaysUnpack", true);

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

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

@ -119,6 +119,31 @@ function do_get_addon(aName) {
return do_get_file("addons/" + aName + ".xpi");
}
/**
* 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";
}
/**
* Check that an array of actual add-ons is the same as an array of
* expected add-ons.
@ -361,8 +386,13 @@ function loadAddonsList() {
function isItemInAddonsList(aType, aDir, aId) {
var path = aDir.clone();
path.append(aId);
var xpiPath = aDir.clone();
xpiPath.append(aId + ".xpi");
for (var i = 0; i < gAddonsList[aType].length; i++) {
if (gAddonsList[aType][i].equals(path))
let file = gAddonsList[aType][i];
if (file.isDirectory() && file.equals(path))
return true;
if (file.isFile() && file.equals(xpiPath))
return true;
}
return false;
@ -408,19 +438,7 @@ function writeLocaleStrings(aData) {
return rdf;
}
/**
* 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
*/
function writeInstallRDFToDir(aData, aDir) {
function createInstallRDF(aData) {
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';
@ -466,7 +484,25 @@ function writeInstallRDFToDir(aData, aDir) {
}
rdf += "</Description>\n</RDF>\n";
return rdf;
}
/**
* 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);
if (!aDir.exists())
aDir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
var file = aDir.clone();
@ -480,6 +516,60 @@ function writeInstallRDFToDir(aData, aDir) {
FileUtils.PERMS_FILE, 0);
fos.write(rdf, rdf.length);
fos.close();
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;
}
function registerDirectory(aKey, aDir) {

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

@ -50,10 +50,7 @@ const REPOSITORY_UPDATEDATE = 9;
function get_subfile_uri(aId, aFilename) {
let file = gProfD.clone();
file.append("extensions");
file.append(aId);
if (aFilename)
file.append(aFilename);
return NetUtil.newURI(file).spec;
return do_get_addon_root_uri(file, aId) + aFilename;
}
@ -180,8 +177,10 @@ const WITHOUT_CACHE = [{
type: "theme",
name: "XPI Add-on 3",
version: "1.3",
iconURL: get_subfile_uri(ADDON_IDS[2], "icon.png"),
screenshots: [{ url: get_subfile_uri(ADDON_IDS[2], "preview.png") }],
get iconURL () {
return get_subfile_uri(ADDON_IDS[2], "icon.png");
},
screenshots: [{ get url () { return get_subfile_uri(ADDON_IDS[2], "preview.png"); } }],
sourceURI: NetUtil.newURI(ADDON_FILES[2]).spec
}];
@ -268,7 +267,9 @@ const WITH_CACHE = [{
type: "theme",
name: "XPI Add-on 3",
version: "1.3",
iconURL: get_subfile_uri(ADDON_IDS[2], "icon.png"),
get iconURL () {
return get_subfile_uri(ADDON_IDS[2], "icon.png");
},
screenshots: [{
url: BASE_URL + "/repo/3/firstFull.png",
thumbnailURL: BASE_URL + "/repo/3/firstThumbnail.png",

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

@ -98,11 +98,8 @@ function check_test_1() {
do_check_false(b1.hasResource("foo.bar"));
do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0");
let dir = profileDir.clone();
dir.append("bootstrap1@tests.mozilla.org");
dir.append("bootstrap.js");
let uri = Services.io.newFileURI(dir).spec;
do_check_eq(b1.getResourceURI("bootstrap.js").spec, uri);
let dir = do_get_addon_root_uri(profileDir, "bootstrap1@tests.mozilla.org");
do_check_eq(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js");
AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
do_check_eq(list.length, 0);

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

@ -65,8 +65,7 @@ function initTest()
// Install a test extension into the profile
let dir = gProfD.clone();
dir.append("extensions");
dir.append("test@mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "test@mozilla.org",
version: "1.0",
name: "Test extension",

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

@ -41,32 +41,29 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2.1a4", "2");
// inject the add-ons into the profile
var dest = gProfD.clone();
dest.append("extensions");
var profileDir = gProfD.clone();
profileDir.append("extensions");
var dest = profileDir.clone();
dest.append("bug470377_1@tests.mozilla.org");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
var source = do_get_file("data/test_bug470377/install_1.rdf");
source.copyTo(dest, "install.rdf");
dest = gProfD.clone();
dest.append("extensions");
dest = profileDir.clone();
dest.append("bug470377_2@tests.mozilla.org");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
source = do_get_file("data/test_bug470377/install_2.rdf");
source.copyTo(dest, "install.rdf");
dest = gProfD.clone();
dest.append("extensions");
dest = profileDir.clone();
dest.append("bug470377_3@tests.mozilla.org");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
source = do_get_file("data/test_bug470377/install_3.rdf");
source.copyTo(dest, "install.rdf");
dest = gProfD.clone();
dest.append("extensions");
dest = profileDir.clone();
dest.append("bug470377_4@tests.mozilla.org");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
source = do_get_file("data/test_bug470377/install_4.rdf");
source.copyTo(dest, "install.rdf");
dest = gProfD.clone();
dest.append("extensions");
dest = profileDir.clone();
dest.append("bug470377_5@tests.mozilla.org");
dest.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
source = do_get_file("data/test_bug470377/install_5.rdf");

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

@ -40,8 +40,6 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
const dataDir = do_get_file("data");
startupManager();
installAllFiles([do_get_file("data/test_bug526598_1.xpi"),

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

@ -205,9 +205,7 @@ function run_test() {
// Add an extension to the profile to make sure the dialog doesn't show up
// on new profiles
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
var dest = writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -216,7 +214,7 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
startupManager();

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

@ -11,9 +11,7 @@ profileDir.append("extensions");
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -23,7 +21,7 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
startupManager();

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

@ -13,9 +13,7 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
dest = profileDir.clone();
dest.append("default@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "default@tests.mozilla.org",
version: "1.0",
name: "Default",
@ -25,11 +23,9 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
var dest = profileDir.clone();
dest.append("alternate@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "alternate@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -40,7 +36,7 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
startupManager();

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

@ -12,9 +12,7 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "1.9.2");
dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
var dest = writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
name: "Test",
@ -23,7 +21,7 @@ function run_test() {
minVersion: "1",
maxVersion: "1"
}]
}, dest);
}, profileDir);
// Attempt to make this look like it was added some time in the past so
// the update makes the last modified time change.
dest.lastModifiedTime -= 5000;
@ -38,7 +36,7 @@ function run_test() {
do_check_false(a.isActive);
do_check_false(isExtensionInAddonsList(profileDir, a.id));
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "2.0",
name: "Test",
@ -47,7 +45,7 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
restartManager();

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

@ -27,9 +27,7 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
writeInstallRDFForExtension(addon1, profileDir);
startupManager();

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

@ -95,27 +95,13 @@ profileDir.append("extensions");
function run_test() {
do_test_pending();
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
dest = profileDir.clone();
dest.append("addon6@tests.mozilla.org");
writeInstallRDFToDir(addon6, dest);
dest = profileDir.clone();
dest.append("addon7@tests.mozilla.org");
writeInstallRDFToDir(addon7, dest);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
writeInstallRDFForExtension(addon5, profileDir);
writeInstallRDFForExtension(addon6, profileDir);
writeInstallRDFForExtension(addon7, profileDir);
startupManager();

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

@ -21,9 +21,7 @@ function run_test() {
testserver.registerDirectory("/addons/", do_get_file("addons"));
testserver.start(4444);
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_missing.rdf",
@ -33,7 +31,7 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
startupManager();

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

@ -34,9 +34,7 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
writeInstallRDFForExtension(addon1, profileDir);
startupManager();
@ -46,12 +44,10 @@ function run_test() {
shutdownManager();
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
writeInstallRDFForExtension(addon2, profileDir);
startupManager();

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

@ -64,9 +64,7 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2.2.3", "2");
ADDONS.forEach(function(a) {
let dest = profileDir.clone();
dest.append(a.id);
writeInstallRDFToDir(a, dest);
writeInstallRDFForExtension(a, profileDir);
});
startupManager();

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

@ -36,13 +36,8 @@ function run_test() {
do_check_eq(a1, null);
do_check_not_in_crash_annotation(addon1.id, addon1.version);
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
// Add a fake icon to the extension
dest.append("icon.png");
dest.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
gIconURL = NetUtil.newURI(dest);
writeInstallRDFForExtension(addon1, profileDir, addon1.id, "icon.png");
gIconURL = do_get_addon_root_uri(profileDir.clone(), addon1.id) + "icon.png";
restartManager();
@ -100,7 +95,7 @@ function run_test_1() {
do_check_true(newa1.userDisabled);
do_check_eq(newa1.aboutURL, null);
do_check_eq(newa1.optionsURL, null);
do_check_eq(newa1.iconURL, gIconURL.spec);
do_check_eq(newa1.iconURL, gIconURL);
do_check_false(isExtensionInAddonsList(profileDir, newa1.id));
do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
@ -125,7 +120,7 @@ function run_test_2() {
a1.userDisabled = false;
do_check_eq(a1.aboutURL, null);
do_check_eq(a1.optionsURL, null);
do_check_eq(a1.iconURL, gIconURL.spec);
do_check_eq(a1.iconURL, gIconURL);
do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE);

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

@ -37,9 +37,7 @@ function run_test() {
Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0");
Services.prefs.setBoolPref(PREF_EXTENSIONS_DSS_ENABLED, true);
var dest = profileDir.clone();
dest.append("theme1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme1@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -50,11 +48,9 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme2@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -64,13 +60,11 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
// We need a default theme for some of these things to work but we have hidden
// the one in the application directory.
dest = profileDir.clone();
dest.append("default@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "default@tests.mozilla.org",
version: "1.0",
name: "Default",
@ -80,7 +74,7 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
startupManager();
// Make sure we only register once despite multiple calls
@ -177,7 +171,7 @@ function check_test_1() {
// case since we don't have the default theme installed)
function run_test_2() {
var dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org"));
dest.remove(true);
restartManager();
@ -203,9 +197,7 @@ function run_test_2() {
// Installing a lightweight theme should happen instantly and disable the default theme
function run_test_3() {
var dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme2@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -215,7 +207,7 @@ function run_test_3() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
restartManager();
prepare_test({
@ -676,11 +668,9 @@ function check_test_11() {
restartManager();
AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
do_check_neq(t1, null);
var preview = profileDir.clone();
preview.append("theme1@tests.mozilla.org");
preview.append("preview.png");
var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png";
do_check_eq(t1.screenshots.length, 1);
do_check_eq(t1.screenshots[0], NetUtil.newURI(preview).spec);
do_check_eq(t1.screenshots[0], previewSpec);
do_check_false(gLWThemeChanged);
run_test_12();

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

@ -70,9 +70,7 @@ function run_test() {
const profileDir = gProfD.clone();
profileDir.append("extensions");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
name: "Test Addon",
@ -81,7 +79,7 @@ function run_test() {
minVersion: "1",
maxVersion: "1"
}],
}, dest);
}, profileDir);
startupManager();

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

@ -40,35 +40,27 @@ function run_test() {
let addonDir = gProfD.clone();
addonDir.append("extensions");
addonDir.append("addon1@tests.mozilla.org");
let rootUri = do_get_addon_root_uri(addonDir, "addon1@tests.mozilla.org");
let uri = a1.getResourceURI();
do_check_true(uri instanceof AM_Ci.nsIFileURL);
do_check_eq(uri.file.path, addonDir.path);
let uri = a1.getResourceURI("/");
do_check_eq(uri.spec, rootUri);
let file = addonDir.clone();
file.append("install.rdf");
let file = rootUri + "install.rdf";
do_check_true(a1.hasResource("install.rdf"));
uri = a1.getResourceURI("install.rdf")
do_check_true(uri instanceof AM_Ci.nsIFileURL);
do_check_eq(uri.file.path, file.path);
do_check_eq(uri.spec, file);
file = addonDir.clone();
file.append("icon.png");
file = rootUri + "icon.png";
do_check_true(a1.hasResource("icon.png"));
uri = a1.getResourceURI("icon.png")
do_check_true(uri instanceof AM_Ci.nsIFileURL);
do_check_eq(uri.file.path, file.path);
do_check_eq(uri.spec, file);
do_check_false(a1.hasResource("missing.txt"));
file = addonDir.clone();
file.append("subdir");
file.append("subfile.txt");
file = rootUri + "subdir/subfile.txt";
do_check_true(a1.hasResource("subdir/subfile.txt"));
uri = a1.getResourceURI("subdir/subfile.txt")
do_check_true(uri instanceof AM_Ci.nsIFileURL);
do_check_eq(uri.file.path, file.path);
do_check_eq(uri.spec, file);
do_check_false(a1.hasResource("subdir/missing.txt"));

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

@ -113,9 +113,25 @@ function check_test_1() {
AddonManager.getAddonsWithOperationsByTypes(null, function(pendingAddons) {
do_check_eq(pendingAddons.length, 1);
do_check_eq(pendingAddons[0].id, "addon1@tests.mozilla.org");
let iconFile = NetUtil.newURI(pendingAddons[0].iconURL)
.QueryInterface(AM_Ci.nsIFileURL).file;
do_check_true(iconFile.exists());
let uri = NetUtil.newURI(pendingAddons[0].iconURL);
if (uri instanceof AM_Ci.nsIJARURI) {
let jarURI = uri.QueryInterface(AM_Ci.nsIJARURI);
let archiveURI = jarURI.JARFile;
let archiveFile = archiveURI.QueryInterface(AM_Ci.nsIFileURL).file;
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
createInstance(Ci.nsIZipReader);
try {
zipReader.open(archiveFile);
do_check_true(zipReader.hasEntry(jarURI.JAREntry));
}
finally {
zipReader.close();
}
}
else {
let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file;
do_check_true(iconFile.exists());
}
restartManager();
@ -146,9 +162,7 @@ function check_test_1() {
do_check_true(a1.hasResource("install.rdf"));
do_check_false(a1.hasResource("foo.bar"));
let dir = profileDir.clone();
dir.append("addon1@tests.mozilla.org");
let uri = Services.io.newFileURI(dir).spec;
let uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");
do_check_eq(a1.getResourceURI("install.rdf").spec, uri + "install.rdf");
do_check_eq(a1.iconURL, uri + "icon.png");
do_check_eq(a1.icon64URL, uri + "icon64.png");

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

@ -11,9 +11,7 @@ function run_test() {
const profileDir = gProfD.clone();
profileDir.append("extensions");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
optionsURL: "chrome://test/content/options.xul",
@ -41,11 +39,9 @@ function run_test() {
"Test Contributor 1",
"Test Contributor 2"
]
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "1.0",
updateURL: "https://www.foo.com",
@ -55,11 +51,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 2"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon3@tests.mozilla.org",
version: "1.0",
updateURL: "http://www.foo.com",
@ -69,11 +63,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 3"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "1.0",
updateURL: "http://www.foo.com",
@ -84,11 +76,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 4"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon5@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -97,11 +87,9 @@ function run_test() {
maxVersion: "*"
}],
name: "Test Addon 5"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon6@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon6@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -110,11 +98,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 6"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon7@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon7@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -123,11 +109,9 @@ function run_test() {
maxVersion: "0"
}],
name: "Test Addon 7"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon8@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon8@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -136,11 +120,9 @@ function run_test() {
maxVersion: "*"
}],
name: "Test Addon 8"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon9@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon9@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -149,11 +131,9 @@ function run_test() {
maxVersion: "1.9.*"
}],
name: "Test Addon 9"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon10@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon10@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -162,11 +142,9 @@ function run_test() {
maxVersion: "1.9.*"
}],
name: "Test Addon 10"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon11@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon11@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -175,11 +153,9 @@ function run_test() {
maxVersion: "1.9.2"
}],
name: "Test Addon 11"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon12@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon12@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -188,11 +164,9 @@ function run_test() {
maxVersion: "1.9.1.*"
}],
name: "Test Addon 12"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon13@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon13@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -205,11 +179,9 @@ function run_test() {
maxVersion: "0.5"
}],
name: "Test Addon 13"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon14@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon14@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -222,11 +194,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 14"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon15@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon15@tests.mozilla.org",
version: "1.0",
updateKey: "foo",
@ -236,11 +206,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 15"
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon16@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon16@tests.mozilla.org",
version: "1.0",
updateKey: "foo",
@ -251,7 +219,7 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 16"
}, dest);
}, profileDir);
do_test_pending();
startupManager();

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

@ -92,27 +92,13 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
dest = profileDir.clone();
dest.append("theme1@tests.mozilla.org");
writeInstallRDFToDir(theme1, dest);
dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
writeInstallRDFToDir(theme2, dest);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
writeInstallRDFForExtension(addon5, profileDir);
writeInstallRDFForExtension(theme1, profileDir);
writeInstallRDFForExtension(theme2, profileDir);
let old = do_get_file("data/test_migrate.rdf");
old.copyTo(gProfD, "extensions.rdf");

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

@ -77,24 +77,12 @@ function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
dest = profileDir.clone();
dest.append("addon6@tests.mozilla.org");
writeInstallRDFToDir(addon6, dest);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
writeInstallRDFForExtension(addon5, profileDir);
writeInstallRDFForExtension(addon6, profileDir);
// Write out a minimal database
let dbfile = gProfD.clone();

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

@ -32,12 +32,8 @@ var addon2 = {
}]
};
const addon1Dir = gProfD.clone();
addon1Dir.append("addon1");
writeInstallRDFToDir(addon1, addon1Dir);
const addon2Dir = gProfD.clone();
addon2Dir.append("addon2");
writeInstallRDFToDir(addon2, addon2Dir);
const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1");
const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2");
function run_test() {
// This test only works where there is a registry.
@ -141,7 +137,7 @@ function run_test_4() {
MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"SOFTWARE\\Mozilla\\XPCShell\\Extensions",
"addon2@tests.mozilla.org", addon1Dir.path);
writeInstallRDFToDir(addon2, addon1Dir);
writeInstallRDFForExtension(addon2, gProfD, "addon1");
restartManager();

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

@ -116,24 +116,14 @@ function end_test() {
// Try to install all the items into the profile
function run_test_1() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
writeInstallRDFForExtension(addon1, profileDir);
var dest = writeInstallRDFForExtension(addon2, profileDir);
// Attempt to make this look like it was added some time in the past so
// the change in run_test_2 makes the last modified time change.
dest.lastModifiedTime -= 5000;
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
writeInstallRDFForExtension(addon5, profileDir);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
@ -179,13 +169,13 @@ function run_test_1() {
do_check_eq(a4, null);
do_check_false(isExtensionInAddonsList(profileDir, "addon4@tests.mozilla.org"));
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
do_check_false(dest.exists());
do_check_eq(a5, null);
do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon5@tests.mozilla.org"));
do_check_false(dest.exists());
AddonManager.getAddonsByTypes(["extension"], function(extensionAddons) {
@ -199,24 +189,16 @@ function run_test_1() {
// Test that modified items are detected and items in other install locations
// are ignored
function run_test_2() {
var dest = userDir.clone();
dest.append("addon1@tests.mozilla.org");
addon1.version = "1.1";
writeInstallRDFToDir(addon1, dest);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFForExtension(addon1, userDir);
addon2.version="2.1";
writeInstallRDFToDir(addon2, dest);
dest = globalDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFForExtension(addon2, profileDir);
addon2.version="2.2";
writeInstallRDFToDir(addon2, dest);
dest = userDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFForExtension(addon2, globalDir);
addon2.version="2.3";
writeInstallRDFToDir(addon2, dest);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFForExtension(addon2, userDir);
var dest = profileDir.clone();
dest.append(do_get_expected_addon_name("addon3@tests.mozilla.org"));
dest.remove(true);
restartManager();
@ -266,14 +248,12 @@ function run_test_2() {
// Check that removing items from the profile reveals their hidden versions.
function run_test_3() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
writeInstallRDFForExtension(addon3, profileDir, "addon4@tests.mozilla.org");
restartManager();
@ -315,7 +295,7 @@ function run_test_3() {
do_check_false(isExtensionInAddonsList(profileDir, "addon5@tests.mozilla.org"));
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
do_check_false(dest.exists());
run_test_4();
@ -432,12 +412,10 @@ function run_test_6() {
// Check that items in the profile hide the others again.
function run_test_7() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
addon1.version = "1.2";
writeInstallRDFToDir(addon1, dest);
dest = userDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFForExtension(addon1, profileDir);
var dest = userDir.clone();
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
restartManager();
@ -520,15 +498,13 @@ function run_test_9() {
Services.prefs.clearUserPref("extensions.enabledScopes", 0);
var dest = userDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = globalDir.clone();
dest.append("addon2@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
addon2.version = "2.4";
writeInstallRDFToDir(addon2, dest);
writeInstallRDFForExtension(addon2, profileDir);
restartManager();
@ -575,12 +551,10 @@ function run_test_9() {
// for the same item is handled
function run_test_10() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = userDir.clone();
dest.append("addon1@tests.mozilla.org");
addon1.version = "1.3";
writeInstallRDFToDir(addon1, dest);
writeInstallRDFForExtension(addon1, userDir);
restartManager();
@ -626,10 +600,10 @@ function run_test_10() {
// This should remove any remaining items
function run_test_11() {
var dest = userDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
dest.remove(true);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon2@tests.mozilla.org"));
dest.remove(true);
restartManager();

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

@ -92,21 +92,11 @@ profileDir.append("extensions");
function run_test() {
do_test_pending();
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
var dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir(addon2, dest);
var dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir(addon3, dest);
var dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir(addon4, dest);
var dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir(addon5, dest);
writeInstallRDFForExtension(addon1, profileDir);
writeInstallRDFForExtension(addon2, profileDir);
writeInstallRDFForExtension(addon3, profileDir);
writeInstallRDFForExtension(addon4, profileDir);
writeInstallRDFForExtension(addon5, profileDir);
restartManager();
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",

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

@ -39,9 +39,7 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0");
var dest = profileDir.clone();
dest.append("theme1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme1@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -53,11 +51,9 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme2@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -68,13 +64,11 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
// We need a default theme for some of these things to work but we have hidden
// the one in the application directory.
dest = profileDir.clone();
dest.append("default@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "default@tests.mozilla.org",
version: "1.0",
name: "Default",
@ -84,7 +78,7 @@ function run_test() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
startupManager();
// Make sure we only register once despite multiple calls
@ -192,7 +186,7 @@ function check_test_1() {
// case since we don't have the default theme installed)
function run_test_2() {
var dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org"));
dest.remove(true);
restartManager();
@ -218,9 +212,7 @@ function run_test_2() {
// Installing a lightweight theme should happen instantly and disable the default theme
function run_test_3() {
var dest = profileDir.clone();
dest.append("theme2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "theme2@tests.mozilla.org",
version: "1.0",
name: "Test 1",
@ -230,7 +222,7 @@ function run_test_3() {
minVersion: "1",
maxVersion: "2"
}]
}, dest);
}, profileDir);
restartManager();
prepare_test({
@ -697,11 +689,9 @@ function run_test_11() {
function check_test_11() {
AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
do_check_neq(t1, null);
var preview = profileDir.clone();
preview.append("theme1@tests.mozilla.org");
preview.append("preview.png");
var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png";
do_check_eq(t1.screenshots.length, 1);
do_check_eq(t1.screenshots[0], NetUtil.newURI(preview).spec);
do_check_eq(t1.screenshots[0], previewSpec);
do_check_true(t1.skinnable);
do_check_false(gLWThemeChanged);

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

@ -28,9 +28,7 @@ function run_test() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(olda1) {
do_check_eq(olda1, null);
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir(addon1, dest);
writeInstallRDFForExtension(addon1, profileDir);
restartManager();
@ -86,9 +84,9 @@ function check_test_1() {
do_check_not_in_crash_annotation(addon1.id, addon1.version);
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
do_check_false(dest.exists());
writeInstallRDFToDir(addon1, dest);
writeInstallRDFForExtension(addon1, profileDir);
restartManager();
run_test_2();

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

@ -32,9 +32,7 @@ function run_test() {
testserver.registerDirectory("/addons/", do_get_file("addons"));
testserver.start(4444);
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -44,11 +42,9 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -58,11 +54,9 @@ function run_test() {
maxVersion: "0"
}],
name: "Test Addon 2",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon3@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -72,7 +66,7 @@ function run_test() {
maxVersion: "5"
}],
name: "Test Addon 3",
}, dest);
}, profileDir);
startupManager();
@ -313,9 +307,7 @@ function check_test_5() {
// Test that background update checks work
function run_test_6() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -325,7 +317,7 @@ function run_test_6() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
restartManager();
prepare_test({}, [
@ -457,9 +449,7 @@ function check_test_7() {
// Verify the parameter escaping in update urls.
function run_test_8() {
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "5.0",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -469,11 +459,9 @@ function run_test_8() {
maxVersion: "2"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "67.0.5b1",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -483,11 +471,9 @@ function run_test_8() {
maxVersion: "3"
}],
name: "Test Addon 2",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon3@tests.mozilla.org",
version: "1.3+",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -501,11 +487,9 @@ function run_test_8() {
maxVersion: "3"
}],
name: "Test Addon 3",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "0.5ab6",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -515,11 +499,9 @@ function run_test_8() {
maxVersion: "5"
}],
name: "Test Addon 4",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon5@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon5@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -529,11 +511,9 @@ function run_test_8() {
maxVersion: "1"
}],
name: "Test Addon 5",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon6@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon6@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/param_test.rdf" + PARAMS,
@ -543,7 +523,7 @@ function run_test_8() {
maxVersion: "1"
}],
name: "Test Addon 6",
}, dest);
}, profileDir);
restartManager();
@ -669,9 +649,7 @@ function run_test_8() {
// Tests that if an install.rdf claims compatibility then the add-on will be
// seen as compatible regardless of what the update.rdf says.
function run_test_9() {
var dest = profileDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "5.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -681,7 +659,7 @@ function run_test_9() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
restartManager();
@ -741,9 +719,7 @@ function run_test_12() {
// version of the app that the caller requested an update check for.
function run_test_13() {
// Not initially compatible but the update check will make it compatible
dest = profileDir.clone();
dest.append("addon7@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon7@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -753,7 +729,7 @@ function run_test_13() {
maxVersion: "0"
}],
name: "Test Addon 7",
}, dest);
}, profileDir);
restartManager();
AddonManager.getAddonByID("addon7@tests.mozilla.org", function(a7) {
@ -800,9 +776,7 @@ function check_test_13() {
// allowed to update automatically.
function run_test_14() {
// Have an add-on there that will be updated so we see some events from it
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -812,11 +786,9 @@ function run_test_14() {
maxVersion: "1"
}],
name: "Test Addon 1",
}, dest);
}, profileDir);
dest = profileDir.clone();
dest.append("addon8@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon8@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
@ -826,7 +798,7 @@ function run_test_14() {
maxVersion: "1"
}],
name: "Test Addon 8",
}, dest);
}, profileDir);
restartManager();
AddonManager.getAddonByID("addon8@tests.mozilla.org", function(a8) {

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

@ -22,9 +22,7 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
// Will be enabled in the first version and disabled in subsequent versions
var dest = profileDir.clone();
dest.append("addon1@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon1@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -37,12 +35,10 @@ function run_test() {
"XPCShell",
"WINNT_x86",
]
}, dest);
}, profileDir);
// Works in all tested versions
dest = profileDir.clone();
dest.append("addon2@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon2@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -54,12 +50,10 @@ function run_test() {
targetPlatforms: [
"XPCShell_noarch-spidermonkey"
]
}, dest);
}, profileDir);
// Will be disabled in the first version and enabled in the second.
dest = profileDir.clone();
dest.append("addon3@tests.mozilla.org");
writeInstallRDFToDir({
writeInstallRDFForExtension({
id: "addon3@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -68,12 +62,10 @@ function run_test() {
maxVersion: "2"
}],
name: "Test Addon 3",
}, dest);
}, profileDir);
// Will be enabled in both versions but will change version in between
dest = globalDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
var dest = writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "1.0",
targetApplications: [{
@ -82,7 +74,7 @@ function run_test() {
maxVersion: "1"
}],
name: "Test Addon 4",
}, dest);
}, globalDir);
dest.lastModifiedTime = gInstallTime;
do_test_pending();
@ -95,7 +87,7 @@ function end_test() {
globalDir.remove(true);
}
else {
globalDir.append("addon4@tests.mozilla.org");
globalDir.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
globalDir.remove(true);
}
do_test_finished();
@ -131,9 +123,7 @@ function run_test_1() {
// Test that upgrading the application disables now incompatible add-ons
function run_test_2() {
// Upgrade the extension
dest = globalDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
var dest = writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "2.0",
targetApplications: [{
@ -142,7 +132,7 @@ function run_test_2() {
maxVersion: "2"
}],
name: "Test Addon 4",
}, dest);
}, globalDir);
dest.lastModifiedTime = gInstallTime;
restartManager("2");
@ -172,9 +162,7 @@ function run_test_2() {
// Test that nothing changes when only the build ID changes.
function run_test_3() {
// Upgrade the extension
dest = globalDir.clone();
dest.append("addon4@tests.mozilla.org");
writeInstallRDFToDir({
var dest = writeInstallRDFForExtension({
id: "addon4@tests.mozilla.org",
version: "3.0",
targetApplications: [{
@ -183,7 +171,7 @@ function run_test_3() {
maxVersion: "3"
}],
name: "Test Addon 4",
}, dest);
}, globalDir);
dest.lastModifiedTime = gInstallTime;
// Simulates a simple Build ID change, the platform deletes extensions.ini

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

@ -49,6 +49,7 @@
#include "nsILocalFile.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIProfileChangeStatus.h"
#include "nsISimpleEnumerator.h"
#include "nsIToolkitChromeRegistry.h"
@ -507,6 +508,8 @@ LoadExtensionDirectories(nsINIParser &parser,
{
nsresult rv;
PRInt32 i = 0;
nsCOMPtr<nsIPrefServiceInternal> prefs =
do_GetService("@mozilla.org/preferences-service;1");
do {
nsCAutoString buf("Extension");
buf.AppendInt(i++);
@ -524,11 +527,19 @@ LoadExtensionDirectories(nsINIParser &parser,
if (NS_FAILED(rv))
continue;
aDirectories.AppendObject(dir);
if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_CSTRING(".xpi"))) {
XRE_AddJarManifestLocation(aType, dir);
if (!prefs)
continue;
prefs->ReadExtensionPrefs(dir);
}
else {
aDirectories.AppendObject(dir);
nsCOMPtr<nsILocalFile> manifest =
CloneAndAppend(dir, "chrome.manifest");
XRE_AddManifestLocation(aType, manifest);
nsCOMPtr<nsILocalFile> manifest =
CloneAndAppend(dir, "chrome.manifest");
XRE_AddManifestLocation(aType, manifest);
}
}
while (PR_TRUE);
}