Skip to content

Commit

Permalink
Bug 1720812 [wpt PR 29684] - [WPT] Move/merge COEP/COOP dispatcher fr…
Browse files Browse the repository at this point in the history
…amework 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
(web-platform-tests/wpt#28950),
this CL merges two sets of dispatcher/executor files under COEP and COOP
and move them to `/common`.

Relevant discussion is also in
web-platform-tests/rfcs#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 <[email protected]>
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Kouhei Ueno <[email protected]>
Cr-Commit-Position: refs/heads/main@{#921511}

Co-authored-by: Hiroshige Hayashizaki <[email protected]>
--

wpt-commits: bb06b9cd1abb9467a296177d468da156f6df2bbc
wpt-pr: 29684
  • Loading branch information
chromium-wpt-export-bot authored and moz-wptsync-bot committed Oct 2, 2021
1 parent e8b7f01 commit 8f34a98
Show file tree
Hide file tree
Showing 90 changed files with 231 additions and 359 deletions.
33 changes: 33 additions & 0 deletions testing/web-platform/tests/common/dispatcher/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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''
Expand All @@ -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:
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="../credentialless/resources/common.js"></script>
<script src="../credentialless/resources/dispatcher.js"></script>
<body>
<script>
const {ORIGIN, REMOTE_ORIGIN} = get_host_info();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="../credentialless/resources/common.js"></script>
<script src="../credentialless/resources/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="../credentialless/resources/common.js"></script>
<script src="../credentialless/resources/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# Helper files:

- `resources/dispatcher.js` provides `send()` and `receive()`. This is an
universal message passing API. 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.

- `resources/executor.html` is a document. Test can send arbitrary javascript 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.

# Related documents:
- https://github.com/mikewest/credentiallessness/
- https://github.com/w3ctag/design-reviews/issues/582
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script>

// Fetch a resource and store it into CacheStorage from |storer| context. Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script>

// With COEP:credentialless, requesting a resource without credentials MUST NOT
Expand All @@ -24,8 +24,6 @@
const cookie_value = "coep_cache_value";
const same_origin = get_host_info().HTTPS_ORIGIN;
const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const cacheable_response_path =
"/html/cross-origin-embedder-policy/credentialless/resources/cacheable-response.py";

const GetCookie = (response) => {
return parseCookies(JSON.parse(response))[cookie_key];
Expand All @@ -49,8 +47,7 @@

// A request toward a "cross-origin" cacheable response.
const request_token = token();
const request_url = cross_origin + cacheable_response_path +
`?uuid=${request_token}`;
const request_url = cacheableShowRequestHeaders(cross_origin, request_token);

promise_setup(async test => {
await setCookie(cross_origin, cookie_key, cookie_value + cookie_same_site_none);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script>

const http = get_host_info().HTTP_ORIGIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script>

const same_origin = get_host_info().HTTPS_ORIGIN;
Expand Down Expand Up @@ -56,7 +56,7 @@
const worker_error_1 = token();
const worker_error_2 = token();

const w_worker_src_1 = same_origin + executor_js_path +
const w_worker_src_1 = same_origin + executor_worker_path +
coep_for_worker + `&uuid=${worker_token_1}`;
send(w_control_token, `
new Worker("${w_worker_src_1}", {});
Expand All @@ -65,7 +65,7 @@
}
`);

const w_worker_src_2 = same_origin + executor_js_path +
const w_worker_src_2 = same_origin + executor_worker_path +
coep_for_worker + `&uuid=${worker_token_2}`;
send(w_credentialless_token, `
const worker = new Worker("${w_worker_src_2}", {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script>

promise_test(async test => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script src="./resources/iframeTest.js"></script>
<script src="/common/subset-tests.js"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script src="./resources/iframeTest.js"></script>
<script src="/common/subset-tests.js"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>
<script src="./resources/iframeTest.js"></script>
<script src="/common/subset-tests.js"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>

<script>
const same_origin = get_host_info().HTTPS_ORIGIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>

<script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>

<script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>

<script>
const same_origin = get_host_info().HTTPS_ORIGIN;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const directory = '/html/cross-origin-embedder-policy/credentialless';
const executor_path = directory + '/resources/executor.html?pipe=';
const executor_js_path = directory + '/resources/executor.js?pipe=';
const sw_executor_js_path = directory + '/resources/sw_executor.js?pipe=';
const executor_path = '/common/dispatcher/executor.html?pipe=';
const executor_worker_path = '/common/dispatcher/executor-worker.js?pipe=';
const executor_service_worker_path = '/common/dispatcher/executor-service-worker.js?pipe=';

// COEP
const coep_none =
Expand Down Expand Up @@ -108,21 +107,21 @@ const environments = {

dedicated_worker: headers => {
const tok = token();
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
const url = window.origin + executor_worker_path + headers + `&uuid=${tok}`;
const context = new Worker(url);
return [tok, new Promise(resolve => context.onerror = resolve)];
},

shared_worker: headers => {
const tok = token();
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
const url = window.origin + executor_worker_path + headers + `&uuid=${tok}`;
const context = new SharedWorker(url);
return [tok, new Promise(resolve => context.onerror = resolve)];
},

service_worker: headers => {
const tok = token();
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
const url = window.origin + executor_worker_path + headers + `&uuid=${tok}`;
const scope = url; // Generate a one-time scope for service worker.
const error = new Promise(resolve => {
navigator.serviceWorker.register(url, {scope: scope})
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<script src="./resources/dispatcher.js"></script>

<script>

Expand Down
Loading

0 comments on commit 8f34a98

Please sign in to comment.