Skip to content

Commit

Permalink
[WebCodecs] Mark SharedWorker as unsupported in serialization.
Browse files Browse the repository at this point in the history
Test incorrectly assumes SharedWorker support, so ensure it instead
tests that passing to a shared worker is unsupported.

Fixes w3c/webcodecs#635

Bug: 1412203
Change-Id: I596fa79508a3cd8e2ed253d9be378b142edca4d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4216102
Reviewed-by: Thomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1101160}
  • Loading branch information
dalecurtis authored and marcoscaceres committed Mar 28, 2023
1 parent 229fa3b commit 068d353
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions webcodecs/videoFrame-serialization.crossAgentCluster.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
};
</script>
<script id='sharedWorkerCode' type='javascript/worker'>
let received = new Map();
self.onconnect = function (event) {
const port = event.ports[0];
port.onmessage = function (e) {
let frame = e.data.frame;
if (e.data.transfer) {
port.postMessage(frame, [frame]);
} else {
port.postMessage(frame);
if (e.data.hasOwnProperty('id')) {
port.postMessage(
received.get(e.data.id) ? 'RECEIVED' : 'NOT_RECEIVED');
return;
}
if (e.data.toString() == '[object VideoFrame]') {
received.set(e.data.timestamp, e.data);
}
};
};
Expand Down Expand Up @@ -70,12 +73,12 @@
const worker = new SharedWorker(window.URL.createObjectURL(blob));
let frame = createVideoFrame(40);
worker.port.postMessage({frame: frame, transfer: false});
worker.port.postMessage({'id': 40});
const received = await new Promise(resolve => worker.port.onmessage = e => {
resolve(e.data);
});
assert_equals(received.toString(), '[object VideoFrame]');
assert_equals(received.timestamp, 40);
}, 'Verify frames can be passed back and forth between main and sharedworker');
assert_equals(received, 'NOT_RECEIVED');
}, 'Verify frames cannot be passed to sharedworker');

promise_test(async () => {
navigator.serviceWorker.register('videoFrame-serialization.crossAgentCluster.serviceworker.js');
Expand Down Expand Up @@ -124,12 +127,12 @@
const worker = new SharedWorker(window.URL.createObjectURL(blob));
let frame = createVideoFrame(90);
worker.port.postMessage({frame: frame, transfer: true});
worker.port.postMessage({'id': 90});
const received = await new Promise(resolve => worker.port.onmessage = e => {
resolve(e.data);
});
assert_equals(received.toString(), '[object VideoFrame]');
assert_equals(received.timestamp, 90);
}, 'Verify frames can be transferred back and forth between main and sharedworker');
assert_equals(received, 'NOT_RECEIVED');
}, 'Verify frames cannot be transferred to a sharedworker');

promise_test(async () => {
navigator.serviceWorker.register('videoFrame-serialization.crossAgentCluster.serviceworker.js');
Expand Down

0 comments on commit 068d353

Please sign in to comment.