Bug 858135 - Update LocalMediaStreamPlayback inheritance to use Object.create(). r=jesup
authorHenrik Skupin <hskupin@mozilla.com>
Thu, 11 Apr 2013 07:48:09 -0400
changeset 128431 41f71920a83b68f48f5fa90184562e4a4709c83b
parent 128430 c6dae4b543df3a830044fc8a722db487e7b9ee20
child 128432 7fc45d104920bd1b9110cbacdf07ce087d3976b1
push id24528
push userryanvm@gmail.com
push dateThu, 11 Apr 2013 19:19:41 +0000
treeherdermozilla-central@7b8ed29c6bc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs858135
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 858135 - Update LocalMediaStreamPlayback inheritance to use Object.create(). r=jesup
dom/media/tests/mochitest/mediaStreamPlayback.js
--- a/dom/media/tests/mochitest/mediaStreamPlayback.js
+++ b/dom/media/tests/mochitest/mediaStreamPlayback.js
@@ -169,77 +169,78 @@ MediaStreamPlayback.prototype = {
  *                                       the mediaElement for playback
  */
 function LocalMediaStreamPlayback(mediaElement, mediaStream) {
   ok(mediaStream instanceof LocalMediaStream,
      "Stream should be a LocalMediaStream");
   MediaStreamPlayback.call(this, mediaElement, mediaStream);
 }
 
-// Sets up the inheritance chain from LMSP --> MSP
-LocalMediaStreamPlayback.prototype = new MediaStreamPlayback();
-LocalMediaStreamPlayback.prototype.constructor = LocalMediaStreamPlayback;
-
-/**
- * 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
- * @param {Function} onSuccess the success callback if the media element
- *                             successfully fires ended on a stop() call
- *                             on the stream
- * @param {Function} onError the error callback if the media element fails
- *                           to fire an ended callback on a stop() call
- *                           on the stream
- */
-LocalMediaStreamPlayback.prototype.playMediaWithStreamStop = function(
-  isResume, onSuccess, onError) {
-  var self = this;
+LocalMediaStreamPlayback.prototype = Object.create(MediaStreamPlayback.prototype, {
 
-  this.startMedia(isResume, function() {
-    self.stopStreamInMediaPlayback(function() {
-      self.stopMediaElement();
-      onSuccess();
-    }, onError);
-  }, onError);
-}
+  /**
+   * 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
+   * @param {Function} onSuccess the success callback if the media element
+   *                             successfully fires ended on a stop() call
+   *                             on the stream
+   * @param {Function} onError the error callback if the media element fails
+   *                           to fire an ended callback on a stop() call
+   *                           on the stream
+   */
+  playMediaWithStreamStop : {
+    value: function (isResume, onSuccess, onError) {
+      var self = this;
 
-/**
- * Stops the local media stream while it's currently in playback in
- * a media element.
- *
- * Precondition: The media stream and element should both be actively
- *               being played.
- *
- * @param {Function} onSuccess the success callback if the media element
- *                             fires an ended event from stop() being called
- * @param {Function} onError the error callback if the media element
- *                           fails to fire an ended event from stop() being
- *                           called
- */
-LocalMediaStreamPlayback.prototype.stopStreamInMediaPlayback = function(
-  onSuccess, onError) {
-  var endedFired = false;
-  var self = this;
+      this.startMedia(isResume, function() {
+        self.stopStreamInMediaPlayback(function() {
+          self.stopMediaElement();
+          onSuccess();
+        }, onError);
+      }, onError);
+    }
+  },
 
   /**
-   * Callback fired when the ended event fires when stop() is called on the
-   * stream.
+   * Stops the local media stream while it's currently in playback in
+   * a media element.
+   *
+   * Precondition: The media stream and element should both be actively
+   *               being played.
+   *
+   * @param {Function} onSuccess the success callback if the media element
+   *                             fires an ended event from stop() being called
+   * @param {Function} onError the error callback if the media element
+   *                           fails to fire an ended event from stop() being
+   *                           called
    */
-  var endedCallback = function() {
-    endedFired = true;
-    self.mediaElement.removeEventListener('ended', endedCallback, false);
-    ok(true, "ended event successfully fired");
-    onSuccess();
-  };
+  stopStreamInMediaPlayback : {
+    value: function (onSuccess, onError) {
+      var endedFired = false;
+      var self = this;
 
-  this.mediaElement.addEventListener('ended', endedCallback, false);
-  this.mediaStream.stop();
+      /**
+       * Callback fired when the ended event fires when stop() is called on the
+       * stream.
+       */
+      var endedCallback = function() {
+        endedFired = true;
+        self.mediaElement.removeEventListener('ended', endedCallback, false);
+        ok(true, "ended event successfully fired");
+        onSuccess();
+      };
 
-  // If ended doesn't fire in enough time, then we fail the test
-  setTimeout(function() {
-    if (!endedFired) {
-      ok(false, "ended event never fired");
-      onError();
+      this.mediaElement.addEventListener('ended', endedCallback, false);
+      this.mediaStream.stop();
+
+      // If ended doesn't fire in enough time, then we fail the test
+      setTimeout(function() {
+        if (!endedFired) {
+          ok(false, "ended event never fired");
+          onError();
+        }
+      }, TIMEOUT_LENGTH);
     }
-  }, TIMEOUT_LENGTH);
-}
+  }
+});