From a45d50478ef81051c483b6739fef709b410b4f2e Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Wed, 12 May 2021 14:49:34 -0700 Subject: [PATCH] [resource timing] Improve document.domain tests (reland) (#28965) This CL is a fixed up reland of [1], which was reverted due to a rename in entry-invariants.js that it was relying on. [1] https://chromium-review.googlesource.com/c/chromium/src/+/2878852 Bug: 1171767, 1208054 Change-Id: I436bf6973e4399d142ce45e77c07f26d0e7e1cd1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2888667 Reviewed-by: Tom McKee Commit-Queue: Yoav Weiss Cr-Commit-Position: refs/heads/master@{#881945} Co-authored-by: Yoav Weiss Co-authored-by: Kyle Ju --- common/get-host-info.sub.js | 1 + .../document-domain-no-impact-loader.sub.html | 15 --------- .../document-domain-no-impact-opener.html | 16 +++++++++ .../resources/document-domain-no-impact.html | 28 ++++++++++++++++ .../document-domain-no-impact.sub.html | 33 ------------------- resource-timing/resources/entry-invariants.js | 24 ++++++++++---- resource-timing/resources/resource-loaders.js | 5 ++- 7 files changed, 66 insertions(+), 56 deletions(-) delete mode 100644 resource-timing/document-domain-no-impact-loader.sub.html create mode 100644 resource-timing/document-domain-no-impact-opener.html create mode 100644 resource-timing/resources/document-domain-no-impact.html delete mode 100644 resource-timing/resources/document-domain-no-impact.sub.html diff --git a/common/get-host-info.sub.js b/common/get-host-info.sub.js index 8f37d557583b99..53602a632f3387 100644 --- a/common/get-host-info.sub.js +++ b/common/get-host-info.sub.js @@ -33,6 +33,7 @@ function get_host_info() { HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED, HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED, REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED, + OTHER_ORIGIN: PROTOCOL + "//" + OTHER_HOST + PORT_ELIDED, HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED, HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED, HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED, diff --git a/resource-timing/document-domain-no-impact-loader.sub.html b/resource-timing/document-domain-no-impact-loader.sub.html deleted file mode 100644 index 8a1c433a5c3a7b..00000000000000 --- a/resource-timing/document-domain-no-impact-loader.sub.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - diff --git a/resource-timing/document-domain-no-impact-opener.html b/resource-timing/document-domain-no-impact-opener.html new file mode 100644 index 00000000000000..69df2f27fa5b19 --- /dev/null +++ b/resource-timing/document-domain-no-impact-opener.html @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/resource-timing/resources/document-domain-no-impact.html b/resource-timing/resources/document-domain-no-impact.html new file mode 100644 index 00000000000000..bacae10b13a9a9 --- /dev/null +++ b/resource-timing/resources/document-domain-no-impact.html @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/resource-timing/resources/document-domain-no-impact.sub.html b/resource-timing/resources/document-domain-no-impact.sub.html deleted file mode 100644 index fbd7bc3b6e21ee..00000000000000 --- a/resource-timing/resources/document-domain-no-impact.sub.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/resource-timing/resources/entry-invariants.js b/resource-timing/resources/entry-invariants.js index 93bc9933d9f371..462284473c0b36 100644 --- a/resource-timing/resources/entry-invariants.js +++ b/resource-timing/resources/entry-invariants.js @@ -168,10 +168,7 @@ const invariants = { } }; -// Given a resource-loader, a path (a relative path or absolute URL), and a -// PerformanceResourceTiming validator, applies the loader to the resource path -// and applies the validator to the resulting PerformanceResourceTiming entry. -const attribute_test = (loader, path, validate, test_label) => { +const attribute_test_internal = (loader, path, validator, run_test, test_label) => { promise_test( async () => { let loaded_entry = new Promise((resolve, reject) => { @@ -190,8 +187,21 @@ const attribute_test = (loader, path, validate, test_label) => { }).observe({"type": "resource"}); }); - await loader(path); + await loader(path, validator); const entry = await(loaded_entry); - validate(entry); + run_test(entry); }, test_label); -} +}; + +// Given a resource-loader, a path (a relative path or absolute URL), and a +// PerformanceResourceTiming test, applies the loader to the resource path +// and tests the resulting PerformanceResourceTiming entry. +const attribute_test = (loader, path, run_test, test_label) => { + attribute_test_internal(loader, path, () => {}, run_test, test_label); +}; + +// Similar to attribute test, but on top of that, validates the added element, +// to ensure the test does what it intends to do. +const attribute_test_with_validator = (loader, path, validator, run_test, test_label) => { + attribute_test_internal(loader, path, validator, run_test, test_label); +}; diff --git a/resource-timing/resources/resource-loaders.js b/resource-timing/resources/resource-loaders.js index a02de4fe0a63f1..1760628c78bdb8 100644 --- a/resource-timing/resources/resource-loaders.js +++ b/resource-timing/resources/resource-loaders.js @@ -54,7 +54,7 @@ const load = { // Returns a promise that settles once the given path has been fetched as an // iframe. - iframe: async path => { + iframe: async (path, validator) => { const frame = document.createElement("iframe"); const loaded = new Promise(resolve => { frame.onload = frame.onerror = resolve; @@ -62,6 +62,9 @@ const load = { frame.src = load.cache_bust(path); document.body.appendChild(frame); await loaded; + if (validator instanceof Function) { + validator(frame); + } document.body.removeChild(frame); },