|
1 const Cc = Components.classes; |
|
2 const Ci = Components.interfaces; |
|
3 const Cr = Components.results; |
|
4 const Cu = Components.utils; |
|
5 |
|
6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
7 |
|
8 try { |
|
9 // In the context of xpcshell tests, there won't be a default AppInfo |
|
10 Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); |
|
11 } |
|
12 catch(ex) { |
|
13 |
|
14 // Make sure to provide the right OS so crypto loads the right binaries |
|
15 let OS = "XPCShell"; |
|
16 if ("@mozilla.org/windows-registry-key;1" in Cc) |
|
17 OS = "WINNT"; |
|
18 else if ("nsILocalFileMac" in Ci) |
|
19 OS = "Darwin"; |
|
20 else |
|
21 OS = "Linux"; |
|
22 |
|
23 let XULAppInfo = { |
|
24 vendor: "Mozilla", |
|
25 name: "XPCShell", |
|
26 ID: "{3e3ba16c-1675-4e88-b9c8-afef81b3d2ef}", |
|
27 version: "1", |
|
28 appBuildID: "20100621", |
|
29 platformVersion: "", |
|
30 platformBuildID: "20100621", |
|
31 inSafeMode: false, |
|
32 logConsoleErrors: true, |
|
33 OS: OS, |
|
34 XPCOMABI: "noarch-spidermonkey", |
|
35 QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]) |
|
36 }; |
|
37 |
|
38 let XULAppInfoFactory = { |
|
39 createInstance: function (outer, iid) { |
|
40 if (outer != null) |
|
41 throw Cr.NS_ERROR_NO_AGGREGATION; |
|
42 return XULAppInfo.QueryInterface(iid); |
|
43 } |
|
44 }; |
|
45 |
|
46 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
|
47 registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), |
|
48 "XULAppInfo", "@mozilla.org/xre/app-info;1", |
|
49 XULAppInfoFactory); |
|
50 |
|
51 } |
|
52 |
|
53 // Register resource alias. Normally done in SyncComponents.manifest. |
|
54 function addResourceAlias() { |
|
55 Cu.import("resource://gre/modules/Services.jsm"); |
|
56 const resProt = Services.io.getProtocolHandler("resource") |
|
57 .QueryInterface(Ci.nsIResProtocolHandler); |
|
58 let uri = Services.io.newURI("resource://gre/modules/services-crypto/", |
|
59 null, null); |
|
60 resProt.setSubstitution("services-crypto", uri); |
|
61 } |
|
62 addResourceAlias(); |
|
63 |
|
64 /** |
|
65 * Print some debug message to the console. All arguments will be printed, |
|
66 * separated by spaces. |
|
67 * |
|
68 * @param [arg0, arg1, arg2, ...] |
|
69 * Any number of arguments to print out |
|
70 * @usage _("Hello World") -> prints "Hello World" |
|
71 * @usage _(1, 2, 3) -> prints "1 2 3" |
|
72 */ |
|
73 let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" ")); |