Bug 1412893 - Change instances of using getService to Services.jsm where possible in toolkit/components/url-classifier r=francois
authorMark Banner <standard8@mozilla.com>
Tue, 31 Oct 2017 20:22:58 +0000
changeset 443742 73f8a7bbae047d9af6bf291aa1aaeb5554221d1f
parent 443741 bd1481d9e7cd45a697523f5d03266b347131a6a3
child 443743 46f5bb50f656fcc1f905ad18ef7e6acabfbaa0a6
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1412893
milestone58.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 1412893 - Change instances of using getService to Services.jsm where possible in toolkit/components/url-classifier r=francois MozReview-Commit-ID: 7ejzcckcwQ1
toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_always_activate.js
toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_ask_to_activate.js
toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_never_activate.js
toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_always_activate.js
toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_ask_to_activate.js
toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_never_activate.js
toolkit/components/url-classifier/tests/browser/classifierHelper.js
toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
toolkit/components/url-classifier/tests/mochitest/test_classifier.html
toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html
toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html
toolkit/components/url-classifier/tests/mochitest/test_safebrowsing_bug1272239.html
toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js
toolkit/components/url-classifier/tests/unit/test_dbservice.js
toolkit/components/url-classifier/tests/unit/test_digest256.js
toolkit/components/url-classifier/tests/unit/test_hashcompleter_v4.js
toolkit/components/url-classifier/tests/unit/test_listmanager.js
toolkit/components/url-classifier/tests/unit/test_malwaretable_pref.js
toolkit/components/url-classifier/tests/unit/test_prefixset.js
toolkit/components/url-classifier/tests/unit/test_provider_url.js
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_always_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_always_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: false,
     flashSetting: classifierTester.ALWAYS_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_ask_to_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_ask_to_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: false,
     flashSetting: classifierTester.ASK_TO_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_never_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_off_with_never_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: false,
     flashSetting: classifierTester.NEVER_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_always_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_always_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: true,
     flashSetting: classifierTester.ALWAYS_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_ask_to_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_ask_to_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: true,
     flashSetting: classifierTester.ASK_TO_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_never_activate.js
+++ b/toolkit/components/url-classifier/tests/browser/browser_flashblock_on_with_never_activate.js
@@ -1,24 +1,22 @@
 /* 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/. */
 "use strict";
 requestLongerTimeout(3);
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-const scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
 /* import-globals-from classifierHelper.js */
-scriptLoader.loadSubScript(
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierHelper.js",
   this);
-  /* import-globals-from classifierTester.js */
-scriptLoader.loadSubScript(
+/* import-globals-from classifierTester.js */
+Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/url-classifier/tests/browser/classifierTester.js",
   this);
 
 add_task(async function checkFlashBlockLists() {
   classifierTester.setPrefs({
     setDBs: true,
     flashBlockEnable: true,
     flashSetting: classifierTester.NEVER_ACTIVATE_PREF_VALUE
--- a/toolkit/components/url-classifier/tests/browser/classifierHelper.js
+++ b/toolkit/components/url-classifier/tests/browser/classifierHelper.js
@@ -29,31 +29,24 @@ classifierHelper._curAddChunkNum = 1;
 classifierHelper._updatesToCleanup = [];
 
 // This function returns a Promise resolved when SafeBrowsing.jsm is initialized.
 // SafeBrowsing.jsm is initialized after mozEntries are added. Add observer
 // to receive "finished" event. For the case when this function is called
 // after the event had already been notified, we lookup entries to see if
 // they are already added to database.
 classifierHelper.waitForInit = function() {
-  let observerService = Cc["@mozilla.org/observer-service;1"]
-                        .getService(Ci.nsIObserverService);
-  let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
-               .getService(Ci.nsIScriptSecurityManager);
-  let iosvc = Cc["@mozilla.org/network/io-service;1"]
-              .getService(Ci.nsIIOService);
-
   // This url must sync with the table, url in SafeBrowsing.jsm addMozEntries
   const table = "test-phish-simple";
   const url = "http://itisatrap.org/firefox/its-a-trap.html";
-  let principal = secMan.createCodebasePrincipal(
-    iosvc.newURI(url), {});
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+    Services.io.newURI(url), {});
 
   return new Promise(function(resolve, reject) {
-    observerService.addObserver(function() {
+    Services.obs.addObserver(function() {
       resolve();
     }, "mozentries-update-finished");
 
     let listener = {
       QueryInterface(iid) {
         if (iid.equals(Ci.nsISupports) ||
           iid.equals(Ci.nsIUrlClassifierUpdateObserver))
           return this;
--- a/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
+++ b/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
@@ -1,14 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* eslint-env mozilla/frame-script */
 
-const { classes: Cc, interfaces: Ci, results: Cr } = Components;
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
 
 var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
                 .getService(Ci.nsIUrlClassifierDBService);
 
 var timer;
 function setTimeout(callback, delay) {
   timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
   timer.initWithCallback({ notify: callback },
@@ -57,34 +59,26 @@ function doReload() {
   }
 }
 
 // SafeBrowsing.jsm is initialized after mozEntries are added. Add observer
 // to receive "finished" event. For the case when this function is called
 // after the event had already been notified, we lookup entries to see if
 // they are already added to database.
 function waitForInit() {
-  let observerService = Cc["@mozilla.org/observer-service;1"]
-                        .getService(Ci.nsIObserverService);
-
-  observerService.addObserver(function() {
+  Services.obs.addObserver(function() {
     sendAsyncMessage("safeBrowsingInited");
   }, "mozentries-update-finished");
 
   // This url must sync with the table, url in SafeBrowsing.jsm addMozEntries
   const table = "test-phish-simple";
   const url = "http://itisatrap.org/firefox/its-a-trap.html";
 
-  let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
-               .getService(Ci.nsIScriptSecurityManager);
-  let iosvc = Cc["@mozilla.org/network/io-service;1"]
-              .getService(Ci.nsIIOService);
-
-  let principal = secMan.createCodebasePrincipal(
-    iosvc.newURI(url), {});
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+    Services.io.newURI(url), {});
 
   let listener = {
     QueryInterface(iid) {
       if (iid.equals(Ci.nsISupports) ||
         iid.equals(Ci.nsIUrlClassifierUpdateObserver))
         return this;
       throw Cr.NS_ERROR_NO_INTERFACE;
     },
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
@@ -134,29 +134,25 @@ function updateError(errorCode) {
   // Abort test.
   SimpleTest.finish();
 }
 
 function testService() {
   return new Promise(resolve => {
     let service = Cc["@mozilla.org/url-classifier/dbservice;1"].
                     getService(Ci.nsIURIClassifier);
-    let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].
-                getService(Ci.nsIScriptSecurityManager);
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-                getService(Ci.nsIIOService);
     function runNextTest() {
       if (!testURLs.length) {
         resolve();
         return;
       }
       let test = testURLs.shift();
       let tables = "test-malware-simple,test-unwanted-simple,test-phish-simple,test-track-simple,test-block-simple,test-harmful-simple";
-      let uri = ios.newURI(test.url);
-      let prin = ssm.createCodebasePrincipal(uri, {});
+      let uri = SpecialPowers.Services.io.newURI(test.url);
+      let prin = SpecialPowers.Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
       is(service.classifyLocal(uri, tables), test.table,
          `Successful synchronous classification of ${test.url} with TP=${test.trackingProtection}`);
       SpecialPowers.doUrlClassify(prin, null, test.trackingProtection, function(errorCode) {
         is(errorCode, test.result,
            `Successful asynchronous classification of ${test.url} with TP=${test.trackingProtection}`);
 
         // Same as classifyLocal except for the 'async' call.
         SpecialPowers.doUrlClassifyLocal(uri, tables, function(errorCode1, tables1) {
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html
@@ -17,19 +17,16 @@
 <script class="testbody" type="text/javascript">
 
 const testTable = "moz-track-digest256";
 const UPDATE_URL = "http://mochi.test:8888/tests/toolkit/components/url-classifier/tests/mochitest/update.sjs";
 
 var Cc = SpecialPowers.Cc;
 var Ci = SpecialPowers.Ci;
 
-var prefService = Cc["@mozilla.org/preferences-service;1"]
-                  .getService(Ci.nsIPrefService);
-
 var timer = Cc["@mozilla.org/timer;1"]
             .createInstance(Ci.nsITimer);
 
 // If default preference contain the table we want to test,
 // We should change test table to a different one.
 var trackingTables = SpecialPowers.getCharPref("urlclassifier.trackingTable").split(",");
 ok(!trackingTables.includes(testTable), "test table should not be in the preference");
 
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html
@@ -142,28 +142,24 @@ function setupTestData(datas) {
   }
   prefArray.push([activeTablePref, activeTable]);
 
   return SpecialPowers.pushPrefEnv({set: prefArray});
 }
 
 function runTest() {
   return new Promise(resolve => {
-    let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].
-                getService(Ci.nsIScriptSecurityManager);
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-                getService(Ci.nsIIOService);
     function runNextTest() {
       if (!testDatas.length) {
         resolve();
         return;
       }
       let test = testDatas.shift();
-      let uri = ios.newURI(test.url);
-      let prin = ssm.createCodebasePrincipal(uri, {});
+      let uri = SpecialPowers.Services.io.newURI(test.url);
+      let prin = SpecialPowers.Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
       SpecialPowers.doUrlClassify(prin, null, false, function(errorCode, table, provider, fullhash) {
         is(errorCode, test.expect.error, `Test url ${test.url} correct error`);
         is(table, test.expect.table, `Test url ${test.url} correct table`);
         is(provider, test.expect.provider, `Test url ${test.url} correct provider`);
         is(fullhash, btoa(test.expect.fullhash), `Test url ${test.url} correct full hash`);
         runNextTest();
       });
     }
--- a/toolkit/components/url-classifier/tests/mochitest/test_safebrowsing_bug1272239.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_safebrowsing_bug1272239.html
@@ -23,23 +23,20 @@ const prefs = [
   "urlclassifier.malwareTable",
   "urlclassifier.downloadBlockTable",
   "urlclassifier.downloadAllowTable",
   "urlclassifier.trackingTable",
   "urlclassifier.trackingWhitelistTable",
   "urlclassifier.blockedTable"
 ];
 
-var prefService = Cc["@mozilla.org/preferences-service;1"]
-                  .getService(Ci.nsIPrefService);
-
 // Get providers
 var providers = {};
 
-var branch = prefService.getBranch("browser.safebrowsing.provider.");
+var branch = SpecialPowers.Services.prefs.getBranch("browser.safebrowsing.provider.");
 var children = branch.getChildList("", {});
 
 for (var child of children) {
   var prefComponents =  child.split(".");
   var providerName = prefComponents[0];
   providers[providerName] = {};
 }
 
--- a/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
+++ b/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js
@@ -7,49 +7,41 @@ const NS_APP_USER_PROFILE_50_DIR = "Prof
 const NS_APP_USER_PROFILE_LOCAL_50_DIR = "ProfLD";
 
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cu = Components.utils;
 var Cr = Components.results;
 
 Cu.import("resource://testing-common/httpd.js");
+Cu.import("resource://gre/modules/Services.jsm");
 
 do_get_profile();
 
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-
 // Ensure PSM is initialized before the test
 Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
 
-var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-
-var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
-               .getService(Ci.nsIScriptSecurityManager);
-
 // Disable hashcompleter noise for tests
-var prefBranch = Cc["@mozilla.org/preferences-service;1"].
-                 getService(Ci.nsIPrefBranch);
-prefBranch.setIntPref("urlclassifier.gethashnoise", 0);
+Services.prefs.setIntPref("urlclassifier.gethashnoise", 0);
 
 // Enable malware/phishing checking for tests
-prefBranch.setBoolPref("browser.safebrowsing.malware.enabled", true);
-prefBranch.setBoolPref("browser.safebrowsing.blockedURIs.enabled", true);
-prefBranch.setBoolPref("browser.safebrowsing.phishing.enabled", true);
+Services.prefs.setBoolPref("browser.safebrowsing.malware.enabled", true);
+Services.prefs.setBoolPref("browser.safebrowsing.blockedURIs.enabled", true);
+Services.prefs.setBoolPref("browser.safebrowsing.phishing.enabled", true);
 
 // Enable all completions for tests
-prefBranch.setCharPref("urlclassifier.disallow_completions", "");
+Services.prefs.setCharPref("urlclassifier.disallow_completions", "");
 
 // Hash completion timeout
-prefBranch.setIntPref("urlclassifier.gethash.timeout_ms", 5000);
+Services.prefs.setIntPref("urlclassifier.gethash.timeout_ms", 5000);
 
 function delFile(name) {
   try {
     // Delete a previously created sqlite file
-    var file = dirSvc.get("ProfLD", Ci.nsIFile);
+    var file = Services.dirsvc.get("ProfLD", Ci.nsIFile);
     file.append(name);
     if (file.exists())
       file.remove(false);
   } catch (e) {
   }
 }
 
 function cleanUp() {
@@ -228,31 +220,31 @@ tableData(expectedTables, cb) {
 
 checkUrls(urls, expected, cb, useMoz = false) {
   // work with a copy of the list.
   urls = urls.slice(0);
   var doLookup = function() {
     if (urls.length > 0) {
       var tables = useMoz ? mozTables : allTables;
       var fragment = urls.shift();
-      var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + fragment), {});
+      var principal = Services.scriptSecurityManager.createCodebasePrincipal(Services.io.newURI("http://" + fragment), {});
       dbservice.lookup(principal, tables,
                                 function(arg) {
                                   do_check_eq(expected, arg);
                                   doLookup();
                                 }, true);
     } else {
       cb();
     }
   };
   doLookup();
 },
 
 checkTables(url, expected, cb) {
-  var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + url), {});
+  var principal = Services.scriptSecurityManager.createCodebasePrincipal(Services.io.newURI("http://" + url), {});
   dbservice.lookup(principal, allTables, function(tables) {
     // Rebuild tables in a predictable order.
     var parts = tables.split(",");
     while (parts[parts.length - 1] == "") {
       parts.pop();
     }
     parts.sort();
     tables = parts.join(",");
--- a/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js
+++ b/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js
@@ -1,10 +1,9 @@
 Cu.import("resource://gre/modules/SafeBrowsing.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://testing-common/AppInfo.jsm");
 
 // 'Cc["@mozilla.org/xre/app-info;1"]' for xpcshell has no nsIXULAppInfo
 // so that we have to update it to make nsURLFormatter.js happy.
 // (SafeBrowsing.init() will indirectly use nsURLFormatter.js)
 updateAppInfo();
 
 function run_test() {
--- a/toolkit/components/url-classifier/tests/unit/test_dbservice.js
+++ b/toolkit/components/url-classifier/tests/unit/test_dbservice.js
@@ -104,17 +104,18 @@ var numExpecting;
 function testFailure(arg) {
   do_throw(arg);
 }
 
 function checkNoHost() {
   // Looking up a no-host uri such as a data: uri should throw an exception.
   var exception;
   try {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("data:text/html,<b>test</b>"), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("data:text/html,<b>test</b>"), {});
     dbservice.lookup(principal, allTables);
 
     exception = false;
   } catch (e) {
     exception = true;
   }
   do_check_true(exception);
 
@@ -213,41 +214,46 @@ function blockedExists(result) {
   }
 }
 
 function checkState() {
   numExpecting = 0;
 
 
   for (let key in phishExpected) {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + key), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("http://" + key), {});
     dbservice.lookup(principal, allTables, phishExists, true);
     numExpecting++;
   }
 
   for (let key in phishUnexpected) {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + key), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("http://" + key), {});
     dbservice.lookup(principal, allTables, phishDoesntExist, true);
     numExpecting++;
   }
 
   for (let key in malwareExpected) {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + key), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("http://" + key), {});
     dbservice.lookup(principal, allTables, malwareExists, true);
     numExpecting++;
   }
 
   for (let key in unwantedExpected) {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + key), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("http://" + key), {});
     dbservice.lookup(principal, allTables, unwantedExists, true);
     numExpecting++;
   }
 
   for (let key in blockedExpected) {
-    let principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + key), {});
+    let principal = Services.scriptSecurityManager.createCodebasePrincipal(
+      Services.io.newURI("http://" + key), {});
     dbservice.lookup(principal, allTables, blockedExists, true);
     numExpecting++;
   }
 }
 
 function testSubSuccess(result) {
   do_check_eq(result, "1000");
   checkState();
--- a/toolkit/components/url-classifier/tests/unit/test_digest256.js
+++ b/toolkit/components/url-classifier/tests/unit/test_digest256.js
@@ -2,19 +2,16 @@ Cu.import("resource://gre/modules/XPCOMU
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 // Global test server for serving safebrowsing updates.
 var gHttpServ = null;
 // Global nsIUrlClassifierDBService
 var gDbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
   .getService(Ci.nsIUrlClassifierDBService);
-// Security manager for creating nsIPrincipals from URIs
-var gSecMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
-  .getService(Ci.nsIScriptSecurityManager);
 
 // A map of tables to arrays of update redirect urls.
 var gTables = {};
 
 // Construct an update from a file.
 function readFileToString(aFilename) {
   let f = do_get_file(aFilename);
   let stream = Cc["@mozilla.org/network/file-input-stream;1"]
@@ -79,22 +76,16 @@ function run_test() {
     response.setStatusLine(request.httpVersion, 200, "OK");
     response.bodyOutputStream.write(blob, blob.length);
   });
 
   gHttpServ.start(4444);
   run_next_test();
 }
 
-function createURI(s) {
-  let service = Cc["@mozilla.org/network/io-service;1"]
-    .getService(Ci.nsIIOService);
-  return service.newURI(s);
-}
-
 // Just throw if we ever get an update or download error.
 function handleError(aEvent) {
   do_throw("We didn't download or update correctly: " + aEvent);
 }
 
 add_test(function test_update() {
   let streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
     .getService(Ci.nsIUrlClassifierStreamUpdater);
@@ -115,29 +106,29 @@ add_test(function test_update() {
     "goog-downloadwhite-digest256",
     "goog-downloadwhite-digest256;\n",
     true,
     "http://localhost:4444/downloads",
     updateSuccess, handleError, handleError);
 });
 
 add_test(function test_url_not_whitelisted() {
-  let uri = createURI("http://example.com");
-  let principal = gSecMan.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI("http://example.com");
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
   gDbService.lookup(principal, "goog-downloadwhite-digest256",
     function handleEvent(aEvent) {
       // This URI is not on any lists.
       do_check_eq("", aEvent);
       run_next_test();
     });
 });
 
 add_test(function test_url_whitelisted() {
   // Hash of "whitelisted.com/" (canonicalized URL) is:
   // 93CA5F48E15E9861CD37C2D95DB43D23CC6E6DE5C3F8FA6E8BE66F97CC518907
-  let uri = createURI("http://whitelisted.com");
-  let principal = gSecMan.createCodebasePrincipal(uri, {});
+  let uri = Services.io.newURI("http://whitelisted.com");
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
   gDbService.lookup(principal, "goog-downloadwhite-digest256",
     function handleEvent(aEvent) {
       do_check_eq("goog-downloadwhite-digest256", aEvent);
       run_next_test();
     });
 });
--- a/toolkit/components/url-classifier/tests/unit/test_hashcompleter_v4.js
+++ b/toolkit/components/url-classifier/tests/unit/test_hashcompleter_v4.js
@@ -1,10 +1,9 @@
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
 
 // These tables have a different update URL (for v4).
 const TEST_TABLE_DATA_V4 = {
   tableName: "test-phish-proto",
   providerName: "google4",
   updateUrl: "http://localhost:5555/safebrowsing/update?",
   gethashUrl: "http://localhost:5555/safebrowsing/gethash-v4?",
 };
@@ -51,37 +50,37 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "nsIUrlClassifierUtils");
 
 // Handles request for TEST_TABLE_DATA_V4.
 let gHttpServV4 = null;
 
 const NEW_CLIENT_STATE = "sta\0te";
 const CHECKSUM = "\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78";
 
-prefBranch.setBoolPref("browser.safebrowsing.debug", true);
+Services.prefs.setBoolPref("browser.safebrowsing.debug", true);
 
 // The "\xFF\xFF" is to generate a base64 string with "/".
-prefBranch.setCharPref("browser.safebrowsing.id", "Firefox\xFF\xFF");
+Services.prefs.setCharPref("browser.safebrowsing.id", "Firefox\xFF\xFF");
 
 // Register tables.
 gListManager.registerTable(TEST_TABLE_DATA_V4.tableName,
                            TEST_TABLE_DATA_V4.providerName,
                            TEST_TABLE_DATA_V4.updateUrl,
                            TEST_TABLE_DATA_V4.gethashUrl);
 
 // This is unfortunately needed since v4 gethash request
 // requires the threat type (table name) as well as the
 // state it's associated with. We have to run the update once
 // to have the state written.
 add_test(function test_update_v4() {
   gListManager.disableUpdate(TEST_TABLE_DATA_V4.tableName);
   gListManager.enableUpdate(TEST_TABLE_DATA_V4.tableName);
 
   // Force table update.
-  prefBranch.setCharPref(PREF_NEXTUPDATETIME_V4, "1");
+  Services.prefs.setCharPref(PREF_NEXTUPDATETIME_V4, "1");
   gListManager.maybeToggleUpdateChecking();
 });
 
 add_test(function test_getHashRequestV4() {
   let request = gUrlUtil.makeFindFullHashRequestV4([TEST_TABLE_DATA_V4.tableName],
                                                    [btoa(NEW_CLIENT_STATE)],
                                                    [btoa("0123"), btoa("1234567"), btoa("1111")].sort(),
                                                    1,
--- a/toolkit/components/url-classifier/tests/unit/test_listmanager.js
+++ b/toolkit/components/url-classifier/tests/unit/test_listmanager.js
@@ -1,10 +1,9 @@
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 
 // These tables share the same updateURL.
 const TEST_TABLE_DATA_LIST = [
   // 0:
   {
@@ -66,20 +65,20 @@ let gHttpServV4 = null;
 // These two variables are used to synchronize the last two racing updates
 // (in terms of "update URL") in test_update_all_tables().
 let gUpdatedCntForTableData = 0; // For TEST_TABLE_DATA_LIST.
 let gIsV4Updated = false; // For TEST_TABLE_DATA_V4.
 
 const NEW_CLIENT_STATE = "sta\0te";
 const CHECKSUM = "\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78";
 
-prefBranch.setBoolPref("browser.safebrowsing.debug", true);
+Services.prefs.setBoolPref("browser.safebrowsing.debug", true);
 
 // The "\xFF\xFF" is to generate a base64 string with "/".
-prefBranch.setCharPref("browser.safebrowsing.id", "Firefox\xFF\xFF");
+Services.prefs.setCharPref("browser.safebrowsing.id", "Firefox\xFF\xFF");
 
 // Register tables.
 TEST_TABLE_DATA_LIST.forEach(function(t) {
   gListManager.registerTable(t.tableName,
                              t.providerName,
                              t.updateUrl,
                              t.gethashUrl);
 });
@@ -298,30 +297,30 @@ function run_test() {
   gHttpServV4.start(5555);
 
   run_next_test();
 }
 
 // A trick to force updating tables. However, before calling this, we have to
 // call disableAllUpdates() first to clean up the updateCheckers in listmanager.
 function forceTableUpdate() {
-  prefBranch.setCharPref(PREF_NEXTUPDATETIME, "1");
-  prefBranch.setCharPref(PREF_NEXTUPDATETIME_V4, "1");
+  Services.prefs.setCharPref(PREF_NEXTUPDATETIME, "1");
+  Services.prefs.setCharPref(PREF_NEXTUPDATETIME_V4, "1");
   gListManager.maybeToggleUpdateChecking();
 }
 
 function disableAllUpdates() {
   TEST_TABLE_DATA_LIST.forEach(t => gListManager.disableUpdate(t.tableName));
   gListManager.disableUpdate(TEST_TABLE_DATA_V4.tableName);
 }
 
 // Since there's no public interface on listmanager to know the update success,
 // we could only rely on the refresh of "nextupdatetime".
 function waitForUpdateSuccess(callback) {
-  let nextupdatetime = parseInt(prefBranch.getCharPref(PREF_NEXTUPDATETIME));
+  let nextupdatetime = parseInt(Services.prefs.getCharPref(PREF_NEXTUPDATETIME));
   do_print("nextupdatetime: " + nextupdatetime);
   if (nextupdatetime !== 1) {
     callback();
     return;
   }
   do_timeout(1000, waitForUpdateSuccess.bind(null, callback));
 }
 
--- a/toolkit/components/url-classifier/tests/unit/test_malwaretable_pref.js
+++ b/toolkit/components/url-classifier/tests/unit/test_malwaretable_pref.js
@@ -1,4 +1,4 @@
 // Ensure that the default value of malwareTable is always in sorted order
-let originalValue = prefBranch.getCharPref("urlclassifier.malwareTable");
+let originalValue = Services.prefs.getCharPref("urlclassifier.malwareTable");
 let sortedValue = originalValue.split(",").sort().join(",");
 do_check_eq(originalValue, sortedValue);
--- a/toolkit/components/url-classifier/tests/unit/test_prefixset.js
+++ b/toolkit/components/url-classifier/tests/unit/test_prefixset.js
@@ -155,17 +155,17 @@ function testLoadSaveLargeSet() {
   pset.setPrefixes(arr, arr.length);
 
   doExpectedLookups(pset, arr, 1);
   doRandomLookups(pset, arr, 1000);
 
   checkContents(pset, arr);
 
   // Now try to save, restore, and redo the lookups
-  var file = dirSvc.get("ProfLD", Ci.nsIFile);
+  var file = Services.dirsvc.get("ProfLD", Ci.nsIFile);
   file.append("testLarge.pset");
 
   pset.storeToFile(file);
 
   let psetLoaded = newPset();
   psetLoaded.loadFromFile(file);
 
   doExpectedLookups(psetLoaded, arr, 1);
@@ -200,17 +200,17 @@ function testLoadSaveNoDelta() {
     arr.push(((1 << 16) + 1) * i);
   }
 
   let pset = newPset();
   pset.setPrefixes(arr, arr.length);
 
   doExpectedLookups(pset, arr, 1);
 
-  var file = dirSvc.get("ProfLD", Ci.nsIFile);
+  var file = Services.dirsvc.get("ProfLD", Ci.nsIFile);
   file.append("testNoDelta.pset");
 
   pset.storeToFile(file);
   pset.loadFromFile(file);
 
   doExpectedLookups(pset, arr, 1);
 }
 
--- a/toolkit/components/url-classifier/tests/unit/test_provider_url.js
+++ b/toolkit/components/url-classifier/tests/unit/test_provider_url.js
@@ -1,10 +1,9 @@
 Cu.import("resource://testing-common/AppInfo.jsm", this);
-Cu.import("resource://gre/modules/Services.jsm");
 
 function updateVersion(version) {
   updateAppInfo({ version });
 }
 
 add_test(function test_provider_url() {
   let urls = [
     "browser.safebrowsing.provider.google.updateURL",