summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html')
-rw-r--r--testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html111
1 files changed, 111 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html b/testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html
new file mode 100644
index 0000000000..5822cb8415
--- /dev/null
+++ b/testing/web-platform/tests/webcodecs/videoFrame-serialization.crossAgentCluster.https.html
@@ -0,0 +1,111 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src='/resources/testharness.js'></script>
+ <script src='/resources/testharnessreport.js'></script>
+ <script src='/common/get-host-info.sub.js'></script>
+ <script id='workerCode' type='javascript/worker'>
+ self.onmessage = (e) => {
+ postMessage(e.data);
+ };
+ </script>
+ <script id='sharedWorkerCode' type='javascript/worker'>
+ self.onconnect = function (event) {
+ const port = event.ports[0];
+ port.onmessage = function (e) {
+ port.postMessage(e.data);
+ };
+ };
+ </script>
+</head>
+<body>
+<script>
+const HELPER = '/webcodecs/videoFrame-serialization.crossAgentCluster.helper.html';
+const SAMEORIGIN_BASE = get_host_info().HTTPS_ORIGIN;
+const CROSSORIGIN_BASE = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
+const SAMEORIGIN_HELPER = SAMEORIGIN_BASE + HELPER;
+const CROSSORIGIN_HELPER = CROSSORIGIN_BASE + HELPER;
+
+promise_test(async () => {
+ const target = (await appendIframe(SAMEORIGIN_HELPER)).contentWindow;
+ let frame = createVideoFrame(10);
+ assert_true(await canSendVideoFrame(target, frame));
+}, 'Verify frames can be passed within the same agent clusters');
+
+promise_test(async () => {
+ const target = (await appendIframe(CROSSORIGIN_HELPER)).contentWindow;
+ let frame = createVideoFrame(20);
+ assert_false(await canSendVideoFrame(target, frame));
+}, 'Verify frames cannot be passed accross the different agent clusters');
+
+promise_test(async () => {
+ const blob = new Blob([document.querySelector('#workerCode').textContent], {
+ type: 'text/javascript',
+ });
+ const worker = new Worker(window.URL.createObjectURL(blob));
+ let frame = createVideoFrame(30);
+ worker.postMessage(frame);
+ const received = await new Promise(resolve => worker.onmessage = e => {
+ resolve(e.data);
+ });
+ assert_equals(received.toString(), '[object VideoFrame]');
+ assert_equals(received.timestamp, 30);
+}, 'Verify frames can be passed back and forth between main and worker');
+
+promise_test(async () => {
+ const blob = new Blob([document.querySelector('#sharedWorkerCode').textContent], {
+ type: 'text/javascript',
+ });
+ const worker = new SharedWorker(window.URL.createObjectURL(blob));
+ let frame = createVideoFrame(40);
+ worker.port.postMessage(frame);
+ 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');
+
+promise_test(async () => {
+ navigator.serviceWorker.register('videoFrame-serialization.crossAgentCluster.serviceworker.js');
+ navigator.serviceWorker.ready.then((registration) => {
+ let frame = createVideoFrame(50);
+ registration.active.postMessage(frame);
+ registration.active.postMessage({'id': 50});
+ });
+ const received = await new Promise(resolve => navigator.serviceWorker.onmessage = (e) => {
+ resolve(e.data);
+ });
+ assert_equals(received, 'NOT_RECEIVED');
+}, 'Verify frames cannot be passed to serviceworker');
+
+function appendIframe(src) {
+ const frame = document.createElement('iframe');
+ document.body.appendChild(frame);
+ frame.src = src;
+ return new Promise(resolve => frame.onload = () => resolve(frame));
+};
+
+function createVideoFrame(ts) {
+ let data = new Uint8Array([
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ ]);
+ return new VideoFrame(data, {
+ timestamp: ts,
+ codedWidth: 2,
+ codedHeight: 2,
+ format: 'RGBA',
+ });
+}
+
+function canSendVideoFrame(target, vf) {
+ target.postMessage(vf, '*');
+ target.postMessage({'id': vf.timestamp}, '*');
+ return new Promise(resolve => window.onmessage = e => {
+ resolve(e.data == 'RECEIVED');
+ });
+};
+</script>
+</body>
+</html>