Skip to content

Commit 53c7a93

Browse files
authored
HTML: COEP and ImageBitmap
Helps with whatwg/html#4734 and #18354.
1 parent a2d1acf commit 53c7a93

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// META: script=/common/utils.js
2+
// META: script=/common/get-host-info.sub.js
3+
4+
function taintedImageBitmap(t) {
5+
return new Promise(resolve => {
6+
const img = new Image();
7+
img.src = `${get_host_info().HTTPS_REMOTE_ORIGIN}/images/blue.png`;
8+
img.onload = t.step_func(() => {
9+
resolve(createImageBitmap(img));
10+
});
11+
img.onerror = t.unreached_func();
12+
});
13+
}
14+
15+
async_test(t => {
16+
const bc = new BroadcastChannel(token());
17+
const popup = window.open(`resources/coop-coep-popup.html?channel=${bc.name}`);
18+
const popupReady = new Promise(resolve => {
19+
bc.onmessage = t.step_func(resolve);
20+
});
21+
const imageReady = taintedImageBitmap(t);
22+
Promise.all([popupReady, imageReady]).then(t.step_func(([, bitmap]) => {
23+
bc.onmessage = t.step_func_done(e => {
24+
assert_equals(e.data, "Got failure as expected.");
25+
});
26+
bc.postMessage(bitmap);
27+
}));
28+
}, "BroadcastChannel'ing a tainted ImageBitmap to a COOP+COEP popup");
29+
30+
[
31+
{
32+
"type": "serialize/deserialize",
33+
"message": (port, bitmap) => port.postMessage(bitmap)
34+
},
35+
{
36+
"type": "transfer",
37+
"message": (port, bitmap) => port.postMessage(bitmap, [bitmap])
38+
}
39+
].forEach(({ type, message }) => {
40+
async_test(t => {
41+
const sw = new SharedWorker("resources/coop-coep-worker.js");
42+
const imageReady = taintedImageBitmap(t);
43+
imageReady.then(t.step_func(bitmap => {
44+
sw.port.onmessage = t.step_func_done(e => {
45+
assert_equals(e.data, "Got failure as expected.");
46+
});
47+
message(sw.port, bitmap);
48+
}));
49+
}, `Messaging a tainted ImageBitMap via ${type} to a COEP shared worker`);
50+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
const channel = new URLSearchParams(location.search).get("channel");
3+
const bc = new BroadcastChannel(channel);
4+
bc.onmessageerror = e => {
5+
bc.postMessage("Got failure as expected.");
6+
}
7+
bc.onmessage = e => {
8+
bc.postMessage("Got message, expected failure.");
9+
}
10+
bc.postMessage("Initialize");
11+
</script>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cross-Origin-Opener-Policy: same-origin
2+
Cross-Origin-Embedder-Policy: require-corp
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
onconnect = e => {
2+
const port = e.source;
3+
port.onmessageerror = e => {
4+
port.postMessage("Got failure as expected.");
5+
}
6+
port.onmessage = e => {
7+
port.postMessage("Got message, expected failure.");
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cross-Origin-Embedder-Policy: require-corp

0 commit comments

Comments
 (0)