Bug 1395853 - Add a mochitest for audio codec content flow across a PeerConnection. r?jib
MozReview-Commit-ID: 8cb7fgR5nO7
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -89,16 +89,18 @@ skip-if = toolkit == 'android' # no scre
[test_getUserMedia_stopVideoStream.html]
[test_getUserMedia_stopVideoStreamWithFollowupVideo.html]
[test_getUserMedia_trackCloneCleanup.html]
[test_getUserMedia_trackEnded.html]
[test_getUserMedia_peerIdentity.html]
[test_peerConnection_addIceCandidate.html]
[test_peerConnection_addtrack_removetrack_events.html]
skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_audioCodecs.html]
+skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_basicAudio.html]
skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_basicAudioNATSrflx.html]
skip-if = toolkit == 'android' # websockets don't work on android (bug 1266217)
[test_peerConnection_basicAudioNATRelay.html]
skip-if = toolkit == 'android' # websockets don't work on android (bug 1266217)
[test_peerConnection_basicAudioNATRelayTCP.html]
skip-if = toolkit == 'android' # websockets don't work on android (bug 1266217)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_audioCodecs.html
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+ createHTML({
+ bug: "1395853",
+ title: "Verify audio content over WebRTC for every audio codec",
+ });
+
+ // We match the format member against the sdp to figure out the payload type,
+ // So all other present codecs can be removed.
+ const codecs = [ "opus", "G722", "PCMU", "PCMA" ];
+
+ async function testAudioCodec(options = {}, codec) {
+ // sdputils checks for opus as part of its sdp sanity test
+ options.opus = codec == "opus";
+
+ let test = new PeerConnectionTest(options);
+ test.setMediaConstraints([{audio: true, fake: true}], []);
+
+ test.chain.insertBefore("PC_LOCAL_SET_LOCAL_DESCRIPTION", [
+ function PC_LOCAL_FILTER_OUT_CODECS() {
+ let otherCodec = codecs.find(c => c != codec);
+ let otherId = sdputils.findCodecId(test.originalOffer.sdp, otherCodec);
+
+ let id = sdputils.findCodecId(test.originalOffer.sdp, codec);
+ test.originalOffer.sdp =
+ sdputils.removeAllButPayloadType(test.originalOffer.sdp, id);
+
+ ok(!test.originalOffer.sdp.match(new RegExp(`m=.*UDP/TLS/RTP/SAVPF.* ${otherId}[^0-9]`, "gi")),
+ `Other codec ${otherId} should be removed after filtering`);
+ ok(test.originalOffer.sdp.match(new RegExp(`m=.*UDP/TLS/RTP/SAVPF.* ${id}[^0-9]`, "gi")),
+ `Tested codec ${id} should remain after filtering`);
+
+ for (let c of codecs.filter(c => c != codec)) {
+ // Remove rtpmaps for the other codecs so sdp sanity tests pass.
+ let id = sdputils.findCodecId(test.originalOffer.sdp, c);
+ test.originalOffer.sdp =
+ sdputils.removeRtpMapForPayloadType(test.originalOffer.sdp, id);
+ }
+
+ ok(!test.originalOffer.sdp.match(new RegExp(`a=rtpmap:${otherId}.*\\r\\n`, "gi")),
+ `Rtpmap of other codec ${otherId} should be removed after filtering`);
+ ok(test.originalOffer.sdp.match(new RegExp(`a=rtpmap:${id}.*\\r\\n`, "gi")),
+ `Rtpmap of tested codec should remain after filtering`);
+ },
+ ]);
+
+ test.chain.append([
+ async function CHECK_AUDIO_FLOW() {
+ try {
+ await test.pcRemote.checkReceivingToneFrom(new AudioContext(), test.pcLocal);
+ ok(true, "input and output audio data matches");
+ } catch(e) {
+ ok(false, `No audio flow: ${e}`);
+ }
+ },
+ ]);
+
+ // This inlines test.run(), to allow for multiple tests to run.
+ test.updateChainSteps();
+ await test.chain.execute();
+ await test.close();
+ }
+
+ runNetworkTest(async (options) => {
+ for (let codec of codecs) {
+ info(`Testing audio for codec ${codec}`);
+ try {
+ await testAudioCodec(options, codec);
+ } catch(e) {
+ ok(false, `Error in test for codec ${codec}: ${e}\n${e.stack}`);
+ }
+ info(`Tested audio for codec ${codec}`);
+ }
+
+ networkTestFinished();
+ });
+</script>
+</pre>
+</body>
+</html>