From 81fc727ea51e185952e8d05a860a5109b69b2461 Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Sun, 3 Oct 2021 10:17:45 +0000 Subject: [PATCH] Bug 1720812 [wpt PR 29684] - [WPT] Move/merge COEP/COOP dispatcher framework to /common, a=testonly Automatic update from web-platform-tests [WPT] Move/merge COEP/COOP dispatcher framework to /common (#29684) To reduce duplication and prepare for using this framework for BFCache (https://github.com/web-platform-tests/wpt/pull/28950), this CL merges two sets of dispatcher/executor files under COEP and COOP and move them to `/common`. Relevant discussion is also in https://github.com/web-platform-tests/rfcs/pull/89. Most of the changes are simple path renaming, except for: - Service worker's scope is also moved to `/common/dispatcher/` in: /wpt/html/cross-origin-embedder-policy/credentialless/service-worker-coep-credentialless-proxy.tentative.https.html /wpt/html/cross-origin-embedder-policy/credentialless/service-worker-coep-none-proxy.tentative.https.html /wpt/html/cross-origin-opener-policy/popup-coop-by-sw.https.html because the service workers should control executors. - Diffs between COEP and COOP dispatchers are merged, but are trivial (e.g. some functionality exists only one of them, like 6 concurrent accesses to the server, retrying on failure, Access-Control-Allow-Credentials in dispatcher, etc.). - Reporting-related part of `dispatcher.js` is moved to /wpt/html/cross-origin-opener-policy/reporting/resources/reporting-common.js. - README.md about the dispatcher is moved and added. - /wpt/html/cross-origin-embedder-policy/credentialless/resources/cacheable-response.py is also merged into dispatcher.py, because they should access the same stash and already have common code. - Stash paths are moved to '/common/dispatcher'. - `executer.js` and `sw_executer.js` are moved to `executer-worker.js` and `executer-service-worker.js`, respectively, to clarify they are worker scripts, rather than helpers. - Timeout in receive() is removed because no one uses that parameter. - Duplicated/unused const declarations are removed. Bug: 1107415 Change-Id: I0d28e7f4b4cca6599562ac4766a326880139028d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3033199 Commit-Queue: Hiroshige Hayashizaki Reviewed-by: Arthur Sonzogni Reviewed-by: Kouhei Ueno Cr-Commit-Position: refs/heads/main@{#921511} Co-authored-by: Hiroshige Hayashizaki -- wpt-commits: bb06b9cd1abb9467a296177d468da156f6df2bbc wpt-pr: 29684 --- .../tests/common/dispatcher/README.md | 33 +++++++ .../dispatcher}/dispatcher.js | 10 +- .../dispatcher}/dispatcher.py | 10 +- .../dispatcher/executor-service-worker.js} | 0 .../dispatcher/executor-worker.js} | 0 .../dispatcher}/executor.html | 6 +- ...nonymous-iframe-popup.tentative.https.html | 2 +- .../cookie.tentative.https.html | 2 +- .../local-storage.tentative.https.html | 2 +- .../credentialless/README.md | 12 --- .../cache-storage.tentative.https.html | 2 +- .../credentialless/cache.tentative.html | 7 +- .../credentialless/cross-origin-isolated.html | 2 +- .../dedicated-worker.tentative.https.html | 6 +- .../credentialless/fetch.tentative.https.html | 2 +- ...e-coep-credentialless.tentative.https.html | 2 +- .../iframe-coep-none.tentative.https.html | 2 +- ...ame-coep-require-corp.tentative.https.html | 2 +- .../credentialless/iframe.tentative.html | 2 +- .../credentialless/image.tentative.https.html | 2 +- .../credentialless/link.tentative.https.html | 2 +- .../credentialless/redirect.tentative.html | 2 +- .../resources/cacheable-response.py | 24 ----- .../credentialless/resources/common.js | 13 ++- .../credentialless/resources/executor.html | 15 --- .../script.tentative.https.html | 2 +- ...-credentialless-proxy.tentative.https.html | 9 +- ...orker-coep-none-proxy.tentative.https.html | 9 +- .../service-worker.tentative.https.html | 6 +- .../shared-worker.tentative.https.html | 6 +- .../credentialless/video.tentative.https.html | 2 +- ...frame-history-none-require-corp.https.html | 2 +- .../none.https.html | 2 +- ...coop-navigate-same-origin-csp-sandbox.html | 5 +- ...me-origin-allow-popups-document-write.html | 5 +- .../navigate-to-aboutblank.https.html | 5 +- .../navigate-top-to-aboutblank.https.html | 5 +- .../popup-coop-by-sw.https.html | 13 ++- ...direct-same-origin-allow-popups.https.html | 4 +- ...rom-coop-page-to-openee_coop-ro.https.html | 5 +- ...-to-openee_coop-ro_cross-origin.https.html | 5 +- ...rom-coop-page-to-opener_coop-ro.https.html | 5 +- ...-to-opener_coop-ro_cross-origin.https.html | 5 +- ...from-coop-page-to-other_coop-ro.https.html | 5 +- ...e-to-other_coop-ro_cross-origin.https.html | 5 +- ...o-coop-page-from-openee_coop-ro.https.html | 5 +- ...rom-openee_coop-ro_cross-origin.https.html | 5 +- ...o-coop-page-from-opener_coop-ro.https.html | 5 +- ...rom-opener_coop-ro_cross-origin.https.html | 5 +- ...to-coop-page-from-other_coop-ro.https.html | 5 +- ...from-other_coop-ro_cross-origin.https.html | 5 +- .../access-reporting/property-blur.https.html | 3 +- .../property-close.https.html | 3 +- .../property-closed.https.html | 3 +- .../property-focus.https.html | 3 +- .../property-frames.https.html | 3 +- .../property-indexed-getter.https.html | 4 +- .../property-length.https.html | 3 +- .../property-location-get.https.html | 3 +- .../property-location-set.https.html | 3 +- .../property-named-getter.https.html | 5 +- .../property-opener-get.https.html | 3 +- .../property-opener-set.https.html | 3 +- .../property-postmessage-1.https.html | 3 +- .../property-postmessage-2.https.html | 3 +- .../access-reporting/property-self.https.html | 3 +- .../access-reporting/property-top.https.html | 3 +- .../property-window.https.html | 3 +- .../report-to-both_coop-ro.https.html | 5 +- .../access-reporting/reporting-observer.html | 5 +- .../report-only-four-reports.https.html | 2 +- .../report-only-from-unsafe-none.https.html | 2 +- ...port-only-same-origin-report-to.https.html | 2 +- ...me-origin-with-coep-report-only.https.html | 2 +- ...port-only-same-origin-with-coep.https.html | 2 +- .../report-only-same-origin.https.html | 2 +- ...reporting-coop-navigated-opener.https.html | 4 +- .../reporting-coop-navigated-popup.https.html | 2 +- ...e-origin-allow-popups-report-to.https.html | 2 +- ...opup-same-origin-coep-report-to.https.html | 2 +- ...ing-popup-same-origin-report-to.https.html | 2 +- .../reporting-popup-same-origin.https.html | 2 +- ...ing-popup-unsafe-none-report-to.https.html | 2 +- ...t-with-same-origin-allow-popups.https.html | 5 +- .../reporting/resources/reporting-common.js | 44 ++++++++- .../resources/test-access-property.js | 4 - .../resources/dispatcher.js | 94 ------------------- .../resources/dispatcher.py | 27 ------ .../resources/sw_executor.js | 24 ----- testing/web-platform/tests/lint.ignore | 3 +- 90 files changed, 231 insertions(+), 359 deletions(-) create mode 100644 testing/web-platform/tests/common/dispatcher/README.md rename testing/web-platform/tests/{html/cross-origin-embedder-policy/credentialless/resources => common/dispatcher}/dispatcher.js (90%) rename testing/web-platform/tests/{html/cross-origin-embedder-policy/credentialless/resources => common/dispatcher}/dispatcher.py (84%) rename testing/web-platform/tests/{html/cross-origin-embedder-policy/credentialless/resources/sw_executor.js => common/dispatcher/executor-service-worker.js} (100%) rename testing/web-platform/tests/{html/cross-origin-embedder-policy/credentialless/resources/executor.js => common/dispatcher/executor-worker.js} (100%) rename testing/web-platform/tests/{html/cross-origin-opener-policy/resources => common/dispatcher}/executor.html (69%) delete mode 100644 testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/cacheable-response.py delete mode 100644 testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/executor.html delete mode 100644 testing/web-platform/tests/html/cross-origin-opener-policy/resources/dispatcher.js delete mode 100644 testing/web-platform/tests/html/cross-origin-opener-policy/resources/dispatcher.py delete mode 100644 testing/web-platform/tests/html/cross-origin-opener-policy/resources/sw_executor.js diff --git a/testing/web-platform/tests/common/dispatcher/README.md b/testing/web-platform/tests/common/dispatcher/README.md new file mode 100644 index 0000000000000..befbb19ae9116 --- /dev/null +++ b/testing/web-platform/tests/common/dispatcher/README.md @@ -0,0 +1,33 @@ +# Message passing API + +`dispatcher.js` (and its server-side backend `dispatcher.py`) provides a +universal queue-based message passing API. +Each queue is identified by a UUID, and accessed via the following APIs: + +- `send(uuid, message)` pushes a string `message` to the queue `uuid`. +- `receive(uuid)` pops the first item from the queue `uuid`. +- `showRequestHeaders(origin, uuid)` and + `cacheableShowRequestHeaders(origin, uuid)` return URLs, that push request + headers to the queue `uuid` upon fetching. + +It works cross-origin, and even access different browser context groups. + +Messages are queued, this means one doesn't need to wait for the receiver to +listen, before sending the first message +(but still need to wait for the resolution of the promise returned by `send()` +to ensure the order between `send()`s). + +# Executor framework + +The message passing API can be used for sending arbitrary javascript to be +evaluated in another page or worker (the "executor"). + +`executor.html` (as a Document), `executor-worker.js` (as a Web Worker), and +`executor-service-worker.js` (as a Service Worker) are examples of executors. +Tests can send arbitrary javascript to these executors to evaluate in its +execution context. + +This is universal and avoids introducing many specific `XXX-helper.html` +resources. +Moreover, tests are easier to read, because the whole logic of the test can be +defined in a single file. diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.js b/testing/web-platform/tests/common/dispatcher/dispatcher.js similarity index 90% rename from testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.js rename to testing/web-platform/tests/common/dispatcher/dispatcher.js index 122983e85e1d6..8350933e80139 100644 --- a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.js +++ b/testing/web-platform/tests/common/dispatcher/dispatcher.js @@ -1,7 +1,6 @@ // Define an universal message passing API. It works cross-origin and across // browsing context groups. -const dispatcher_path = - "/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.py"; +const dispatcher_path = "/common/dispatcher/dispatcher.py"; const dispatcher_url = new URL(dispatcher_path, location.href).href; // Return a promise, limiting the number of concurrent accesses to a shared @@ -78,6 +77,11 @@ const receive = async function(uuid) { // Returns an URL. When called, the server sends toward the `uuid` queue the // request headers. Useful for determining if something was requested with // Cookies. -const showRequestHeaders= function(origin, uuid) { +const showRequestHeaders = function(origin, uuid) { return origin + dispatcher_path + `?uuid=${uuid}&show-headers`; } + +// Same as above, except for the response is cacheable. +const cacheableShowRequestHeaders = function(origin, uuid) { + return origin + dispatcher_path + `?uuid=${uuid}&cacheable&show-headers`; +} diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.py b/testing/web-platform/tests/common/dispatcher/dispatcher.py similarity index 84% rename from testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.py rename to testing/web-platform/tests/common/dispatcher/dispatcher.py index 22d07229c77ba..9fe7a38ac87da 100644 --- a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.py +++ b/testing/web-platform/tests/common/dispatcher/dispatcher.py @@ -9,9 +9,13 @@ def main(request, response): response.headers.set(b"Access-Control-Allow-Credentials", b"true") response.headers.set(b'Access-Control-Allow-Methods', b'OPTIONS, GET, POST') response.headers.set(b'Access-Control-Allow-Headers', b'Content-Type') - response.headers.set(b'Cache-Control', b'no-cache, no-store, must-revalidate') response.headers.set(b"Access-Control-Allow-Origin", request.headers.get(b"origin") or '*') + if b"cacheable" in request.GET: + response.headers.set(b"Cache-Control", b"max-age=31536000") + else: + response.headers.set(b'Cache-Control', b'no-cache, no-store, must-revalidate') + # CORS preflight if request.method == u'OPTIONS': return b'' @@ -22,7 +26,7 @@ def main(request, response): # The stash is accessed concurrently by many clients. A lock is used to # avoid unterleaved read/write from different clients. with stash.lock: - queue = stash.take(uuid, '/coep-credentialless') or []; + queue = stash.take(uuid, '/common/dispatcher') or []; # Push into the |uuid| queue, the requested headers. if b"show-headers" in request.GET: @@ -45,5 +49,5 @@ def main(request, response): else: ret = queue.pop(0) - stash.put(uuid, queue, '/coep-credentialless') + stash.put(uuid, queue, '/common/dispatcher') return ret; diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/sw_executor.js b/testing/web-platform/tests/common/dispatcher/executor-service-worker.js similarity index 100% rename from testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/sw_executor.js rename to testing/web-platform/tests/common/dispatcher/executor-service-worker.js diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/executor.js b/testing/web-platform/tests/common/dispatcher/executor-worker.js similarity index 100% rename from testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/executor.js rename to testing/web-platform/tests/common/dispatcher/executor-worker.js diff --git a/testing/web-platform/tests/html/cross-origin-opener-policy/resources/executor.html b/testing/web-platform/tests/common/dispatcher/executor.html similarity index 69% rename from testing/web-platform/tests/html/cross-origin-opener-policy/resources/executor.html rename to testing/web-platform/tests/common/dispatcher/executor.html index a4e92075c80b1..5fe6a95efaf97 100644 --- a/testing/web-platform/tests/html/cross-origin-opener-policy/resources/executor.html +++ b/testing/web-platform/tests/common/dispatcher/executor.html @@ -5,8 +5,10 @@ const uuid = params.get('uuid'); let executeOrders = async function() { - while(true) - eval(await receive(uuid)); + while(true) { + let task = await receive(uuid); + eval(`(async () => {${task}})()`); + } }; executeOrders(); diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html b/testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html index 0d1b6402f5da3..4326bb92d608b 100644 --- a/testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html +++ b/testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html @@ -4,8 +4,8 @@ + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - diff --git a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/script.tentative.https.html b/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/script.tentative.https.html index 45464dc4d38de..6a3f6559cb360 100644 --- a/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/script.tentative.https.html +++ b/testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/script.tentative.https.html @@ -2,8 +2,8 @@ + - + - + - + - + - + - + - - + - +

Non-initial empty documents (about:blank) should inherit their cross-origin-opener-policy from the navigation's initiator top level document, @@ -24,8 +24,7 @@ + -

Non-initial empty documents (about:blank) should inherit their @@ -28,8 +28,7 @@ + - - +

+ - + + - + + - + + - + + - + + - + + - + + - + - + + - + + + - + + - + - + + - + + - + + - + + - + + - + - + + - + + - + + - + - + + - + + - + + - + + - + + - + + - + + + - + + - + + - + - + - + - + - + - - + + - + + - + - > + - + - + - - + +