Bug 1423839 - Part 2: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (manual changes) r=Standard8,jdm
authorJames Lee <jamesl33info@gmail.com>
Mon, 22 Oct 2018 23:42:48 +0000
changeset 490891 0dc37e5676af1f7851a7a86a339d9903fa42e59c
parent 490890 eff50d9238028b1202f7a3d68a7c9da92ddbadcd
child 490892 6615d7dcdec1cde7705d880c932a6ed33b52d806
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
netwerk/test/unit/test_NetUtil.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);
--- a/netwerk/test/unit/test_NetUtil.js
+++ b/netwerk/test/unit/test_NetUtil.js
@@ -245,22 +245,16 @@ function test_newURI_takes_nsIFile()
   // method.
   let iosURI = ios.newFileURI(file);
   let NetUtilURI = NetUtil.newURI(file);
   Assert.ok(iosURI.equals(NetUtilURI));
 
   run_next_test();
 }
 
-function test_ioService()
-{
-  Assert.ok(NetUtil.ioService instanceof Ci.nsIIOService);
-  run_next_test();
-}
-
 function test_asyncFetch_no_channel()
 {
   try {
     NetUtil.asyncFetch(null, function() { });
     do_throw("should throw!");
   }
   catch (e) {
     Assert.equal(e.result, Cr.NS_ERROR_INVALID_ARG);
@@ -514,17 +508,17 @@ function test_newChannel_no_specifier()
 }
 
 function test_newChannel_with_string()
 {
   const TEST_SPEC = "http://mozilla.org";
 
   // Check that we get the same URI back from channel the IO service creates and
   // the channel the utility method creates.
-  let ios = NetUtil.ioService;
+  let ios = Services.io
   let iosChannel = ios.newChannel2(TEST_SPEC,
                                    null,
                                    null,
                                    null,      // aLoadingNode
                                    Services.scriptSecurityManager.getSystemPrincipal(),
                                    null,      // aTriggeringPrincipal
                                    Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                    Ci.nsIContentPolicy.TYPE_OTHER);
@@ -539,41 +533,41 @@ function test_newChannel_with_string()
 
 function test_newChannel_with_nsIURI()
 {
   const TEST_SPEC = "http://mozilla.org";
 
   // Check that we get the same URI back from channel the IO service creates and
   // the channel the utility method creates.
   let uri = NetUtil.newURI(TEST_SPEC);
-  let iosChannel = NetUtil.ioService.newChannelFromURI2(uri,
-                                                        null,      // aLoadingNode
-                                                        Services.scriptSecurityManager.getSystemPrincipal(),
-                                                        null,      // aTriggeringPrincipal
-                                                        Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
-                                                        Ci.nsIContentPolicy.TYPE_OTHER);
+  let iosChannel = Services.io.newChannelFromURI2(uri,
+                                                  null,      // aLoadingNode
+                                                  Services.scriptSecurityManager.getSystemPrincipal(),
+                                                  null,      // aTriggeringPrincipal
+                                                  Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
+                                                  Ci.nsIContentPolicy.TYPE_OTHER);
   let NetUtilChannel = NetUtil.newChannel({
     uri: uri,
     loadUsingSystemPrincipal: true
   });
   Assert.ok(iosChannel.URI.equals(NetUtilChannel.URI));
 
   run_next_test();
 }
 
 function test_newChannel_with_options()
 {
   let uri = "data:text/plain,";
 
-  let iosChannel = NetUtil.ioService.newChannelFromURI2(NetUtil.newURI(uri),
-                                                        null,      // aLoadingNode
-                                                        Services.scriptSecurityManager.getSystemPrincipal(),
-                                                        null,      // aTriggeringPrincipal
-                                                        Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
-                                                        Ci.nsIContentPolicy.TYPE_OTHER);
+  let iosChannel = Services.io.newChannelFromURI2(NetUtil.newURI(uri),
+                                                  null,      // aLoadingNode
+                                                  Services.scriptSecurityManager.getSystemPrincipal(),
+                                                  null,      // aTriggeringPrincipal
+                                                  Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
+                                                  Ci.nsIContentPolicy.TYPE_OTHER);
 
   function checkEqualToIOSChannel(channel) {
     Assert.ok(iosChannel.URI.equals(channel.URI));  
   }
 
   checkEqualToIOSChannel(NetUtil.newChannel({
     uri,
     loadingPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
@@ -773,17 +767,16 @@ function test_readInputStreamToString_in
   test_async_copy,
   test_async_write_file,
   test_async_write_file_deferred,
   test_async_write_file_safe,
   test_async_write_file_safe_deferred,
   test_newURI_no_spec_throws,
   test_newURI,
   test_newURI_takes_nsIFile,
-  test_ioService,
   test_asyncFetch_no_channel,
   test_asyncFetch_no_callback,
   test_asyncFetch_with_nsIChannel,
   test_asyncFetch_with_nsIURI,
   test_asyncFetch_with_string,
   test_asyncFetch_with_nsIFile,
   test_asyncFetch_with_nsIInputString,
   test_asyncFetch_does_not_block,