Bug 1208328 - Add test for "addtrack" on recv side of RTCPeerConnection. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 16 Jun 2016 15:28:46 +0100
changeset 303629 0e39947767d4ff214bfd95d8efba78426c3133b1
parent 303628 b68b0a07b1dc487aa52cc13d06c47c31aec787d4
child 303630 628f41d0df69133c1f2bde028ed711bf605691a4
push id79133
push userpehrsons@gmail.com
push dateTue, 05 Jul 2016 09:26:07 +0000
treeherdermozilla-inbound@750df2678990 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1208328
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1208328 - Add test for "addtrack" on recv side of RTCPeerConnection. r=jib MozReview-Commit-ID: 2KkAc5uFjAZ
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_addtrack_removetrack_events.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -437,18 +437,18 @@ function checkMediaStreamTrackCloneAgain
      "Track clone's kind should be same as the original's");
   is(clone.enabled, original.enabled,
      "Track clone's kind should be same as the original's");
 }
 
 /*** Utility methods */
 
 /** The dreadful setTimeout, use sparingly */
-function wait(time) {
-  return new Promise(r => setTimeout(r, time));
+function wait(time, message) {
+  return new Promise(r => setTimeout(() => r(message), time));
 }
 
 /** The even more dreadful setInterval, use even more sparingly */
 function waitUntil(func, time) {
   return new Promise(resolve => {
     var interval = setInterval(() => {
       if (func())  {
         clearInterval(interval);
@@ -478,18 +478,18 @@ var addFinallyToPromise = promise => {
     );
   }
   return promise;
 }
 
 /** Use event listener to call passed-in function on fire until it returns true */
 var listenUntil = (target, eventName, onFire) => {
   return new Promise(resolve => target.addEventListener(eventName,
-                                                        function callback() {
-    var result = onFire();
+                                                        function callback(event) {
+    var result = onFire(event);
     if (result) {
       target.removeEventListener(eventName, callback, false);
       resolve(result);
     }
   }, false));
 };
 
 /* Test that a function throws the right error */
@@ -605,18 +605,17 @@ function createOneShotEventWrapper(wrapp
  *        so we can avoid logging results after a test has finished.
  */
 function haveEvent(target, name, cancelPromise) {
   var listener;
   var p = Promise.race([
     (cancelPromise || new Promise()).then(e => Promise.reject(e)),
     new Promise(resolve => target.addEventListener(name, listener = resolve))
   ]);
-  p.then(() => target.removeEventListener(name, listener));
-  return p;
+  return p.then(event => (target.removeEventListener(name, listener), event));
 };
 
 /**
  * This class executes a series of functions in a continuous sequence.
  * Promise-bearing functions are executed after the previous promise completes.
  *
  * @constructor
  * @param {object} framework
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -78,16 +78,18 @@ skip-if = (toolkit == 'gonk' || buildapp
 [test_getUserMedia_stopVideoAudioStream.html]
 [test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html]
 [test_getUserMedia_stopVideoStream.html]
 [test_getUserMedia_stopVideoStreamWithFollowupVideo.html]
 [test_getUserMedia_trackEnded.html]
 [test_getUserMedia_peerIdentity.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 1021776, too --ing slow on b2g)
 [test_peerConnection_addIceCandidate.html]
+[test_peerConnection_addtrack_removetrack_events.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_basicAudio.html]
 skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
 [test_peerConnection_basicAudioNATSrflx.html]
 skip-if = toolkit == 'gonk' || toolkit == 'android' # B2G emulator is too slow to handle a two-way audio call reliably, websockets don't work on android (bug 1266217)
 [test_peerConnection_basicAudioNATRelay.html]
 skip-if = toolkit == 'gonk' || toolkit == 'android' # B2G emulator is too slow to handle a two-way audio call reliably, websockets don't work on android (bug 1266217)
 [test_peerConnection_basicAudioNATRelayTCP.html]
 skip-if = toolkit == 'gonk' || toolkit == 'android' # B2G emulator is too slow to handle a two-way audio call reliably, websockets don't work on android (bug 1266217)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_addtrack_removetrack_events.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+"use strict";
+
+createHTML({
+  title: "MediaStream's 'addtrack' and 'removetrack' events with gUM",
+  bug: "1208328"
+});
+
+runNetworkTest(function (options) {
+  let test = new PeerConnectionTest(options);
+  let eventsPromise;
+  addRenegotiation(test.chain,
+    [
+      function PC_LOCAL_SWAP_VIDEO_TRACKS(test) {
+        return getUserMedia({video: true}).then(stream => {
+          let localStream = test.pcLocal._pc.getLocalStreams()[0];
+          let remoteStream = test.pcRemote._pc.getRemoteStreams()[0];
+
+          let newTrack = stream.getTracks()[0];
+
+          let videoSenderIndex =
+            test.pcLocal._pc.getSenders().findIndex(s => s.track.kind == "video");
+          isnot(videoSenderIndex, -1, "Should have video sender");
+
+          test.pcLocal.removeSender(videoSenderIndex);
+          test.pcLocal.attachLocalTrack(stream.getTracks()[0], localStream);
+
+          let onNextLoop = wait(0);
+          eventsPromise = haveEvent(remoteStream, "addtrack", wait(50000, "No addtrack event"))
+            .then(trackEvent => {
+              ok(trackEvent instanceof MediaStreamTrackEvent,
+                 "Expected event to be instance of MediaStreamTrackEvent");
+              is(trackEvent.type, "addtrack",
+                 "Expected addtrack event type");
+              is(trackEvent.track.id, newTrack.id, "Expected track in event");
+              is(trackEvent.track.readyState, "live",
+                 "added track should be live");
+            })
+            .then(() => haveEvent(remoteStream, "addtrack", onNextLoop)
+              .then(() => Promise.reject("Unexpected addtrack event for remote stream " + remoteStream.id),
+                    () => Promise.resolve())
+            );
+          remoteStream.addEventListener("removetrack",
+                                        function onRemovetrack(trackEvent) {
+            ok(false, "UA shouldn't raise 'removetrack' when receiving peer connection");
+          })
+        });
+      },
+    ],
+    [
+      function PC_REMOTE_CHECK_EVENTS(test) {
+        return eventsPromise;
+      },
+    ]
+  );
+
+  test.setMediaConstraints([{audio: true, video: true}], []);
+  test.run();
+});
+</script>
+</pre>
+</body>
+</html>