Bug 1552248 support ftp channel in proxy api r=mayhemer,kmag
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 20 May 2019 15:05:26 +0000
changeset 536395 8e0d5b9e2749609e129311f753a2e52812d7b628
parent 536394 eacd30627fc660844795e43a26e1889a74220518
child 536396 02dcc7ca124a724fa2c5fe193a24a349ef10d603
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, kmag
bugs1552248
milestone68.0
Bug 1552248 support ftp channel in proxy api r=mayhemer,kmag ChannelWrapper is used throughout webext APIs and it requires a channel to support weakref. FTPChannel did not, thus ftp requests did not go through proxy.onRequest. Differential Revision: https://phabricator.services.mozilla.com/D31540
netwerk/protocol/ftp/nsFTPChannel.cpp
netwerk/protocol/ftp/nsFTPChannel.h
toolkit/components/extensions/test/xpcshell/test_proxy_listener.js
toolkit/components/extensions/test/xpcshell/test_proxy_scripts_results.js
--- a/netwerk/protocol/ftp/nsFTPChannel.cpp
+++ b/netwerk/protocol/ftp/nsFTPChannel.cpp
@@ -22,16 +22,17 @@ extern LazyLogModule gFTPLog;
 // initiated by the server (PORT command) or by the client (PASV command).
 // Client initiation is the most common case and is attempted first.
 
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS_INHERITED(nsFtpChannel, nsBaseChannel, nsIUploadChannel,
                             nsIResumableChannel, nsIFTPChannel,
                             nsIProxiedChannel, nsIForcePendingChannel,
+                            nsISupportsWeakReference,
                             nsIChannelWithDivertableParentListener)
 
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsFtpChannel::SetUploadStream(nsIInputStream* stream,
                               const nsACString& contentType,
                               int64_t contentLength) {
--- a/netwerk/protocol/ftp/nsFTPChannel.h
+++ b/netwerk/protocol/ftp/nsFTPChannel.h
@@ -13,26 +13,28 @@
 #include "nsCOMPtr.h"
 #include "nsIChannelWithDivertableParentListener.h"
 #include "nsIFTPChannel.h"
 #include "nsIForcePendingChannel.h"
 #include "nsIUploadChannel.h"
 #include "nsIProxyInfo.h"
 #include "nsIProxiedChannel.h"
 #include "nsIResumableChannel.h"
+#include "nsWeakReference.h"
 
 class nsIURI;
 using mozilla::net::ADivertableParentChannel;
 
 class nsFtpChannel final : public nsBaseChannel,
                            public nsIFTPChannel,
                            public nsIUploadChannel,
                            public nsIResumableChannel,
                            public nsIProxiedChannel,
                            public nsIForcePendingChannel,
+                           public nsSupportsWeakReference,
                            public nsIChannelWithDivertableParentListener {
  public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIUPLOADCHANNEL
   NS_DECL_NSIRESUMABLECHANNEL
   NS_DECL_NSIPROXIEDCHANNEL
   NS_DECL_NSICHANNELWITHDIVERTABLEPARENTLISTENER
 
--- a/toolkit/components/extensions/test/xpcshell/test_proxy_listener.js
+++ b/toolkit/components/extensions/test/xpcshell/test_proxy_listener.js
@@ -153,27 +153,25 @@ add_task(async function test_proxy_liste
 });
 
 async function getExtension(expectedProxyInfo) {
   function background(proxyInfo) {
     browser.test.log(`testing proxy.onRequest with proxyInfo = ${JSON.stringify(proxyInfo)}`);
     browser.proxy.onRequest.addListener(details => {
       return proxyInfo;
     }, {urls: ["<all_urls>"]});
-    browser.test.sendMessage("ready");
   }
   let extensionData = {
     manifest: {
       "permissions": ["proxy", "<all_urls>"],
     },
     background: `(${background})(${JSON.stringify(expectedProxyInfo)})`,
   };
   let extension = ExtensionTestUtils.loadExtension(extensionData);
   await extension.startup();
-  await extension.awaitMessage("ready");
   return extension;
 }
 
 add_task(async function test_passthrough() {
   let ext1 = await getExtension(null);
   let ext2 = await getExtension({host: "1.2.3.4", port: 8888, type: "https"});
 
   // Also use a restricted url to test the ability to proxy those.
@@ -184,8 +182,20 @@ add_task(async function test_passthrough
   equal(proxyInfo.type, "https", `second extension won`);
 
   await ext2.unload();
 
   proxyInfo = await getProxyInfo();
   equal(proxyInfo, null, `expected no proxy`);
   await ext1.unload();
 });
+
+add_task(async function test_ftp() {
+  let extension = await getExtension({host: "1.2.3.4", port: 8888, type: "http"});
+
+  let proxyInfo = await getProxyInfo("ftp://somewhere.mozilla.org/");
+
+  equal(proxyInfo.host, "1.2.3.4", `proxy host correct`);
+  equal(proxyInfo.port, "8888", `proxy port correct`);
+  equal(proxyInfo.type, "http", `proxy type correct`);
+
+  await extension.unload();
+});
--- a/toolkit/components/extensions/test/xpcshell/test_proxy_scripts_results.js
+++ b/toolkit/components/extensions/test/xpcshell/test_proxy_scripts_results.js
@@ -51,24 +51,24 @@ add_task(async function setup() {
 
 async function setupProxyScript(proxy) {
   extension.sendMessage("set-proxy", {proxy});
   let proxyInfoSent = await extension.awaitMessage("proxy-set");
   deepEqual(proxyInfoSent, proxy, "got back proxy data from proxy script");
 }
 
 async function testProxyResolution(test) {
-  let {proxy, expected} = test;
+  let {uri, proxy, expected} = test;
   let errorMsg;
   if (expected.error) {
     errorMsg = extension.awaitMessage("proxy-error-received");
   }
   let proxyInfo = await new Promise((resolve, reject) => {
     let channel = NetUtil.newChannel({
-      uri: "http://www.mozilla.org/",
+      uri,
       loadUsingSystemPrincipal: true,
     });
 
     gProxyService.asyncResolve(channel, 0, {
       onProxyAvailable(req, uri, pi, status) {
         resolve(pi && pi.QueryInterface(Ci.nsIProxyInfo));
       },
     });
@@ -198,16 +198,28 @@ add_task(async function test_pac_results
           host: "1.2.3.4",
           port: "8080",
           type: "http",
           failoverProxy: null,
         },
       },
     },
     {
+      uri: "ftp://mozilla.org",
+      proxy: "PROXY 1.2.3.4:8080",
+      expected: {
+        proxyInfo: {
+          host: "1.2.3.4",
+          port: "8080",
+          type: "http",
+          failoverProxy: null,
+        },
+      },
+    },
+    {
       proxy: "   PROXY    2.3.4.5:8080      ",
       expected: {
         proxyInfo: {
           host: "2.3.4.5",
           port: "8080",
           type: "http",
           failoverProxy: null,
         },
@@ -324,16 +336,19 @@ add_task(async function test_pac_results
             },
           },
         },
       },
     },
   ];
   for (let test of tests) {
     await setupProxyScript(test.proxy);
+    if (!test.uri) {
+      test.uri = "http://www.mozilla.org/";
+    }
     await testProxyResolution(test);
     // Our proxy script for testing is stateless, so repeating the test should
     // yield exactly the same results.
     await testProxyResolution(test);
   }
 });
 
 add_task(async function shutdown() {