Bug 1521729 - P2: Fix failure tests r=mayhemer
authorKershaw Chang <kershaw@mozilla.com>
Mon, 18 Mar 2019 14:50:56 +0000
changeset 464834 70b9b6dbe5b8e2b55a240aa3b39ff6087de92276
parent 464833 917f02e20ab6edac88ba0d41d24a3b65409becdd
child 464835 af46b1e88998c876d71d38b76ce4a9f7809d80a7
push id35727
push userdvarga@mozilla.com
push dateTue, 19 Mar 2019 09:48:59 +0000
treeherdermozilla-central@70baa37ae1eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1521729
milestone68.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 1521729 - P2: Fix failure tests r=mayhemer Due to the p1 patch, the first time we get the result back from NS_ShouldSecureUpgrade is always asynchronously. This means that the first http request could be completed slower than the http requests opened after the first one. There are some tests affected by this change, since these tests assume that http requests should be completed in the same order as these requests were created. This patch fixes the tests by introducing a new method in nsIHttpProtocolHandler. This method returns a promise and makes sure the HSTS data is ready to read synchronously when the promise is resolved. Once the HSTS is ready to read, the order of open/close channels will be the same. Differential Revision: https://phabricator.services.mozilla.com/D21683
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
netwerk/ipc/PNecko.ipdl
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
netwerk/protocol/http/nsIHttpProtocolHandler.idl
netwerk/test/unit/test_bug596443.js
netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js
netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js
netwerk/test/unit/test_cache2-29c-concurrent_read_half-interrupted.js
netwerk/test/unit/test_cache2-29d-concurrent_read_half-corrupted-206.js
netwerk/test/unit/test_cache2-29e-concurrent_read_half-non-206-response.js
netwerk/test/unit/test_channel_close.js
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -47,16 +47,17 @@
 #include "nsHTMLDNSPrefetch.h"
 #include "nsEscape.h"
 #include "SerializedLoadContext.h"
 #include "nsAuthInformationHolder.h"
 #include "nsIAuthPromptCallback.h"
 #include "nsINetworkPredictor.h"
 #include "nsINetworkPredictorVerifier.h"
 #include "nsISpeculativeConnect.h"
+#include "nsHttpHandler.h"
 #include "nsNetUtil.h"
 
 using IPC::SerializedLoadContext;
 using mozilla::OriginAttributes;
 using mozilla::dom::ChromeUtils;
 using mozilla::dom::ContentParent;
 using mozilla::dom::ServiceWorkerManager;
 using mozilla::dom::TabContext;
@@ -971,10 +972,20 @@ mozilla::ipc::IPCResult NeckoParent::Rec
     return IPC_OK();
   }
 
   aResolver(std::move(childEndpoint));
   mSocketProcessBridgeInited = true;
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult NeckoParent::RecvEnsureHSTSData(
+    EnsureHSTSDataResolver&& aResolver) {
+  auto callback = [aResolver{std::move(aResolver)}](bool aResult) {
+    aResolver(aResult);
+  };
+  gHttpHandler->EnsureHSTSDataReadyNative(
+      new HSTSDataCallbackWrapper(std::move(callback)));
+  return IPC_OK();
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -232,14 +232,17 @@ class NeckoParent : public PNeckoParent 
 
   virtual mozilla::ipc::IPCResult RecvPClassifierDummyChannelConstructor(
       PClassifierDummyChannelParent* aActor, nsIURI* aURI,
       nsIURI* aTopWindowURI, const nsresult& aTopWindowURIResult,
       const Maybe<LoadInfoArgs>& aLoadInfo) override;
 
   mozilla::ipc::IPCResult RecvInitSocketProcessBridge(
       InitSocketProcessBridgeResolver&& aResolver);
+
+  mozilla::ipc::IPCResult RecvEnsureHSTSData(
+      EnsureHSTSDataResolver&& aResolver);
 };
 
 }  // namespace net
 }  // namespace mozilla
 
 #endif  // mozilla_net_NeckoParent_h
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -139,16 +139,19 @@ parent:
    * WebExtension-specific remote resource loading
    */
   async GetExtensionStream(URIParams uri) returns (nsIInputStream stream);
   async GetExtensionFD(URIParams uri) returns (FileDescriptor fd);
 
   async InitSocketProcessBridge()
     returns (Endpoint<PSocketProcessBridgeChild> endpoint);
 
+  async EnsureHSTSData()
+    returns (bool result);
+
 child:
   /*
    * Bring up the http auth prompt for a nested remote mozbrowser.
    * NestedFrameId is the id corresponding to the PBrowser.  It is the same id
    * that was passed to the PBrowserOrId param in to the PHttpChannel constructor
    */
   async AsyncAuthPromptForNestedFrame(TabId nestedFrameId, nsCString uri,
                                       nsString realm, uint64_t callbackId);
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -43,16 +43,17 @@
 #include "nsISiteSecurityService.h"
 #include "nsIStreamConverterService.h"
 #include "nsCRT.h"
 #include "nsIMemoryReporter.h"
 #include "nsIParentalControlsService.h"
 #include "nsPIDOMWindow.h"
 #include "nsINetworkLinkService.h"
 #include "nsHttpChannelAuthProvider.h"
+#include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsSocketTransportService2.h"
 #include "nsIOService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIXULRuntime.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsRFPService.h"
@@ -64,16 +65,17 @@
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/LazyIdleThread.h"
 
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/Navigator.h"
+#include "mozilla/dom/Promise.h"
 #include "mozilla/dom/network/Connection.h"
 
 #include "nsNSSComponent.h"
 
 #if defined(XP_UNIX)
 #  include <sys/utsname.h>
 #endif
 
@@ -126,16 +128,17 @@
 #define HTTP_PREF(_pref) HTTP_PREF_PREFIX _pref
 #define BROWSER_PREF(_pref) BROWSER_PREF_PREFIX _pref
 
 #define NS_HTTP_PROTOCOL_FLAGS \
   (URI_STD | ALLOWS_PROXY | ALLOWS_PROXY_HTTP | URI_LOADABLE_BY_ANYONE)
 
 //-----------------------------------------------------------------------------
 
+using mozilla::dom::Promise;
 using mozilla::Telemetry::LABELS_NETWORK_HTTP_REDIRECT_TO_SCHEME;
 
 namespace mozilla {
 namespace net {
 
 LazyLogModule gHttpLog("nsHttp");
 
 static nsresult NewURI(const nsACString &aSpec, const char *aCharset,
@@ -2583,16 +2586,85 @@ nsHttpsHandler::NewChannel(nsIURI *aURI,
 
 NS_IMETHODIMP
 nsHttpsHandler::AllowPort(int32_t aPort, const char *aScheme, bool *_retval) {
   // don't override anything.
   *_retval = false;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsHttpHandler::EnsureHSTSDataReadyNative(HSTSDataCallbackWrapper *aCallback) {
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aCallback);
+
+  nsCOMPtr<nsIURI> uri;
+  nsresult rv = NS_NewURI(getter_AddRefs(uri), "http://example.com");
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  bool shouldUpgrade = false;
+  bool willCallback = false;
+  OriginAttributes originAttributes;
+  RefPtr<HSTSDataCallbackWrapper> callback = aCallback;
+  auto func = [callback{std::move(callback)}](bool aResult, nsresult aStatus) {
+    callback->DoCallback(aResult);
+  };
+  rv = NS_ShouldSecureUpgrade(uri, nullptr, nullptr, false, false,
+                              originAttributes, shouldUpgrade, std::move(func),
+                              willCallback);
+  if (NS_FAILED(rv) || !willCallback) {
+    aCallback->DoCallback(false);
+    return rv;
+  }
+
+  return rv;
+}
+
+NS_IMETHODIMP
+nsHttpHandler::EnsureHSTSDataReady(JSContext *aCx, Promise **aPromise) {
+  if (NS_WARN_IF(!aCx)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsIGlobalObject *globalObject = xpc::CurrentNativeGlobal(aCx);
+  if (NS_WARN_IF(!globalObject)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  ErrorResult result;
+  RefPtr<Promise> promise = Promise::Create(globalObject, result);
+  if (NS_WARN_IF(result.Failed())) {
+    return result.StealNSResult();
+  }
+
+  if (IsNeckoChild()) {
+    gNeckoChild->SendEnsureHSTSData()->Then(
+        GetMainThreadSerialEventTarget(), __func__,
+        [promise(promise)](
+            NeckoChild::EnsureHSTSDataPromise::ResolveOrRejectValue &&aResult) {
+          if (aResult.IsResolve()) {
+            promise->MaybeResolve(aResult.ResolveValue());
+          } else {
+            promise->MaybeReject(NS_ERROR_FAILURE);
+          }
+        });
+    promise.forget(aPromise);
+    return NS_OK;
+  }
+
+  auto callback = [promise(promise)](bool aResult) {
+    promise->MaybeResolve(aResult);
+  };
+
+  RefPtr<HSTSDataCallbackWrapper> wrapper =
+      new HSTSDataCallbackWrapper(std::move(callback));
+  promise.forget(aPromise);
+  return EnsureHSTSDataReadyNative(wrapper);
+}
+
 void nsHttpHandler::ShutdownConnectionManager() {
   // ensure connection manager is shutdown
   if (mConnMgr) {
     nsresult rv = mConnMgr->Shutdown();
     if (NS_FAILED(rv)) {
       LOG(
           ("nsHttpHandler::ShutdownConnectionManager\n"
            "    failed to shutdown connection manager\n"));
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsHttpHandler_h__
 #define nsHttpHandler_h__
 
+#include <functional>
+
 #include "nsHttp.h"
 #include "nsHttpAuthCache.h"
 #include "nsHttpConnectionMgr.h"
 #include "ASpdySession.h"
 
 #include "mozilla/Mutex.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TimeStamp.h"
@@ -749,12 +751,38 @@ class nsHttpsHandler : public nsIHttpPro
   NS_FORWARD_NSIHTTPPROTOCOLHANDLER(gHttpHandler->)
   NS_FORWARD_NSISPECULATIVECONNECT(gHttpHandler->)
 
   nsHttpsHandler() = default;
 
   MOZ_MUST_USE nsresult Init();
 };
 
+//-----------------------------------------------------------------------------
+// HSTSDataCallbackWrapper - A threadsafe helper class to wrap the callback.
+//
+// We need this because dom::promise and EnsureHSTSDataResolver are not
+// threadsafe.
+//-----------------------------------------------------------------------------
+class HSTSDataCallbackWrapper final {
+ public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(HSTSDataCallbackWrapper)
+
+  explicit HSTSDataCallbackWrapper(std::function<void(bool)> &&aCallback)
+      : mCallback(std::move(aCallback)) {
+    MOZ_ASSERT(NS_IsMainThread());
+  }
+
+  void DoCallback(bool aResult) {
+    MOZ_ASSERT(NS_IsMainThread());
+    mCallback(aResult);
+  }
+
+ private:
+  ~HSTSDataCallbackWrapper() = default;
+
+  std::function<void(bool)> mCallback;
+};
+
 }  // namespace net
 }  // namespace mozilla
 
 #endif  // nsHttpHandler_h__
--- a/netwerk/protocol/http/nsIHttpProtocolHandler.idl
+++ b/netwerk/protocol/http/nsIHttpProtocolHandler.idl
@@ -1,15 +1,24 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIProxiedProtocolHandler.idl"
 
+%{C++
+namespace mozilla {
+namespace net {
+class HSTSDataCallbackWrapper;
+}
+}
+%}
+[ptr] native HSTSDataCallbackWrapperPtr(mozilla::net::HSTSDataCallbackWrapper);
+
 [scriptable, uuid(c48126d9-2ddd-485b-a51a-378e917e75f8)]
 interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
 {
     /**
      * Get the HTTP advertised user agent string.
      */
     [must_use] readonly attribute ACString userAgent;
 
@@ -42,16 +51,30 @@ interface nsIHttpProtocolHandler : nsIPr
      */
     [must_use] readonly attribute ACString oscpu;
 
     /**
      * Get the application comment misc portion.
      */
     [must_use] readonly attribute ACString misc;
 
+    /**
+     * This function is used to ensure HSTS data storage is ready to read after
+     * the returned promise is resolved.
+     * Note that this function should only used for testing.
+     * See bug 1521729 for more details.
+     */
+    [implicit_jscontext]
+    Promise EnsureHSTSDataReady();
+
+    /**
+     * A C++ friendly version of EnsureHSTSDataReady
+     */
+    [noscript]
+    void EnsureHSTSDataReadyNative(in HSTSDataCallbackWrapperPtr aCallback);
 };
 
 %{C++
 // ----------- Categories -----------
 /**
  * At initialization time, the HTTP handler will initialize each service
  * registered under this category:
  */
--- a/netwerk/test/unit/test_bug596443.js
+++ b/netwerk/test/unit/test_bug596443.js
@@ -1,11 +1,14 @@
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
+
 var httpserver = new HttpServer();
 
 var expectedOnStopRequests = 3;
 
 function setupChannel(suffix, xRequest, flags) {
     var chan = NetUtil.newChannel({
         uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
         loadUsingSystemPrincipal: true
@@ -56,24 +59,26 @@ function run_test() {
     Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
     // make sure we have a profile so we can use the disk-cache
     do_get_profile();
 
     // clear cache
     evict_cache_entries();
 
-    var ch0 = setupChannel("/bug596443", "Response0", Ci.nsIRequest.LOAD_BYPASS_CACHE);
-    ch0.asyncOpen(new Listener("Response0"));
+    httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+        var ch0 = setupChannel("/bug596443", "Response0", Ci.nsIRequest.LOAD_BYPASS_CACHE);
+        ch0.asyncOpen(new Listener("Response0"));
 
-    var ch1 = setupChannel("/bug596443", "Response1", Ci.nsIRequest.LOAD_BYPASS_CACHE);
-    ch1.asyncOpen(new Listener("Response1"));
+        var ch1 = setupChannel("/bug596443", "Response1", Ci.nsIRequest.LOAD_BYPASS_CACHE);
+        ch1.asyncOpen(new Listener("Response1"));
 
-    var ch2 = setupChannel("/bug596443", "Should not be used");
-    ch2.asyncOpen(new Listener("Response1")); // Note param: we expect this to come from cache
+        var ch2 = setupChannel("/bug596443", "Should not be used");
+        ch2.asyncOpen(new Listener("Response1")); // Note param: we expect this to come from cache
+    });
 
     do_test_pending();
 }
 
 function triggerHandlers() {
     do_timeout(100, handlers[1]);
     do_timeout(100, handlers[0]);
 }
--- a/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js
+++ b/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js
@@ -9,16 +9,18 @@ This test is using a resumable response.
 - second channel now must engage interrupted concurrent write algorithm and read the content again from the network
 - both channels must deliver full content w/o errors
 
 */
 
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
 
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpServer.identity.primaryPort;
 });
 
 var httpServer = null;
 
 function make_channel(url, callback, ctx) {
@@ -47,20 +49,22 @@ function run_test()
 
   Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 0);
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   httpServer = new HttpServer();
   httpServer.registerPathHandler("/content", contentHandler);
   httpServer.start(-1);
 
-  var chan1 = make_channel(URL + "/content");
-  chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
-  var chan2 = make_channel(URL + "/content");
-  chan2.asyncOpen(new ChannelListener(secondTimeThrough, null));
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var chan1 = make_channel(URL + "/content");
+    chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
+    var chan2 = make_channel(URL + "/content");
+    chan2.asyncOpen(new ChannelListener(secondTimeThrough, null));
+  });
 
   do_test_pending();
 }
 
 function firstTimeThrough(request, buffer)
 {
   Assert.equal(buffer, responseBody);
 }
--- a/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js
+++ b/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js
@@ -11,16 +11,19 @@ This test is using a non-resumable respo
 - second channel must read the content again from the network
 - both channels must deliver full content w/o errors
 
 */
 
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
+
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpServer.identity.primaryPort;
 });
 
 var httpServer = null;
 
 function make_channel(url, callback, ctx) {
   return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
@@ -46,20 +49,22 @@ function run_test()
 
   Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 0);
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   httpServer = new HttpServer();
   httpServer.registerPathHandler("/content", contentHandler);
   httpServer.start(-1);
 
-  var chan1 = make_channel(URL + "/content");
-  chan1.asyncOpen(new ChannelListener(firstTimeThrough, null, CL_ALLOW_UNKNOWN_CL));
-  var chan2 = make_channel(URL + "/content");
-  chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_ALLOW_UNKNOWN_CL));
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var chan1 = make_channel(URL + "/content");
+    chan1.asyncOpen(new ChannelListener(firstTimeThrough, null, CL_ALLOW_UNKNOWN_CL));
+    var chan2 = make_channel(URL + "/content");
+    chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_ALLOW_UNKNOWN_CL));
+  });
 
   do_test_pending();
 }
 
 function firstTimeThrough(request, buffer)
 {
   Assert.equal(buffer, responseBodyDecoded);
 }
--- a/netwerk/test/unit/test_cache2-29c-concurrent_read_half-interrupted.js
+++ b/netwerk/test/unit/test_cache2-29c-concurrent_read_half-interrupted.js
@@ -11,16 +11,18 @@ This test is using a resumable response.
 - second channel now must engage interrupted concurrent write algorithm and read the rest of the content from the network
 - both channels must deliver full content w/o errors
 
 */
 
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
 
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpServer.identity.primaryPort;
 });
 
 var httpServer = null;
 
 function make_channel(url, callback, ctx) {
@@ -66,20 +68,22 @@ function run_test()
 
   Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1);
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   httpServer = new HttpServer();
   httpServer.registerPathHandler("/content", contentHandler);
   httpServer.start(-1);
 
-  var chan1 = make_channel(URL + "/content");
-  chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
-  var chan2 = make_channel(URL + "/content");
-  chan2.asyncOpen(new ChannelListener(secondTimeThrough, null));
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var chan1 = make_channel(URL + "/content");
+    chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
+    var chan2 = make_channel(URL + "/content");
+    chan2.asyncOpen(new ChannelListener(secondTimeThrough, null));
+  });
 
   do_test_pending();
 }
 
 function firstTimeThrough(request, buffer)
 {
   Assert.equal(buffer, responseBody);
 }
--- a/netwerk/test/unit/test_cache2-29d-concurrent_read_half-corrupted-206.js
+++ b/netwerk/test/unit/test_cache2-29d-concurrent_read_half-corrupted-206.js
@@ -12,16 +12,18 @@ This test is using a resumable response.
 - the first must deliver full content w/o errors
 - the second channel must correctly fail
 
 */
 
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
 
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpServer.identity.primaryPort;
 });
 
 var httpServer = null;
 
 function make_channel(url, callback, ctx) {
@@ -66,20 +68,22 @@ function run_test()
 
   Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1);
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   httpServer = new HttpServer();
   httpServer.registerPathHandler("/content", contentHandler);
   httpServer.start(-1);
 
-  var chan1 = make_channel(URL + "/content");
-  chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
-  var chan2 = make_channel(URL + "/content");
-  chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_EXPECT_FAILURE));
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var chan1 = make_channel(URL + "/content");
+    chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
+    var chan2 = make_channel(URL + "/content");
+    chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_EXPECT_FAILURE));
+  });
 
   do_test_pending();
 }
 
 function firstTimeThrough(request, buffer)
 {
   Assert.equal(buffer, responseBody);
 }
--- a/netwerk/test/unit/test_cache2-29e-concurrent_read_half-non-206-response.js
+++ b/netwerk/test/unit/test_cache2-29e-concurrent_read_half-non-206-response.js
@@ -12,16 +12,18 @@ This test is using a resumable response.
 - the first must deliver full content w/o errors
 - the second channel must correctly fail
 
 */
 
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
 
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpServer.identity.primaryPort;
 });
 
 var httpServer = null;
 
 function make_channel(url, callback, ctx) {
@@ -61,20 +63,22 @@ function run_test()
 
   Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1);
   Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
 
   httpServer = new HttpServer();
   httpServer.registerPathHandler("/content", contentHandler);
   httpServer.start(-1);
 
-  var chan1 = make_channel(URL + "/content");
-  chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
-  var chan2 = make_channel(URL + "/content");
-  chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_EXPECT_FAILURE));
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var chan1 = make_channel(URL + "/content");
+    chan1.asyncOpen(new ChannelListener(firstTimeThrough, null));
+    var chan2 = make_channel(URL + "/content");
+    chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_EXPECT_FAILURE));
+  });
 
   do_test_pending();
 }
 
 function firstTimeThrough(request, buffer)
 {
   Assert.equal(buffer, responseBody);
 }
--- a/netwerk/test/unit/test_channel_close.js
+++ b/netwerk/test/unit/test_channel_close.js
@@ -1,40 +1,45 @@
 const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
+var httpProtocolHandler = Cc["@mozilla.org/network/protocol;1?name=http"]
+                          .getService(Ci.nsIHttpProtocolHandler);
+
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpserver.identity.primaryPort;
 });
 
 var httpserver = new HttpServer();
 var testpath = "/simple";
 var httpbody = "0123456789";
 
 var live_channels = [];
 
 function run_test() {
   httpserver.registerPathHandler(testpath, serverHandler);
   httpserver.start(-1);
 
-  var local_channel;
+  httpProtocolHandler.EnsureHSTSDataReady().then(function() {
+    var local_channel;
 
-  // Opened channel that has no remaining references on shutdown
-  local_channel = setupChannel(testpath);
-  local_channel.asyncOpen(new ChannelListener(checkRequest, local_channel));
+    // Opened channel that has no remaining references on shutdown
+    local_channel = setupChannel(testpath);
+    local_channel.asyncOpen(new ChannelListener(checkRequest, local_channel));
 
-  // Opened channel that has no remaining references after being opened
-  setupChannel(testpath).asyncOpen(new ChannelListener(function() {}, null));
-  
-  // Unopened channel that has remaining references on shutdown
-  live_channels.push(setupChannel(testpath));
+    // Opened channel that has no remaining references after being opened
+    setupChannel(testpath).asyncOpen(new ChannelListener(function() {}, null));
 
-  // Opened channel that has remaining references on shutdown
-  live_channels.push(setupChannel(testpath));
-  live_channels[1].asyncOpen(new ChannelListener(checkRequestFinish, live_channels[1]));
+    // Unopened channel that has remaining references on shutdown
+    live_channels.push(setupChannel(testpath));
+
+    // Opened channel that has remaining references on shutdown
+    live_channels.push(setupChannel(testpath));
+    live_channels[1].asyncOpen(new ChannelListener(checkRequestFinish, live_channels[1]));
+  });
 
   do_test_pending();
 }
 
 function setupChannel(path) {
   var chan = NetUtil.newChannel({
     uri: URL + path,
     loadUsingSystemPrincipal: true