bug 829646 PAC mIPAddress() problem outside of FindProxyForURL() r=biesi a=bajaj
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 14 Jan 2013 14:18:24 -0500
changeset 127123 c238a35cfba858c898666472707030e9cc4f777e
parent 127122 c75343566eeabfe1112ca6ef0cb7c24a974c9019
child 127124 b37131b881b60f5bd879e925c578be498713f68a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi, bajaj
bugs829646
milestone20.0a2
bug 829646 PAC mIPAddress() problem outside of FindProxyForURL() r=biesi a=bajaj
netwerk/base/src/ProxyAutoConfig.cpp
netwerk/test/unit/test_protocolproxyservice.js
--- a/netwerk/base/src/ProxyAutoConfig.cpp
+++ b/netwerk/base/src/ProxyAutoConfig.cpp
@@ -581,27 +581,30 @@ ProxyAutoConfig::SetupJS()
     return NS_ERROR_FAILURE;
 
   mJSRuntime = JSRuntimeWrapper::Create();
   if (!mJSRuntime)
     return NS_ERROR_FAILURE;
 
   JSAutoRequest ar(mJSRuntime->Context());
 
+  sRunning = this;
   JSScript *script = JS_CompileScript(mJSRuntime->Context(),
                                       mJSRuntime->Global(),
                                       mPACScript.get(), mPACScript.Length(),
                                       mPACURI.get(), 1);
   if (!script ||
       !JS_ExecuteScript(mJSRuntime->Context(), mJSRuntime->Global(), script, nullptr)) {
     nsString alertMessage(NS_LITERAL_STRING("PAC file failed to install from "));
     alertMessage += NS_ConvertUTF8toUTF16(mPACURI);
     PACLogToConsole(alertMessage);
+    sRunning = nullptr;
     return NS_ERROR_FAILURE;
   }
+  sRunning = nullptr;
 
   mJSRuntime->SetOK();
   nsString alertMessage(NS_LITERAL_STRING("PAC file installed from "));
   alertMessage += NS_ConvertUTF8toUTF16(mPACURI);
   PACLogToConsole(alertMessage);
 
   // we don't need these now
   mPACScript.Truncate();
--- a/netwerk/test/unit/test_protocolproxyservice.js
+++ b/netwerk/test/unit/test_protocolproxyservice.js
@@ -592,17 +592,51 @@ function myipaddress_callback(pi)
   do_check_neq(pi, null);
   do_check_eq(pi.type, "http");
   do_check_eq(pi.port, 1234);
 
   // make sure we didn't return localhost
   do_check_neq(pi.host, null);
   do_check_neq(pi.host, "127.0.0.1");
   do_check_neq(pi.host, "::1");
+  
+  run_myipaddress_test_2();
+}
 
+function run_myipaddress_test_2()
+{
+  // test that myIPAddress() can be used outside of the scope of
+  // FindProxyForURL(). bug 829646.
+
+  var pac = 'data:text/plain,' +
+            'var myaddr = myIpAddress(); ' +
+            'function FindProxyForURL(url, host) {' +
+            ' return "PROXY " + myaddr + ":5678";' +
+            '}';
+
+  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 = myipaddress2_callback;
+  var req = pps.asyncResolve(uri, 0, cb);
+}
+
+function myipaddress2_callback(pi)
+{
+  do_check_neq(pi, null);
+  do_check_eq(pi.type, "http");
+  do_check_eq(pi.port, 5678);
+
+  // make sure we didn't return localhost
+  do_check_neq(pi.host, null);
+  do_check_neq(pi.host, "127.0.0.1");
+  do_check_neq(pi.host, "::1");
+  
   run_failed_script_test();
 }
 
 function run_failed_script_test()
 {
   // test to make sure we go direct with invalid PAC
   var pac = 'data:text/plain,' +
             '\nfor(;\n';