summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html')
-rw-r--r--testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html153
1 files changed, 153 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html b/testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html
new file mode 100644
index 0000000000..e02982f470
--- /dev/null
+++ b/testing/web-platform/tests/webrtc-encoded-transform/script-transform.https.html
@@ -0,0 +1,153 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+<script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src=/resources/testdriver.js></script>
+<script src=/resources/testdriver-vendor.js></script>
+<script src='../mediacapture-streams/permission-helper.js'></script>
+ </head>
+ <body>
+ <video id="video1" autoplay></video>
+ <video id="video2" autoplay></video>
+ <script src ="routines.js"></script>
+ <script>
+async function waitForMessage(worker, data)
+{
+ while (true) {
+ const received = await new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+ if (data === received)
+ return;
+ }
+}
+
+promise_test(async (test) => {
+ worker = new Worker('script-transform-worker.js');
+ const data = await new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+ assert_equals(data, "registered");
+
+ const channel = new MessageChannel;
+ const transform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: channel.port2}, [channel.port2]);
+ transform.port = channel.port1;
+ const promise = new Promise(resolve => transform.port.onmessage = (event) => resolve(event.data));
+ transform.port.postMessage("test");
+ assert_equals(await promise, "test");
+}, "transform messaging");
+
+promise_test(async (test) => {
+ worker = new Worker('script-transform-worker.js');
+ const data = await new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+ assert_equals(data, "registered");
+
+ const pc = new RTCPeerConnection();
+
+ const senderChannel = new MessageChannel;
+ const receiverChannel = new MessageChannel;
+ const senderTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: senderChannel.port2}, [senderChannel.port2]);
+ const receiverTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: receiverChannel.port2}, [receiverChannel.port2]);
+ senderTransform.port = senderChannel.port1;
+ receiverTransform.port = receiverChannel.port1;
+
+ const sender1 = pc.addTransceiver('audio').sender;
+ const sender2 = pc.addTransceiver('video').sender;
+ const receiver1 = pc.getReceivers()[0];
+ const receiver2 = pc.getReceivers()[1];
+
+ sender1.transform = senderTransform;
+ receiver1.transform = receiverTransform;
+ assert_throws_dom("InvalidStateError", () => sender2.transform = senderTransform);
+ assert_throws_dom("InvalidStateError", () => receiver2.transform = receiverTransform);
+
+ sender1.transform = senderTransform;
+ receiver1.transform = receiverTransform;
+
+ sender1.transform = null;
+ receiver1.transform = null;
+}, "Cannot reuse attached transforms");
+
+promise_test(async (test) => {
+ worker = new Worker('script-transform-worker.js');
+ const data = await new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+ assert_equals(data, "registered");
+ // Video is needed in a later test, so we ask for both permissions
+ await setMediaPermission();
+ const localStream = await navigator.mediaDevices.getUserMedia({audio: true});
+
+ const senderChannel = new MessageChannel;
+ const receiverChannel = new MessageChannel;
+ let sender, receiver;
+ const senderTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: senderChannel.port2}, [senderChannel.port2]);
+ const receiverTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: receiverChannel.port2}, [receiverChannel.port2]);
+ senderTransform.port = senderChannel.port1;
+ receiverTransform.port = receiverChannel.port1;
+
+ const startedPromise = new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+
+ const stream = await new Promise((resolve, reject) => {
+ createConnections(test, (firstConnection) => {
+ pc1 = firstConnection;
+ sender = firstConnection.addTrack(localStream.getAudioTracks()[0], localStream);
+ sender.transform = senderTransform;
+ }, (secondConnection) => {
+ pc2 = secondConnection;
+ secondConnection.ontrack = (trackEvent) => {
+ receiver = trackEvent.receiver;
+ receiver.transform = receiverTransform;
+ resolve(trackEvent.streams[0]);
+ };
+ });
+ test.step_timeout(() => reject("Test timed out"), 5000);
+ });
+
+ assert_equals(await startedPromise, "started");
+
+ await waitForMessage(worker, "audio chunk");
+
+ video1.srcObject = stream;
+ await video1.play();
+}, "audio exchange with transform");
+
+promise_test(async (test) => {
+ worker = new Worker('script-transform-worker.js');
+ const data = await new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+ assert_equals(data, "registered");
+
+ const localStream = await navigator.mediaDevices.getUserMedia({video: true});
+
+ const senderChannel = new MessageChannel;
+ const receiverChannel = new MessageChannel;
+ let sender, receiver;
+ const senderTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: senderChannel.port2}, [senderChannel.port2]);
+ const receiverTransform = new RTCRtpScriptTransform(worker, {name:'MockRTCRtpTransform', port: receiverChannel.port2}, [receiverChannel.port2]);
+ senderTransform.port = senderChannel.port1;
+ receiverTransform.port = receiverChannel.port1;
+
+ const startedPromise = new Promise(resolve => worker.onmessage = (event) => resolve(event.data));
+
+ const stream = await new Promise((resolve, reject) => {
+ createConnections(test, (firstConnection) => {
+ pc1 = firstConnection;
+ sender = firstConnection.addTrack(localStream.getVideoTracks()[0], localStream);
+ sender.transform = senderTransform;
+ }, (secondConnection) => {
+ pc2 = secondConnection;
+ secondConnection.ontrack = (trackEvent) => {
+ receiver = trackEvent.receiver;
+ receiver.transform = receiverTransform;
+ resolve(trackEvent.streams[0]);
+ };
+ });
+ test.step_timeout(() => reject("Test timed out"), 5000);
+ });
+
+ assert_equals(await startedPromise, "started");
+
+ await waitForMessage(worker, "video chunk");
+
+ video1.srcObject = stream;
+ await video1.play();
+}, "video exchange with transform");
+ </script>
+ </body>
+</html>