Skip to content

Commit 83cae27

Browse files
[WPT] Move/merge COEP/COOP dispatcher framework to /common
To reduce duplication and prepare for using this framework for BFCache (#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
1 parent f0430be commit 83cae27

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

common/dispatcher/README.md

Lines changed: 33 additions & 0 deletions
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.
Lines changed: 7 additions & 3 deletions
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+
}
Lines changed: 7 additions & 3 deletions
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;
File renamed without changes.
File renamed without changes.

html/cross-origin-opener-policy/resources/executor.html renamed to common/dispatcher/executor.html

Lines changed: 4 additions & 2 deletions
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

html/cross-origin-embedder-policy/anonymous-iframe/anonymous-iframe-popup.tentative.https.html

Lines changed: 1 addition & 1 deletion
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();

html/cross-origin-embedder-policy/anonymous-iframe/cookie.tentative.https.html

Lines changed: 1 addition & 1 deletion
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

html/cross-origin-embedder-policy/anonymous-iframe/local-storage.tentative.https.html

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 12 deletions
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

0 commit comments

Comments
 (0)