Bug 1013933 - preserve playbackrate across play/pause. r=padenot
authorAlastor Wu <alwu@mozilla.com>
Fri, 15 Apr 2016 10:33:37 +0800
changeset 331448 765b22823c12f34161aa3c3def3ece3fc003409a
parent 331447 2e1fb077ecdbf1dc01333e4de6768ffbe23a003a
child 331449 34e67475a707a73aa9a853496bf226140160376e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1013933
milestone48.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 1013933 - preserve playbackrate across play/pause. r=padenot MozReview-Commit-ID: KGnh1exMgSw
dom/media/test/mochitest.ini
dom/media/test/test_preserve_playbackrate_after_ui_play.html
toolkit/content/widgets/videocontrols.xml
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -760,16 +760,17 @@ skip-if = appname == "seamonkey"
 skip-if = toolkit == 'gonk' # bug 1128845
 [test_playback_rate.html]
 [test_playback_rate_playpause.html]
 [test_playback_reactivate.html]
 [test_played.html]
 [test_preload_actions.html]
 [test_preload_attribute.html]
 [test_preload_suspend.html]
+[test_preserve_playbackrate_after_ui_play.html]
 [test_progress.html]
 [test_reactivate.html]
 skip-if = toolkit == 'gonk' # bug 1128845 on gonk
 [test_readyState.html]
 [test_referer.html]
 [test_replay_metadata.html]
 [test_reset_events_async.html]
 [test_reset_src.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_preserve_playbackrate_after_ui_play.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title> Bug 1013933 - preserve playbackRate after clicking play button </title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<div id="content">
+  <video width="320" height="240" id="video" controls mozNoDynamicControls preload="auto"></video>
+</div>
+
+<script type="text/javascript">
+/*
+ * Positions of the UI elements, relative to the upper-left corner of the
+ * <video> box.
+ */
+const videoHeight = 240;
+const playButtonWidth = 28;
+const playButtonHeight = 28;
+const playButtonCenterX = 0 + Math.round(playButtonWidth / 2);
+const playButtonCenterY = videoHeight - Math.round(playButtonHeight / 2);
+
+var expectedPlaybackRate = 0.5
+
+function runTest() {
+  var video = document.getElementById("video");
+  video.src = "audio.wav";
+  video.loop = true;
+  video.playbackRate = expectedPlaybackRate;
+
+  video.oncanplaythrough = function() {
+    video.oncanplaythrough = null;
+    is(video.paused, true, "video is not playing yet.");
+    is(video.playbackRate, expectedPlaybackRate,
+       "playbackRate is correct before clicking play button.");
+
+    // Click the play button
+    synthesizeMouse(video, playButtonCenterX, playButtonCenterY, { });
+  };
+
+  video.onplay = function() {
+    video.onplay = null;
+    is(video.paused, false, "video starts playing.");
+    is(video.playbackRate, expectedPlaybackRate,
+       "playbackRate is correct after clicking play button.");
+    video.pause();
+    SimpleTest.finish();
+  };
+}
+
+window.addEventListener("load", runTest, false);
+SimpleTest.waitForExplicitFinish();
+</script>
+</pre>
+</body>
+</html>
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -170,22 +170,20 @@
           <body>
           <![CDATA[
             if (this.type == "scrubber") {
                 this.Utils.log("--- dragStateChanged: " + isDragging + " ---");
                 this.isDragging = isDragging;
                 if (isDragging) {
                     this.wasPausedBeforeDrag = this.Utils.video.paused;
                     this.isDraggingComplete = false;
-                    this.previousPlaybackRate = this.Utils.video.playbackRate;
                     this.Utils.video.pause();
                 } else if (!this.wasPausedBeforeDrag && !this.isDraggingComplete) {
                     this.isDraggingComplete = true;
                     // After the drag ends, resume playing.
-                    this.Utils.video.playbackRate = this.previousPlaybackRate;
                     this.Utils.video.play();
                 } else {
                     this.isDraggingComplete = true;
                 }
             }
           ]]>
           </body>
       </method>
@@ -1018,17 +1016,16 @@
                 },
 
                 _triggeredByControls: false,
 
                 togglePause : function () {
                     if (this.video.paused || this.video.ended) {
                         this._triggeredByControls = true;
                         this.hideClickToPlay();
-                        this.video.playbackRate = this.video.defaultPlaybackRate;
                         this.video.play();
                     } else {
                         this.video.pause();
                     }
 
                     // We'll handle style changes in the event listener for
                     // the "play" and "pause" events, same as if content
                     // script was controlling video playback.