-
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
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
- Loading branch information
1 parent
9716462
commit 53a0498
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