diff --git a/2dcontext/imagebitmap/no-coop-coep.https.window.js b/2dcontext/imagebitmap/no-coop-coep.https.window.js new file mode 100644 index 00000000000000..5295f1e10cfdd5 --- /dev/null +++ b/2dcontext/imagebitmap/no-coop-coep.https.window.js @@ -0,0 +1,50 @@ +// META: script=/common/utils.js +// META: script=/common/get-host-info.sub.js + +function taintedImageBitmap(t) { + return new Promise(resolve => { + const img = new Image(); + img.src = `${get_host_info().HTTPS_REMOTE_ORIGIN}/images/blue.png`; + img.onload = t.step_func(() => { + resolve(createImageBitmap(img)); + }); + img.onerror = t.unreached_func(); + }); +} + +async_test(t => { + const bc = new BroadcastChannel(token()); + const popup = window.open(`resources/coop-coep-popup.html?channel=${bc.name}`); + const popupReady = new Promise(resolve => { + bc.onmessage = t.step_func(resolve); + }); + const imageReady = taintedImageBitmap(t); + Promise.all([popupReady, imageReady]).then(t.step_func(([, bitmap]) => { + bc.onmessage = t.step_func_done(e => { + assert_equals(e.data, "Got failure as expected."); + }); + bc.postMessage(bitmap); + })); +}, "BroadcastChannel'ing a tainted ImageBitmap to a COOP+COEP popup"); + +[ + { + "type": "serialize/deserialize", + "message": (port, bitmap) => port.postMessage(bitmap) + }, + { + "type": "transfer", + "message": (port, bitmap) => port.postMessage(bitmap, [bitmap]) + } +].forEach(({ type, message }) => { + async_test(t => { + const sw = new SharedWorker("resources/coop-coep-worker.js"); + const imageReady = taintedImageBitmap(t); + imageReady.then(t.step_func(bitmap => { + sw.port.onmessage = t.step_func_done(e => { + assert_equals(e.data, "Got failure as expected."); + }); + message(sw.port, bitmap); + })); + }, `Messaging a tainted ImageBitMap via ${type} to a COEP shared worker`); +}); diff --git a/2dcontext/imagebitmap/resources/coop-coep-popup.html b/2dcontext/imagebitmap/resources/coop-coep-popup.html new file mode 100644 index 00000000000000..f0228503ffa8aa --- /dev/null +++ b/2dcontext/imagebitmap/resources/coop-coep-popup.html @@ -0,0 +1,11 @@ + diff --git a/2dcontext/imagebitmap/resources/coop-coep-popup.html.headers b/2dcontext/imagebitmap/resources/coop-coep-popup.html.headers new file mode 100644 index 00000000000000..63b60e490f47f4 --- /dev/null +++ b/2dcontext/imagebitmap/resources/coop-coep-popup.html.headers @@ -0,0 +1,2 @@ +Cross-Origin-Opener-Policy: same-origin +Cross-Origin-Embedder-Policy: require-corp diff --git a/2dcontext/imagebitmap/resources/coop-coep-worker.js b/2dcontext/imagebitmap/resources/coop-coep-worker.js new file mode 100644 index 00000000000000..a6e9cc58935c41 --- /dev/null +++ b/2dcontext/imagebitmap/resources/coop-coep-worker.js @@ -0,0 +1,9 @@ +onconnect = e => { + const port = e.source; + port.onmessageerror = e => { + port.postMessage("Got failure as expected."); + } + port.onmessage = e => { + port.postMessage("Got message, expected failure."); + } +} diff --git a/2dcontext/imagebitmap/resources/coop-coep-worker.js.headers b/2dcontext/imagebitmap/resources/coop-coep-worker.js.headers new file mode 100644 index 00000000000000..6604450991a122 --- /dev/null +++ b/2dcontext/imagebitmap/resources/coop-coep-worker.js.headers @@ -0,0 +1 @@ +Cross-Origin-Embedder-Policy: require-corp