Skip to content

Commit

Permalink
XHR ResourceTiming entry creation (#31027)
Browse files Browse the repository at this point in the history
* XHR ResourceTiming entry creation

Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319

* lint

* Move xhr internals to resource-loaders
  • Loading branch information
noamr committed Oct 4, 2021
1 parent a21ad2a commit 167763f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions resource-timing/resources/resource-loaders.js
Expand Up @@ -120,5 +120,14 @@ const load = {
}
}
xhr.send();
},

xhr_async: path => {
const xhr = new XMLHttpRequest();
xhr.open("GET", path)
xhr.send();
return new Promise(resolve => {
xhr.onload = xhr.onerror = resolve;
});
}
};
29 changes: 29 additions & 0 deletions resource-timing/xhr-resource-timing.html
@@ -0,0 +1,29 @@
<!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="resources/resource-loaders.js"></script>
<script src="resources/entry-invariants.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script>
const {REMOTE_ORIGIN} = get_host_info();

attribute_test(
load.xhr_async, "/common/dummy.xml",
invariants.assert_tao_pass_no_redirect_http,
"Verify resource timing entry creation for successful XHR");

attribute_test(
load.xhr_async, `${REMOTE_ORIGIN}/common/dummy.xml`,
invariants.assert_tao_failure_resource,
"Verify resource timing entry creation for XHR failing with CORS");
</script>
</body>

0 comments on commit 167763f

Please sign in to comment.