michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: try { michael@0: // In the context of xpcshell tests, there won't be a default AppInfo michael@0: Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); michael@0: } michael@0: catch(ex) { michael@0: michael@0: // Make sure to provide the right OS so crypto loads the right binaries michael@0: let OS = "XPCShell"; michael@0: if ("@mozilla.org/windows-registry-key;1" in Cc) michael@0: OS = "WINNT"; michael@0: else if ("nsILocalFileMac" in Ci) michael@0: OS = "Darwin"; michael@0: else michael@0: OS = "Linux"; michael@0: michael@0: let XULAppInfo = { michael@0: vendor: "Mozilla", michael@0: name: "XPCShell", michael@0: ID: "{3e3ba16c-1675-4e88-b9c8-afef81b3d2ef}", michael@0: version: "1", michael@0: appBuildID: "20100621", michael@0: platformVersion: "", michael@0: platformBuildID: "20100621", michael@0: inSafeMode: false, michael@0: logConsoleErrors: true, michael@0: OS: OS, michael@0: XPCOMABI: "noarch-spidermonkey", michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]) michael@0: }; michael@0: michael@0: let XULAppInfoFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Cr.NS_ERROR_NO_AGGREGATION; michael@0: return XULAppInfo.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), michael@0: "XULAppInfo", "@mozilla.org/xre/app-info;1", michael@0: XULAppInfoFactory); michael@0: michael@0: } michael@0: michael@0: // Register resource alias. Normally done in SyncComponents.manifest. michael@0: function addResourceAlias() { michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: const resProt = Services.io.getProtocolHandler("resource") michael@0: .QueryInterface(Ci.nsIResProtocolHandler); michael@0: let uri = Services.io.newURI("resource://gre/modules/services-crypto/", michael@0: null, null); michael@0: resProt.setSubstitution("services-crypto", uri); michael@0: } michael@0: addResourceAlias(); michael@0: michael@0: /** michael@0: * Print some debug message to the console. All arguments will be printed, michael@0: * separated by spaces. michael@0: * michael@0: * @param [arg0, arg1, arg2, ...] michael@0: * Any number of arguments to print out michael@0: * @usage _("Hello World") -> prints "Hello World" michael@0: * @usage _(1, 2, 3) -> prints "1 2 3" michael@0: */ michael@0: let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));