Bug 1208371 - Move track.stop() helpers to MediaStreamPlayback. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:26 +0800
changeset 348443 18b4e37daae69a6e4db060a69c53d351dc5bf30d
parent 348442 62696c71c68042e0edbc8398650f5f3f011c3fe5
child 348444 2e7f1cef9108f39e82d6426e82d8831f4dbce144
push id14828
push userpehrsons@gmail.com
push dateThu, 07 Apr 2016 12:57:27 +0000
reviewersjib
bugs1208371
milestone48.0a1
Bug 1208371 - Move track.stop() helpers to MediaStreamPlayback. r=jib MozReview-Commit-ID: 81pu4jvcrRs
dom/media/tests/mochitest/mediaStreamPlayback.js
--- a/dom/media/tests/mochitest/mediaStreamPlayback.js
+++ b/dom/media/tests/mochitest/mediaStreamPlayback.js
@@ -20,16 +20,59 @@ const VERIFYPLAYING_TIMEOUT_LENGTH = 600
  */
 function MediaStreamPlayback(mediaElement, mediaStream) {
   this.mediaElement = mediaElement;
   this.mediaStream = mediaStream;
 }
 
 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) {
+    this.startMedia(isResume);
+    return this.verifyPlaying()
+      .then(() => this.stopTracksForStreamInMediaPlayback())
+      .then(() => this.stopMediaElement());
+  },
+
+  /**
+   * 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.
+   */
+  stopTracksForStreamInMediaPlayback : function () {
+    var elem = this.mediaElement;
+    var waitForEnded = () => new Promise(resolve => {
+      elem.addEventListener('ended', function ended() {
+        elem.removeEventListener('ended', ended);
+        resolve();
+      });
+    });
+
+    // TODO (bug 910249) Also check that all the tracks are local.
+    this.mediaStream.getTracks().forEach(t => t.stop());
+
+    // XXX (bug 1208316) When we implement MediaStream.active, do not stop
+    // the stream. We just do it now so the media element will raise 'ended'.
+    if (!this.mediaStream.stop) {
+      return;
+    }
+    this.mediaStream.stop();
+    return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
+             .then(() => ok(true, "ended event successfully fired"));
+  },
+
   /**
    * Starts media with a media stream, runs it until a canplaythrough and
    * timeupdate event fires, and stops the media.
    *
    * @param {Boolean} isResume specifies if this media element is being resumed
    *                           from a previous run
    */
   playMedia : function(isResume) {
@@ -126,60 +169,16 @@ MediaStreamPlayback.prototype = {
 function LocalMediaStreamPlayback(mediaElement, mediaStream) {
   ok(mediaStream instanceof LocalMediaStream,
      "Stream should be a LocalMediaStream");
   MediaStreamPlayback.call(this, mediaElement, mediaStream);
 }
 
 LocalMediaStreamPlayback.prototype = Object.create(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: {
-    value: function(isResume) {
-      this.startMedia(isResume);
-      return this.verifyPlaying()
-        .then(() => this.stopTracksForStreamInMediaPlayback())
-        .then(() => this.stopMediaElement());
-    }
-  },
-
-  /**
-   * 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.
-   */
-  stopTracksForStreamInMediaPlayback: {
-    value: function () {
-      var elem = this.mediaElement;
-      var waitForEnded = () => new Promise(resolve => {
-        elem.addEventListener('ended', function ended() {
-          elem.removeEventListener('ended', ended);
-          resolve();
-        });
-      });
-
-      // TODO (bug 910249) Also check that all the tracks are local.
-      this.mediaStream.getTracks().forEach(t => t.stop());
-
-      // XXX (bug 1208316) When we implement MediaStream.active, do not stop
-      // the stream. We just do it now so the media element will raise 'ended'.
-      this.mediaStream.stop();
-      return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
-               .then(() => ok(true, "ended event successfully fired"));
-    }
-  },
-
   /**
    * DEPRECATED - MediaStream.stop() is going away. Use MediaStreamTrack.stop()!
    *
    * Starts media with a media stream, runs it until a canplaythrough and
    * timeupdate event fires, and calls stop() on the stream.
    *
    * @param {Boolean} isResume specifies if this media element is being resumed
    *                           from a previous run