commit ec7a9f32288e6cc6c2a41774b7137122b1fe9674 parent f9dbea87d0277dae63646e101639daccf7bf1e8b Author: Guohui Deng <guohuideng@microsoft.com> Date: Thu, 8 Jan 2026 17:35:07 +0000 Bug 2008758 [wpt PR 57009] - Expose initiator-url in resourceTiming for more resources, a=testonly Automatic update from web-platform-tests Expose initiator-url in resourceTiming for more resources TaskAttribution is extended to track `initiator-url". The progress of the "initiatorUrl" reporting after this CL is the below: A) Supported: (1) Any static resource from a html file; (2) Resources fetched in script, in main thread, that's not an imported script, under the condition that the resource fetch happens after script loading or beyond a number of common ways to dispatch an asynchronous call: postTask(); fulfillments of a promise; queueMicrotask(); requestAnimationFrame(); requestIdleCallback(); setInterval(); setTimeout(); XMLHttpRequest(); B) Not Supported yet but planned: (1) CSS resources that are initiated from another CSS file; (2) Script resources that are imported JS; (3) Resources fetched in the main thread, by the script that are dispatched via an EventHandler, or a MessageHandler; (4) Resource fetched by script running in a worker thread; C) Not planned to support: any rare cases that requires significant efforts, and any resources fetched via deprecated APIs. Example: (1) document.write(); (2) Resources fetched in the main thread, by the script that are dispatched via rarely used asynchronous calls. In addition, previous tests are re-organized and refactored. Credit to previous contributor: Some "inline-script" test cases are merged from(with significant modification): https://chromium-review.googlesource.com/c/chromium/src/+/4812813 And For script initiators, TaskAttributionInfo is used according to this draft CL: https://chromium-review.googlesource.com/c/chromium/src/+/4931296/21 PERFETTO_TESTS=`autoninja -C out/Default perfetto_diff_tests && out/Default/bin/run_perfetto_diff_tests` Bug: 40919714 Change-Id: I125e62d488eec5a85f8afa6cd61c399183c56d86 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6960132 Commit-Queue: Guohui Deng <guohuideng@microsoft.com> Reviewed-by: Scott Haseley <shaseley@chromium.org> Reviewed-by: Mikhail Khokhlov <khokhlov@google.com> Reviewed-by: Michal Mocny <mmocny@chromium.org> Cr-Commit-Position: refs/heads/main@{#1565205} -- wpt-commits: c2537699cbe35a98bd3baa0bae6186fabc7c9651 wpt-pr: 57009 Diffstat:
23 files changed, 581 insertions(+), 137 deletions(-)
diff --git a/testing/web-platform/tests/lint.ignore b/testing/web-platform/tests/lint.ignore @@ -416,6 +416,7 @@ SET TIMEOUT: html/webappapis/dynamic-markup-insertion/opening-the-input-stream/c SET TIMEOUT: html/webappapis/timers/* SET TIMEOUT: portals/history/resources/portal-harness.js SET TIMEOUT: requestidlecallback/deadline-after-expired-timer.html +SET TIMEOUT: resource-timing/tentative/initiator-url/set-timeout.html SET TIMEOUT: resources/* SET TIMEOUT: scheduler/tentative/current-task-signal-async-abort.any.js SET TIMEOUT: scheduler/tentative/current-task-signal-async-priority.any.js diff --git a/testing/web-platform/tests/resource-timing/resources/iframe-post-message.html b/testing/web-platform/tests/resource-timing/resources/iframe-post-message.html @@ -0,0 +1,9 @@ +<!doctype html> +<html> + <script> + window.addEventListener('message', e => { + const port = e.ports?.[0]; + port.postMessage("hello from iframe"); + }); + </script> +</html> diff --git a/testing/web-platform/tests/resource-timing/resources/loading-resource-lib.js b/testing/web-platform/tests/resource-timing/resources/loading-resource-lib.js @@ -0,0 +1,9 @@ +// This js file actually calls fetch to load an image to +// an element. +async function load_image(label, img_element) { + const url = "/images/blue.png?"+label; + const response = await fetch(url); + blob = await response.blob(); + const imgURL = URL.createObjectURL(blob); + img_element.src = imgURL; +} diff --git a/testing/web-platform/tests/resource-timing/resources/loading-resources-in-posted-task.js b/testing/web-platform/tests/resource-timing/resources/loading-resources-in-posted-task.js @@ -0,0 +1,29 @@ +function load_resources() { + //Fetching the Stylesheet + var link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = "resources/empty_style.css?no_cache"; + link.id = "link_id"; + document.head.appendChild(link); + + // Fetching an image + var img = document.createElement("img"); + img.src = "/images/blue.png?no_cache"; + img.alt = "Sample Image for testing initiator Attribute"; + img.id = "img_id" + document.body.appendChild(img); + + // Inserting a script element + var script = document.createElement("script"); + script.src = "resources/empty.js?no_cache"; + script.id = "script_id" + document.body.appendChild(script); + + //Inserting a html document in an iframe + var iframe = document.createElement("iframe"); + iframe.src = "resources/green.html?no_cache"; + iframe.id = "iframe_id"; + document.body.appendChild(iframe); +} + +scheduler.postTask(load_resources); diff --git a/testing/web-platform/tests/resource-timing/resources/loading-resources.js b/testing/web-platform/tests/resource-timing/resources/loading-resources.js @@ -0,0 +1,25 @@ +//Fetching the Stylesheet +var link = document.createElement("link"); +link.rel = "stylesheet"; +link.href = "resources/empty_style.css?no_cache"; +link.id = "link_id"; +document.head.appendChild(link); + +// Fetching an image +var img = document.createElement("img"); +img.src = "/images/blue.png?no_cache"; +img.alt = "Sample Image for testing initiator Attribute"; +img.id = "img_id" +document.body.appendChild(img); + +// Inserting a script element +var script = document.createElement("script"); +script.src = "resources/empty.js?no_cache"; +script.id = "script_id" +document.body.appendChild(script); + +//Inserting a html document in an iframe +var iframe = document.createElement("iframe"); +iframe.src = "resources/green.html?no_cache"; +iframe.id = "iframe_id"; +document.body.appendChild(iframe); diff --git a/testing/web-platform/tests/resource-timing/resources/loadingResources.js b/testing/web-platform/tests/resource-timing/resources/loadingResources.js @@ -1,21 +0,0 @@ -//Fetching the Stylesheet -var link = document.createElement("link"); -link.rel = "stylesheet"; -link.href = "../resources/empty_style.css"; -document.head.appendChild(link); - -// Fetching an image -var img = document.createElement("img"); -img.src = "/images/blue.png"; -img.alt = "Sample Image for testing initiator Attribute"; -document.body.appendChild(img); - -//Inserting a html document in an iframe -var iframe = document.createElement("iframe"); -iframe.src = "../resources/green.html"; -document.body.appendChild(iframe); - -// Inserting a script element -var script = document.createElement("script"); -script.src = "../resources/empty.js"; -document.body.appendChild(script); diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/document-initiated.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/document-initiated.html @@ -1,90 +0,0 @@ -<!DOCTYPE html> -<head> - <script src="/resources/testharness.js"></script> - <script src="/resources/testharnessreport.js"></script> - <script src="/resource-timing/resources/observe-entry.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/display_paragraph.js" 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" /> - <script src="../../resources/display_paragraph.js"></script> - <!-- Inline Styles --> - <style> - body { - background-image: url("/images/blue.png?inline-style"); - font-family: remoteFont, sans-serif; - } - @font-face { - font-family: remoteFont; - /* This query parameter ensures that the Ahem.ttf is not retrieved from the cache. */ - src: url("/fonts/Ahem.ttf?initiator-html"); - } - </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> - display_paragraph(); - - // TODO(crbug.com/40919714): The two elements below are not initiated by html. - // They are initiated by script. They should be moved out of this test. - // As of 08/2025 the two below are passing for chromium but because of wrong - // reasons. They are not recognized to be resources initaited by scripts, so they - // are thought to be initiated from main html, for which the url happens to be - // correct for inline scripts. - - // 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/initiator-url/document-initiated.html"; - - const resources = [ - "empty.js?blocking", - "display_paragraph.js", - "empty.js?async", - "empty.js?deferred", - "empty.js?module", - "empty_style.css?link", - "blue.png?inline-style", - "Ahem.ttf?initiator-html", - "blue.png?using-Img-tag", - /* "green.html", - TODO(crbug.com/40919714): report initiator for iframe element. - */ - "empty_style.css?inline-script", - "blue.png?inline-script", - ]; - for (const resource of resources) { - initiator_url_test(resource, expectedInitiatorUrl, resource+ - " initiatorUrl from document-initiated", resource+" timeout"); - } - - </script> -</body> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/event-handler.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/event-handler.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched via event handler, + the initiator_url points to script that sets up the event handler. + </p> +</body> +<script> + + var img = document.createElement("img"); + document.body.appendChild(img); + + const frame = document.createElement("iframe"); + frame.addEventListener("load", () => { + load_image(label, img); + }); + frame.src = "../resources/green.html"; + document.body.appendChild(frame); + + + const label = "initiator_url_eventhandler"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/event-handler.html"; + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from event handlers", resource + " timeout"); +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/external-script-in-posted-task.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/external-script-in-posted-task.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + +</head> +<body> + <script src="../../resources/loading-resources-in-posted-task.js"></script> + + <h1>Description</h1> + <p> This test loads a number of resources in the loading-resources.js via scheduler.postTask() + and verifies that `iniatitor_url`s in ResourceTiming are expected. + </p> +</body> +<script> + + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + "/resource-timing/resources/loading-resources-in-posted-task.js"; + const resources = [ + "empty_style.css?no_cache", + "blue.png?no_cache", + "empty.js?no_cache", + "green.html?no_cache", + ]; + for (const resource of resources) { + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl by scheduler.postTask() from external scripts", resource + " timeout"); + } +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/external-script.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/external-script.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + +</head> +<body> + <script src="../../resources/loading-resources.js"></script> + + <h1>Description</h1> + <p> This test loads a number of resources in the loading-resources.js and + verifies that `iniatitor_url`s in ResourceTiming entries are as expected. + </p> +</body> +<script> + + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + "/resource-timing/resources/loading-resources.js"; + const resources = [ + "empty_style.css?no_cache", + "blue.png?no_cache", + "empty.js?no_cache", + "green.html?no_cache", + ]; + for (const resource of resources) { + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from external scripts", resource + " timeout"); + } +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/iframe-post-message.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/iframe-post-message.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched via message handler, + the initiator_url points to script that sends the message. + </p> +</body> +<script> + + const channel = new MessageChannel(); + const frame = document.createElement("iframe"); + frame.addEventListener("load", () => { + frame.contentWindow.postMessage("port", "*", [channel.port2]); + }); + frame.src = "../../resources/iframe-post-message.html"; + document.body.appendChild(frame); + + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_iframe_postmessage"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/iframe-post-message.html"; + + channel.port1.onmessage = e => { + load_image(label, img); + } + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from iframe postMessage()", resource + " timeout"); + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/inline-document-write.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/inline-document-write.html @@ -17,8 +17,8 @@ document.write('<link id="css_written" rel="stylesheet" href="../resources/empty_style.css?inline-script-doc-write">'); document.write('<script id="script_written" src="../resources/empty.js?doc-write"><\/script>'); - const host_info = get_host_info(); - const expectedInitiatorUrl = host_info["ORIGIN"] + + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + "/resource-timing/tentative/initiator-url/inline-document-write.html"; const resources = [ diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/inline-script.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/inline-script.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for resources including an + iframe, that are loaded by an inline script, the + initiatorUrl is properly reported. + </p> +</body> +<script> + + const label = "no_cache_inline_script"; + + var ifr = document.createElement("iframe"); + document.body.appendChild(ifr); + ifr.src = "resources/blank_page_green.html?" + label; + + const link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = "../../resources/empty_style.css?" + label; + document.head.appendChild(link); + + const img = document.createElement("img"); + img.src = "/images/blue.png?" + label; + document.body.appendChild(img); + + const resources = [ + "blank_page_green.html?" + label, + "empty_style.css?" + label, + "blue.png?" + label, + ]; + + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/inline-script.html"; + + for (const resource of resources) { + initiator_url_test(resource, expectedInitiatorUrl, resource+ + " initiatorUrl from inline-script", resource+" timeout"); + } + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/post-task.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/post-task.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a postTask, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_posttask"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/post-task.html"; + scheduler.postTask(function() {load_image(label, img)}); + + initiator_url_test(resource, expectedInitiatorUrl, resource+ + " initiatorUrl from postTask()", resource + " timeout"); + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/promise.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/promise.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a Promise, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_promise"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/promise.html"; + const instant_promise = Promise.resolve(); + instant_promise.then( function() {load_image(label, img)} ); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from fullfilled promise", resource + " timeout"); + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/queue-microtask.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/queue-microtask.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a queueMicrotask, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_queuemicrotask"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/queue-microtask.html"; + queueMicrotask( function() {load_image(label, img)} ); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from queueMicrotask()", resource + " timeout"); +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/request-animation-frame.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/request-animation-frame.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a requestAnimationFrame, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_requestanimationframe"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/request-animation-frame.html"; + requestAnimationFrame(function() {load_image(label, img)}); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from requestAnimationFrame()", resource + "timeout"); + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/request-idle-callback.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/request-idle-callback.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a requestIdleCallback, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_requestidlecallback"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/request-idle-callback.html"; + requestIdleCallback(function() {load_image(label, img)}); + + initiator_url_test(resource, expectedInitiatorUrl, test + + " initiatorUrl from requestIdleCallback()", resource + " timeout"); +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/set-interval.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/set-interval.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a setInterval, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_setinterval"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/set-interval.html"; + setInterval( function() {load_image(label, img)} , 10); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from setInterval()", resource + " timeout"); +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/set-timeout.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/set-timeout.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a setTimeout, + the initiator_url points to the async caller script, + instead of the callee script. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_settimeout"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/set-timeout.html"; + setTimeout(function() {load_image(label, img);}, 0); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from setTimeout()", resource + " timeout"); + +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/static-resource.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/static-resource.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/resource-timing/resources/observe-entry.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/display_paragraph.js" 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" /> + <script src="../../resources/display_paragraph.js"></script> + <!-- Inline Styles --> + <style> + body { + background-image: url("/images/blue.png?inline-style"); + font-family: remoteFont, sans-serif; + } + @font-face { + font-family: remoteFont; + /* This query parameter ensures that the Ahem.ttf is not retrieved from the cache. */ + src: url("/fonts/Ahem.ttf?initiator-html"); + } + </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> + display_paragraph(); + + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/static-resource.html"; + + const resources = [ + "empty.js?blocking", + "display_paragraph.js", + "empty.js?async", + "empty.js?deferred", + "empty.js?module", + "empty_style.css?link", + "blue.png?inline-style", + "Ahem.ttf?initiator-html", + "blue.png?using-Img-tag", + "green.html", + ]; + for (const resource of resources) { + initiator_url_test(resource, expectedInitiatorUrl, resource+ + " initiatorUrl from static-resource", resource+" timeout"); + } + + </script> +</body> diff --git a/testing/web-platform/tests/resource-timing/tentative/initiator-url/xml-http-request.html b/testing/web-platform/tests/resource-timing/tentative/initiator-url/xml-http-request.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/common/get-host-info.sub.js"></script> + <script src="../../resources/test-initiator.js"></script> + + <script src="../../resources/loading-resource-lib.js"></script> +</head> +<body> + <h1>Description</h1> + <p> This test verifies that, for a resource fetched with a XMLHttpRequest, + the initiator_url points to the script where xmlhttprequest.send() + happens. + </p> +</body> +<script> + var img = document.createElement("img"); + document.body.appendChild(img); + + const label = "initiator_url_xmlhttprequest"; + const resource = "/images/blue.png?"+label; + const hostInfo = get_host_info(); + const expectedInitiatorUrl = hostInfo["ORIGIN"] + + "/resource-timing/tentative/initiator-url/xml-http-request.html"; + const request = new XMLHttpRequest(); + request.onload = function() {load_image(label, img)}; + request.open("GET", "/resources/blank.html"); + request.send(); + + initiator_url_test(resource, expectedInitiatorUrl, resource + + " initiatorUrl from XMLHttpRequest()", resource + " timeout"); +</script> diff --git a/testing/web-platform/tests/resource-timing/tentative/script-initiated.html b/testing/web-platform/tests/resource-timing/tentative/script-initiated.html @@ -1,24 +0,0 @@ -<!DOCTYPE html> -<head> - <script src="/resources/testharness.js"></script> - <script src="/resources/testharnessreport.js"></script> - - <!-- Helper Functions for getting ResourceID --> - <script src="../resources/get-resourceID.js"></script> - <!-- Responsible for testing Initiator Attribute --> - <script src="../resources/test-initiator.js"></script> - - <!--Script Responsible for loading various other resources --> - <script src="../resources/loadingResources.js"></script> -</head> -<body> -</body> -<script> - promise_test(async (t) => { - const expectedInitiator = await getResourceID("loadingResources.js"); - const resources = ["empty_style.css", "blue.png", "green.html", "empty.js"]; - for (const resource of resources) { - await testResourceInitiator(resource, expectedInitiator); - } - }, "Ensure initiator Attribute matches with Script ResourceID"); -</script>