Bug 1208316 - Test active state in MediaStream constructors and clone tests. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 01 Nov 2016 14:11:03 +0100
changeset 432206 1a831fa02c8a754ec7c87d7c4fb990ad3a01aebf
parent 432205 46de8a01f5e66a8c5d9b43c50c24ab0ea47610ea
child 432207 ccaf05cd7343a22464d17bacf722c3c84734898a
push id34233
push userbmo:pehrson@telenordigital.com
push dateTue, 01 Nov 2016 13:21:40 +0000
reviewersjib
bugs1208316
milestone52.0a1
Bug 1208316 - Test active state in MediaStream constructors and clone tests. r?jib MozReview-Commit-ID: A39coKC0KNc
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/test_getUserMedia_mediaStreamConstructors.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -436,32 +436,36 @@ function checkMediaStreamCloneAgainstOri
   isnot(clone, original,
         "Stream clone should be different from the original");
   isnot(clone.id, original.id,
         "Stream clone's id should be different from the original's");
   is(clone.getAudioTracks().length, original.getAudioTracks().length,
      "All audio tracks should get cloned");
   is(clone.getVideoTracks().length, original.getVideoTracks().length,
      "All video tracks should get cloned");
+  is(clone.active, original.active,
+     "Active state should be preserved");
   original.getTracks()
           .forEach(t => ok(!clone.getTrackById(t.id),
                            "The clone's tracks should be originals"));
 }
 
 function checkMediaStreamTrackCloneAgainstOriginal(clone, original) {
   isnot(clone.id.length, 0,
         "Track clone should have an id string");
   isnot(clone, original,
         "Track clone should be different from the original");
   isnot(clone.id, original.id,
         "Track clone's id should be different from the original's");
   is(clone.kind, original.kind,
      "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");
+  is(clone.readyState, original.readyState,
+     "Track clone's readyState should be same as the original's");
 }
 
 /*** Utility methods */
 
 /** The dreadful setTimeout, use sparingly */
 function wait(time, message) {
   return new Promise(r => setTimeout(() => r(message), time));
 }
--- a/dom/media/tests/mochitest/test_getUserMedia_mediaStreamConstructors.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_mediaStreamConstructors.html
@@ -15,74 +15,105 @@
 
   var audioContext = new AudioContext();
   var videoElement;
 
   runTest(() => Promise.resolve()
     .then(() => videoElement = createMediaElement('video', 'constructorsTest'))
     .then(() => getUserMedia({video: true})).then(gUMStream => {
       info("Test default constructor with video");
+      ok(gUMStream.active, "gUMStream with one track should be active");
       var track = gUMStream.getTracks()[0];
 
       var stream = new MediaStream();
+      ok(!stream.active, "New MediaStream should be inactive");
       checkMediaStreamContains(stream, [], "Default constructed stream");
 
       stream.addTrack(track);
+      ok(stream.active, "MediaStream should be active after adding a track");
       checkMediaStreamContains(stream, [track], "Added video track");
 
       var playback = new MediaStreamPlayback(videoElement, stream);
-      return playback.playMedia(false).then(() => gUMStream.stop());
+      return playback.playMedia(false).then(() => {
+        ok(!gUMStream.active, "gUMStream should be inactive after stopping");
+        ok(!stream.active, "stream with stopped tracks should be inactive");
+      });
     })
     .then(() => getUserMedia({video: true})).then(gUMStream => {
       info("Test copy constructor with gUM stream");
+      ok(gUMStream.active, "gUMStream with one track should be active");
       var track = gUMStream.getTracks()[0];
 
       var stream = new MediaStream(gUMStream);
+      ok(stream.active, "List constructed MediaStream should be active");
       checkMediaStreamContains(stream, [track], "Copy constructed video track");
 
       var playback = new MediaStreamPlayback(videoElement, stream);
-      return playback.playMedia(false).then(() => gUMStream.stop());
+      return playback.playMedia(false).then(() => {
+        ok(!gUMStream.active, "gUMStream should be inactive after stopping");
+        ok(!stream.active, "stream with stopped tracks should be inactive");
+      });
     })
     .then(() => getUserMedia({video: true})).then(gUMStream => {
       info("Test list constructor with empty list");
+      ok(gUMStream.active, "gUMStream with one track should be active");
       var track = gUMStream.getTracks()[0];
 
       var stream = new MediaStream([]);
+      ok(!stream.active, "Empty-list constructed MediaStream should be inactive");
       checkMediaStreamContains(stream, [], "Empty-list constructed stream");
 
       stream.addTrack(track);
+      ok(stream.active, "MediaStream should be active after adding a track");
       checkMediaStreamContains(stream, [track], "Added video track");
 
       var playback = new MediaStreamPlayback(videoElement, stream);
-      return playback.playMedia(false).then(() => gUMStream.stop());
+      return playback.playMedia(false).then(() => {
+        ok(!gUMStream.active, "gUMStream should be inactive after stopping");
+        ok(!stream.active, "stream with stopped tracks should be inactive");
+      });
     })
     .then(() => getUserMedia({audio: true, video: true})).then(gUMStream => {
       info("Test list constructor with a gUM audio/video stream");
+      ok(gUMStream.active, "gUMStream with two tracks should be active");
       var audioTrack = gUMStream.getAudioTracks()[0];
       var videoTrack = gUMStream.getVideoTracks()[0];
 
       var stream = new MediaStream([audioTrack, videoTrack]);
+      ok(stream.active, "List constructed MediaStream should be active");
       checkMediaStreamContains(stream, [audioTrack, videoTrack],
                                "List constructed audio and video tracks");
 
       var playback = new MediaStreamPlayback(videoElement, stream);
-      return playback.playMedia(false).then(() => gUMStream.stop());
+      return playback.playMedia(false).then(() => {
+        ok(!gUMStream.active, "gUMStream should be inactive after stopping");
+        ok(!stream.active, "stream with stopped tracks should be inactive");
+      });
     })
     .then(() => getUserMedia({video: true})).then(gUMStream => {
       info("Test list constructor with gUM-video and WebAudio tracks");
+      ok(gUMStream.active, "gUMStream with one track should be active");
       var audioStream = createOscillatorStream(audioContext, 2000);
+      ok(audioStream.active, "WebAudio stream should be active");
+
       var audioTrack = audioStream.getTracks()[0];
       var videoTrack = gUMStream.getTracks()[0];
 
       var stream = new MediaStream([audioTrack, videoTrack]);
+      ok(stream.active, "List constructed MediaStream should be active");
       checkMediaStreamContains(stream, [audioTrack, videoTrack],
                                "List constructed WebAudio and gUM-video tracks");
 
-      var playback = new MediaStreamPlayback(videoElement, stream);
-      return playback.playMedia(false).then(() => gUMStream.stop());
+      // TODO (bug 1301675) When WebAudio tracks support stop(), uncomment:
+      // var playback = new MediaStreamPlayback(videoElement, stream);
+      // return playback.playMedia(false).then(() => {
+        gUMStream.getTracks().forEach(t => t.stop());
+        ok(!gUMStream.active, "gUMStream should be inactive after stopping");
+      //   ok(!stream.active, "stream with stopped tracks should be inactive");
+      // });
     })
     .then(() => {
       var osc1k = createOscillatorStream(audioContext, 1000);
       var audioTrack1k = osc1k.getTracks()[0];
 
       var osc5k = createOscillatorStream(audioContext, 5000);
       var audioTrack5k = osc5k.getTracks()[0];
 
@@ -96,16 +127,18 @@
         return analyser.waitForAnalysisSuccess(array =>
           array[analyser.binIndexForFrequency(1000)]  < 50 &&
           array[analyser.binIndexForFrequency(5000)]  < 50 &&
           array[analyser.binIndexForFrequency(10000)] < 50)
           .then(() => analyser.disconnect());
       }).then(() => {
         info("Analysing audio output with copy constructed 5k stream");
         var stream = new MediaStream(osc5k);
+        is(stream.active, osc5k.active,
+           "Copy constructed MediaStream should preserve active state");
         var analyser = new AudioStreamAnalyser(audioContext, stream);
         return analyser.waitForAnalysisSuccess(array =>
           array[analyser.binIndexForFrequency(1000)]  < 50 &&
           array[analyser.binIndexForFrequency(5000)]  > 200 &&
           array[analyser.binIndexForFrequency(10000)] < 50)
           .then(() => analyser.disconnect());
       }).then(() => {
         info("Analysing audio output with empty-list constructed stream");
@@ -114,16 +147,18 @@
         return analyser.waitForAnalysisSuccess(array =>
           array[analyser.binIndexForFrequency(1000)]  < 50 &&
           array[analyser.binIndexForFrequency(5000)]  < 50 &&
           array[analyser.binIndexForFrequency(10000)] < 50)
           .then(() => analyser.disconnect());
       }).then(() => {
         info("Analysing audio output with list constructed 1k, 5k and 10k tracks");
         var stream = new MediaStream([audioTrack1k, audioTrack5k, audioTrack10k]);
+        ok(stream.active,
+           "List constructed MediaStream from WebAudio should be active");
         var analyser = new AudioStreamAnalyser(audioContext, stream);
         return analyser.waitForAnalysisSuccess(array =>
           array[analyser.binIndexForFrequency(50)]    < 50 &&
           array[analyser.binIndexForFrequency(1000)]  > 200 &&
           array[analyser.binIndexForFrequency(2500)]  < 50 &&
           array[analyser.binIndexForFrequency(5000)]  > 200 &&
           array[analyser.binIndexForFrequency(7500)]  < 50 &&
           array[analyser.binIndexForFrequency(10000)] > 200 &&