bug 799470 - pac dnsResolve wrong return code on error r=biesi
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 09 Oct 2012 13:52:26 -0400
changeset 109766 1c6b5cae9dc164b2f18ccba4dcfd149fbea1b134
parent 109765 cb9aa35ad1caa4c666dc19053fd40330b995ee08
child 109767 f468573e0725553ad76546cd3d6ce0c22b69c6e5
push id23652
push userryanvm@gmail.com
push dateWed, 10 Oct 2012 01:10:20 +0000
treeherdermozilla-central@5cca0408a73f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi
bugs799470
milestone19.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 799470 - pac dnsResolve wrong return code on error r=biesi
netwerk/base/src/ProxyAutoConfig.cpp
netwerk/test/unit/test_protocolproxyservice.js
--- a/netwerk/base/src/ProxyAutoConfig.cpp
+++ b/netwerk/base/src/ProxyAutoConfig.cpp
@@ -391,21 +391,24 @@ JSBool PACDnsResolve(JSContext *cx, unsi
   if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &arg1))
     return false;
 
   nsDependentJSString hostName;
   nsAutoCString dottedDecimal;
 
   if (!hostName.init(cx, arg1))
     return false;
-  if (!PACResolveToString(NS_ConvertUTF16toUTF8(hostName), dottedDecimal, 0))
-    return false;
-
-  JSString *dottedDecimalString = JS_NewStringCopyZ(cx, dottedDecimal.get());
-  JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(dottedDecimalString));
+  if (PACResolveToString(NS_ConvertUTF16toUTF8(hostName), dottedDecimal, 0)) {
+    JSString *dottedDecimalString = JS_NewStringCopyZ(cx, dottedDecimal.get());
+    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(dottedDecimalString));
+  }
+  else {
+    JS_SET_RVAL(cx, vp, JSVAL_NULL);
+  }
+  
   return true;
 }
 
 // myIpAddress() javascript implementation
 static
 JSBool PACMyIpAddress(JSContext *cx, unsigned int argc, jsval *vp)
 {
   if (NS_IsMainThread()) {
--- a/netwerk/test/unit/test_protocolproxyservice.js
+++ b/netwerk/test/unit/test_protocolproxyservice.js
@@ -11,16 +11,17 @@
 // run_filter_test2()
 // run_filter_test3()
 // run_pref_test();
 // run_pac_test();
 // run_pac_cancel_test();
 // run_proxy_host_filters_test();
 // run_myipaddress_test();
 // run_failed_script_test();
+// run_isresolvable_test();
 
 var ios = Components.classes["@mozilla.org/network/io-service;1"]
                     .getService(Components.interfaces.nsIIOService);
 var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"]
                     .getService();
 var prefs = Components.classes["@mozilla.org/preferences-service;1"]
                      .getService(Components.interfaces.nsIPrefBranch);
 
@@ -649,29 +650,62 @@ var directFilterListener = {
     check_proxy(ctx.proxyInfo, "http", "127.0.0.1", 7246, 0, 0, false);
     pps.unregisterFilter(directFilter);
 
     // check on the PI from on-modify-request
     do_check_true(this.onModifyRequestCalled);
     var obs = Components.classes["@mozilla.org/observer-service;1"].getService();
     obs = obs.QueryInterface(Components.interfaces.nsIObserverService);
     obs.removeObserver(this, "http-on-modify-request");
-    do_test_finished();
+
+    run_isresolvable_test();
   },
 
    observe: function(subject, topic, data) {
      if (topic === "http-on-modify-request" &&
          subject instanceof Components.interfaces.nsIHttpChannel &&
          subject instanceof Components.interfaces.nsIProxiedChannel) {
        check_proxy(subject.proxyInfo, "http", "127.0.0.1", 7246, 0, 0, false);
        this.onModifyRequestCalled = true;
      }
    }
 };
 
+function run_isresolvable_test()
+{
+  // test a non resolvable host in the pac file
+
+  var pac = 'data:text/plain,' +
+            'function FindProxyForURL(url, host) {' +
+            ' if (isResolvable("nonexistant.lan"))' +
+            '   return "DIRECT";' +
+            ' return "PROXY 127.0.0.1:1234";' +
+            '}';
+
+  var uri = ios.newURI("http://www.mozilla.org/", null, null);
+
+  prefs.setIntPref("network.proxy.type", 2);
+  prefs.setCharPref("network.proxy.autoconfig_url", pac);
+
+  var cb = new resolveCallback();
+  cb.nextFunction = isresolvable_callback;
+  var req = pps.asyncResolve(uri, 0, cb);
+}
+
+function isresolvable_callback(pi)
+{
+  do_check_neq(pi, null);
+  do_check_eq(pi.type, "http");
+  do_check_eq(pi.port, 1234);
+  do_check_eq(pi.host, "127.0.0.1");
+
+  prefs.setIntPref("network.proxy.type", 0);
+  do_test_finished();
+}
+
 function run_deprecated_sync_test()
 {
   var uri = ios.newURI("http://www.mozilla.org/", null, null);
 
   pps.QueryInterface(Components.interfaces.nsIProtocolProxyService2);
 
   // Verify initial state
   var pi = pps.deprecatedBlockingResolve(uri, 0);