-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add response status code to Resource Timing (#34828)
This CL introduces a responseStatus field to Performance Resource Timing object. This field is behind a Runtime Enabled Flag. Resource Timing PR : w3c/resource-timing#335 Fetch PR : whatwg/fetch#1468 Bug: 1343293 Change-Id: I60d1b6ba00f055481ca526a490144d88ddaf881b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3754923 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Abin Paul <[email protected]> Reviewed-by: Yoav Weiss <[email protected]> Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Mike West <[email protected]> Reviewed-by: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/main@{#1040902} Co-authored-by: Abin K Paul <[email protected]>
- Loading branch information
1 parent
0e75a8e
commit 9e8b0db
Showing
4 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
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
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,110 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>This test validates the response status of resources.</title> | ||
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/entry-invariants.js"></script> | ||
<script src="resources/resource-loaders.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
const {ORIGIN, REMOTE_ORIGIN} = get_host_info(); | ||
const status_codes = [ | ||
200, 203, | ||
400, 401, 403, 404, | ||
500, 501, 502, 503, | ||
]; | ||
|
||
// Response status for same origin resources is exposed | ||
const run_test = (loader, status) => { | ||
let path = `/resource-timing/resources/status-code.py?status=${status}`; | ||
const url = new URL(path, ORIGIN); | ||
attribute_test( | ||
loader, url, | ||
entry => { | ||
assert_equals(entry.responseStatus, status, | ||
`response status for ${entry.name} should be ${status}`); | ||
}); | ||
} | ||
|
||
let resource_loaders = [ | ||
load.font, | ||
load.image, | ||
load.script, | ||
load.stylesheet, | ||
load.xhr_sync, | ||
load.xhr_async, | ||
load.iframe | ||
]; | ||
|
||
resource_loaders.forEach(loader => { | ||
status_codes.forEach(status => run_test( | ||
loader, status | ||
)); | ||
}); | ||
|
||
|
||
// Response status is exposed for cors request for cross-origin resources | ||
const run_test_cross_origin_allow_origin = (loader_with_attr,status) => { | ||
let path = `/resource-timing/resources/status-code.py?status=${status}&allow_origin=${ORIGIN}`; | ||
const url = new URL(path, REMOTE_ORIGIN); | ||
loader_with_crossOrigin_attr = async url => { | ||
return loader_with_attr(url, {"crossOrigin": "anonymous"}); | ||
} | ||
attribute_test( | ||
loader_with_crossOrigin_attr, url, | ||
entry => { | ||
assert_equals(entry.responseStatus, status, | ||
`response status for ${entry.name} should be ${status}`); | ||
}); | ||
} | ||
|
||
resource_loaders = [ | ||
load.image_with_attrs, | ||
load.script_with_attrs, | ||
load.stylesheet_with_attrs | ||
]; | ||
|
||
resource_loaders.forEach(loader => { | ||
status_codes.forEach(status => run_test_cross_origin_allow_origin( | ||
loader, status | ||
)); | ||
}); | ||
|
||
|
||
// Response status is 0 when a no-cors request is made for cross origin | ||
// fonts, images, scripts, stylesheets. | ||
// Response status is 0 when request's mode is "navigate" and response's | ||
// URL's origin is not same origin with request's origin. So response | ||
// status is not exposed for cross origin iframes. | ||
const run_test_cross_origin = (loader, status) => { | ||
let path = `/resource-timing/resources/status-code.py?status=${status}`; | ||
const url = new URL(path, REMOTE_ORIGIN); | ||
attribute_test( | ||
loader, url, | ||
entry => { | ||
assert_equals(entry.responseStatus, 0, | ||
`response status for ${entry.name} should be 0`); | ||
}); | ||
} | ||
|
||
resource_loaders = [ | ||
load.font, | ||
load.image, | ||
load.script, | ||
load.stylesheet, | ||
load.iframe | ||
]; | ||
|
||
resource_loaders.forEach(loader => { | ||
status_codes.forEach(status => run_test_cross_origin( | ||
loader, status | ||
)); | ||
}); | ||
|
||
</script> | ||
</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