Bug 1260498 - Make test_rel_preconnect work in e10s mode. r=mcmanus
authorNicholas Hurley <hurley@todesschaf.org>
Mon, 28 Mar 2016 16:43:01 -0700
changeset 290958 27bce8aa7584a46e01f5c1f8a094bc0099643aa3
parent 290957 ef6a15d8cf47fdc7820dde93c9bdbc8446567065
child 290959 2832f35108961d4b602b80950894da8aa5956b88
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1260498
milestone48.0a1
Bug 1260498 - Make test_rel_preconnect work in e10s mode. r=mcmanus MozReview-Commit-ID: 3PGA2N73foH
netwerk/ipc/NeckoChild.cpp
netwerk/ipc/NeckoChild.h
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/PNecko.ipdl
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/test/mochitests/mochitest.ini
netwerk/test/mochitests/test_rel_preconnect.html
--- a/netwerk/ipc/NeckoChild.cpp
+++ b/netwerk/ipc/NeckoChild.cpp
@@ -386,11 +386,22 @@ NeckoChild::RecvAppOfflineStatus(const u
   nsCOMPtr<nsIIOService> ioService = do_GetIOService();
   if (gIOService) {
     gIOService->SetAppOfflineInternal(aId, aOffline ?
       nsIAppOfflineInfo::OFFLINE : nsIAppOfflineInfo::ONLINE);
   }
   return true;
 }
 
+bool
+NeckoChild::RecvSpeculativeConnectRequest(const nsCString& aNotificationData)
+{
+  nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
+  if (obsService) {
+    obsService->NotifyObservers(nullptr, "speculative-connect-request",
+                                NS_ConvertUTF8toUTF16(aNotificationData).get());
+  }
+  return true;
+}
+
 } // namespace net
 } // namespace mozilla
 
--- a/netwerk/ipc/NeckoChild.h
+++ b/netwerk/ipc/NeckoChild.h
@@ -82,16 +82,18 @@ protected:
   virtual bool RecvAppOfflineStatus(const uint32_t& aId, const bool& aOffline) override;
   virtual PWebSocketEventListenerChild*
     AllocPWebSocketEventListenerChild(const uint64_t& aInnerWindowID) override;
   virtual bool DeallocPWebSocketEventListenerChild(PWebSocketEventListenerChild*) override;
 
   /* Predictor Messsages */
   virtual bool RecvPredOnPredictPreconnect(const URIParams& aURI) override;
   virtual bool RecvPredOnPredictDNS(const URIParams& aURI) override;
+
+  virtual bool RecvSpeculativeConnectRequest(const nsCString& aNotificationData) override;
 };
 
 /**
  * Reference to the PNecko Child protocol.
  * Null if this is not a content process.
  */
 extern PNeckoChild *gNeckoChild;
 
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -89,16 +89,17 @@ NeckoParent::NeckoParent()
   }
 
   mObserver = new OfflineObserver(this);
   gNeckoParent = this;
 }
 
 NeckoParent::~NeckoParent()
 {
+  gNeckoParent = nullptr;
   if (mObserver) {
     mObserver->RemoveObserver();
   }
 }
 
 static PBOverrideStatus
 PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized)
 {
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -124,16 +124,18 @@ child:
                                       nsString realm, uint64_t callbackId);
   // Notifies child that a given app is now offline (or online)
   async AppOfflineStatus(uint32_t appId, bool offline);
 
   /* Predictor Methods */
   async PredOnPredictPreconnect(URIParams uri);
   async PredOnPredictDNS(URIParams uri);
 
+  async SpeculativeConnectRequest(nsCString notificationData);
+
 both:
   // Actually we need PTCPSocket() for parent. But ipdl disallows us having different
   // signatures on parent and child. So when constructing the parent side object, we just 
   // leave host/port unused.
   async PTCPSocket(nsString host, uint16_t port);
 };
 
 
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -51,18 +51,20 @@
 #include "nsINetworkLinkService.h"
 #include "nsHttpChannelAuthProvider.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsSocketTransportService2.h"
 #include "nsIOService.h"
 
 #include "mozilla/net/NeckoChild.h"
+#include "mozilla/net/NeckoParent.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/unused.h"
 
 #if defined(XP_UNIX)
 #include <sys/utsname.h>
 #endif
 
 #if defined(XP_WIN)
 #include <windows.h>
 #endif
@@ -2170,16 +2172,19 @@ nsHttpHandler::SpeculativeConnectInterna
     if (mDebugObservations && obsService) {
         // this is basically used for test coverage of an otherwise 'hintable' feature
         nsAutoCString spec;
         aURI->GetSpec(spec);
         spec.Append(anonymous ? NS_LITERAL_CSTRING("[A]") : NS_LITERAL_CSTRING("[.]"));
         obsService->NotifyObservers(nullptr,
                                     "speculative-connect-request",
                                     NS_ConvertUTF8toUTF16(spec).get());
+        if (!IsNeckoChild() && gNeckoParent) {
+            Unused << gNeckoParent->SendSpeculativeConnectRequest(spec);
+        }
     }
 
     nsISiteSecurityService* sss = gHttpHandler->GetSSService();
     bool isStsHost = false;
     if (!sss)
         return NS_OK;
 
     nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aCallbacks);
--- a/netwerk/test/mochitests/mochitest.ini
+++ b/netwerk/test/mochitests/mochitest.ini
@@ -14,17 +14,16 @@ support-files =
   redirect_idn.html^headers^
   redirect_idn.html
   empty.html
   redirect.sjs
 
 [test_arraybufferinputstream.html]
 [test_partially_cached_content.html]
 [test_rel_preconnect.html]
-skip-if = e10s
 [test_uri_scheme.html]
 [test_user_agent_overrides.html]
 skip-if = e10s
 [test_user_agent_updates.html]
 skip-if = e10s
 [test_user_agent_updates_reset.html]
 [test_viewsource_unlinkable.html]
 [test_xhr_method_case.html]
--- a/netwerk/test/mochitests/test_rel_preconnect.html
+++ b/netwerk/test/mochitests/test_rel_preconnect.html
@@ -6,77 +6,51 @@
   <title>Test for link rel=preconnect</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css"  href="/tests/SimpleTest/test.css" />
 
 <script type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 const Cc = SpecialPowers.Cc, Ci = SpecialPowers.Ci, Cr = SpecialPowers.Cr;
-var srv;
-
-function TestServer1(nextTest) {
-    this.listener= Cc["@mozilla.org/network/server-socket;1"]
-                   .createInstance(Ci.nsIServerSocket);
-    this.listener.init(-1, true, -1);
-    this.listener.asyncListen(SpecialPowers.wrapCallbackObject(this));
-    this.nextTest = nextTest;
-}
-
-TestServer1.prototype = {
-    QueryInterface: function(iid) {
-      iid = SpecialPowers.wrap(iid);
-        if (iid.equals(Ci.nsIServerSocketListener) ||
-            iid.equals(Ci.nsISupports))
-            return this;
-        throw Cr.NS_ERROR_NO_INTERFACE;
-    },
-    onSocketAccepted: function(socket, trans) {
-        try { socket.close(); } catch(e) {}
-        try { trans.close(); } catch(e) {}
-    },
-    onStopListening: function(socket) {}
-};
 
 var remainder = 4;
 var observer;
 
 function doTest()
 {
-  srv = new TestServer1();
   SpecialPowers.setBoolPref("network.http.debug-observations", true);
   
   observer = SpecialPowers.wrapCallback(function(subject, topic, data) {
     remainder--;
     ok(true, "observed remainder = " + remainder);
     if (!remainder) {
-      srv.listener.close();
       SpecialPowers.removeObserver(observer, "speculative-connect-request");
       SpecialPowers.setBoolPref("network.http.debug-observations", false);
       SimpleTest.finish();
     }
   });
   SpecialPowers.addObserver(observer, "speculative-connect-request", false);
 
   // test the link rel=preconnect element in the head for both normal
   // and crossOrigin=anonymous
   var link = document.createElement("link");
   link.rel = "preconnect";
-  link.href = "//localhost:" +  srv.listener.port;
+  link.href = "//localhost:8888";
   document.head.appendChild(link);
   link = document.createElement("link");
   link.rel = "preconnect";
-  link.href = "//localhost:" +  srv.listener.port;
+  link.href = "//localhost:8888";
   link.crossOrigin = "anonymous";
   document.head.appendChild(link);
 
   // test the http link response header - the test contains both a
   // normal and anonymous preconnect link header
   var iframe = document.createElement('iframe');
-  iframe.src = 'rel_preconnect.sjs?//localhost:' + srv.listener.port;
+  iframe.src = 'rel_preconnect.sjs?//localhost:8888';
 
   document.body.appendChild(iframe);
 }
 
 </script>
 </head>
 <body onload="doTest();">
 <p id="display"></p>