Bug 1395853 - Add a mochitest for video codec content flow across peerconnection. r?jib draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Wed, 13 Sep 2017 09:53:39 +0200
changeset 673360 64852fe31e26092783fb83c43ee6dcbd3e948579
parent 673359 880a5e8a00cfe1304f9a2024f7d40d839bfb80f1
child 734073 cdbdf1fb87e38f4e5336e89d55998d4353b9ba7d
push id82546
push userbmo:apehrson@mozilla.com
push dateMon, 02 Oct 2017 12:05:52 +0000
reviewersjib
bugs1395853
milestone58.0a1
Bug 1395853 - Add a mochitest for video codec content flow across peerconnection. r?jib MozReview-Commit-ID: 2mZ9LkRWden
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_videoCodecs.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -265,16 +265,18 @@ skip-if = android_version == '18' # andr
 [test_peerConnection_addDataChannel.html]
 skip-if = (android_version == '18') # android(bug 1240256, intermittent ICE failures starting w/bug 1232082, possibly from timeout)
 [test_peerConnection_addDataChannelNoBundle.html]
 skip-if = (android_version == '18') # android(bug 1240256, intermittent ICE failures starting w/bug 1232082, possibly from timeout) android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_verifyAudioAfterRenegotiation.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_verifyVideoAfterRenegotiation.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_videoCodecs.html]
+skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_audioRenegotiationInactiveAnswer.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_videoRenegotiationInactiveAnswer.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_webAudio.html]
 tags = webaudio webrtc
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_localRollback.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_videoCodecs.html
@@ -0,0 +1,90 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  createHTML({
+    bug: "1395853",
+    title: "Verify video content over WebRTC for every video codec",
+  });
+
+  async function testVideoCodec(options = {}, codec) {
+    let test = new PeerConnectionTest(options);
+    test.setMediaConstraints([{video: 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.name, otherCodec.offset);
+        let otherRtpmapMatcher = new RegExp(`a=rtpmap:${otherId}.*\\r\\n`, "gi");
+
+        let id = sdputils.findCodecId(test.originalOffer.sdp, codec.name, codec.offset);
+        if (codec.offset) {
+          isnot(id, sdputils.findCodecId(test.originalOffer.sdp, codec.name, 0),
+            "Different offsets should return different payload types");
+        }
+        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`);
+
+        // We only set it now, or the framework would remove non-H264 codecs
+        // for us.
+        options.h264 = codec.name == "H264";
+      },
+    ]);
+
+    test.chain.append([
+      async function CHECK_VIDEO_FLOW() {
+        try {
+          let h = new VideoStreamHelper();
+          await h.checkVideoPlaying(
+              test.pcRemote.remoteMediaElements[0],
+              10, 10, 128);
+          ok(true, `Got video flow for codec ${codec.name}, offset ${codec.offset}`);
+        } catch(e) {
+          ok(false, `No video flow for codec ${codec.name}, offset ${codec.offset}: ${e}`);
+        }
+      },
+    ]);
+
+    // This inlines test.run(), to allow for multiple tests to run.
+    test.updateChainSteps();
+    await test.chain.execute();
+    await test.close();
+  }
+
+  // We match the name against the sdp to figure out the payload type,
+  // so all other present codecs can be removed.
+  // Use `offset` when there are multiple instances of a codec expected in an sdp.
+  const codecs = [
+    { name: "VP8" },
+    { name: "VP9" },
+    { name: "H264" },
+    { name: "H264", offset: 1 },
+  ];
+
+  runNetworkTest(async (options) => {
+    for (let codec of codecs) {
+      info(`Testing video for codec ${codec.name}`);
+      try {
+        await testVideoCodec(options, codec);
+      } catch(e) {
+        ok(false, `Error in test for codec ${codec.name}: ${e}\n${e.stack}`);
+      }
+      info(`Tested video for codec ${codec.name}`);
+    }
+
+    networkTestFinished();
+  });
+</script>
+</pre>
+</body>
+</html>