Bug 1295352 - Changed default MediaStreamPlayback.playMedia() to stop tracks afterwards. r=pehrsons draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 12 Aug 2016 16:43:16 -0400
changeset 428032 dcc61cb13484f21cf4eeafdb152ae200614ca91e
parent 428031 556872690843fe9d2ee3e29935036c215dfd6678
child 428033 e7afe01ba3a67837f54c4b1fa5b3beea02b1e76c
push id33215
push userbmo:pehrson@telenordigital.com
push dateFri, 21 Oct 2016 13:47:09 +0000
reviewerspehrsons
bugs1295352
milestone52.0a1
Bug 1295352 - Changed default MediaStreamPlayback.playMedia() to stop tracks afterwards. r=pehrsons MozReview-Commit-ID: CjkRcALTY7V
dom/media/tests/mochitest/mediaStreamPlayback.js
dom/media/tests/mochitest/test_getUserMedia_addTrackRemoveTrack.html
dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
dom/media/tests/mochitest/test_getUserMedia_basicTabshare.html
dom/media/tests/mochitest/test_getUserMedia_mediaStreamClone.html
dom/media/tests/mochitest/test_getUserMedia_mediaStreamTrackClone.html
--- a/dom/media/tests/mochitest/mediaStreamPlayback.js
+++ b/dom/media/tests/mochitest/mediaStreamPlayback.js
@@ -27,21 +27,21 @@ MediaStreamPlayback.prototype = {
 
    /**
    * Starts media element with a media stream, runs it until a canplaythrough
    * and timeupdate event fires, and calls stop() on all its tracks.
    *
    * @param {Boolean} isResume specifies if this media element is being resumed
    *                           from a previous run
    */
-  playMediaWithMediaStreamTracksStop : function(isResume) {
+  playMedia : function(isResume) {
     this.startMedia(isResume);
     return this.verifyPlaying()
       .then(() => this.stopTracksForStreamInMediaPlayback())
-      .then(() => this.stopMediaElement());
+      .then(() => this.detachFromMediaElement());
   },
 
   /**
    * Stops the local media stream's tracks while it's currently in playback in
    * a media element.
    *
    * Precondition: The media stream and element should both be actively
    *               being played. All the stream's tracks must be local.
@@ -75,25 +75,25 @@ MediaStreamPlayback.prototype = {
     this.mediaStream.stop();
     return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
              .then(() => ok(true, "ended event successfully fired"))
              .then(() => noTrackEnded);
   },
 
   /**
    * Starts media with a media stream, runs it until a canplaythrough and
-   * timeupdate event fires, and stops the media.
+   * timeupdate event fires, and detaches from the element without stopping media.
    *
    * @param {Boolean} isResume specifies if this media element is being resumed
    *                           from a previous run
    */
-  playMedia : function(isResume) {
+  playMediaWithoutStoppingTracks : function(isResume) {
     this.startMedia(isResume);
     return this.verifyPlaying()
-      .then(() => this.stopMediaElement());
+      .then(() => this.detachFromMediaElement());
   },
 
   /**
    * Starts the media with the associated stream.
    *
    * @param {Boolean} isResume specifies if the media element playback
    *                           is being resumed from a previous run
    */
@@ -151,22 +151,22 @@ MediaStreamPlayback.prototype = {
         is(this.mediaElement.preload, "", "Preload should not exist");
         is(this.mediaElement.src, "", "No src should be defined");
         is(this.mediaElement.currentSrc, "",
            "Current src should still be an empty string");
       });
   },
 
   /**
-   * Stops the media with the associated stream.
+   * Detaches from the element without stopping the media.
    *
    * Precondition: The media stream and element should both be actively
    *               being played.
    */
-  stopMediaElement : function() {
+  detachFromMediaElement : function() {
     this.mediaElement.pause();
     this.mediaElement.srcObject = null;
   }
 }
 
 
 /**
  * This class is basically the same as MediaStreamPlayback except
@@ -193,17 +193,17 @@ LocalMediaStreamPlayback.prototype = Obj
    * @param {Boolean} isResume specifies if this media element is being resumed
    *                           from a previous run
    */
   playMediaWithDeprecatedStreamStop : {
     value: function(isResume) {
       this.startMedia(isResume);
       return this.verifyPlaying()
         .then(() => this.deprecatedStopStreamInMediaPlayback())
-        .then(() => this.stopMediaElement());
+        .then(() => this.detachFromMediaElement());
     }
   },
 
   /**
    * DEPRECATED - MediaStream.stop() is going away. Use MediaStreamTrack.stop()!
    *
    * Stops the local media stream while it's currently in playback in
    * a media element.
--- a/dom/media/tests/mochitest/test_getUserMedia_addTrackRemoveTrack.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_addTrackRemoveTrack.html
@@ -23,33 +23,33 @@
         stream.addTrack(track);
         checkMediaStreamContains(stream, [track], "Re-added audio");
 
         stream.addTrack(otherTrack);
         checkMediaStreamContains(stream, [track, otherTrack], "Added video");
 
         var testElem = createMediaElement('video', 'testAddTrackAudioVideo');
         var playback = new LocalMediaStreamPlayback(testElem, stream);
-        return playback.playMediaWithMediaStreamTracksStop(false);
+        return playback.playMedia(false);
     }))
     .then(() => getUserMedia({video: true})).then(stream =>
       getUserMedia({video: true}).then(otherStream => {
         info("Test addTrack()ing a video track to a video-only gUM stream");
         var track = stream.getTracks()[0];
         var otherTrack = otherStream.getTracks()[0];
 
         stream.addTrack(track);
         checkMediaStreamContains(stream, [track], "Re-added video");
 
         stream.addTrack(otherTrack);
         checkMediaStreamContains(stream, [track, otherTrack], "Added video");
 
         var test = createMediaElement('video', 'testAddTrackDoubleVideo');
         var playback = new LocalMediaStreamPlayback(test, stream);
-        return playback.playMediaWithMediaStreamTracksStop(false);
+        return playback.playMedia(false);
     }))
     .then(() => getUserMedia({video: true})).then(stream =>
       getUserMedia({video: true}).then(otherStream => {
         info("Test removeTrack() existing and added video tracks from a video-only gUM stream");
         var track = stream.getTracks()[0];
         var otherTrack = otherStream.getTracks()[0];
 
         stream.removeTrack(otherTrack);
@@ -76,17 +76,17 @@
           ok(!loadeddata, "Stream without tracks shall not raise 'loadeddata' on media element");
           elem.pause();
           elem.srcObject = null;
         })
         .then(() => {
           stream.addTrack(track);
           checkMediaStreamContains(stream, [track], "Re-added added-then-removed track");
           var playback = new LocalMediaStreamPlayback(elem, stream);
-          return playback.playMediaWithMediaStreamTracksStop(false);
+          return playback.playMedia(false);
         })
         .then(() => otherTrack.stop());
     }))
     .then(() => getUserMedia({ audio: true })).then(audioStream =>
       getUserMedia({ video: true }).then(videoStream => {
         info("Test adding track and removing the original");
         var audioTrack = audioStream.getTracks()[0];
         var videoTrack = videoStream.getTracks()[0];
@@ -94,17 +94,17 @@
         audioStream.addTrack(videoTrack);
 
         checkMediaStreamContains(videoStream, [], "1, Removed original track");
         checkMediaStreamContains(audioStream, [audioTrack, videoTrack],
                                  "2, Added external track");
 
         var elem = createMediaElement('video', 'testAddRemoveOriginalTrackVideo');
         var playback = new LocalMediaStreamPlayback(elem, audioStream);
-        return playback.playMediaWithMediaStreamTracksStop(false);
+        return playback.playMedia(false);
       }))
     .then(() => {
       var ac = new AudioContext();
 
       var osc1k = createOscillatorStream(ac, 1000);
       var audioTrack1k = osc1k.getTracks()[0];
 
       var osc5k = createOscillatorStream(ac, 5000);
--- a/dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
@@ -82,16 +82,16 @@
         playback.startMedia(false);
         return playback.verifyPlaying()
           .then(() => Promise.all([
             () => testVideo.srcObject.getVideoTracks()[0].applyConstraints(videoConstraints[1]),
             () => listenUntil(testVideo, "resize", () => true)
           ]))
           .then(() => playback.verifyPlaying()) // still playing
           .then(() => playback.deprecatedStopStreamInMediaPlayback())
-          .then(() => playback.stopMediaElement());
+          .then(() => playback.detachFromMediaElement());
       });
   });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_getUserMedia_basicTabshare.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicTabshare.html
@@ -55,16 +55,16 @@
               viewportOffsetY: 50,
               viewportWidth: 90,
               viewportHeight: 50
             }),
             () => listenUntil(testVideo, "resize", () => true)
           ]))
           .then(() => playback.verifyPlaying()) // still playing
           .then(() => playback.deprecatedStopStreamInMediaPlayback())
-          .then(() => playback.stopMediaElement());
+          .then(() => playback.detachFromMediaElement());
       });
   });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_getUserMedia_mediaStreamClone.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_mediaStreamClone.html
@@ -31,17 +31,17 @@
             "Audio track clone should have an id string");
 
       info("Stopping original tracks");
       stream.getTracks().forEach(t => t.stop());
 
       info("Playing from track clones");
       var test = createMediaElement('video', 'testClonePlayback');
       var playback = new MediaStreamPlayback(test, clone);
-      return playback.playMediaWithMediaStreamTracksStop(false);
+      return playback.playMedia(false);
     })
     .then(() => getUserMedia({video: true})).then(stream =>
       getUserMedia({video: true}).then(otherStream => {
         info("Test addTrack()ing a video track to a stream without affecting its clone");
         var track = stream.getTracks()[0];
         var otherTrack = otherStream.getTracks()[0];
 
         var streamClone = stream.clone();
@@ -62,17 +62,17 @@
                                  "Original not affected");
 
         // Not part of streamClone. Does not get stopped by the playback test.
         otherTrack.stop();
         otherStream.stop();
 
         var test = createMediaElement('video', 'testClonePlayback');
         var playback = new MediaStreamPlayback(test, streamClone);
-        return playback.playMediaWithMediaStreamTracksStop(false)
+        return playback.playMedia(false)
           .then(() => stream.getTracks().forEach(t => t.stop()))
           .then(() => stream.stop());
     }))
     .then(() => getUserMedia({audio: true, video: true})).then(stream => {
       info("Test cloning a stream into inception");
       var inceptionClone = stream.clone().clone().clone().clone().clone()
                                  .clone().clone().clone().clone().clone();
       checkMediaStreamCloneAgainstOriginal(inceptionClone, stream);
@@ -80,17 +80,17 @@
                                        inceptionClone.addTrack(t)));
       is(inceptionClone.getAudioTracks().length, 2,
          "The inception clone should contain the original audio track and a track clone");
       is(inceptionClone.getVideoTracks().length, 2,
          "The inception clone should contain the original video track and a track clone");
 
       var test = createMediaElement('video', 'testClonePlayback');
       var playback = new MediaStreamPlayback(test, inceptionClone);
-      return playback.playMediaWithMediaStreamTracksStop(false);
+      return playback.playMedia(false);
     })
     .then(() => getUserMedia({audio: true, video: true})).then(stream => {
       info("Test adding tracks from many stream clones to the original stream");
 
       const LOOPS = 3;
       for (var i = 0; i < LOOPS; i++) {
         stream.clone().getTracks().forEach(t => stream.addTrack(t));
       }
@@ -100,17 +100,17 @@
          "The original track should contain the original video track and all the video clones");
       stream.getTracks().forEach(t1 => is(stream.getTracks()
                                                 .filter(t2 => t1.id == t2.id)
                                                 .length,
                                           1, "Each track should be unique"));
 
       var test = createMediaElement('video', 'testClonePlayback');
       var playback = new MediaStreamPlayback(test, stream);
-      return playback.playMediaWithMediaStreamTracksStop(false);
+      return playback.playMedia(false);
     })
     .then(() => {
       info("Testing audio content routing with MediaStream.clone()");
       var ac = new AudioContext();
 
       var osc1kOriginal = createOscillatorStream(ac, 1000);
       var audioTrack1kOriginal = osc1kOriginal.getTracks()[0];
       var audioTrack1kClone = osc1kOriginal.clone().getTracks()[0];
--- a/dom/media/tests/mochitest/test_getUserMedia_mediaStreamTrackClone.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_mediaStreamTrackClone.html
@@ -26,17 +26,17 @@
 
     info("Creating new stream for clone");
     var cloneStream = new MediaStream([clone]);
     checkMediaStreamContains(cloneStream, [clone]);
 
     info("Testing playback of track clone");
     var test = createMediaElement('video', 'testClonePlayback');
     var playback = new MediaStreamPlayback(test, cloneStream);
-    return playback.playMediaWithMediaStreamTracksStop(false);
+    return playback.playMedia(false);
   });
 
   runTest(() => Promise.resolve()
     .then(() => testSingleTrackClonePlayback({audio: true}))
     .then(() => testSingleTrackClonePlayback({video: true}))
     .then(() => getUserMedia({video: true})).then(stream => {
       info("Test cloning a track into inception");
       var track = stream.getTracks()[0];
@@ -47,17 +47,17 @@
       var cloneStream = new MediaStream();
       cloneStream.addTrack(inceptionClone);
 
       // cloneStream is now essentially the same as stream.clone();
       checkMediaStreamCloneAgainstOriginal(cloneStream, stream);
 
       var test = createMediaElement('video', 'testClonePlayback');
       var playback = new MediaStreamPlayback(test, cloneStream);
-      return playback.playMediaWithMediaStreamTracksStop(false)
+      return playback.playMedia(false)
         .then(() => info("Testing that clones of ended tracks are ended"))
         .then(() => cloneStream.clone().getTracks().forEach(t =>
           is(t.readyState, "ended", "Track " + t.id + " should be ended")));
     })
     .then(() => getUserMedia({audio: true, video: true})).then(stream => {
       info("Test adding many track clones to the original stream");
 
       const LOOPS = 3;
@@ -68,17 +68,17 @@
          "The original track should contain the original video track and all the video clones");
       stream.getTracks().forEach(t1 => is(stream.getTracks()
                                                 .filter(t2 => t1.id == t2.id)
                                                 .length,
                                           1, "Each track should be unique"));
 
       var test = createMediaElement('video', 'testClonePlayback');
       var playback = new MediaStreamPlayback(test, stream);
-      return playback.playMediaWithMediaStreamTracksStop(false);
+      return playback.playMedia(false);
     })
     .then(() => {
       info("Testing audio content routing with MediaStreamTrack.clone()");
       var ac = new AudioContext();
 
       var osc1kOriginal = createOscillatorStream(ac, 1000);
       var audioTrack1kOriginal = osc1kOriginal.getTracks()[0];
       var audioTrack1kClone = audioTrack1kOriginal.clone();