michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * This file tests the Services.jsm module. michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// Globals michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: const Cr = Components.results; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function checkService(service, interface) { michael@0: do_print("Checking that Services." + service + " is an " + interface); michael@0: do_check_true(service in Services); michael@0: do_check_true(Services[service] instanceof interface); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// Tests michael@0: michael@0: function run_test() michael@0: { michael@0: do_get_profile(); michael@0: michael@0: checkService("appShell", Ci.nsIAppShellService); michael@0: checkService("appinfo", Ci.nsIXULRuntime); michael@0: checkService("blocklist", Ci.nsIBlocklistService); michael@0: checkService("cache", Ci.nsICacheService); michael@0: checkService("cache2", Ci.nsICacheStorageService); michael@0: checkService("clipboard", Ci.nsIClipboard); michael@0: checkService("console", Ci.nsIConsoleService); michael@0: checkService("contentPrefs", Ci.nsIContentPrefService); michael@0: checkService("cookies", Ci.nsICookieManager2); michael@0: checkService("dirsvc", Ci.nsIDirectoryService); michael@0: checkService("dirsvc", Ci.nsIProperties); michael@0: checkService("DOMRequest", Ci.nsIDOMRequestService); michael@0: checkService("domStorageManager", Ci.nsIDOMStorageManager); michael@0: checkService("downloads", Ci.nsIDownloadManager); michael@0: checkService("droppedLinkHandler", Ci.nsIDroppedLinkHandler); michael@0: checkService("eTLD", Ci.nsIEffectiveTLDService); michael@0: checkService("focus", Ci.nsIFocusManager); michael@0: checkService("io", Ci.nsIIOService); michael@0: checkService("io", Ci.nsIIOService2); michael@0: checkService("locale", Ci.nsILocaleService); michael@0: checkService("logins", Ci.nsILoginManager); michael@0: checkService("obs", Ci.nsIObserverService); michael@0: checkService("perms", Ci.nsIPermissionManager); michael@0: checkService("prefs", Ci.nsIPrefBranch); michael@0: checkService("prefs", Ci.nsIPrefService); michael@0: checkService("prompt", Ci.nsIPromptService); michael@0: checkService("scriptSecurityManager", Ci.nsIScriptSecurityManager); michael@0: checkService("scriptloader", Ci.mozIJSSubScriptLoader); michael@0: checkService("startup", Ci.nsIAppStartup); michael@0: checkService("storage", Ci.mozIStorageService); michael@0: checkService("strings", Ci.nsIStringBundleService); michael@0: checkService("sysinfo", Ci.nsIPropertyBag2); michael@0: checkService("telemetry", Ci.nsITelemetry); michael@0: checkService("tm", Ci.nsIThreadManager); michael@0: checkService("uriFixup", Ci.nsIURIFixup); michael@0: checkService("urlFormatter", Ci.nsIURLFormatter); michael@0: checkService("vc", Ci.nsIVersionComparator); michael@0: checkService("wm", Ci.nsIWindowMediator); michael@0: checkService("ww", Ci.nsIWindowWatcher); michael@0: if ("nsIBrowserSearchService" in Ci) { michael@0: checkService("search", Ci.nsIBrowserSearchService); michael@0: } michael@0: if ("nsIAndroidBridge" in Ci) { michael@0: checkService("androidBridge", Ci.nsIAndroidBridge); michael@0: } michael@0: michael@0: // In xpcshell tests, the "@mozilla.org/xre/app-info;1" component implements michael@0: // only the nsIXULRuntime interface, but not nsIXULAppInfo. To test the michael@0: // service getter for the latter interface, we define a minimal mock factory michael@0: // that returns an object defining both interfaces. michael@0: let contractID = "@mozilla.org/xre/app-info;1"; michael@0: let mockFactory = { michael@0: createInstance: function (aOuter, aIid) { michael@0: return { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULRuntime, michael@0: Ci.nsIXULAppInfo]), michael@0: }.QueryInterface(aIid); michael@0: } michael@0: }; michael@0: michael@0: let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: let cid = registrar.contractIDToCID(contractID); michael@0: let oldFactory = Components.manager.getClassObject(Cc[contractID], michael@0: Ci.nsIFactory); michael@0: registrar.unregisterFactory(cid, oldFactory); michael@0: registrar.registerFactory(cid, "", contractID, mockFactory); michael@0: michael@0: // We need to reload the module to update the lazy getter. michael@0: Cu.unload("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: checkService("appinfo", Ci.nsIXULAppInfo); michael@0: michael@0: // Clean up. michael@0: registrar.unregisterFactory(cid, mockFactory); michael@0: registrar.registerFactory(cid, "", contractID, oldFactory); michael@0: michael@0: Cu.unload("resource://gre/modules/Services.jsm"); michael@0: }