diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 9dceeb4745a2..7efd6bf03c4e 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -3721,7 +3721,10 @@ nsresult HttpChannelChild::AsyncCallImpl( } nsresult HttpChannelChild::SetReferrerHeader(const nsACString& aReferrer) { - ENSURE_CALLED_BEFORE_CONNECT(); + // Normally this would be ENSURE_CALLED_BEFORE_CONNECT, but since the + // "connect" is done in the main process, and mRequestObserversCalled is never + // set in the ChannelChild, before connect basically means before asyncOpen. + ENSURE_CALLED_BEFORE_ASYNC_OPEN(); // remove old referrer if any, loop backwards for (int i = mClientSetRequestHeaders.Length() - 1; i >= 0; --i) { diff --git a/netwerk/test/unit/test_httpcancel.js b/netwerk/test/unit/test_httpcancel.js index 9cface8225f9..587faf18cfbb 100644 --- a/netwerk/test/unit/test_httpcancel.js +++ b/netwerk/test/unit/test_httpcancel.js @@ -6,6 +6,12 @@ const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js"); +function inChildProcess() { + return Cc["@mozilla.org/xre/app-info;1"] + .getService(Ci.nsIXULRuntime) + .processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; +} + var ios = Cc["@mozilla.org/network/io-service;1"] .getService(Ci.nsIIOService); var ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1", @@ -90,9 +96,11 @@ function execute_test() { var chan = makeChan("http://localhost:" + httpserv.identity.primaryPort + "/failtest"); - var obs = Cc["@mozilla.org/observer-service;1"].getService(); - obs = obs.QueryInterface(Ci.nsIObserverService); - obs.addObserver(observer, "http-on-modify-request"); + if (!inChildProcess()) { + var obs = Cc["@mozilla.org/observer-service;1"].getService(); + obs = obs.QueryInterface(Ci.nsIObserverService); + obs.addObserver(observer, "http-on-modify-request"); + } chan.asyncOpen(listener); } diff --git a/netwerk/test/unit_ipc/test_httpcancel_wrap.js b/netwerk/test/unit_ipc/test_httpcancel_wrap.js new file mode 100644 index 000000000000..469e748266e8 --- /dev/null +++ b/netwerk/test/unit_ipc/test_httpcancel_wrap.js @@ -0,0 +1,46 @@ +"use strict"; + +const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js"); +const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +const ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1", + "nsIReferrerInfo", + "init"); + +let observer = { + QueryInterface: function eventsink_qi(iid) { + if (iid.equals(Ci.nsISupports) || + iid.equals(Ci.nsIObserver)) + return this; + throw Cr.NS_ERROR_NO_INTERFACE; + }, + + observe: function(subject, topic, data) { + subject = subject.QueryInterface(Ci.nsIRequest); + subject.cancel(Cr.NS_BINDING_ABORTED); + + // ENSURE_CALLED_BEFORE_CONNECT: setting values should still work + try { + subject.QueryInterface(Ci.nsIHttpChannel); + let currentReferrer = subject.getRequestHeader("Referer"); + Assert.equal(currentReferrer, "http://site1.com/"); + let uri = Services.io.newURI("http://site2.com"); + subject.referrerInfo = new ReferrerInfo(Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, uri); + } catch (ex) { + do_throw("Exception: " + ex); + } + + let obs = Cc["@mozilla.org/observer-service;1"].getService(); + obs = obs.QueryInterface(Ci.nsIObserverService); + obs.removeObserver(observer, "http-on-modify-request"); + } +}; + +function run_test() { + + let obs = Cc["@mozilla.org/observer-service;1"].getService(); + obs = obs.QueryInterface(Ci.nsIObserverService); + obs.addObserver(observer, "http-on-modify-request"); + + run_test_in_child("../unit/test_httpcancel.js"); +} diff --git a/netwerk/test/unit_ipc/xpcshell.ini b/netwerk/test/unit_ipc/xpcshell.ini index 26ada9b70042..12aee430a8b8 100644 --- a/netwerk/test/unit_ipc/xpcshell.ini +++ b/netwerk/test/unit_ipc/xpcshell.ini @@ -58,6 +58,7 @@ support-files = !/netwerk/test/unit/test_multipart_streamconv.js !/netwerk/test/unit/test_original_sent_received_head.js !/netwerk/test/unit/test_alt-data_cross_process.js + !/netwerk/test/unit/test_httpcancel.js child_cookie_header.js [test_bug528292_wrap.js] @@ -106,3 +107,4 @@ skip-if = true [test_channel_priority_wrap.js] [test_multipart_streamconv_wrap.js] [test_alt-data_cross_process_wrap.js] +[test_httpcancel_wrap.js]