toolkit/modules/tests/xpcshell/test_Services.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial