|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * This file tests the Services.jsm module. |
|
6 */ |
|
7 |
|
8 //////////////////////////////////////////////////////////////////////////////// |
|
9 /// Globals |
|
10 |
|
11 const Cc = Components.classes; |
|
12 const Ci = Components.interfaces; |
|
13 const Cu = Components.utils; |
|
14 const Cr = Components.results; |
|
15 |
|
16 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
17 Cu.import("resource://gre/modules/Services.jsm"); |
|
18 |
|
19 function checkService(service, interface) { |
|
20 do_print("Checking that Services." + service + " is an " + interface); |
|
21 do_check_true(service in Services); |
|
22 do_check_true(Services[service] instanceof interface); |
|
23 } |
|
24 |
|
25 //////////////////////////////////////////////////////////////////////////////// |
|
26 /// Tests |
|
27 |
|
28 function run_test() |
|
29 { |
|
30 do_get_profile(); |
|
31 |
|
32 checkService("appShell", Ci.nsIAppShellService); |
|
33 checkService("appinfo", Ci.nsIXULRuntime); |
|
34 checkService("blocklist", Ci.nsIBlocklistService); |
|
35 checkService("cache", Ci.nsICacheService); |
|
36 checkService("cache2", Ci.nsICacheStorageService); |
|
37 checkService("clipboard", Ci.nsIClipboard); |
|
38 checkService("console", Ci.nsIConsoleService); |
|
39 checkService("contentPrefs", Ci.nsIContentPrefService); |
|
40 checkService("cookies", Ci.nsICookieManager2); |
|
41 checkService("dirsvc", Ci.nsIDirectoryService); |
|
42 checkService("dirsvc", Ci.nsIProperties); |
|
43 checkService("DOMRequest", Ci.nsIDOMRequestService); |
|
44 checkService("domStorageManager", Ci.nsIDOMStorageManager); |
|
45 checkService("downloads", Ci.nsIDownloadManager); |
|
46 checkService("droppedLinkHandler", Ci.nsIDroppedLinkHandler); |
|
47 checkService("eTLD", Ci.nsIEffectiveTLDService); |
|
48 checkService("focus", Ci.nsIFocusManager); |
|
49 checkService("io", Ci.nsIIOService); |
|
50 checkService("io", Ci.nsIIOService2); |
|
51 checkService("locale", Ci.nsILocaleService); |
|
52 checkService("logins", Ci.nsILoginManager); |
|
53 checkService("obs", Ci.nsIObserverService); |
|
54 checkService("perms", Ci.nsIPermissionManager); |
|
55 checkService("prefs", Ci.nsIPrefBranch); |
|
56 checkService("prefs", Ci.nsIPrefService); |
|
57 checkService("prompt", Ci.nsIPromptService); |
|
58 checkService("scriptSecurityManager", Ci.nsIScriptSecurityManager); |
|
59 checkService("scriptloader", Ci.mozIJSSubScriptLoader); |
|
60 checkService("startup", Ci.nsIAppStartup); |
|
61 checkService("storage", Ci.mozIStorageService); |
|
62 checkService("strings", Ci.nsIStringBundleService); |
|
63 checkService("sysinfo", Ci.nsIPropertyBag2); |
|
64 checkService("telemetry", Ci.nsITelemetry); |
|
65 checkService("tm", Ci.nsIThreadManager); |
|
66 checkService("uriFixup", Ci.nsIURIFixup); |
|
67 checkService("urlFormatter", Ci.nsIURLFormatter); |
|
68 checkService("vc", Ci.nsIVersionComparator); |
|
69 checkService("wm", Ci.nsIWindowMediator); |
|
70 checkService("ww", Ci.nsIWindowWatcher); |
|
71 if ("nsIBrowserSearchService" in Ci) { |
|
72 checkService("search", Ci.nsIBrowserSearchService); |
|
73 } |
|
74 if ("nsIAndroidBridge" in Ci) { |
|
75 checkService("androidBridge", Ci.nsIAndroidBridge); |
|
76 } |
|
77 |
|
78 // In xpcshell tests, the "@mozilla.org/xre/app-info;1" component implements |
|
79 // only the nsIXULRuntime interface, but not nsIXULAppInfo. To test the |
|
80 // service getter for the latter interface, we define a minimal mock factory |
|
81 // that returns an object defining both interfaces. |
|
82 let contractID = "@mozilla.org/xre/app-info;1"; |
|
83 let mockFactory = { |
|
84 createInstance: function (aOuter, aIid) { |
|
85 return { |
|
86 QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULRuntime, |
|
87 Ci.nsIXULAppInfo]), |
|
88 }.QueryInterface(aIid); |
|
89 } |
|
90 }; |
|
91 |
|
92 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
|
93 let cid = registrar.contractIDToCID(contractID); |
|
94 let oldFactory = Components.manager.getClassObject(Cc[contractID], |
|
95 Ci.nsIFactory); |
|
96 registrar.unregisterFactory(cid, oldFactory); |
|
97 registrar.registerFactory(cid, "", contractID, mockFactory); |
|
98 |
|
99 // We need to reload the module to update the lazy getter. |
|
100 Cu.unload("resource://gre/modules/Services.jsm"); |
|
101 Cu.import("resource://gre/modules/Services.jsm"); |
|
102 |
|
103 checkService("appinfo", Ci.nsIXULAppInfo); |
|
104 |
|
105 // Clean up. |
|
106 registrar.unregisterFactory(cid, mockFactory); |
|
107 registrar.registerFactory(cid, "", contractID, oldFactory); |
|
108 |
|
109 Cu.unload("resource://gre/modules/Services.jsm"); |
|
110 } |