diff options
Diffstat (limited to 'testing/web-platform/tests/webrtc-encoded-transform')
3 files changed, 158 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk-worker.js b/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk-worker.js new file mode 100644 index 0000000000..cc9dee42ac --- /dev/null +++ b/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk-worker.js @@ -0,0 +1,13 @@ +onrtctransform = async (event) => { + const { port } = event.transformer.options; + port.postMessage("started"); + + const reader = event.transformer.readable.getReader(); + const writer = event.transformer.writable.getWriter(); + + const { done, value } = await reader.read(); + + writer.write(null).catch(err => port.postMessage([err.name, 'null'])); + writer.write(value).catch(err => port.postMessage([err.name, value.constructor.name])); +}; +self.postMessage('registered'); diff --git a/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk.https.html b/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk.https.html new file mode 100644 index 0000000000..a837f627f2 --- /dev/null +++ b/testing/web-platform/tests/webrtc-encoded-transform/RTCRtpScriptTransform-bad-chunk.https.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src ="routines.js"></script> + +<video id="video1" autoplay></video> + +<script> +promise_test(async (test) => { + const {sender, receiver, senderPc, receiverPc} = await createConnectionWithTransform(test, 'RTCRtpScriptTransform-bad-chunk-worker.js', {audio: true}); + + assert_array_equals(await getNextMessage(sender.transform.port), ["TypeError", "null"]); + assert_array_equals(await getNextMessage(sender.transform.port), ["TypeError", "RTCEncodedAudioFrame"]); +}, "Writing bad chunks should error the stream"); +</script> diff --git a/testing/web-platform/tests/webrtc-encoded-transform/tentative/RTCEncodedAudioFrame-metadata.https.html b/testing/web-platform/tests/webrtc-encoded-transform/tentative/RTCEncodedAudioFrame-metadata.https.html new file mode 100644 index 0000000000..1e420e6f72 --- /dev/null +++ b/testing/web-platform/tests/webrtc-encoded-transform/tentative/RTCEncodedAudioFrame-metadata.https.html @@ -0,0 +1,129 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>RTCEncodedAudioFrame can be cloned and distributed</title> +<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> +<script src="../../webrtc/RTCPeerConnection-helper.js"></script> +<script src="../../service-workers/service-worker/resources/test-helpers.sub.js"></script> + +<script> +"use strict"; +promise_test(async t => { + const caller1 = new RTCPeerConnection(); + t.add_cleanup(() => caller1.close()); + const callee1 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => callee1.close()); + await setMediaPermission("granted", ["microphone"]); + const inputStream = await navigator.mediaDevices.getUserMedia({audio:true}); + const inputTrack = inputStream.getAudioTracks()[0]; + t.add_cleanup(() => inputTrack.stop()); + caller1.addTrack(inputTrack) + exchangeIceCandidates(caller1, callee1); + + const caller2 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => caller2.close()); + const sender2 = caller2.addTransceiver("audio").sender; + const writer2 = sender2.createEncodedStreams().writable.getWriter(); + sender2.replaceTrack(new MediaStreamTrackGenerator({ kind: 'audio' })); + + const framesReceivedCorrectly = new Promise((resolve, reject) => { + callee1.ontrack = async e => { + const receiverStreams = e.receiver.createEncodedStreams(); + const receiverReader = receiverStreams.readable.getReader(); + const result = await receiverReader.read(); + const original = result.value; + let newFrame = new RTCEncodedAudioFrame(original); + assert_equals(original.getMetadata().rtpTimestamp, newFrame.getMetadata().rtpTimestamp); + assert_equals(original.getMetadata().absCaptureTime, newFrame.getMetadata().absCaptureTime); + assert_array_equals(Array.from(original.data), Array.from(newFrame.data)); + await writer2.write(newFrame); + resolve(); + } + }); + + await exchangeOfferAnswer(caller1, callee1); + + return framesReceivedCorrectly; +}, "Constructing audio frame before sending works"); + +promise_test(async t => { + const caller1 = new RTCPeerConnection(); + + t.add_cleanup(() => caller1.close()); + const callee1 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => callee1.close()); + await setMediaPermission("granted", ["microphone"]); + const inputStream = await navigator.mediaDevices.getUserMedia({audio:true}); + const inputTrack = inputStream.getAudioTracks()[0]; + t.add_cleanup(() => inputTrack.stop()); + caller1.addTrack(inputTrack) + exchangeIceCandidates(caller1, callee1); + + const caller2 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => caller2.close()); + const sender2 = caller2.addTransceiver("audio").sender; + const writer2 = sender2.createEncodedStreams().writable.getWriter(); + sender2.replaceTrack(new MediaStreamTrackGenerator({ kind: 'audio' })); + + const framesReceivedCorrectly = new Promise((resolve, reject) => { + callee1.ontrack = async e => { + const receiverStreams = e.receiver.createEncodedStreams(); + const receiverReader = receiverStreams.readable.getReader(); + const result = await receiverReader.read(); + const original = result.value; + let newMetadata = original.getMetadata(); + newMetadata.rtpTimestamp = newMetadata.rtpTimestamp + 1; + let newFrame = new RTCEncodedAudioFrame(original, newMetadata); + assert_not_equals(original.getMetadata().rtpTimestamp, newFrame.getMetadata().rtpTimestamp); + assert_equals(newMetadata.rtpTimestamp, newFrame.getMetadata().rtpTimestamp); + assert_equals(original.getMetadata().absCaptureTime, newFrame.getMetadata().absCaptureTime); + assert_array_equals(Array.from(original.data), Array.from(newFrame.data)); + await writer2.write(newFrame); + resolve(); + } + }); + + await exchangeOfferAnswer(caller1, callee1); + + return framesReceivedCorrectly; +}, "Constructing audio frame with metadata argument before sending works"); + +promise_test(async t => { + const caller1 = new RTCPeerConnection(); + t.add_cleanup(() => caller1.close()); + const callee1 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => callee1.close()); + await setMediaPermission("granted", ["microphone"]); + const inputStream = await navigator.mediaDevices.getUserMedia({audio:true}); + const inputTrack = inputStream.getAudioTracks()[0]; + t.add_cleanup(() => inputTrack.stop()); + caller1.addTrack(inputTrack) + exchangeIceCandidates(caller1, callee1); + + const caller2 = new RTCPeerConnection({encodedInsertableStreams:true}); + t.add_cleanup(() => caller2.close()); + const sender2 = caller2.addTransceiver("audio").sender; + const writer2 = sender2.createEncodedStreams().writable.getWriter(); + sender2.replaceTrack(new MediaStreamTrackGenerator({ kind: 'audio' })); + + const framesReceivedCorrectly = new Promise((resolve, reject) => { + callee1.ontrack = async e => { + const receiverStreams = e.receiver.createEncodedStreams(); + const receiverReader = receiverStreams.readable.getReader(); + const result = await receiverReader.read(); + const original = result.value; + let newMetadata = original.getMetadata(); + newMetadata.synchronizationSource = newMetadata.synchronizationSource + 1; + assert_throws_dom("InvalidModificationError", () => new RTCEncodedAudioFrame(original, newMetadata)); + resolve(); + } + }); + + await exchangeOfferAnswer(caller1, callee1); + + return framesReceivedCorrectly; +}, "Constructing audio frame with bad metadata argument before sending does not work"); +</script> |