Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Web Inspector: XHR request with same URL as main resource should have…
… type XHR https://bugs.webkit.org/show_bug.cgi?id=257407 Reviewed by Devin Rousso. Only use cached resource type when couldn't infer resource type based on the current ResourceRequest because CachedResource for the same URL may have different type. This fixes the bug where XHR is sent with the same URL as the main resource and was wrongly marked as another request with type Document rather than XHR. * LayoutTests/http/tests/inspector/network/xhr-request-type-expected.txt: Added. * LayoutTests/http/tests/inspector/network/xhr-request-type.html: Added. * Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp: (WebCore::InspectorNetworkAgent::willSendRequest): * LayoutTests/platform/mac-wk1/TestExpectations: ignore new test in WK1. Canonical link: https://commits.webkit.org/264686@main
- Loading branch information
Showing
4 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
LayoutTests/http/tests/inspector/network/xhr-request-type-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Tests that XHRs requests have type XHR, inlcuding those with the same URL as the main resource. | ||
|
||
Bug 68646 Bug 257407 | ||
|
||
== Running test suite: Resource.Type.XHR | ||
-- Running test case: Resource.Type.XHR.Same.As.Main.Resource.Url | ||
PASS: Resource should be XHR type. | ||
PASS: Resource should be a GET request. | ||
PASS: Resource should have a 200 response. | ||
PASS: Resource should receive main resource in response. | ||
|
||
-- Running test case: Resource.Type.XHR.Another.Url | ||
PASS: Resource should be XHR type. | ||
PASS: Resource should be a GET request. | ||
PASS: Resource should have a 200 response. | ||
PASS: Resource should receive json in response. | ||
|
66 changes: 66 additions & 0 deletions
66
LayoutTests/http/tests/inspector/network/xhr-request-type.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../resources/inspector-test.js"></script> | ||
<script> | ||
function triggerXHR(path) { | ||
const x = new XMLHttpRequest(); | ||
x.open("GET", path || location.href, false); | ||
x.send(); | ||
} | ||
|
||
// ---- | ||
|
||
function test() | ||
{ | ||
const suite = InspectorTest.createAsyncSuite("Resource.Type.XHR"); | ||
|
||
function addTestCase({name, description, expression, resourceHandler}) { | ||
suite.addTestCase({ | ||
name, description, | ||
async test() { | ||
const completeEvent = InspectorTest.awaitEvent("Completed"); | ||
InspectorTest.evaluateInPage(expression); | ||
const event = await WI.Frame.awaitEvent(WI.Frame.Event.ResourceWasAdded); | ||
const resource = event.data.resource; | ||
InspectorTest.expectEqual(resource.type, WI.Resource.Type.XHR, "Resource should be XHR type."); | ||
InspectorTest.expectEqual(resource.requestMethod, "GET", "Resource should be a GET request."); | ||
await resource.awaitEvent(WI.Resource.Event.LoadingDidFinish); | ||
const content = await resource.requestContentFromBackend() | ||
resourceHandler(resource, content); | ||
} | ||
}); | ||
} | ||
|
||
addTestCase({ | ||
name: "Resource.Type.XHR.Same.As.Main.Resource.Url", | ||
description: "XHR with the same URL as main resource.", | ||
expression: "triggerXHR()", | ||
resourceHandler(resource, content) { | ||
InspectorTest.expectEqual(resource.statusCode, 200, "Resource should have a 200 response."); | ||
InspectorTest.expectThat(content.body.includes("Tests that XHRs with the same url as a main resource have correct type"), "Resource should receive main resource in response."); | ||
} | ||
}); | ||
|
||
addTestCase({ | ||
name: "Resource.Type.XHR.Another.Url", | ||
description: "XHR with the same URL as main resource.", | ||
expression: "triggerXHR('/inspector/network/resources/data.json')", | ||
resourceHandler(resource, content) { | ||
InspectorTest.expectEqual(resource.statusCode, 200, "Resource should have a 200 response."); | ||
InspectorTest.expectEqual(content.body, `{"json": true, "value": 42}\n`, "Resource should receive json in response."); | ||
} | ||
}); | ||
|
||
suite.runTestCasesAndFinish(); | ||
} | ||
</script> | ||
</head> | ||
<body onload="runTest()"> | ||
<p>Tests that XHRs requests have type XHR, inlcuding those with the same URL as the main resource.</p> | ||
<a href="https://bugs.webkit.org/show_bug.cgi?id=68646">Bug 68646</a> | ||
<a href="https://bugs.webkit.org/show_bug.cgi?id=257407">Bug 257407</a> | ||
<div id="log"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters