Bug 1259236 - test pc.addTrack of track in constructed stream. draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 24 Mar 2016 13:32:10 -0400
changeset 344512 09174a9809dc0090bd8c16b127ffb66963e2ed42
parent 344441 a036d65d2a28bd5f2b00b99083e997c3ba711db8
child 516974 95e8feb6f731a7b561ad63e693b0ee1187b9c414
push id13844
push userjbruaroey@mozilla.com
push dateThu, 24 Mar 2016 19:38:20 +0000
bugs1259236
milestone48.0a1
Bug 1259236 - test pc.addTrack of track in constructed stream. MozReview-Commit-ID: E1qFH7xYY0H
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_addTrack.html
dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -415,16 +415,27 @@ var listenUntil = (target, eventName, on
     var result = onFire();
     if (result) {
       target.removeEventListener(eventName, callback, false);
       resolve(result);
     }
   }, false));
 };
 
+/* Test that a function throws the right error */
+function mustThrowWith(msg, reason, f) {
+  try {
+    f();
+    ok(false, msg + " must throw");
+  } catch (e) {
+    is(e.name, reason, msg + " must throw: " + e.message);
+  }
+};
+
+
 /*** Test control flow methods */
 
 /**
  * Generates a callback function fired only under unexpected circumstances
  * while running the tests. The generated function kills off the test as well
  * gracefully.
  *
  * @param {String} [message]
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -65,16 +65,17 @@ skip-if = (toolkit == 'gonk' || buildapp
 [test_getUserMedia_stopAudioStreamWithFollowupAudio.html]
 [test_getUserMedia_stopVideoAudioStream.html]
 [test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html]
 [test_getUserMedia_stopVideoStream.html]
 [test_getUserMedia_stopVideoStreamWithFollowupVideo.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.html]
 [test_peerConnection_basicAudio.html]
 skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
 [test_peerConnection_basicAudioRequireEOC.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_basicAudioPcmaPcmuOnly.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
 [test_peerConnection_basicAudioDynamicPtMissingRtpmap.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_addTrack.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript;version=1.8">
+  createHTML({
+    bug: "1259236",
+    title: "PeerConnection addTrack errors",
+    visible: true
+  });
+
+  runNetworkTest(function() {
+    navigator.mediaDevices.getUserMedia({ video: true })
+    .then(gumStream => {
+      let newStream = new MediaStream(gumStream.getTracks());
+
+      mustThrowWith("pc.addTrack a track from a constructed MediaStream",
+                    "NotSupportedError",
+                    () => new RTCPeerConnection().addTrack(newStream.getTracks()[0],
+                                                           newStream));
+    })
+    .catch(e => ok(false, "unexpected failure: " + e))
+    .then(networkTestFinished);
+  });
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
+++ b/dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
@@ -14,25 +14,16 @@
 
   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());
 
-  function mustThrowWith(msg, reason, f) {
-    try {
-      f();
-      ok(false, msg + " must throw");
-    } catch (e) {
-      is(e.name, reason, msg + " must throw: " + e.message);
-    }
-  };
-
   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].getTracks().some(track => track == e.track), "has track");
     ok(pc2.getReceivers().some(receiver => receiver == e.receiver), "has receiver");
     if (e.streams[0].getTracks().length == 2) {
       // Test RTCTrackEvent required args here.