Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create resource timing entries for fetch network errors #30970

Merged
merged 9 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions resource-timing/entries-for-network-errors.sub.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>This test validates that a failed cross-origin fetch creates an opaque network timing entry.
</title>
<link rel="author" title="Noam Rosenthal" href="[email protected]">
<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="/common/get-host-info.sub.js"></script>
<script src="resources/entry-invariants.js"></script>
</head>
<body>
<script>
const validDataURL = 'data:,Hello%2C%20World%21'
const {REMOTE_ORIGIN, ORIGINAL_HOST, HTTP_PORT} = get_host_info();
const validXmlUrl = '/common/dummy.xml';

network_error_entry_test(
`${REMOTE_ORIGIN}${validXmlUrl}`, null, `failed cross-origin requests`);

network_error_entry_test(`/common/redirect.py?location=${validDataURL}`, null, "non-HTTP redirect");
network_error_entry_test('//{{hosts[][nonexistent]}}/common/dummy.xml', null, "DNS failure");
yoavweiss marked this conversation as resolved.
Show resolved Hide resolved
network_error_entry_test(`http://${ORIGINAL_HOST}:${HTTP_PORT}/commo/dummy.xml`, null, "Mixed content");

network_error_entry_test('/common/dummy.xml', {cache: 'only-if-cached'},
"only-if-cached resource that was not cached");

network_error_entry_test(
`/element-timing/resources/multiple-redirects.py?redirect_count=22&final_resource=${validXmlUrl}`,
null, "too many redirects");
</script>
</body>
</html>
21 changes: 21 additions & 0 deletions resource-timing/resources/entry-invariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,24 @@ const attribute_test = (loader, path, run_test, test_label) => {
const attribute_test_with_validator = (loader, path, validator, run_test, test_label) => {
attribute_test_internal(loader, path, validator, run_test, test_label);
};

const network_error_entry_test = (originalURL, args, label) => {
const url = new URL(originalURL, location.href);
const search = new URLSearchParams(url.search.substr(1));
const timeBefore = performance.now();
loader = () => new Promise(resolve => fetch(url, args).catch(resolve));

attribute_test(
loader, url,
() => {
const timeAfter = performance.now();
const names = performance.getEntriesByType('resource').filter(e => e.initiatorType === 'fetch').map(e => e.name);
const entries = performance.getEntriesByName(url.toString());
assert_equals(entries.length, 1, 'resource timing entry for network error');
const entry = entries[0]
assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');
assert_greater_than_equal(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');
assert_greater_than_equal(timeAfter, entry.responseEnd, 'endTime should be less than the time right after returning from the fetch');
invariants.assert_tao_failure_resource(entry);
}, `A ResourceTiming entry should be created for network error of type ${label}`);
}