Bug 1208373 - Add test for MediaStreamTrack "ended" event and "readyState" attribute. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 04 May 2016 11:29:44 +0200
changeset 363327 b31fb1aa64748d7296e32d8fd2823eb0c5f7fccc
parent 363326 8e50d2ed8a9c416b70cb615f6613eb72f32e9d6f
child 363328 e6e399b43857270379e07e2c72c9e7cd6a426fa0
push id17172
push userpehrsons@gmail.com
push dateWed, 04 May 2016 14:35:55 +0000
reviewersjib
bugs1208373
milestone49.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
@@ -73,16 +73,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_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)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_trackEnded.html
@@ -0,0 +1,51 @@
+<!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;
+    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 onended handler for track " + t.id);
+          return new Promise(resolve => t.onended = e => {
+            info("onended handler invoked for track " + t.id);
+            is(e.target, t, "Target should be correct");
+            resolve();
+          });
+        }));
+        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>