1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/crypto/tests/unit/head_helpers.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +const Cc = Components.classes; 1.5 +const Ci = Components.interfaces; 1.6 +const Cr = Components.results; 1.7 +const Cu = Components.utils; 1.8 + 1.9 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.10 + 1.11 +try { 1.12 + // In the context of xpcshell tests, there won't be a default AppInfo 1.13 + Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); 1.14 +} 1.15 +catch(ex) { 1.16 + 1.17 +// Make sure to provide the right OS so crypto loads the right binaries 1.18 +let OS = "XPCShell"; 1.19 +if ("@mozilla.org/windows-registry-key;1" in Cc) 1.20 + OS = "WINNT"; 1.21 +else if ("nsILocalFileMac" in Ci) 1.22 + OS = "Darwin"; 1.23 +else 1.24 + OS = "Linux"; 1.25 + 1.26 +let XULAppInfo = { 1.27 + vendor: "Mozilla", 1.28 + name: "XPCShell", 1.29 + ID: "{3e3ba16c-1675-4e88-b9c8-afef81b3d2ef}", 1.30 + version: "1", 1.31 + appBuildID: "20100621", 1.32 + platformVersion: "", 1.33 + platformBuildID: "20100621", 1.34 + inSafeMode: false, 1.35 + logConsoleErrors: true, 1.36 + OS: OS, 1.37 + XPCOMABI: "noarch-spidermonkey", 1.38 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]) 1.39 +}; 1.40 + 1.41 +let XULAppInfoFactory = { 1.42 + createInstance: function (outer, iid) { 1.43 + if (outer != null) 1.44 + throw Cr.NS_ERROR_NO_AGGREGATION; 1.45 + return XULAppInfo.QueryInterface(iid); 1.46 + } 1.47 +}; 1.48 + 1.49 +let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.50 +registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), 1.51 + "XULAppInfo", "@mozilla.org/xre/app-info;1", 1.52 + XULAppInfoFactory); 1.53 + 1.54 +} 1.55 + 1.56 +// Register resource alias. Normally done in SyncComponents.manifest. 1.57 +function addResourceAlias() { 1.58 + Cu.import("resource://gre/modules/Services.jsm"); 1.59 + const resProt = Services.io.getProtocolHandler("resource") 1.60 + .QueryInterface(Ci.nsIResProtocolHandler); 1.61 + let uri = Services.io.newURI("resource://gre/modules/services-crypto/", 1.62 + null, null); 1.63 + resProt.setSubstitution("services-crypto", uri); 1.64 +} 1.65 +addResourceAlias(); 1.66 + 1.67 +/** 1.68 + * Print some debug message to the console. All arguments will be printed, 1.69 + * separated by spaces. 1.70 + * 1.71 + * @param [arg0, arg1, arg2, ...] 1.72 + * Any number of arguments to print out 1.73 + * @usage _("Hello World") -> prints "Hello World" 1.74 + * @usage _(1, 2, 3) -> prints "1 2 3" 1.75 + */ 1.76 +let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));