Skip to content

Commit e8c0f85

Browse files
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 (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
1 parent 646e806 commit e8c0f85

File tree

90 files changed

+231
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+231
-359
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Message passing API
2+
3+
`dispatcher.js` (and its server-side backend `dispatcher.py`) provides a
4+
universal queue-based message passing API.
5+
Each queue is identified by a UUID, and accessed via the following APIs:
6+
7+
- `send(uuid, message)` pushes a string `message` to the queue `uuid`.
8+
- `receive(uuid)` pops the first item from the queue `uuid`.
9+
- `showRequestHeaders(origin, uuid)` and
10+
`cacheableShowRequestHeaders(origin, uuid)` return URLs, that push request
11+
headers to the queue `uuid` upon fetching.
12+
13+
It works cross-origin, and even access different browser context groups.
14+
15+
Messages are queued, this means one doesn't need to wait for the receiver to
16+
listen, before sending the first message
17+
(but still need to wait for the resolution of the promise returned by `send()`
18+
to ensure the order between `send()`s).
19+
20+
# Executor framework
21+
22+
The message passing API can be used for sending arbitrary javascript to be
23+
evaluated in another page or worker (the "executor").
24+
25+
`executor.html` (as a Document), `executor-worker.js` (as a Web Worker), and
26+
`executor-service-worker.js` (as a Service Worker) are examples of executors.
27+
Tests can send arbitrary javascript to these executors to evaluate in its
28+
execution context.
29+
30+
This is universal and avoids introducing many specific `XXX-helper.html`
31+
resources.
32+
Moreover, tests are easier to read, because the whole logic of the test can be
33+
defined in a single file.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Define an universal message passing API. It works cross-origin and across
22
// browsing context groups.
3-
const dispatcher_path =
4-
"/html/cross-origin-embedder-policy/credentialless/resources/dispatcher.py";
3+
const dispatcher_path = "/common/dispatcher/dispatcher.py";
54
const dispatcher_url = new URL(dispatcher_path, location.href).href;
65

76
// Return a promise, limiting the number of concurrent accesses to a shared
@@ -78,6 +77,11 @@ const receive = async function(uuid) {
7877
// Returns an URL. When called, the server sends toward the `uuid` queue the
7978
// request headers. Useful for determining if something was requested with
8079
// Cookies.
81-
const showRequestHeaders= function(origin, uuid) {
80+
const showRequestHeaders = function(origin, uuid) {
8281
return origin + dispatcher_path + `?uuid=${uuid}&show-headers`;
8382
}
83+
84+
// Same as above, except for the response is cacheable.
85+
const cacheableShowRequestHeaders = function(origin, uuid) {
86+
return origin + dispatcher_path + `?uuid=${uuid}&cacheable&show-headers`;
87+
}
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ def main(request, response):
99
response.headers.set(b"Access-Control-Allow-Credentials", b"true")
1010
response.headers.set(b'Access-Control-Allow-Methods', b'OPTIONS, GET, POST')
1111
response.headers.set(b'Access-Control-Allow-Headers', b'Content-Type')
12-
response.headers.set(b'Cache-Control', b'no-cache, no-store, must-revalidate')
1312
response.headers.set(b"Access-Control-Allow-Origin", request.headers.get(b"origin") or '*')
1413

14+
if b"cacheable" in request.GET:
15+
response.headers.set(b"Cache-Control", b"max-age=31536000")
16+
else:
17+
response.headers.set(b'Cache-Control', b'no-cache, no-store, must-revalidate')
18+
1519
# CORS preflight
1620
if request.method == u'OPTIONS':
1721
return b''
@@ -22,7 +26,7 @@ def main(request, response):
2226
# The stash is accessed concurrently by many clients. A lock is used to
2327
# avoid unterleaved read/write from different clients.
2428
with stash.lock:
25-
queue = stash.take(uuid, '/coep-credentialless') or [];
29+
queue = stash.take(uuid, '/common/dispatcher') or [];
2630

2731
# Push into the |uuid| queue, the requested headers.
2832
if b"show-headers" in request.GET:
@@ -45,5 +49,5 @@ def main(request, response):
4549
else:
4650
ret = queue.pop(0)
4751

48-
stash.put(uuid, queue, '/coep-credentialless')
52+
stash.put(uuid, queue, '/common/dispatcher')
4953
return ret;

testing/web-platform/tests/html/cross-origin-opener-policy/resources/executor.html testing/web-platform/tests/common/dispatcher/executor.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
const uuid = params.get('uuid');
66

77
let executeOrders = async function() {
8-
while(true)
9-
eval(await receive(uuid));
8+
while(true) {
9+
let task = await receive(uuid);
10+
eval(`(async () => {${task}})()`);
11+
}
1012
};
1113
executeOrders();
1214

testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<script src="/resources/testharnessreport.js"></script>
55
<script src="/common/get-host-info.sub.js"></script>
66
<script src="/common/utils.js"></script>
7+
<script src="/common/dispatcher/dispatcher.js"></script>
78
<script src="../credentialless/resources/common.js"></script>
8-
<script src="../credentialless/resources/dispatcher.js"></script>
99
<body>
1010
<script>
1111
const {ORIGIN, REMOTE_ORIGIN} = get_host_info();

testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/cookie.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="../credentialless/resources/common.js"></script>
6-
<script src="../credentialless/resources/dispatcher.js"></script>
77
<script src="./resources/common.js"></script>
88
<script>
99

testing/web-platform/tests/html/cross-origin-embedder-policy/anonymous-iframe/local-storage.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="../credentialless/resources/common.js"></script>
6-
<script src="../credentialless/resources/dispatcher.js"></script>
77
<script src="./resources/common.js"></script>
88
<script>
99

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# Helper files:
2-
3-
- `resources/dispatcher.js` provides `send()` and `receive()`. This is an
4-
universal message passing API. It works cross-origin, and even access
5-
different browser context groups. Messages are queued, this means one doesn't
6-
need to wait for the receiver to listen, before sending the first message.
7-
8-
- `resources/executor.html` is a document. Test can send arbitrary javascript to evaluate
9-
in its execution context. This is universal and avoids introducing many
10-
specific `XXX-helper.html` resources. Moreover, tests are easier to read,
11-
because the whole logic of the test can be defined in a single file.
12-
131
# Related documents:
142
- https://github.com/mikewest/credentiallessness/
153
- https://github.com/w3ctag/design-reviews/issues/582

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/cache-storage.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<script src=/resources/testharnessreport.js></script>
88
<script src="/common/get-host-info.sub.js"></script>
99
<script src="/common/utils.js"></script>
10+
<script src="/common/dispatcher/dispatcher.js"></script>
1011
<script src="./resources/common.js"></script>
11-
<script src="./resources/dispatcher.js"></script>
1212
<script>
1313

1414
// Fetch a resource and store it into CacheStorage from |storer| context. Then

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/cache.tentative.html

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77
<script>
88

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

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

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

5552
promise_setup(async test => {
5653
await setCookie(cross_origin, cookie_key, cookie_value + cookie_same_site_none);

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/cross-origin-isolated.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77
<script>
88

99
const http = get_host_info().HTTP_ORIGIN;

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/dedicated-worker.tentative.https.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<script src=/resources/testharnessreport.js></script>
55
<script src="/common/get-host-info.sub.js"></script>
66
<script src="/common/utils.js"></script>
7+
<script src="/common/dispatcher/dispatcher.js"></script>
78
<script src="./resources/common.js"></script>
8-
<script src="./resources/dispatcher.js"></script>
99
<script>
1010

1111
const same_origin = get_host_info().HTTPS_ORIGIN;
@@ -56,7 +56,7 @@
5656
const worker_error_1 = token();
5757
const worker_error_2 = token();
5858

59-
const w_worker_src_1 = same_origin + executor_js_path +
59+
const w_worker_src_1 = same_origin + executor_worker_path +
6060
coep_for_worker + `&uuid=${worker_token_1}`;
6161
send(w_control_token, `
6262
new Worker("${w_worker_src_1}", {});
@@ -65,7 +65,7 @@
6565
}
6666
`);
6767

68-
const w_worker_src_2 = same_origin + executor_js_path +
68+
const w_worker_src_2 = same_origin + executor_worker_path +
6969
coep_for_worker + `&uuid=${worker_token_2}`;
7070
send(w_credentialless_token, `
7171
const worker = new Worker("${w_worker_src_2}", {});

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/fetch.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77
<script>
88

99
promise_test(async test => {

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/iframe-coep-credentialless.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<script src="/resources/testharnessreport.js"></script>
66
<script src="/common/get-host-info.sub.js"></script>
77
<script src="/common/utils.js"></script>
8+
<script src="/common/dispatcher/dispatcher.js"></script>
89
<script src="./resources/common.js"></script>
9-
<script src="./resources/dispatcher.js"></script>
1010
<script src="./resources/iframeTest.js"></script>
1111
<script src="/common/subset-tests.js"></script>
1212
<script>

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/iframe-coep-none.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<script src="/resources/testharnessreport.js"></script>
55
<script src="/common/get-host-info.sub.js"></script>
66
<script src="/common/utils.js"></script>
7+
<script src="/common/dispatcher/dispatcher.js"></script>
78
<script src="./resources/common.js"></script>
8-
<script src="./resources/dispatcher.js"></script>
99
<script src="./resources/iframeTest.js"></script>
1010
<script src="/common/subset-tests.js"></script>
1111
<script>

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/iframe-coep-require-corp.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<script src="/resources/testharnessreport.js"></script>
66
<script src="/common/get-host-info.sub.js"></script>
77
<script src="/common/utils.js"></script>
8+
<script src="/common/dispatcher/dispatcher.js"></script>
89
<script src="./resources/common.js"></script>
9-
<script src="./resources/dispatcher.js"></script>
1010
<script src="./resources/iframeTest.js"></script>
1111
<script src="/common/subset-tests.js"></script>
1212
<script>

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/iframe.tentative.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<script src="/resources/testharnessreport.js"></script>
44
<script src="/common/get-host-info.sub.js"></script>
55
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
67
<script src="./resources/common.js"></script>
7-
<script src="./resources/dispatcher.js"></script>
88

99
<script>
1010
const same_origin = get_host_info().HTTPS_ORIGIN;

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/image.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77

88
<script>
99

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/link.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77

88
<script>
99

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/redirect.tentative.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<script src="/resources/testharnessreport.js"></script>
44
<script src="/common/get-host-info.sub.js"></script>
55
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
67
<script src="./resources/common.js"></script>
7-
<script src="./resources/dispatcher.js"></script>
88

99
<script>
1010
const same_origin = get_host_info().HTTPS_ORIGIN;

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/cacheable-response.py

-24
This file was deleted.

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/common.js

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

65
// COEP
76
const coep_none =
@@ -108,21 +107,21 @@ const environments = {
108107

109108
dedicated_worker: headers => {
110109
const tok = token();
111-
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
110+
const url = window.origin + executor_worker_path + headers + `&uuid=${tok}`;
112111
const context = new Worker(url);
113112
return [tok, new Promise(resolve => context.onerror = resolve)];
114113
},
115114

116115
shared_worker: headers => {
117116
const tok = token();
118-
const url = window.origin + executor_js_path + headers + `&uuid=${tok}`;
117+
const url = window.origin + executor_worker_path + headers + `&uuid=${tok}`;
119118
const context = new SharedWorker(url);
120119
return [tok, new Promise(resolve => context.onerror = resolve)];
121120
},
122121

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

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/resources/executor.html

-15
This file was deleted.

testing/web-platform/tests/html/cross-origin-embedder-policy/credentialless/script.tentative.https.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<script src="/resources/testharnessreport.js"></script>
33
<script src="/common/get-host-info.sub.js"></script>
44
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
56
<script src="./resources/common.js"></script>
6-
<script src="./resources/dispatcher.js"></script>
77

88
<script>
99

0 commit comments

Comments
 (0)