Bug 1424862 - Enable mozilla/use-services from chrome/. r=mossop
authorMark Banner <standard8@mozilla.com>
Mon, 11 Dec 2017 20:29:28 +0000
changeset 396254 cc95b6d1680b26b327c7c430082eb6bc45982d18
parent 396253 a5c733e0b6d18d8516b3711fe3060a212d4c8787
child 396255 358f1c414f3ed3b6c7a08a131032155e4c467938
push id56960
push usermbanner@mozilla.com
push dateWed, 13 Dec 2017 22:57:15 +0000
treeherderautoland@cc95b6d1680b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1424862
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 1424862 - Enable mozilla/use-services from chrome/. r=mossop MozReview-Commit-ID: ILZTMzuBAZ1
.eslintrc.js
chrome/test/unit/head_crtestutils.js
chrome/test/unit/test_bug292789.js
chrome/test/unit/test_bug380398.js
chrome/test/unit/test_bug397073.js
chrome/test/unit/test_bug399707.js
chrome/test/unit/test_bug401153.js
chrome/test/unit/test_bug415367.js
chrome/test/unit/test_bug564667.js
chrome/test/unit/test_bug848297.js
chrome/test/unit/test_crlf.js
chrome/test/unit/test_data_protocol_registration.js
chrome/test/unit/test_no_remote_registration.js
chrome/test/unit/test_resolve_uris.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": [
       "accessible/**",
       // Browser: Bug 1421379
       "browser/extensions/shield-recipe-client/test/browser/head.js",
       "browser/modules/offlineAppCache.jsm",
-      "chrome/**",
       "devtools/**",
       "dom/indexedDB/**",
       "dom/media/**",
       "extensions/pref/**",
       "mobile/android/**",
       "security/**",
       "testing/**",
       "tools/profiler/**",
--- a/chrome/test/unit/head_crtestutils.js
+++ b/chrome/test/unit/head_crtestutils.js
@@ -1,13 +1,12 @@
 const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
 const XULAPPINFO_CID = Components.ID("{4ba645d3-be6f-40d6-a42a-01b2f40091b8}");
 
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
+let {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
 
 function registerManifests(manifests) {
   var reg = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
   for (var manifest of manifests)
     reg.autoRegister(manifest);
 }
--- a/chrome/test/unit/test_bug292789.js
+++ b/chrome/test/unit/test_bug292789.js
@@ -4,28 +4,25 @@
  */
 
 const MANIFESTS = [
   do_get_file("data/test_bug292789.manifest")
 ];
 
 registerManifests(MANIFESTS);
 
-var gIOS;
 var gCR;
 
 function check_accessibility(spec, desired) {
-  var uri = gIOS.newURI(spec);
+  var uri = Services.io.newURI(spec);
   var actual = gCR.allowContentToAccess(uri);
   do_check_eq(desired, actual);
 }
 
 function run_test() {
-  gIOS = Cc["@mozilla.org/network/io-service;1"].
-    getService(Ci.nsIIOService);
   gCR = Cc["@mozilla.org/chrome/chrome-registry;1"].
     getService(Ci.nsIXULChromeRegistry);
   gCR.checkForNewChrome();
 
   check_accessibility("chrome://test1/content/", false);
   check_accessibility("chrome://test1/content/foo.js", false);
   check_accessibility("chrome://test2/content/", true);
   check_accessibility("chrome://test2/content/foo.js", true);
--- a/chrome/test/unit/test_bug380398.js
+++ b/chrome/test/unit/test_bug380398.js
@@ -13,37 +13,35 @@ registerManifests(MANIFESTS);
 Components.utils.import("resource://testing-common/AppInfo.jsm", this);
 updateAppInfo({
   name: "XPCShell",
   id: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
   version: "5",
   platformVersion: "1.9",
 });
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"]
-            .getService(Ci.nsIIOService);
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                  .getService(Ci.nsIChromeRegistry);
 chromeReg.checkForNewChrome();
 
-var target = gIOS.newFileURI(do_get_file("data"));
+var target = Services.io.newFileURI(do_get_file("data"));
 target = target.spec + "test/test.xul";
 
 function test_succeeded_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     var result = chromeReg.convertChromeURL(uri);
     do_check_eq(result.spec, target);
   } catch (ex) {
     do_throw(namespace);
   }
 }
 
 function test_failed_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     chromeReg.convertChromeURL(uri);
     do_throw(namespace);
   } catch (ex) {
   }
 }
 
 function run_test() {
--- a/chrome/test/unit/test_bug397073.js
+++ b/chrome/test/unit/test_bug397073.js
@@ -13,37 +13,35 @@ registerManifests(MANIFESTS);
 Components.utils.import("resource://testing-common/AppInfo.jsm", this);
 updateAppInfo({
   name: "XPCShell",
   ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
   version: "5",
   platformVersion: "1.9",
 });
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"]
-            .getService(Ci.nsIIOService);
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                  .getService(Ci.nsIChromeRegistry);
 chromeReg.checkForNewChrome();
 
-var target = gIOS.newFileURI(do_get_file("data"));
+var target = Services.io.newFileURI(do_get_file("data"));
 target = target.spec + "test/test.xul";
 
 function test_succeeded_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     var result = chromeReg.convertChromeURL(uri);
     do_check_eq(result.spec, target);
   } catch (ex) {
     do_throw(namespace);
   }
 }
 
 function test_failed_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     chromeReg.convertChromeURL(uri);
     do_throw(namespace);
   } catch (ex) {
   }
 }
 
 function run_test() {
--- a/chrome/test/unit/test_bug399707.js
+++ b/chrome/test/unit/test_bug399707.js
@@ -12,37 +12,35 @@ registerManifests(MANIFESTS);
 Components.utils.import("resource://testing-common/AppInfo.jsm", this);
 updateAppInfo({
   name: "XPCShell",
   ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
   version: "5",
   platformVersion: "1.9",
 });
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"]
-            .getService(Ci.nsIIOService);
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                  .getService(Ci.nsIChromeRegistry);
 chromeReg.checkForNewChrome();
 
-var target = gIOS.newFileURI(do_get_file("data"));
+var target = Services.io.newFileURI(do_get_file("data"));
 target = target.spec + "test/test.xul";
 
 function test_succeeded_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     var result = chromeReg.convertChromeURL(uri);
     do_check_eq(result.spec, target);
   } catch (ex) {
     do_throw(namespace);
   }
 }
 
 function test_failed_mapping(namespace) {
-  var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul");
+  var uri = Services.io.newURI("chrome://" + namespace + "/content/test.xul");
   try {
     chromeReg.convertChromeURL(uri);
     do_throw(namespace);
   } catch (ex) {
   }
 }
 
 function run_test() {
--- a/chrome/test/unit/test_bug401153.js
+++ b/chrome/test/unit/test_bug401153.js
@@ -12,40 +12,38 @@ registerManifests(MANIFESTS);
 Components.utils.import("resource://testing-common/AppInfo.jsm", this);
 updateAppInfo({
   name: "XPCShell",
   ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
   version: "5",
   platformVersion: "1.9",
 });
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"]
-            .getService(Ci.nsIIOService);
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                  .getService(Ci.nsIChromeRegistry);
 chromeReg.checkForNewChrome();
 
-var rph = gIOS.getProtocolHandler("resource")
+var rph = Services.io.getProtocolHandler("resource")
               .QueryInterface(Ci.nsIResProtocolHandler);
 
 function test_succeeded_mapping(namespace, target) {
   try {
     do_check_true(rph.hasSubstitution(namespace));
-    var uri = gIOS.newURI("resource://" + namespace);
+    var uri = Services.io.newURI("resource://" + namespace);
     dump("### checking for " + target + ", getting " + rph.resolveURI(uri) + "\n");
     do_check_eq(rph.resolveURI(uri), target);
   } catch (ex) {
     dump(ex + "\n");
     do_throw(namespace);
   }
 }
 
 function test_failed_mapping(namespace) {
   do_check_false(rph.hasSubstitution(namespace));
 }
 
 function run_test() {
-  var data = gIOS.newFileURI(do_get_file("data")).spec;
+  var data = Services.io.newFileURI(do_get_file("data")).spec;
   test_succeeded_mapping("test1", data + "test1/");
   test_succeeded_mapping("test3", "jar:" + data + "test3.jar!/resources/");
   test_failed_mapping("test4");
   test_succeeded_mapping("test5", data + "test5/");
 }
--- a/chrome/test/unit/test_bug415367.js
+++ b/chrome/test/unit/test_bug415367.js
@@ -1,22 +1,19 @@
 /* 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/.
  */
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"]
-            .getService(Ci.nsIIOService);
-
 function test_uri(obj) {
   var uri = null;
   var failed = false;
   var message = "";
   try {
-    uri = gIOS.newURI(obj.uri);
+    uri = Services.io.newURI(obj.uri);
     if (!obj.result) {
       failed = true;
       message = obj.uri + " should not be accepted as a valid URI";
     }
   } catch (ex) {
     if (obj.result) {
       failed = true;
       message = obj.uri + " should be accepted as a valid URI";
--- a/chrome/test/unit/test_bug564667.js
+++ b/chrome/test/unit/test_bug564667.js
@@ -1,58 +1,55 @@
 /* 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 UNPACKAGED_ADDON = do_get_file("data/test_bug564667");
 const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi");
 
-var gIOS = Cc["@mozilla.org/network/io-service;1"].
-           getService(Ci.nsIIOService);
-
 var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"].
           getService(Ci.nsIChromeRegistry).
           QueryInterface(Ci.nsIXULOverlayProvider);
 
 /*
  * Checks that a mapping was added
  */
 function test_mapping(chromeURL, target) {
-  var uri = gIOS.newURI(chromeURL);
+  var uri = Services.io.newURI(chromeURL);
 
   try {
     var result = gCR.convertChromeURL(uri);
     do_check_eq(result.spec, target);
   } catch (ex) {
     do_throw(chromeURL + " not Registered");
   }
 }
 
 /*
  * Checks that a mapping was removed
  */
 function test_removed_mapping(chromeURL, target) {
-  var uri = gIOS.newURI(chromeURL);
+  var uri = Services.io.newURI(chromeURL);
   try {
     gCR.convertChromeURL(uri);
     do_throw(chromeURL + " not removed");
   } catch (ex) {
     // This should throw
   }
 }
 
 /*
  * Checks if any overlay was added after loading
  * the manifest files
  *
  * @param type The type of overlay: overlay|style
  */
 function test_no_overlays(chromeURL, target, type = "overlay") {
-  var uri = gIOS.newURI(chromeURL);
+  var uri = Services.io.newURI(chromeURL);
   var overlays = (type == "overlay") ?
       gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri);
 
   // We shouldn't be allowed to register overlays nor styles
   if (overlays.hasMoreElements()) {
     if (type == "styles")
       do_throw("Style Registered: " + chromeURL);
     else
@@ -104,13 +101,13 @@ function testManifest(manifestPath, base
 
   // Test Removing Manifest URL
   test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul");
   test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
 }
 
 function run_test() {
   // Test an unpackaged addon
-  testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec);
+  testManifest(UNPACKAGED_ADDON, Services.io.newFileURI(UNPACKAGED_ADDON).spec);
 
   // Test a packaged addon
-  testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/");
+  testManifest(PACKAGED_ADDON, "jar:" + Services.io.newFileURI(PACKAGED_ADDON).spec + "!/");
 }
--- a/chrome/test/unit/test_bug848297.js
+++ b/chrome/test/unit/test_bug848297.js
@@ -13,20 +13,16 @@ Components.utils.import("resource://gre/
 
 registerManifests(MANIFESTS);
 
 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
                 .getService(Ci.nsIXULChromeRegistry)
                 .QueryInterface(Ci.nsIToolkitChromeRegistry);
 chromeReg.checkForNewChrome();
 
-var prefService = Cc["@mozilla.org/preferences-service;1"]
-                  .getService(Ci.nsIPrefService)
-                  .QueryInterface(Ci.nsIPrefBranch);
-
 function enum_to_array(strings) {
   let rv = [];
   while (strings.hasMore()) {
     rv.push(strings.getNext());
   }
   rv.sort();
   return rv;
 }
@@ -36,14 +32,14 @@ function run_test() {
   // without override
   Services.locale.setRequestedLocales(["de"]);
   do_check_eq(chromeReg.getSelectedLocale("basepack"), "en-US");
   do_check_eq(chromeReg.getSelectedLocale("overpack"), "de");
   do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")),
                    ["en-US", "fr"]);
 
   // with override
-  prefService.setCharPref("chrome.override_package.basepack", "overpack");
+  Services.prefs.setCharPref("chrome.override_package.basepack", "overpack");
   do_check_eq(chromeReg.getSelectedLocale("basepack"), "de");
   do_check_matches(enum_to_array(chromeReg.getLocalesForPackage("basepack")),
                    ["de", "en-US"]);
 
 }
--- a/chrome/test/unit/test_crlf.js
+++ b/chrome/test/unit/test_crlf.js
@@ -1,14 +1,12 @@
 registerManifests([do_get_file("data/test_crlf.manifest")]);
 
 function run_test() {
   let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
     getService(Ci.nsIChromeRegistry);
 
-  let ios = Cc["@mozilla.org/network/io-service;1"].
-    getService(Ci.nsIIOService);
-  let sourceURI = ios.newURI("chrome://test_crlf/content/");
+  let sourceURI = Services.io.newURI("chrome://test_crlf/content/");
   // this throws for packages that are not registered
   let file = cr.convertChromeURL(sourceURI).QueryInterface(Ci.nsIFileURL).file;
 
   do_check_true(file.equals(do_get_file("data/test_crlf.xul", true)));
 }
--- a/chrome/test/unit/test_data_protocol_registration.js
+++ b/chrome/test/unit/test_data_protocol_registration.js
@@ -73,19 +73,17 @@ function run_test() {
   let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
            getService(Ci.nsIChromeRegistry);
   cr.checkForNewChrome();
 
   // Check that our override worked
   let expectedURI = "data:application/vnd.mozilla.xul+xml,";
   let sourceURI = "chrome://good-package/content/test.xul";
   try {
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-              getService(Ci.nsIIOService);
-    sourceURI = ios.newURI(sourceURI);
+    sourceURI = Services.io.newURI(sourceURI);
     // this throws for packages that are not registered
     let uri = cr.convertChromeURL(sourceURI).spec;
 
     do_check_eq(expectedURI, uri);
   } catch (e) {
     dump(e + "\n");
     do_throw("Should have registered our URI!");
   }
--- a/chrome/test/unit/test_no_remote_registration.js
+++ b/chrome/test/unit/test_no_remote_registration.js
@@ -173,23 +173,21 @@ function run_test() {
           sourceURI = "chrome://good-package/content/override-" +
                       protocol.scheme + ".xul";
           break;
         case "resource":
           sourceURI = "resource://" + protocol.scheme + "/";
           break;
       }
       try {
-        let ios = Cc["@mozilla.org/network/io-service;1"].
-                  getService(Ci.nsIIOService);
-        sourceURI = ios.newURI(sourceURI);
+        sourceURI = Services.io.newURI(sourceURI);
         let uri;
         if (type == "resource") {
           // resources go about a slightly different way than everything else
-          let rph = ios.getProtocolHandler("resource").
+          let rph = Services.io.getProtocolHandler("resource").
                     QueryInterface(Ci.nsIResProtocolHandler);
           // this throws for packages that are not registered
           uri = rph.resolveURI(sourceURI);
         } else {
           // this throws for packages that are not registered
           uri = cr.convertChromeURL(sourceURI).spec;
         }
 
--- a/chrome/test/unit/test_resolve_uris.js
+++ b/chrome/test/unit/test_resolve_uris.js
@@ -8,27 +8,25 @@ if (typeof registerManifests === "undefi
   load("../unit/head_crtestutils.js");
 }
 
 var manifestFile = do_get_file("../unit/data/test_resolve_uris.manifest");
 
 var manifests = [ manifestFile ];
 registerManifests(manifests);
 
-var ios = Cc["@mozilla.org/network/io-service;1"].
-          getService(Ci.nsIIOService);
-
 function do_run_test() {
   let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
            getService(Ci.nsIChromeRegistry);
 
   // If we don't have libxul or e10s then we don't have process separation, so
   // we don't need to worry about checking for new chrome.
   var appInfo = Cc["@mozilla.org/xre/app-info;1"];
   if (!appInfo ||
+      // eslint-disable-next-line mozilla/use-services
       (appInfo.getService(Ci.nsIXULRuntime).processType ==
        Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)) {
     cr.checkForNewChrome();
   }
 
   // See if our various things were able to register
   let registrationTypes = [
       "content",
@@ -53,26 +51,26 @@ function do_run_test() {
       case "skin":
         expectedURI += "foo.css";
         break;
       case "override":
         sourceURI = "chrome://good-package/content/override-me.xul";
         expectedURI += "override-me.xul";
         break;
       case "resource":
-        expectedURI = ios.newFileURI(manifestFile.parent).spec;
+        expectedURI = Services.io.newFileURI(manifestFile.parent).spec;
         sourceURI = "resource://foo/";
         break;
     }
     try {
-      sourceURI = ios.newURI(sourceURI);
+      sourceURI = Services.io.newURI(sourceURI);
       let uri;
       if (type == "resource") {
         // resources go about a slightly different way than everything else
-        let rph = ios.getProtocolHandler("resource").
+        let rph = Services.io.getProtocolHandler("resource").
             QueryInterface(Ci.nsIResProtocolHandler);
         uri = rph.resolveURI(sourceURI);
       } else {
         uri = cr.convertChromeURL(sourceURI).spec;
       }
 
       do_check_eq(expectedURI, uri);
     } catch (e) {