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 @@ + - - +
+ - + + - + + - + + - + + - + + - + + - + + - + - + + - + + + - + + - + - + + - + + - + + - + + - + + - + - + + - + + - + + - + - + + - + + - + + - + + - + + - + + - + + + - + + - + + - + - + - + - + - + - - + + - + + - + - > + - + - + - - + +