Skip to content

Commit

Permalink
Bug 1743782 [wpt PR 30970] - Create resource timing entries for fetch…
Browse files Browse the repository at this point in the history
… network errors, a=testonly

Automatic update from web-platform-tests
Create resource timing entries for fetch network errors (#30970)

* Create resource timing entries for fetch network errors

An initial test for whatwg/fetch#1215

* Remove a few ambiguous errors

* Remove timeout scenario

* Remove unnecessary lines

* Added mixed content case

* Try to make test less flaky

* Make test not flaky

* Use attribute_test

* lint
--

wpt-commits: 029d8d6672ceaed11b0cfef841621ece520a78ec
wpt-pr: 30970
  • Loading branch information
noamr authored and moz-wptsync-bot committed Dec 9, 2021
1 parent f1653b2 commit 41017ac
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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="noam@webkit.org">
<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");
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>
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}`);
}

0 comments on commit 41017ac

Please sign in to comment.