Bug 1429701 - Enable ESLint rule mozilla/use-services for dom/indexedDB. r=bevis
authorMark Banner <standard8@mozilla.com>
Wed, 10 Jan 2018 17:25:52 +0000
changeset 453269 698ae46fa6340bfc93f5e9f212391bf8bc6feaa5
parent 453268 8b29651a367a0ff830bc64800752a3a6caffa484
child 453270 686aaeae4c9239c508f561669a2766b8f9a02d4a
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbevis
bugs1429701
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1429701 - Enable ESLint rule mozilla/use-services for dom/indexedDB. r=bevis MozReview-Commit-ID: 9OgcN56ziip
.eslintrc.js
dom/indexedDB/test/bug839193.js
dom/indexedDB/test/head.js
dom/indexedDB/test/helpers.js
dom/indexedDB/test/test_filehandle_lifetimes_nested.html
dom/indexedDB/test/test_filehandle_success_events_after_abort.html
dom/indexedDB/test/unit/test_bad_origin_directory.js
dom/indexedDB/test/unit/test_globalObjects_other.js
dom/indexedDB/test/unit/test_idle_maintenance.js
dom/indexedDB/test/unit/test_metadata2Restore.js
dom/indexedDB/test/unit/test_metadataRestore.js
dom/indexedDB/test/unit/test_oldDirectories.js
dom/indexedDB/test/unit/test_open_for_principal.js
dom/indexedDB/test/unit/test_open_objectStore.js
dom/indexedDB/test/unit/test_success_events_after_abort.js
dom/indexedDB/test/unit/test_transaction_lifetimes_nested.js
dom/indexedDB/test/unit/xpcshell-head-child-process.js
dom/indexedDB/test/unit/xpcshell-head-parent-process.js
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -27,17 +27,16 @@ module.exports = {
   }, {
     // XXX Bug 1421969. These files/directories are still being fixed,
     // so turn off mozilla/use-services for them for now.
     "files": [
       // Browser: Bug 1421379
       "browser/extensions/shield-recipe-client/test/browser/head.js",
       "browser/modules/offlineAppCache.jsm",
       "devtools/**",
-      "dom/indexedDB/**",
       "extensions/pref/**",
       "mobile/android/**",
       "testing/**",
     ],
     "rules": {
       "mozilla/use-services": "off",
     }
   }]
--- a/dom/indexedDB/test/bug839193.js
+++ b/dom/indexedDB/test/bug839193.js
@@ -1,32 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const nsIQuotaManagerService = Components.interfaces.nsIQuotaManagerService;
 
-var gURI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI("http://localhost");
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var gURI = Services.io.newURI("http://localhost");
 
 function onUsageCallback(request) {}
 
 function onLoad()
 {
   var quotaManagerService =
     Components.classes["@mozilla.org/dom/quota-manager-service;1"]
               .getService(nsIQuotaManagerService);
-  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                            .getService(Components.interfaces.nsIScriptSecurityManager)
-                            .createCodebasePrincipal(gURI, {});
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(gURI, {});
   var quotaRequest = quotaManagerService.getUsageForPrincipal(principal,
                                                               onUsageCallback);
   quotaRequest.cancel();
-  Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService)
-            .notifyObservers(window, "bug839193-loaded");
+  Services.obs.notifyObservers(window, "bug839193-loaded");
 }
 
 function onUnload()
 {
-  Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService)
-            .notifyObservers(window, "bug839193-unloaded");
+  Services.obs.notifyObservers(window, "bug839193-unloaded");
 }
--- a/dom/indexedDB/test/head.js
+++ b/dom/indexedDB/test/head.js
@@ -112,50 +112,30 @@ function dispatchEvent(eventName)
   info("dispatching event: " + eventName);
   let event = document.createEvent("Events");
   event.initEvent(eventName, false, false);
   gBrowser.selectedBrowser.contentWindow.dispatchEvent(event);
 }
 
 function setPermission(url, permission)
 {
-  const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
+  let uri = Services.io.newURI(url);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
-  let uri = Components.classes["@mozilla.org/network/io-service;1"]
-                      .getService(Components.interfaces.nsIIOService)
-                      .newURI(url);
-  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                      .getService(Ci.nsIScriptSecurityManager);
-  let principal = ssm.createCodebasePrincipal(uri, {});
-
-  Components.classes["@mozilla.org/permissionmanager;1"]
-            .getService(nsIPermissionManager)
-            .addFromPrincipal(principal, permission,
-                              nsIPermissionManager.ALLOW_ACTION);
+  Services.perms.addFromPrincipal(principal, permission,
+                                  Ci.nsIPermissionManager.ALLOW_ACTION);
 }
 
 function removePermission(url, permission)
 {
-  let uri = Components.classes["@mozilla.org/network/io-service;1"]
-                      .getService(Components.interfaces.nsIIOService)
-                      .newURI(url);
-  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                      .getService(Ci.nsIScriptSecurityManager);
-  let principal = ssm.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI(url);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
-  Components.classes["@mozilla.org/permissionmanager;1"]
-            .getService(Components.interfaces.nsIPermissionManager)
-            .removeFromPrincipal(principal, permission);
+  Services.perms.removeFromPrincipal(principal, permission);
 }
 
 function getPermission(url, permission)
 {
-  let uri = Components.classes["@mozilla.org/network/io-service;1"]
-                      .getService(Components.interfaces.nsIIOService)
-                      .newURI(url);
-  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                      .getService(Ci.nsIScriptSecurityManager);
-  let principal = ssm.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI(url);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
-  return Components.classes["@mozilla.org/permissionmanager;1"]
-                   .getService(Components.interfaces.nsIPermissionManager)
-                   .testPermissionFromPrincipal(principal, permission);
+  return Services.perms.testPermissionFromPrincipal(principal, permission);
 }
--- a/dom/indexedDB/test/helpers.js
+++ b/dom/indexedDB/test/helpers.js
@@ -18,22 +18,17 @@ var testGenerator = testSteps();
 var c = Object.getOwnPropertyDescriptor(this, "Components");
 if ((!c.value || c.writable) && typeof SpecialPowers === "object") {
   // eslint-disable-next-line no-native-reassign
   Components = SpecialPowers.Components;
 }
 
 function executeSoon(aFun)
 {
-  let comp = SpecialPowers.wrap(Components);
-
-  let tm = comp.classes["@mozilla.org/thread-manager;1"]
-               .getService(comp.interfaces.nsIThreadManager);
-
-  tm.dispatchToMainThread({
+  SpecialPowers.Services.tm.dispatchToMainThread({
     run() {
       aFun();
     }
   });
 }
 
 function clearAllDatabases(callback) {
   let qms = SpecialPowers.Services.qms;
--- a/dom/indexedDB/test/test_filehandle_lifetimes_nested.html
+++ b/dom/indexedDB/test/test_filehandle_lifetimes_nested.html
@@ -30,20 +30,17 @@
 
     let mutableFile = event.target.result;
     mutableFile.onerror = errorHandler;
 
     mutableFile.open();
 
     let fileHandle2;
 
-    let comp = SpecialPowers.wrap(SpecialPowers.Components);
-    let thread = comp.classes["@mozilla.org/thread-manager;1"]
-                     .getService(comp.interfaces.nsIThreadManager)
-                     .currentThread;
+    let thread = SpecialPowers.Services.tm.currentThread;
 
     let eventHasRun;
 
     thread.dispatch(function() {
       eventHasRun = true;
 
       fileHandle2 = mutableFile.open();
     }, SpecialPowers.Ci.nsIThread.DISPATCH_NORMAL);
--- a/dom/indexedDB/test/test_filehandle_success_events_after_abort.html
+++ b/dom/indexedDB/test/test_filehandle_success_events_after_abort.html
@@ -49,20 +49,17 @@
     fileHandle.abort();
 
     event = yield undefined;
 
     is(event.type, "abort", "Got abort event");
     is(sawError, true, "Saw getMetadata() error");
 
     // Make sure the success event isn't queued somehow.
-    let comp = SpecialPowers.wrap(SpecialPowers.Components);
-    var thread = comp.classes["@mozilla.org/thread-manager;1"]
-                     .getService(comp.interfaces.nsIThreadManager)
-                     .currentThread;
+    var thread = SpecialPowers.Services.tm.currentThread;
     while (thread.hasPendingEvents()) {
       thread.processNextEvent(false);
     }
 
     finishTest();
   }
   </script>
   <script type="text/javascript" src="helpers.js"></script>
--- a/dom/indexedDB/test/unit/test_bad_origin_directory.js
+++ b/dom/indexedDB/test/unit/test_bad_origin_directory.js
@@ -5,25 +5,19 @@
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
   const url = "ftp://ftp.example.com";
   const name = "test_bad_origin_directory.js";
 
-  let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
-                         .getService(SpecialPowers.Ci.nsIIOService);
-
-  let uri = ios.newURI(url);
+  let uri = Services.io.newURI(url);
 
-  let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
-                         .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
-
-  let principal = ssm.createCodebasePrincipal(uri, {});
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
   info("Opening database");
 
   let request = indexedDB.openForPrincipal(principal, name);
   request.onerror = continueToNextStepSync;
   request.onsuccess = unexpectedSuccessHandler;
   yield undefined;
 
--- a/dom/indexedDB/test/unit/test_globalObjects_other.js
+++ b/dom/indexedDB/test/unit/test_globalObjects_other.js
@@ -2,22 +2,19 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
-  let ioService =
-    Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-
   function getSpec(filename) {
     let file = do_get_file(filename);
-    let uri = ioService.newFileURI(file);
+    let uri = Services.io.newFileURI(file);
     return uri.spec;
   }
 
   // Test for IDBKeyRange and indexedDB availability in JS modules.
   /* import-globals-from GlobalObjectsModule.jsm */
   Cu.import(getSpec("GlobalObjectsModule.jsm"));
   let test = new GlobalObjectsModule();
   test.ok = ok;
--- a/dom/indexedDB/test/unit/test_idle_maintenance.js
+++ b/dom/indexedDB/test/unit/test_idle_maintenance.js
@@ -3,44 +3,33 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 /* eslint-disable mozilla/no-arbitrary-setTimeout */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
-  let uri = Cc["@mozilla.org/network/io-service;1"].
-            getService(Ci.nsIIOService).
-            newURI("https://www.example.com");
-  let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(Ci.nsIScriptSecurityManager);
-  let principal = ssm.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI("https://www.example.com");
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
   info("Setting permissions");
 
-  let permMgr =
-    Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
-  permMgr.add(uri, "indexedDB", Ci.nsIPermissionManager.ALLOW_ACTION);
+  Services.perms.add(uri, "indexedDB", Ci.nsIPermissionManager.ALLOW_ACTION);
 
   info("Setting idle preferences to prevent real 'idle-daily' notification");
 
-  let prefs =
-    Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  prefs.setIntPref("idle.lastDailyNotification", (Date.now() / 1000) - 10);
+  Services.prefs.setIntPref("idle.lastDailyNotification", (Date.now() / 1000) - 10);
 
   info("Activating real idle service");
 
   do_get_idle();
 
   info("Creating databases");
 
-  let quotaManagerService = Cc["@mozilla.org/dom/quota-manager-service;1"].
-                            getService(Ci.nsIQuotaManagerService);
-
   // Keep at least one database open.
   let req = indexedDB.open("foo-a", 1);
   req.onerror = errorHandler;
   req.onsuccess = grabEventAndContinueHandler;
   let event = yield undefined;
 
   // Keep at least one factory operation alive by deleting a database that is
   // stil open.
@@ -113,27 +102,27 @@ function* testSteps()
     }
   }
   yield undefined;
 
   info("Getting usage before maintenance");
 
   let usageBeforeMaintenance;
 
-  quotaManagerService.getUsageForPrincipal(principal, (request) => {
+  Services.qms.getUsageForPrincipal(principal, (request) => {
     let usage = request.result.usage;
     ok(usage > 0, "Usage is non-zero");
     usageBeforeMaintenance = usage;
     continueToNextStep();
   });
   yield undefined;
 
   info("Sending fake 'idle-daily' notification to QuotaManager");
 
-  let observer = quotaManagerService.QueryInterface(Ci.nsIObserver);
+  let observer = Services.qms.QueryInterface(Ci.nsIObserver);
   observer.observe(null, "idle-daily", "");
 
   info("Opening database while maintenance is performed");
 
   req = indexedDB.open("foo-c", 1);
   req.onerror = errorHandler;
   req.onsuccess = grabEventAndContinueHandler;
   yield undefined;
@@ -147,17 +136,17 @@ function* testSteps()
   // shutting down in the middle of maintenance.
   setTimeout(continueToNextStep, 10000);
   yield undefined;
 
   info("Getting usage after maintenance");
 
   let usageAfterMaintenance;
 
-  quotaManagerService.getUsageForPrincipal(principal, (request) => {
+  Services.qms.getUsageForPrincipal(principal, (request) => {
     let usage = request.result.usage;
     ok(usage > 0, "Usage is non-zero");
     usageAfterMaintenance = usage;
     continueToNextStep();
   });
   yield undefined;
 
   info("Usage before: " + usageBeforeMaintenance + ". " +
--- a/dom/indexedDB/test/unit/test_metadata2Restore.js
+++ b/dom/indexedDB/test/unit/test_metadata2Restore.js
@@ -211,27 +211,22 @@ function* testSteps()
     // the group,
     // the 32 bit origin length and
     // the origin
     // for this origin directory to test restoring.
     { attrs: { userContextId: 1 }, url: "http://localhost:98", dbName: "dbT",
       dbOptions: { version: 1, storage: "default" } }
   ];
 
-  let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
-                         .getService(SpecialPowers.Ci.nsIIOService);
-
-  let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
-                         .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
-
   function openDatabase(params) {
     let request;
     if ("url" in params) {
-      let uri = ios.newURI(params.url);
-      let principal = ssm.createCodebasePrincipal(uri, params.attrs || {});
+      let uri = Services.io.newURI(params.url);
+      let principal = Services.scriptSecurityManager
+        .createCodebasePrincipal(uri, params.attrs || {});
       request = indexedDB.openForPrincipal(principal, params.dbName,
                                            params.dbOptions);
     } else {
       request = indexedDB.open(params.dbName, params.dbOptions);
     }
     return request;
   }
 
--- a/dom/indexedDB/test/unit/test_metadataRestore.js
+++ b/dom/indexedDB/test/unit/test_metadataRestore.js
@@ -52,27 +52,22 @@ function* testSteps()
     { url: "http://localhost:89", dbName: "dbK",
       dbOptions: { version: 1, storage: "default" } },
 
     // This one lives in storage/default/http+++localhost+90
     { url: "http://localhost:90", dbName: "dbL",
       dbOptions: { version: 1, storage: "default" } }
   ];
 
-  let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
-                         .getService(SpecialPowers.Ci.nsIIOService);
-
-  let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
-                         .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
-
   function openDatabase(params) {
     let request;
     if ("url" in params) {
-      let uri = ios.newURI(params.url);
-      let principal = ssm.createCodebasePrincipal(uri, {});
+      let uri = Services.io.newURI(params.url);
+      let principal = Services.scriptSecurityManager
+        .createCodebasePrincipal(uri, {});
       request = indexedDB.openForPrincipal(principal, params.dbName,
                                            params.dbOptions);
     } else {
       request = indexedDB.open(params.dbName, params.dbOptions);
     }
     return request;
   }
 
--- a/dom/indexedDB/test/unit/test_oldDirectories.js
+++ b/dom/indexedDB/test/unit/test_oldDirectories.js
@@ -7,25 +7,20 @@ var testGenerator = testSteps();
 
 function* testSteps()
 {
   // This lives in storage/default/http+++www.mozilla.org
   const url = "http://www.mozilla.org";
   const dbName = "dbC";
   const dbVersion = 1;
 
-  let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
-                         .getService(SpecialPowers.Ci.nsIIOService);
-
-  let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
-                         .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
-
   function openDatabase() {
-    let uri = ios.newURI(url);
-    let principal = ssm.createCodebasePrincipal(uri, {});
+    let uri = Services.io.newURI(url);
+    let principal = Services.scriptSecurityManager
+      .createCodebasePrincipal(uri, {});
     let request = indexedDB.openForPrincipal(principal, dbName, dbVersion);
     return request;
   }
 
   clearAllDatabases(continueToNextStepSync);
   yield undefined;
 
   installPackagedProfile("oldDirectories_profile");
@@ -44,20 +39,17 @@ function* testSteps()
   request = openDatabase();
   request.onerror = errorHandler;
   request.onupgradeneeded = unexpectedSuccessHandler;
   request.onsuccess = grabEventAndContinueHandler;
   event = yield undefined;
 
   is(event.type, "success", "Correct event type");
 
-  let directoryService = Cc["@mozilla.org/file/directory_service;1"]
-                         .getService(Ci.nsIProperties);
-
-  let profileDir = directoryService.get("ProfD", Ci.nsIFile);
+  let profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
 
   let dir = profileDir.clone();
   dir.append("indexedDB");
 
   let exists = dir.exists();
   ok(!exists, "indexedDB doesn't exist");
 
   dir = profileDir.clone();
--- a/dom/indexedDB/test/unit/test_open_for_principal.js
+++ b/dom/indexedDB/test/unit/test_open_for_principal.js
@@ -40,22 +40,18 @@ function* testSteps()
   is(event.target.result, null, "Got no data");
 
   request = objectStore.add(data.value, data.key);
   request.onsuccess = grabEventAndContinueHandler;
   event = yield undefined;
 
   is(event.target.result, data.key, "Got correct key");
 
-  let uri = Components.classes["@mozilla.org/network/io-service;1"]
-                      .getService(Components.interfaces.nsIIOService)
-                      .newURI("http://appdata.example.com");
-  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                      .getService(Components.interfaces.nsIScriptSecurityManager);
-  let principal = ssm.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI("http://appdata.example.com");
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 
   request = indexedDB.openForPrincipal(principal, name, 1);
   request.onerror = errorHandler;
   request.onupgradeneeded = grabEventAndContinueHandler;
   request.onsuccess = grabEventAndContinueHandler;
   event = yield undefined;
 
   is(event.type, "upgradeneeded", "Got correct event type");
--- a/dom/indexedDB/test/unit/test_open_objectStore.js
+++ b/dom/indexedDB/test/unit/test_open_objectStore.js
@@ -26,13 +26,12 @@ function* testSteps()
   is(db.objectStoreNames.item(0), objectStoreName, "Bad name");
 
   yield undefined;
 
   objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
 
   is(objectStore.name, objectStoreName, "Bad name");
   is(objectStore.keyPath, "foo", "Bad keyPath");
-  if (objectStore.indexNames.length, 0, "Bad indexNames");
+  is(objectStore.indexNames.length, 0, "Bad indexNames");
 
   finishTest();
 }
-
--- a/dom/indexedDB/test/unit/test_success_events_after_abort.js
+++ b/dom/indexedDB/test/unit/test_success_events_after_abort.js
@@ -40,17 +40,13 @@ function* testSteps()
   transaction.abort();
 
   event = yield undefined;
 
   is(event.type, "abort", "Got abort event");
   is(sawError, true, "Saw get() error");
   if (this.window) {
     // Make sure the success event isn't queued somehow.
-    let comp = SpecialPowers.wrap(Components);
-    let tm = comp.classes["@mozilla.org/thread-manager;1"]
-                 .getService(comp.interfaces.nsIThreadManager);
-    tm.spinEventLoopUntilEmpty();
+    SpecialPowers.Services.tm.spinEventLoopUntilEmpty();
   }
 
   finishTest();
 }
-
--- a/dom/indexedDB/test/unit/test_transaction_lifetimes_nested.js
+++ b/dom/indexedDB/test/unit/test_transaction_lifetimes_nested.js
@@ -20,21 +20,19 @@ function* testSteps()
   event.target.onsuccess = continueToNextStep;
   db.createObjectStore("foo");
   yield undefined;
 
   db.transaction("foo");
 
   let transaction2;
 
-  let comp = this.window ? SpecialPowers.wrap(Components) : Components;
-  let tm = comp.classes["@mozilla.org/thread-manager;1"]
-               .getService(comp.interfaces.nsIThreadManager);
+  let eventHasRun;
 
-  let eventHasRun;
+  let tm = SpecialPowers.Services ? SpecialPowers.Services.tm : Services.tm;
 
   tm.dispatchToMainThread(function() {
     eventHasRun = true;
 
     transaction2 = db.transaction("foo");
   });
 
   tm.spinEventLoopUntil(() => eventHasRun);
--- a/dom/indexedDB/test/unit/xpcshell-head-child-process.js
+++ b/dom/indexedDB/test/unit/xpcshell-head-child-process.js
@@ -1,29 +1,28 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 function run_test() {
   const { "classes": Cc, "interfaces": Ci, "utils": Cu } = Components;
 
+  Cu.import("resource://gre/modules/Services.jsm");
+
   const INDEXEDDB_HEAD_FILE = "xpcshell-head-parent-process.js";
   const INDEXEDDB_PREF_EXPERIMENTAL = "dom.indexedDB.experimental";
 
   // IndexedDB needs a profile.
   do_get_profile();
 
   let thisTest = _TEST_FILE.toString().replace(/\\/g, "/");
   thisTest = thisTest.substring(thisTest.lastIndexOf("/") + 1);
 
   // This is defined globally via xpcshell.
   /* global _HEAD_FILES */
   _HEAD_FILES.push(do_get_file(INDEXEDDB_HEAD_FILE).path.replace(/\\/g, "/"));
 
 
-  let prefs =
-    Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
-                                            .getBranch(null);
-  prefs.setBoolPref(INDEXEDDB_PREF_EXPERIMENTAL, true);
+  Services.prefs.setBoolPref(INDEXEDDB_PREF_EXPERIMENTAL, true);
 
   run_test_in_child(thisTest);
 }
--- a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
+++ b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
@@ -3,16 +3,18 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests using testGenerator are expected to define it themselves.
 /* global testGenerator */
 
 var { "classes": Cc, "interfaces": Ci, "utils": Cu } = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
+
 if (!("self" in this)) {
   this.self = this;
 }
 
 const DOMException = Ci.nsIDOMDOMException;
 
 var bufferCache = [];
 
@@ -231,35 +233,32 @@ function setTimeout(fun, timeout) {
   return timer;
 }
 
 function resetOrClearAllDatabases(callback, clear) {
   if (!SpecialPowers.isMainProcess()) {
     throw new Error("clearAllDatabases not implemented for child processes!");
   }
 
-  let quotaManagerService = Cc["@mozilla.org/dom/quota-manager-service;1"]
-                              .getService(Ci.nsIQuotaManagerService);
-
   const quotaPref = "dom.quotaManager.testing";
 
   let oldPrefValue;
-  if (SpecialPowers._getPrefs().prefHasUserValue(quotaPref)) {
+  if (Services.prefs.prefHasUserValue(quotaPref)) {
     oldPrefValue = SpecialPowers.getBoolPref(quotaPref);
   }
 
   SpecialPowers.setBoolPref(quotaPref, true);
 
   let request;
 
   try {
     if (clear) {
-      request = quotaManagerService.clear();
+      request = Services.qms.clear();
     } else {
-      request = quotaManagerService.reset();
+      request = Services.qms.reset();
     }
   } catch (e) {
     if (oldPrefValue !== undefined) {
       SpecialPowers.setBoolPref(quotaPref, oldPrefValue);
     } else {
       SpecialPowers.clearUserPref(quotaPref);
     }
     throw e;
@@ -273,22 +272,19 @@ function resetAllDatabases(callback) {
 }
 
 function clearAllDatabases(callback) {
   resetOrClearAllDatabases(callback, true);
 }
 
 function installPackagedProfile(packageName)
 {
-  let directoryService = Cc["@mozilla.org/file/directory_service;1"]
-                         .getService(Ci.nsIProperties);
+  let profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
 
-  let profileDir = directoryService.get("ProfD", Ci.nsIFile);
-
-  let currentDir = directoryService.get("CurWorkD", Ci.nsIFile);
+  let currentDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
 
   let packageFile = currentDir.clone();
   packageFile.append(packageName + ".zip");
 
   let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
                   .createInstance(Ci.nsIZipReader);
   zipReader.open(packageFile);
 
@@ -331,20 +327,17 @@ function installPackagedProfile(packageN
     }
   }
 
   zipReader.close();
 }
 
 function getChromeFilesDir()
 {
-  let dirService = Cc["@mozilla.org/file/directory_service;1"]
-                   .getService(Ci.nsIProperties);
-
-  let profileDir = dirService.get("ProfD", Ci.nsIFile);
+  let profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
 
   let idbDir = profileDir.clone();
   idbDir.append("storage");
   idbDir.append("permanent");
   idbDir.append("chrome");
   idbDir.append("idb");
 
   let idbEntries = idbDir.directoryEntries;
@@ -511,21 +504,19 @@ function verifyWasmModule(module1, modul
 
 function grabFileUsageAndContinueHandler(request)
 {
   testGenerator.next(request.result.fileUsage);
 }
 
 function getCurrentUsage(usageHandler)
 {
-  let qms = Cc["@mozilla.org/dom/quota-manager-service;1"]
-              .getService(Ci.nsIQuotaManagerService);
   let principal = Cc["@mozilla.org/systemprincipal;1"]
                     .createInstance(Ci.nsIPrincipal);
-  qms.getUsageForPrincipal(principal, usageHandler);
+  Services.qms.getUsageForPrincipal(principal, usageHandler);
 }
 
 function setTemporaryStorageLimit(limit)
 {
   const pref = "dom.quotaManager.temporaryStorage.fixedLimit";
   if (limit) {
     info("Setting temporary storage limit to " + limit);
     SpecialPowers.setIntPref(pref, limit);
@@ -544,52 +535,44 @@ function setDataThreshold(threshold)
 function setMaxSerializedMsgSize(aSize)
 {
   info("Setting maximal size of a serialized message to " + aSize);
   SpecialPowers.setIntPref("dom.indexedDB.maxSerializedMsgSize", aSize);
 }
 
 function getPrincipal(url)
 {
-  let uri = Cc["@mozilla.org/network/io-service;1"]
-              .getService(Ci.nsIIOService)
-              .newURI(url);
-  let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(Ci.nsIScriptSecurityManager);
-  return ssm.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI(url);
+  return Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
 }
 
 var SpecialPowers = {
   isMainProcess() {
-    return Components.classes["@mozilla.org/xre/app-info;1"]
-                     .getService(Components.interfaces.nsIXULRuntime)
-                     .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+    return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
   },
   notifyObservers(subject, topic, data) {
-    var obsvc = Cc["@mozilla.org/observer-service;1"]
-                   .getService(Ci.nsIObserverService);
-    obsvc.notifyObservers(subject, topic, data);
+    Services.obs.notifyObservers(subject, topic, data);
   },
   notifyObserversInParentProcess(subject, topic, data) {
     if (subject) {
       throw new Error("Can't send subject to another process!");
     }
     return this.notifyObservers(subject, topic, data);
   },
   getBoolPref(prefName) {
-    return this._getPrefs().getBoolPref(prefName);
+    return Services.prefs.getBoolPref(prefName);
   },
   setBoolPref(prefName, value) {
-    this._getPrefs().setBoolPref(prefName, value);
+    Services.prefs.setBoolPref(prefName, value);
   },
   setIntPref(prefName, value) {
-    this._getPrefs().setIntPref(prefName, value);
+    Services.prefs.setIntPref(prefName, value);
   },
   clearUserPref(prefName) {
-    this._getPrefs().clearUserPref(prefName);
+    Services.prefs.clearUserPref(prefName);
   },
   // Copied (and slightly adjusted) from specialpowersAPI.js
   exactGC(callback) {
     let count = 0;
 
     function doPreciseGCandCC() {
       function scheduledGCCallback() {
         Components.utils.forceCC();
@@ -602,46 +585,39 @@ var SpecialPowers = {
       }
 
       Components.utils.schedulePreciseGC(scheduledGCCallback);
     }
 
     doPreciseGCandCC();
   },
 
-  _getPrefs() {
-    var prefService =
-      Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
-    return prefService.getBranch(null);
-  },
-
   get Cc() {
     return Cc;
   },
 
   get Ci() {
     return Ci;
   },
 
   get Cu() {
     return Cu;
   },
 
   // Based on SpecialPowersObserver.prototype.receiveMessage
   createFiles(requests, callback) {
-    let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
     let filePaths = [];
     if (!this._createdFiles) {
       this._createdFiles = [];
     }
     let createdFiles = this._createdFiles;
     let promises = [];
     requests.forEach(function(request) {
       const filePerms = 0o666;
-      let testFile = dirSvc.get("ProfD", Ci.nsIFile);
+      let testFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
       if (request.name) {
         testFile.append(request.name);
       } else {
         testFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, filePerms);
       }
       let outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
       outStream.init(testFile, 0x02 | 0x08 | 0x20, // PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE
                      filePerms, 0);