Bug 1461966 - Enable ESLint rule mozilla/use-services for extensions/pref. r=mkaply
authorMark Banner <standard8@mozilla.com>
Wed, 16 May 2018 14:39:29 +0100
changeset 472713 91762db62c2b724685bab9235b9f55baa46a2f1e
parent 472712 d90a5a4aab56b989e8780970ede900dd39916535
child 472714 b51c2e39a12a52fe7310f9dfa21e51e61fa48105
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply
bugs1461966
milestone62.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 1461966 - Enable ESLint rule mozilla/use-services for extensions/pref. r=mkaply MozReview-Commit-ID: 77pSaX70zdJ
.eslintrc.js
extensions/pref/autoconfig/src/prefcalls.js
extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -34,25 +34,16 @@ module.exports = {
       "browser/base/content/urlbarBindings.xml",
       "browser/components/search/content/search.xml",
       "browser/components/translation/translation-infobar.xml",
       "toolkit/components/prompts/content/tabprompts.xml"
     ],
     "env": {
       "mozilla/browser-window": true
     }
-  },{
-    // XXX Bug 1421969. These files/directories are still being fixed,
-    // so turn off mozilla/use-services for them for now.
-    "files": [
-      "extensions/pref/**",
-    ],
-    "rules": {
-      "mozilla/use-services": "off",
-    }
   }, {
     // XXX Bug 1436303. These directories are still being fixed, so turn off
     // mozilla/no-cc-etc for now.
     "files": [
       "devtools/**"
     ],
     "rules": {
       "mozilla/no-define-cc-etc": "off",
--- a/extensions/pref/autoconfig/src/prefcalls.js
+++ b/extensions/pref/autoconfig/src/prefcalls.js
@@ -6,16 +6,19 @@
 
 const nsILDAPURL = Ci.nsILDAPURL;
 const LDAPURLContractID = "@mozilla.org/network/ldap-url;1";
 const nsILDAPSyncQuery = Ci.nsILDAPSyncQuery;
 const LDAPSyncQueryContractID = "@mozilla.org/ldapsyncquery;1";
 const nsIPrefService = Ci.nsIPrefService;
 const PrefServiceContractID = "@mozilla.org/preferences-service;1";
 
+// ChromeUtils isn't available here, so we can't use Services.*
+/* eslint-disable mozilla/use-services */
+
 var gVersion;
 var gIsUTF8;
 
 function getPrefBranch() {
 
     var prefService = Cc[PrefServiceContractID]
                         .getService(nsIPrefService);
     return prefService.getBranch(null);
--- a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
+++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
@@ -1,35 +1,30 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* eslint no-unsafe-finally: "off"*/
 /* Turning off this rule to allow control flow operations in finally block
  * http://eslint.org/docs/rules/no-unsafe-finally  */
+
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 function run_test() {
-  let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  let obsvc = Cc["@mozilla.org/observer-service;1"].
-              getService(Ci.nsIObserverService);
-  let ps = Cc["@mozilla.org/preferences-service;1"].
-           getService(Ci.nsIPrefService);
-  let prefs = ps.getBranch(null);
-
-  let greD = dirSvc.get("GreD", Ci.nsIFile);
-  let defaultPrefD = dirSvc.get("PrfDef", Ci.nsIFile);
+  let greD = Services.dirsvc.get("GreD", Ci.nsIFile);
+  let defaultPrefD = Services.dirsvc.get("PrfDef", Ci.nsIFile);
   let testDir = do_get_cwd();
 
   try {
     let autoConfigJS = testDir.clone();
     autoConfigJS.append("autoconfig.js");
     autoConfigJS.copyTo(defaultPrefD, "autoconfig.js");
 
     // Make sure nsReadConfig is initialized.
     Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports);
-    ps.resetPrefs();
+    Services.prefs.resetPrefs();
 
     var tests = [{
       filename: "autoconfig-utf8.cfg",
       prefs: {
         "_test.string.ASCII": "UTF-8",
         "_test.string.non-ASCII": "日本語",
         "_test.string.getPref": "日本語",
         "_test.string.gIsUTF8": "true"
@@ -42,34 +37,34 @@ function run_test() {
         "_test.string.getPref": "日本語",
         "_test.string.gIsUTF8": "false",
       }
     }];
 
     function testAutoConfig(test) {
       // Make sure pref values are unset.
       for (let prefName in test.prefs) {
-        Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, prefs.getPrefType(prefName));
+        Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, Services.prefs.getPrefType(prefName));
       }
 
       let autoConfigCfg = testDir.clone();
       autoConfigCfg.append(test.filename);
       autoConfigCfg.copyTo(greD, "autoconfig.cfg");
 
-      obsvc.notifyObservers(ps, "prefservice:before-read-userprefs");
+      Services.obs.notifyObservers(Services.prefs, "prefservice:before-read-userprefs");
 
       for (let prefName in test.prefs) {
         Assert.equal(test.prefs[prefName],
-                     prefs.getStringPref(prefName));
+                     Services.prefs.getStringPref(prefName));
       }
 
-      ps.resetPrefs();
+      Services.prefs.resetPrefs();
       // Make sure pref values are reset.
       for (let prefName in test.prefs) {
-        Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, prefs.getPrefType(prefName));
+        Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, Services.prefs.getPrefType(prefName));
       }
     }
 
     tests.forEach(testAutoConfig);
 
   } finally {
     try {
       let autoConfigJS = defaultPrefD.clone();
@@ -86,11 +81,11 @@ function run_test() {
       autoConfigCfg.append("autoconfig.cfg");
       autoConfigCfg.remove(false);
     } catch (e) {
       if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
         throw e;
       }
     }
 
-    ps.resetPrefs();
+    Services.prefs.resetPrefs();
   }
 }