Bug 1273652: mochi test to verify rendering happens after double negotiation. r=jesup draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Tue, 12 Jul 2016 16:36:59 -0700
changeset 386882 4092535f255858736f95b065bae1390cb557a4be
parent 386302 214884d507ee369c1cf14edb26527c4f9a97bf48
child 525237 7b74fe33df404c1e75af6179b8a99afa3cfeb415
push id22838
push userdrno@ohlmeier.org
push dateTue, 12 Jul 2016 23:44:31 +0000
reviewersjesup
bugs1273652
milestone50.0a1
Bug 1273652: mochi test to verify rendering happens after double negotiation. r=jesup MozReview-Commit-ID: 9g8oa306DCE
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_renderAfterRenegotiation.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -161,16 +161,18 @@ skip-if = toolkit == 'gonk' # B2G emulat
 skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
 [test_peerConnection_offerRequiresReceiveAudio.html]
 [test_peerConnection_offerRequiresReceiveVideo.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_offerRequiresReceiveVideoAudio.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_promiseSendOnly.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_renderAfterRenegotiation.html]
+skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_restartIce.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version # b2g (Bug 1059867)
 [test_peerConnection_restartIceNoBundle.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version # b2g (Bug 1059867)
 [test_peerConnection_restartIceNoBundleNoRtcpMux.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version # b2g (Bug 1059867)
 [test_peerConnection_restartIceNoRtcpMux.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version # b2g (Bug 1059867)
copy from dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
copy to dom/media/tests/mochitest/test_peerConnection_renderAfterRenegotiation.html
--- a/dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
+++ b/dom/media/tests/mochitest/test_peerConnection_renderAfterRenegotiation.html
@@ -1,63 +1,85 @@
 <!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;version=1.8">
   createHTML({
-    bug: "1091898",
-    title: "PeerConnection with promises (sendonly)",
+    bug: "1273652",
+    title: "Video receiver still renders after renegotiation",
     visible: true
   });
 
   var pc1 = new RTCPeerConnection();
   var pc2 = new RTCPeerConnection();
 
   var add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed);
   pc1.onicecandidate = e => add(pc2, e.candidate, generateErrorCallback());
   pc2.onicecandidate = e => add(pc1, e.candidate, generateErrorCallback());
 
   var v1, v2;
   var delivered = new Promise(resolve => pc2.ontrack = e => {
     // Test RTCTrackEvent here.
     ok(e.streams.length > 0, "has streams");
     ok(e.streams[0].getTrackById(e.track.id), "has track");
     ok(pc2.getReceivers().some(receiver => receiver == e.receiver), "has receiver");
-    if (e.streams[0].getTracks().length == 2) {
+    if (e.streams[0].getTracks().length == 1) {
       // Test RTCTrackEvent required args here.
       mustThrowWith("RTCTrackEvent wo/required args",
                     "TypeError", () => new RTCTrackEvent("track", {}));
       v2.srcObject = e.streams[0];
       resolve();
     }
   });
 
   runNetworkTest(function() {
-    v1 = createMediaElement('video', 'v1');
+    var h = new CaptureStreamTestHelper2D();
+    var canvas = document.createElement('canvas');
+    canvas.id = 'source_canvas';
+    canvas.width = canvas.height = 10;
+    document.getElementById('content').appendChild(canvas);
+
     v2 = createMediaElement('video', 'v2');
-    var canPlayThrough = new Promise(resolve => v2.canplaythrough = e => resolve());
-
     is(v2.currentTime, 0, "v2.currentTime is zero at outset");
 
-    navigator.mediaDevices.getUserMedia({ video: true, audio: true })
-    .then(stream => (v1.srcObject = stream).getTracks().forEach(t => pc1.addTrack(t, stream)))
-    .then(() => pc1.createOffer({})) // check that createOffer accepts arg.
+    h.drawColor(canvas, h.blue);
+    var stream = canvas.captureStream(0);
+    stream.getTracks().forEach(t => pc1.addTrack(t, stream));
+
+    pc1.createOffer({})
     .then(offer => pc1.setLocalDescription(offer))
     .then(() => pc2.setRemoteDescription(pc1.localDescription))
     .then(() => pc2.createAnswer({}))  // check that createAnswer accepts arg.
     .then(answer => pc2.setLocalDescription(answer))
     .then(() => pc1.setRemoteDescription(pc2.localDescription))
+
+    // re-negotiate to trigger the race condition in the jitter buffer
+    .then(() => pc1.createOffer({})) // check that createOffer accepts arg.
+    .then(offer => pc1.setLocalDescription(offer))
+    .then(() => pc2.setRemoteDescription(pc1.localDescription))
+    .then(() => pc2.createAnswer({}))
+    .then(answer => pc2.setLocalDescription(answer))
+    .then(() => pc1.setRemoteDescription(pc2.localDescription))
     .then(() => delivered)
-//    .then(() => canPlayThrough)    // why doesn't this fire?
-    .then(() => waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0))
-    .then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
-    .then(() => ok(true, "Connected."))
+
+    // now verify that actually something gets rendered into the remote video
+    // element
+    .then(() => h.waitForPixelColor(v2, h.blue, 128,
+                                    "pcRemote's video should become green"))
+    .then(() => {
+      stream.requestFrame();
+      h.drawColor(canvas, h.red);
+      })
+    .then(() => h.waitForPixelColor(v2, h.red, 128,
+                                    "pcRemote's video should become green"))
+
     .catch(reason => ok(false, "unexpected failure: " + reason))
     .then(networkTestFinished);
   });
 </script>
 </pre>
 </body>
 </html>