Bug 1013933 - preserve playbackrate across play/pause
MozReview-Commit-ID: KGnh1exMgSw
--- 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.