2011-12-14 17:10:34 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2012-04-05 23:26:06 -07:00
|
|
|
Cu.import("resource://services-common/async.js");
|
2010-11-29 16:41:17 -08:00
|
|
|
|
2008-04-30 13:01:17 -07:00
|
|
|
let provider = {
|
|
|
|
getFile: function(prop, persistent) {
|
|
|
|
persistent.value = true;
|
2010-08-09 09:38:18 -07:00
|
|
|
switch (prop) {
|
|
|
|
case "ExtPrefDL":
|
2011-05-20 18:45:51 -07:00
|
|
|
return [Services.dirsvc.get("CurProcD", Ci.nsIFile)];
|
2010-08-09 09:38:18 -07:00
|
|
|
default:
|
|
|
|
throw Cr.NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-04-30 13:01:17 -07:00
|
|
|
},
|
2011-05-20 18:45:51 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider])
|
2008-06-16 16:42:32 -07:00
|
|
|
};
|
2011-05-20 18:45:51 -07:00
|
|
|
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
2008-06-16 16:42:32 -07:00
|
|
|
|
2011-12-14 17:10:34 -08:00
|
|
|
// This is needed for loadAddonTestFunctions().
|
|
|
|
let gGlobalScope = this;
|
|
|
|
|
|
|
|
function ExtensionsTestPath(path) {
|
|
|
|
if (path[0] != "/") {
|
|
|
|
throw Error("Path must begin with '/': " + path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "../../../../toolkit/mozapps/extensions/test/xpcshell" + path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the AddonManager test functions by importing its test file.
|
|
|
|
*
|
|
|
|
* This should be called in the global scope of any test file needing to
|
|
|
|
* interface with the AddonManager. It should only be called once, or the
|
|
|
|
* universe will end.
|
|
|
|
*/
|
|
|
|
function loadAddonTestFunctions() {
|
|
|
|
const path = ExtensionsTestPath("/head_addons.js");
|
|
|
|
let file = do_get_file(path);
|
|
|
|
let uri = Services.io.newFileURI(file);
|
|
|
|
Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
|
|
|
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAddonInstall(name) {
|
|
|
|
let f = do_get_file(ExtensionsTestPath("/addons/" + name + ".xpi"));
|
|
|
|
let cb = Async.makeSyncCallback();
|
|
|
|
AddonManager.getInstallForFile(f, cb);
|
|
|
|
|
|
|
|
return Async.waitForSyncCallback(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an addon from the add-on manager by id.
|
|
|
|
*
|
|
|
|
* This is merely a synchronous wrapper.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* ID of add-on to fetch
|
|
|
|
* @return addon object on success or undefined or null on failure
|
|
|
|
*/
|
|
|
|
function getAddonFromAddonManagerByID(id) {
|
|
|
|
let cb = Async.makeSyncCallback();
|
|
|
|
AddonManager.getAddonByID(id, cb);
|
|
|
|
return Async.waitForSyncCallback(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs an add-on synchronously from an addonInstall
|
|
|
|
*
|
|
|
|
* @param install addonInstall instance to install
|
|
|
|
*/
|
|
|
|
function installAddonFromInstall(install) {
|
|
|
|
let cb = Async.makeSyncCallback();
|
|
|
|
let listener = {onInstallEnded: cb};
|
|
|
|
AddonManager.addInstallListener(listener);
|
|
|
|
install.install();
|
|
|
|
Async.waitForSyncCallback(cb);
|
|
|
|
AddonManager.removeAddonListener(listener);
|
|
|
|
|
|
|
|
do_check_neq(null, install.addon);
|
|
|
|
do_check_neq(null, install.addon.syncGUID);
|
|
|
|
|
|
|
|
return install.addon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to install an add-on from the extensions unit tests.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* String name of add-on to install. e.g. test_install1
|
|
|
|
* @return addon object that was installed
|
|
|
|
*/
|
|
|
|
function installAddon(name) {
|
|
|
|
let install = getAddonInstall(name);
|
|
|
|
do_check_neq(null, install);
|
|
|
|
return installAddonFromInstall(install);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to uninstall an add-on synchronously.
|
|
|
|
*
|
|
|
|
* @param addon
|
|
|
|
* Addon instance to uninstall
|
|
|
|
*/
|
|
|
|
function uninstallAddon(addon) {
|
|
|
|
let cb = Async.makeSyncCallback();
|
|
|
|
let listener = {onUninstalled: function(uninstalled) {
|
|
|
|
if (uninstalled.id == addon.id) {
|
|
|
|
AddonManager.removeAddonListener(listener);
|
|
|
|
cb(uninstalled);
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
AddonManager.addAddonListener(listener);
|
|
|
|
addon.uninstall();
|
|
|
|
Async.waitForSyncCallback(cb);
|
|
|
|
}
|
|
|
|
|
2012-09-14 16:02:33 -07:00
|
|
|
function generateNewKeys(collectionKeys, collections=null) {
|
|
|
|
let wbo = collectionKeys.generateNewKeysWBO(collections);
|
2011-04-19 12:35:04 -07:00
|
|
|
let modified = new_timestamp();
|
2012-09-14 16:02:33 -07:00
|
|
|
collectionKeys.setContents(wbo.cleartext, modified);
|
2011-04-19 12:35:04 -07:00
|
|
|
}
|
|
|
|
|