Bug 1423839 - Part 2: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (manual changes) r=Standard8,jdm
☠☠ backed out by bb628db88145 ☠ ☠
authorJames Lee <jamesl33info@gmail.com>
Mon, 22 Oct 2018 19:41:58 +0000
changeset 490815 501fffbf872d0a320069448010aa0706d3b81409
parent 490814 406ca9722ffaa14caf02923c541942725f835d32
child 490816 6ad9bd572bf46896dead808303c652bfb9f8d37a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersStandard8, jdm
bugs1423839
milestone65.0a1
Bug 1423839 - Part 2: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (manual changes) r=Standard8,jdm Depends on D9293. Differential Revision: https://phabricator.services.mozilla.com/D9294
netwerk/base/NetUtil.jsm
netwerk/cookie/test/unit/test_bug1155169.js
netwerk/cookie/test/unit/test_bug1321912.js
netwerk/cookie/test/unit/test_eviction.js
netwerk/cookie/test/unit/test_parser_0001.js
netwerk/cookie/test/unit/test_parser_0019.js
--- a/netwerk/base/NetUtil.jsm
+++ b/netwerk/base/NetUtil.jsm
@@ -12,17 +12,16 @@ var EXPORTED_SYMBOLS = [
  * Necko utilities
  */
 
 // //////////////////////////////////////////////////////////////////////////////
 // // Constants
 
 const PR_UINT32_MAX = 0xffffffff;
 
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
                                                  "nsIBinaryInputStream", "setInputStream");
 
 // //////////////////////////////////////////////////////////////////////////////
 // // NetUtil Object
 
@@ -188,20 +187,20 @@ var NetUtil = {
                 "Must have a non-null string spec or nsIFile object",
                 Cr.NS_ERROR_INVALID_ARG,
                 Components.stack.caller
             );
             throw exception;
         }
 
         if (aTarget instanceof Ci.nsIFile) {
-            return this.ioService.newFileURI(aTarget);
+            return Services.io.newFileURI(aTarget);
         }
 
-        return this.ioService.newURI(aTarget, aOriginCharset, aBaseURI);
+        return Services.io.newURI(aTarget, aOriginCharset, aBaseURI);
     },
 
     /**
      * Constructs a new channel for the given source.
      *
      * Keep in mind that URIs coming from a webpage should *never* use the
      * systemPrincipal as the loadingPrincipal.
      *
@@ -311,22 +310,22 @@ var NetUtil = {
                     " the options object unless loading from system principal.",
                     Cr.NS_ERROR_INVALID_ARG,
                     Components.stack.caller
                 );
             }
             contentPolicyType = Ci.nsIContentPolicy.TYPE_OTHER;
         }
 
-        return this.ioService.newChannelFromURI2(uri,
-                                                 loadingNode || null,
-                                                 loadingPrincipal || null,
-                                                 triggeringPrincipal || null,
-                                                 securityFlags,
-                                                 contentPolicyType);
+        return Services.io.newChannelFromURI2(uri,
+                                              loadingNode || null,
+                                              loadingPrincipal || null,
+                                              triggeringPrincipal || null,
+                                              securityFlags,
+                                              contentPolicyType);
     },
 
     /**
      * Reads aCount bytes from aInputStream into a string.
      *
      * @param aInputStream
      *        The input stream to read from.
      * @param aCount
@@ -436,20 +435,9 @@ var NetUtil = {
             aCount = aInputStream.available();
         }
 
         let stream = new BinaryInputStream(aInputStream);
         let result = new ArrayBuffer(aCount);
         stream.readArrayBuffer(result.byteLength, result);
         return result;
     },
-
-    /**
-     * Returns a reference to nsIIOService.
-     *
-     * @return a reference to nsIIOService.
-     */
-    get ioService() {
-        delete this.ioService;
-        return this.ioService = Cc["@mozilla.org/network/io-service;1"].
-                                getService(Ci.nsIIOService);
-    },
 };
--- a/netwerk/cookie/test/unit/test_bug1155169.js
+++ b/netwerk/cookie/test/unit/test_bug1155169.js
@@ -36,35 +36,35 @@ function run_test() {
 
   // Reset cookie.
   setCookie("foo=bar", {
     type: "changed", isSession: true, isSecure: false, isHttpOnly: false,
   });
 }
 
 function setCookie(value, expected) {
-  function setCookieInternal(value, expected = null) {
+  function setCookieInternal(valueInternal, expectedInternal = null) {
     function observer(subject, topic, data) {
-      if (!expected) {
+      if (!expectedInternal) {
         do_throw("no notification expected");
         return;
       }
 
       // Check we saw the right notification.
-      Assert.equal(data, expected.type);
+      Assert.equal(data, expectedInternal.type);
 
       // Check cookie details.
       let cookie = subject.QueryInterface(Ci.nsICookie2);
-      Assert.equal(cookie.isSession, expected.isSession);
-      Assert.equal(cookie.isSecure, expected.isSecure);
-      Assert.equal(cookie.isHttpOnly, expected.isHttpOnly);
+      Assert.equal(cookie.isSession, expectedInternal.isSession);
+      Assert.equal(cookie.isSecure, expectedInternal.isSecure);
+      Assert.equal(cookie.isHttpOnly, expectedInternal.isHttpOnly);
     }
 
     Services.obs.addObserver(observer, "cookie-changed");
-    cs.setCookieStringFromHttp(URI, null, null, value, null, null);
+    cs.setCookieStringFromHttp(URI, null, null, valueInternal, null, null);
     Services.obs.removeObserver(observer, "cookie-changed");
   }
 
   // Check that updating/inserting the cookie works.
   setCookieInternal(value, expected);
 
   // Check that we ignore identical cookies.
   setCookieInternal(value);
--- a/netwerk/cookie/test/unit/test_bug1321912.js
+++ b/netwerk/cookie/test/unit/test_bug1321912.js
@@ -1,19 +1,17 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 do_get_profile();
-const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
+const dirSvc = Services.dirsvc;
 
 let dbFile = dirSvc.get("ProfD", Ci.nsIFile);
 dbFile.append("cookies.sqlite");
 
-let storage = Cc["@mozilla.org/storage/service;1"].
-              getService(Ci.mozIStorageService);
+let storage = Services.storage;
 let properties = Cc["@mozilla.org/hash-property-bag;1"].
                  createInstance(Ci.nsIWritablePropertyBag);
 properties.setProperty("shared", true);
 let conn = storage.openDatabase(dbFile);
 
 // Write the schema v7 to the database.
 conn.schemaVersion = 7;
 conn.executeSimpleSQL("CREATE TABLE moz_cookies (" +
@@ -44,18 +42,17 @@ let now = Date.now();
 conn.executeSimpleSQL("INSERT INTO moz_cookies(" +
   "baseDomain, host, name, value, path, expiry, " +
   "lastAccessed, creationTime, isSecure, isHttpOnly) VALUES (" +
   "'foo.com', '.foo.com', 'foo', 'bar=baz', '/', " +
   now + ", " + now + ", " + now + ", 1, 1)");
 
 // Now start the cookie service, and then check the fields in the table.
 // Get sessionEnumerator to wait for the initialization in cookie thread
-const enumerator = Cc["@mozilla.org/cookieService;1"].
-                   getService(Ci.nsICookieManager).sessionEnumerator;
+const enumerator = Services.cookies.sessionEnumerator;
 
 Assert.equal(conn.schemaVersion, 9);
 let stmt = conn.createStatement("SELECT sql FROM sqlite_master " +
                                   "WHERE type = 'table' AND " +
                                   "      name = 'moz_cookies'");
 try {
   Assert.ok(stmt.executeStep());
   let sql = stmt.getString(0);
--- a/netwerk/cookie/test/unit/test_eviction.js
+++ b/netwerk/cookie/test/unit/test_eviction.js
@@ -2,17 +2,16 @@ ChromeUtils.import("resource://gre/modul
 
 const BASE_HOSTNAMES = ["example.org", "example.co.uk"];
 const SUBDOMAINS = ["", "pub.", "www.", "other."];
 
 const cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
 const cm = cs.QueryInterface(Ci.nsICookieManager);
 
 function run_test() {
-    var tests = [];
     Services.prefs.setIntPref("network.cookie.staleThreshold", 0);
     add_task(async function() {
         await test_basic_eviction("example.org");
         cm.removeAll();
     });
 
     run_next_test();
 }
--- a/netwerk/cookie/test/unit/test_parser_0001.js
+++ b/netwerk/cookie/test/unit/test_parser_0001.js
@@ -1,15 +1,13 @@
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 function inChildProcess() {
-  return Cc["@mozilla.org/xre/app-info;1"]
-           .getService(Ci.nsIXULRuntime)
-           .processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+  return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
 }
 
 function run_test() {
   // Allow all cookies if the pref service is available in this process.
   if (!inChildProcess())
     Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
   let cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
--- a/netwerk/cookie/test/unit/test_parser_0019.js
+++ b/netwerk/cookie/test/unit/test_parser_0019.js
@@ -1,15 +1,13 @@
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 function inChildProcess() {
-  return Cc["@mozilla.org/xre/app-info;1"]
-           .getService(Ci.nsIXULRuntime)
-           .processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+  return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
 }
 
 function run_test() {
   // Allow all cookies if the pref service is available in this process.
   if (!inChildProcess())
     Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
   let cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);