Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /resource-timing/tentative/document-initiated.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-initiator.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<!-- Empty Blocking Script -->
<script src="../resources/empty.js?blocking"></script>
<!-- Empty Preloaded Script -->
<link rel="preload" href="../resources/empty.js?preload" as="script" />
<!-- Loading arbitrary Empty Blocking Async Script -->
<script async src="../resources/empty.js?async"></script>
<!-- Loading arbitrary Empty Deferred Script -->
<script defer src="../resources/empty.js?deferred"></script>
<!-- Loading arbitrary Empty Module Script -->
<script type="module" src="../resources/empty.js?module"></script>
<!-- Empty Stylesheet -->
<link rel="stylesheet" href="../resources/empty_style.css?link" />
<!-- Inline Styles -->
<style>
body {
background-image: url("/images/blue.png?inline-style");
font-family: remoteFont, sans-serif;
}
@font-face {
font-family: remoteFont;
src: url("/fonts/Ahem.ttf");
}
</style>
</head>
<body>
<!-- Loading an arbitrary Image using <img> tag -->
<img
src="/images/blue.png?using-Img-tag"
alt="Sample Image for testing initiator Attribute"
/>
<iframe src="../resources/green.html"></iframe>
<script>
function waitForLoad(obj) {
return new Promise(resolve => {
obj.addEventListener("load", resolve, { once: true });
});
}
// Load arbitrary stylesheet with inline script
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "../resources/empty_style.css?inline-script";
document.head.appendChild(link);
// Load arbitrary image with inline script
const img = document.createElement("img");
img.src = "/images/blue.png?inline-script";
document.body.appendChild(img);
const host_info = get_host_info();
const expectedInitiatorUrl = host_info["ORIGIN"] + "/resource-timing/tentative/document-initiated.html";
// Testing Initiator of all the resources loaded
promise_test(async (t) => {
await waitForLoad(link);
await waitForLoad(img);
const resources = [
"empty.js?blocking",
"empty.js?preload",
"empty.js?async",
"empty.js?deferred",
"empty.js?module",
"empty_style.css?link",
"blue.png?inline-style",
"Ahem.ttf",
"blue.png?using-Img-tag",
/* "green.html",
TODO(guohuideng@microsoft.com): report initiator for iframe element.
*/
"empty_style.css?inline-script",
"blue.png?inline-script",
];
for (const resource of resources) {
await testResourceInitiatorUrl(resource, expectedInitiatorUrl);
}
}, "initiatorUrl by main html file");
// Finally, test with the case document.write().
promise_test(async (t) => {
document.open();
document.write('<img id="img_written" src="/images/blue.png?inline-script-doc-write">');
document.close();
await waitForLoad(document.getElementById("img_written"));
await testResourceInitiatorUrl("blue.png?inline-script-doc-write", expectedInitiatorUrl);
document.open();
document.write('<link id="css_written" rel="stylesheet" href="../resources/empty_style.css?inline-script-doc-write">');
document.close();
await waitForLoad(document.getElementById("css_written"));
await testResourceInitiatorUrl("empty_style.css?inline-script-doc-write", expectedInitiatorUrl);
document.open();
document.write('<script id="script_written" src="../resources/empty.js?doc-write"><\/script>');
document.close();
await waitForLoad(document.getElementById("script_written"));
await testResourceInitiatorUrl("empty.js?doc-write", expectedInitiatorUrl);
}, "initiatorUrl for resource by document.write()");
</script>
</body>