Bug 1162657 - Turn NewChannel deprecation warnings into assertions (r=sworkman,sicking,paolo)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Wed, 13 May 2015 17:58:52 -0700
changeset 243788 66a72727e1b3247834e8828b3727d8926dfd2c73
parent 243787 9c18f3e4d02ae785e942c9a6525a7d7217339b48
child 243789 5017c72ac8aa928a83a9934b5bb4d0a8621715fa
push id28753
push userkwierso@gmail.com
push dateThu, 14 May 2015 22:33:43 +0000
treeherdermozilla-central@07e2e15703cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman, sicking, paolo
bugs1162657
milestone41.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 1162657 - Turn NewChannel deprecation warnings into assertions (r=sworkman,sicking,paolo)
netwerk/base/nsIOService.cpp
netwerk/test/unit/test_NetUtil.js
toolkit/components/jsdownloads/test/unit/head.js
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -595,17 +595,17 @@ nsIOService::NewChannelFromURIWithLoadIn
  *        * aSecurityFlags
  *        * aContentPolicyType
  *
  * See nsIIoService.idl for a detailed description of those arguments
  */
 NS_IMETHODIMP
 nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
 {
-  NS_WARNING("Deprecated, use NewChannelFromURI2 providing loadInfo arguments!");
+  NS_ASSERTION(false, "Deprecated, use NewChannelFromURI2 providing loadInfo arguments!");
   return NewChannelFromURI2(aURI,
                             nullptr, // aLoadingNode
                             nullptr, // aLoadingPrincipal
                             nullptr, // aTriggeringPrincipal
                             nsILoadInfo::SEC_NORMAL,
                             nsIContentPolicy::TYPE_OTHER,
                             result);
 }
@@ -759,20 +759,18 @@ nsIOService::NewChannelFromURIWithProxyF
 
     if (aLoadingNode || aLoadingPrincipal) {
       nsCOMPtr<nsINode> loadingNode(do_QueryInterface(aLoadingNode));
       loadInfo = new mozilla::LoadInfo(aLoadingPrincipal,
                                        aTriggeringPrincipal,
                                        loadingNode,
                                        aSecurityFlags,
                                        aContentPolicyType);
-      if (!loadInfo) {
-        return NS_ERROR_UNEXPECTED;
-      }
     }
+    NS_ASSERTION(loadInfo, "Please pass security info when creating a channel");
     return NewChannelFromURIWithProxyFlagsInternal(aURI,
                                                    aProxyURI,
                                                    aProxyFlags,
                                                    loadInfo,
                                                    result);
 }
 
 /*  ***** DEPRECATED *****
@@ -786,17 +784,17 @@ nsIOService::NewChannelFromURIWithProxyF
  * See nsIIoService.idl for a detailed description of those arguments
  */
 NS_IMETHODIMP
 nsIOService::NewChannelFromURIWithProxyFlags(nsIURI *aURI,
                                              nsIURI *aProxyURI,
                                              uint32_t aProxyFlags,
                                              nsIChannel **result)
 {
-  NS_WARNING("Deprecated, use NewChannelFromURIWithProxyFlags2 providing loadInfo arguments!");
+  NS_ASSERTION(false, "Deprecated, use NewChannelFromURIWithProxyFlags2 providing loadInfo arguments!");
   return NewChannelFromURIWithProxyFlags2(aURI,
                                           aProxyURI,
                                           aProxyFlags,
                                           nullptr, // aLoadingNode
                                           nullptr, // aLoadingPrincipal
                                           nullptr, // aTriggeringPrincipal
                                           nsILoadInfo::SEC_NORMAL,
                                           nsIContentPolicy::TYPE_OTHER,
@@ -836,17 +834,17 @@ nsIOService::NewChannel2(const nsACStrin
  *        * aSecurityFlags
  *        * aContentPolicyType
  *
  * See nsIIoService.idl for a detailed description of those arguments
  */
 NS_IMETHODIMP
 nsIOService::NewChannel(const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, nsIChannel **result)
 {
-  NS_WARNING("Deprecated, use NewChannel2 providing loadInfo arguments!");
+  NS_ASSERTION(false, "Deprecated, use NewChannel2 providing loadInfo arguments!");
   return NewChannel2(aSpec,
                      aCharset,
                      aBaseURI,
                      nullptr, // aLoadingNode
                      nullptr, // aLoadingPrincipal
                      nullptr, // aTriggeringPrincipal
                      nsILoadInfo::SEC_NORMAL,
                      nsIContentPolicy::TYPE_OTHER,
--- a/netwerk/test/unit/test_NetUtil.js
+++ b/netwerk/test/unit/test_NetUtil.js
@@ -525,17 +525,20 @@ function test_newChannel_with_string()
   let iosChannel = ios.newChannel2(TEST_SPEC,
                                    null,
                                    null,
                                    null,      // aLoadingNode
                                    Services.scriptSecurityManager.getSystemPrincipal(),
                                    null,      // aTriggeringPrincipal
                                    Ci.nsILoadInfo.SEC_NORMAL,
                                    Ci.nsIContentPolicy.TYPE_OTHER);
-  let NetUtilChannel = NetUtil.newChannel(TEST_SPEC);
+  let NetUtilChannel = NetUtil.newChannel({
+    uri: TEST_SPEC,
+    loadUsingSystemPrincipal: true
+  });
   do_check_true(iosChannel.URI.equals(NetUtilChannel.URI));
 
   run_next_test();
 }
 
 function test_newChannel_with_nsIURI()
 {
   const TEST_SPEC = "http://mozilla.org";
@@ -544,39 +547,20 @@ function test_newChannel_with_nsIURI()
   // 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_NORMAL,
                                                         Ci.nsIContentPolicy.TYPE_OTHER);
-  let NetUtilChannel = NetUtil.newChannel(uri);
-  do_check_true(iosChannel.URI.equals(NetUtilChannel.URI));
-
-  run_next_test();
-}
-
-function test_newChannel_with_nsIFile()
-{
-  let file = Cc["@mozilla.org/file/directory_service;1"].
-             getService(Ci.nsIProperties).
-             get("ProfD", Ci.nsIFile);
-  file.append("NetUtil-test-file.tmp");
-
-  // 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(file);
-  let iosChannel = NetUtil.ioService.newChannelFromURI2(uri,
-                                                        null,      // aLoadingNode
-                                                        Services.scriptSecurityManager.getSystemPrincipal(),
-                                                        null,      // aTriggeringPrincipal
-                                                        Ci.nsILoadInfo.SEC_NORMAL,
-                                                        Ci.nsIContentPolicy.TYPE_OTHER);
-  let NetUtilChannel = NetUtil.newChannel(file);
+  let NetUtilChannel = NetUtil.newChannel({
+    uri: uri,
+    loadUsingSystemPrincipal: true
+  });
   do_check_true(iosChannel.URI.equals(NetUtilChannel.URI));
 
   run_next_test();
 }
 
 function test_newChannel_with_options()
 {
   let uri = "data:text/plain,";
@@ -797,17 +781,16 @@ function test_readInputStreamToString_in
   test_asyncFetch_with_nsIURI,
   test_asyncFetch_with_string,
   test_asyncFetch_with_nsIFile,
   test_asyncFetch_with_nsIInputString,
   test_asyncFetch_does_not_block,
   test_newChannel_no_specifier,
   test_newChannel_with_string,
   test_newChannel_with_nsIURI,
-  test_newChannel_with_nsIFile,
   test_newChannel_with_options,
   test_newChannel_with_wrong_options,
   test_readInputStreamToString,
   test_readInputStreamToString_no_input_stream,
   test_readInputStreamToString_no_bytes_arg,
   test_readInputStreamToString_blocking_stream,
   test_readInputStreamToString_too_many_bytes,
   test_readInputStreamToString_with_charset,
--- a/toolkit/components/jsdownloads/test/unit/head.js
+++ b/toolkit/components/jsdownloads/test/unit/head.js
@@ -529,17 +529,17 @@ function promiseVerifyContents(aPath, aE
     }
 
     if ((yield OS.File.stat(aPath)).size == 0) {
       do_throw("File is empty: " + aPath);
     }
 
     let deferred = Promise.defer();
     NetUtil.asyncFetch(
-      file,
+      { uri: NetUtil.newURI(file), loadUsingSystemPrincipal: true },
       function(aInputStream, aStatus) {
         do_check_true(Components.isSuccessCode(aStatus));
         let contents = NetUtil.readInputStreamToString(aInputStream,
                                                        aInputStream.available());
         if (contents.length > TEST_DATA_SHORT.length * 2 ||
             /[^\x20-\x7E]/.test(contents)) {
           // Do not print the entire content string to the test log.
           do_check_eq(contents.length, aExpectedContents.length);