зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1405286: Part 3 - Test that filterResponseData from cached onHeadersReceived doesn't crash. r=mixedpuppy
It currently isn't possible to suspend a channel from onHeadersReceived for a cached response. And since it's not possible to add a new stream filter after a response has started, adding a stream filter at that point will crash if the channel is still registered. This test is a basic sanity check for that scenario. MozReview-Commit-ID: ALYUtxX7mci --HG-- extra : rebase_source : 120889fd8f9edd097a7dae807b54eb3fd283f0f6
This commit is contained in:
Родитель
3967e13d94
Коммит
f0b1b98a83
|
@ -407,6 +407,48 @@ add_task(async function() {
|
|||
await extension.unload();
|
||||
});
|
||||
|
||||
// Test that registering a listener for a cached response does not cause a crash.
|
||||
add_task(async function test_cachedResponse() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
background() {
|
||||
browser.webRequest.onHeadersReceived.addListener(data => {
|
||||
let filter = browser.webRequest.filterResponseData(data.requestId);
|
||||
|
||||
filter.onstop = event => {
|
||||
filter.close();
|
||||
};
|
||||
filter.ondata = event => {
|
||||
filter.write(event.data);
|
||||
};
|
||||
|
||||
if (data.fromCache) {
|
||||
browser.test.sendMessage("from-cache");
|
||||
}
|
||||
}, {
|
||||
urls: ["http://mochi.test/*/file_sample.html?r=*"],
|
||||
},
|
||||
["blocking"]);
|
||||
},
|
||||
|
||||
manifest: {
|
||||
permissions: [
|
||||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"http://mochi.test/",
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await extension.startup();
|
||||
|
||||
let url = `file_sample.html?r=${Math.random()}`;
|
||||
await fetch(url);
|
||||
await fetch(url);
|
||||
await extension.awaitMessage("from-cache");
|
||||
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_permissions() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
background() {
|
||||
|
|
|
@ -630,6 +630,12 @@ ChannelWrapper::GetFrameAncestors(nsILoadInfo* aLoadInfo, nsTArray<dom::MozFrame
|
|||
void
|
||||
ChannelWrapper::RegisterTraceableChannel(const WebExtensionPolicy& aAddon, nsITabParent* aTabParent)
|
||||
{
|
||||
// We can't attach new listeners after the response has started, so don't
|
||||
// bother registering anything.
|
||||
if (mResponseStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
mAddonEntries.Put(aAddon.Id(), aTabParent);
|
||||
if (!mChannelEntry) {
|
||||
mChannelEntry = WebRequestService::GetSingleton().RegisterChannel(this);
|
||||
|
@ -914,6 +920,7 @@ ChannelWrapper::RequestListener::OnStartRequest(nsIRequest *request, nsISupports
|
|||
MOZ_ASSERT(mOrigStreamListener, "Should have mOrigStreamListener");
|
||||
|
||||
mChannelWrapper->mChannelEntry = nullptr;
|
||||
mChannelWrapper->mResponseStarted = true;
|
||||
mChannelWrapper->ErrorCheck();
|
||||
mChannelWrapper->FireEvent(NS_LITERAL_STRING("start"));
|
||||
|
||||
|
|
|
@ -288,6 +288,7 @@ private:
|
|||
bool mAddedStreamListener = false;
|
||||
bool mFiredErrorEvent = false;
|
||||
bool mSuspended = false;
|
||||
bool mResponseStarted = false;
|
||||
|
||||
|
||||
nsInterfaceHashtable<nsPtrHashKey<const nsAtom>, nsITabParent> mAddonEntries;
|
||||
|
|
|
@ -166,7 +166,7 @@ class ResponseHeaderChanger extends HeaderChanger {
|
|||
}
|
||||
|
||||
const MAYBE_CACHED_EVENTS = new Set([
|
||||
"onResponseStarted", "onBeforeRedirect", "onCompleted", "onErrorOccurred",
|
||||
"onResponseStarted", "onHeadersReceived", "onBeforeRedirect", "onCompleted", "onErrorOccurred",
|
||||
]);
|
||||
|
||||
const OPTIONAL_PROPERTIES = [
|
||||
|
|
Загрузка…
Ссылка в новой задаче