bug 758673 - nsprotocolproxyservice::asyncResolve applies filters twice r=biesi
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 27 Aug 2012 16:25:53 -0400
changeset 105685 03dce8e94aa9c66c6f824089317401800af09439
parent 105684 1a3111e8b478f7899e8750626578153197c3b9f3
child 105686 cd551da155fb1c6d9c56f3193164ac085118728f
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersbiesi
bugs758673
milestone18.0a1
bug 758673 - nsprotocolproxyservice::asyncResolve applies filters twice r=biesi
netwerk/base/src/nsProtocolProxyService.cpp
netwerk/test/unit/test_protocolproxyservice.js
--- a/netwerk/base/src/nsProtocolProxyService.cpp
+++ b/netwerk/base/src/nsProtocolProxyService.cpp
@@ -140,22 +140,21 @@ private:
         // the queue that wants to call DoCallback.  No need to wait for
         // it, just run the callback now.
         DoCallback();
     }
 
     void DoCallback()
     {
         // Generate proxy info from the PAC string if appropriate
-        if (NS_SUCCEEDED(mStatus) && !mProxyInfo && !mPACString.IsEmpty())
+        if (NS_SUCCEEDED(mStatus) && !mProxyInfo && !mPACString.IsEmpty()) {
             mPPS->ProcessPACString(mPACString, mResolveFlags,
                                    getter_AddRefs(mProxyInfo));
 
-        // Now apply proxy filters
-        if (NS_SUCCEEDED(mStatus)) {
+            // Now apply proxy filters
             nsProtocolInfo info;
             mStatus = mPPS->GetProtocolInfo(mURI, &info);
             if (NS_SUCCEEDED(mStatus))
                 mPPS->ApplyFilters(mURI, info, mProxyInfo);
             else
                 mProxyInfo = nullptr;
         }
 
--- a/netwerk/test/unit/test_protocolproxyservice.js
+++ b/netwerk/test/unit/test_protocolproxyservice.js
@@ -117,16 +117,33 @@ BasicFilter.prototype = {
     throw Components.results.NS_ERROR_NO_INTERFACE;
   },
   applyFilter: function(pps, uri, pi) {
     return pps.newProxyInfo("http", "localhost", 8080, 0, 10,
            pps.newProxyInfo("direct", "", -1, 0, 0, null));
   }
 };
 
+function resolveCallback() { }
+resolveCallback.prototype = {
+  nextFunction: null,
+
+  QueryInterface : function (iid) {
+    const interfaces = [Components.interfaces.nsIProtocolProxyCallback,
+                        Components.interfaces..nsISupports];
+    if (!interfaces.some( function(v) { return iid.equals(v) } ))
+      throw Components.results.NS_ERROR_NO_INTERFACE;
+    return this;
+  },
+
+  onProxyAvailable : function (req, uri, pi, status) {
+    this.nextFunction(pi);
+  }
+};
+
 function run_filter_test() {
   var uri = ios.newURI("http://www.mozilla.org/", null, null);
 
   // Verify initial state
 
   var pi = pps.resolve(uri, 0);
   do_check_eq(pi, null);
 
@@ -178,16 +195,39 @@ function run_filter_test2() {
 
   // Remove filter and verify that we return to the initial state
 
   pps.unregisterFilter(filter1);
   pi = pps.resolve(uri, 0);
   do_check_eq(pi, null);
 }
 
+var filter_3_1;
+
+function run_filter_test3() {
+  var uri = ios.newURI("http://www.mozilla.org/", null, null);
+
+  // Push a filter and verify the results asynchronously
+
+  filter_3_1 = new TestFilter("http", "foo", 8080, 0, 10);
+  pps.registerFilter(filter_3_1, 20);
+
+  var cb = new resolveCallback();
+  cb.nextFunction = filter_test3_1;
+  var req = pps.asyncResolve(uri, 0, cb);
+  do_test_pending();
+}
+
+function filter_test3_1(pi) {
+  check_proxy(pi, "http", "foo", 8080, 0, 10, false);
+  pps.unregisterFilter(filter_3_1);
+  run_test_continued_3();
+  do_test_finished();
+}
+
 function run_pref_test() {
   var uri = ios.newURI("http://www.mozilla.org/", null, null);
 
   var prefs = Components.classes["@mozilla.org/preferences-service;1"]
                         .getService(Components.interfaces.nsIPrefBranch);
 
   // Verify 'direct' setting
 
@@ -431,14 +471,18 @@ function run_test() {
   run_filter_test2();
   run_pref_test();
   run_pac_test();
   // additional tests may be added to run_test_continued
 }
 
 function run_test_continued() {
   run_pac_cancel_test();
-  // additional tests may be added to run_test_continued_2
+  // additional tests may be added to run_test_continued_3
 }
 
 function run_test_continued_2() {
+  run_filter_test3();
+}
+
+function run_test_continued_3() {
   run_proxy_host_filters_test();
 }