Bug 1208373 - Add test for MediaStreamTrack "ended" event and "readyState" attribute. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 12 May 2016 14:02:10 +0200
changeset 376727 5a0e00713d39664af7ca2064e72c4a9c50ed0a4d
parent 376726 4a4c3d223e52922f932e116d1f12fa7fd931366f
child 376728 459b42dee0e4671dfde23e85417ca167c5785ddf
push id20652
push userpehrsons@gmail.com
push dateWed, 08 Jun 2016 15:10:47 +0000
reviewersjib
bugs1208373
milestone50.0a1
Bug 1208373 - Add test for MediaStreamTrack "ended" event and "readyState" attribute. r?jib MozReview-Commit-ID: INZ0XtRTgt1
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_trackEnded.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -74,16 +74,17 @@ skip-if = toolkit == 'gonk' || buildapp 
 [test_getUserMedia_spinEventLoop.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # copied from basicAudio
 [test_getUserMedia_stopAudioStream.html]
 [test_getUserMedia_stopAudioStreamWithFollowupAudio.html]
 [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_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]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_trackEnded.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<iframe id="iframe" srcdoc="
+  <script type='application/javascript'>
+  document.gUM = (constraints, success, failure) =>
+    navigator.mediaDevices.getUserMedia(constraints).then(success, failure);
+  </script>">
+</iframe>
+<script type="application/javascript">
+  "use strict";
+
+  createHTML({
+    title: "getUserMedia MediaStreamTrack 'ended' event on navigating",
+    bug: "1208373",
+  });
+
+  runTest(() => {
+    let iframe = document.getElementById("iframe");
+    let stream;
+    // We're passing callbacks into a method in the iframe here, because
+    // a Promise created in the iframe is unusable after the iframe has
+    // navigated away (see bug 1269400 for details).
+    return new Promise((resolve, reject) =>
+        iframe.contentDocument.gUM({audio: true, video: true}, resolve, reject))
+      .then(s => stream = s)
+      .then(() => {
+        var allTracksEnded = Promise.all(stream.getTracks().map(t => {
+          info("Set up ended handler for track " + t.id);
+          return haveEvent(t, "ended", wait(5000))
+            .then(event => {
+              info("ended handler invoked for track " + t.id);
+              is(event.target, t, "Target should be correct");
+            }, e => e ? Promise.reject(e)
+                      : ok(false, "ended event never raised for track " + t.id));
+        }));
+        stream.getTracks().forEach(t =>
+          is(t.readyState, "live",
+             "Non-ended track should have readyState 'live'"));
+        iframe.srcdoc = "";
+        info("iframe has been reset. Waiting for tracks to end.");
+        return allTracksEnded;
+      })
+      .then(() => stream.getTracks().forEach(t =>
+        is(t.readyState, "ended",
+           "Ended track should have readyState 'ended'")));
+  });
+</script>
+</pre>
+</body>
+</html>