Bug 1120339 - Add setPlaybackRate method to AnimationPlayerActor; r=past
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 25 Mar 2015 18:56:54 +0100
changeset 266036 16dff8194cdeb9268b29d1b5216ed6037d038190
parent 266035 3bf5485eb14b0bcb71363ca85a711f91926c5fd6
child 266037 8a1bac74ed807e4e0e7f272761ada3a4979bff2b
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1120339
milestone39.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 1120339 - Add setPlaybackRate method to AnimationPlayerActor; r=past
toolkit/devtools/server/actors/animation.js
toolkit/devtools/server/tests/browser/browser.ini
toolkit/devtools/server/tests/browser/browser_animation_actors_03.js
toolkit/devtools/server/tests/browser/browser_animation_actors_12.js
--- a/toolkit/devtools/server/actors/animation.js
+++ b/toolkit/devtools/server/actors/animation.js
@@ -203,16 +203,17 @@ let AnimationPlayerActor = ActorClass({
     // Note that if you add a new property to the state object, make sure you
     // add the corresponding property in the AnimationPlayerFront' initialState
     // getter.
     let newState = {
       // startTime is null whenever the animation is paused or waiting to start.
       startTime: this.player.startTime,
       currentTime: this.player.currentTime,
       playState: this.player.playState,
+      playbackRate: this.player.playbackRate,
       name: this.player.source.effect.name,
       duration: this.getDuration(),
       delay: this.getDelay(),
       iterationCount: this.getIterationCount(),
       // isRunningOnCompositor is important for developers to know if their
       // animation is hitting the fast path or not. Currently only true for
       // Firefox OS (where we have compositor animations enabled).
       // Returns false whenever the animation is paused as it is taken off the
@@ -291,16 +292,28 @@ let AnimationPlayerActor = ActorClass({
    */
   setCurrentTime: method(function(currentTime) {
     this.player.currentTime = currentTime;
   }, {
     request: {
       currentTime: Arg(0, "number")
     },
     response: {}
+  }),
+
+  /**
+   * Set the playback rate of the animation player.
+   */
+  setPlaybackRate: method(function(playbackRate) {
+    this.player.playbackRate = playbackRate;
+  }, {
+    request: {
+      currentTime: Arg(0, "number")
+    },
+    response: {}
   })
 });
 
 let AnimationPlayerFront = FrontClass(AnimationPlayerActor, {
   AUTO_REFRESH_EVENT: "updated-state",
 
   initialize: function(conn, form, detail, ctx) {
     EventEmitter.decorate(this);
@@ -327,16 +340,17 @@ let AnimationPlayerFront = FrontClass(An
    * Getter for the initial state of the player. Up to date states can be
    * retrieved by calling the getCurrentState method.
    */
   get initialState() {
     return {
       startTime: this._form.startTime,
       currentTime: this._form.currentTime,
       playState: this._form.playState,
+      playbackRate: this._form.playbackRate,
       name: this._form.name,
       duration: this._form.duration,
       delay: this._form.delay,
       iterationCount: this._form.iterationCount,
       isRunningOnCompositor: this._form.isRunningOnCompositor
     }
   },
 
--- a/toolkit/devtools/server/tests/browser/browser.ini
+++ b/toolkit/devtools/server/tests/browser/browser.ini
@@ -21,16 +21,17 @@ support-files =
 [browser_animation_actors_04.js]
 [browser_animation_actors_05.js]
 [browser_animation_actors_06.js]
 [browser_animation_actors_07.js]
 [browser_animation_actors_08.js]
 [browser_animation_actors_09.js]
 [browser_animation_actors_10.js]
 [browser_animation_actors_11.js]
+[browser_animation_actors_12.js]
 [browser_canvasframe_helper_01.js]
 [browser_canvasframe_helper_02.js]
 [browser_canvasframe_helper_03.js]
 [browser_canvasframe_helper_04.js]
 [browser_canvasframe_helper_05.js]
 [browser_canvasframe_helper_06.js]
 [browser_navigateEvents.js]
 [browser_storage_dynamic_windows.js]
--- a/toolkit/devtools/server/tests/browser/browser_animation_actors_03.js
+++ b/toolkit/devtools/server/tests/browser/browser_animation_actors_03.js
@@ -29,50 +29,54 @@ add_task(function*() {
 function* playerHasAnInitialState(walker, front) {
   let node = yield walker.querySelector(walker.rootNode, ".simple-animation");
   let [player] = yield front.getAnimationPlayersForNode(node);
 
   ok(player.initialState, "The player front has an initial state");
   ok("startTime" in player.initialState, "Player's state has startTime");
   ok("currentTime" in player.initialState, "Player's state has currentTime");
   ok("playState" in player.initialState, "Player's state has playState");
+  ok("playbackRate" in player.initialState, "Player's state has playbackRate");
   ok("name" in player.initialState, "Player's state has name");
   ok("duration" in player.initialState, "Player's state has duration");
   ok("delay" in player.initialState, "Player's state has delay");
   ok("iterationCount" in player.initialState, "Player's state has iterationCount");
   ok("isRunningOnCompositor" in player.initialState, "Player's state has isRunningOnCompositor");
 }
 
 function* playerStateIsCorrect(walker, front) {
   info("Checking the state of the simple animation");
 
   let state = yield getAnimationStateForNode(walker, front, ".simple-animation", 0);
   is(state.name, "move", "Name is correct");
   is(state.duration, 2000, "Duration is correct");
   // null = infinite count
   is(state.iterationCount, null, "Iteration count is correct");
   is(state.playState, "running", "PlayState is correct");
+  is(state.playbackRate, 1, "PlaybackRate is correct");
 
   info("Checking the state of the transition");
 
   state = yield getAnimationStateForNode(walker, front, ".transition", 0);
   is(state.name, "", "Transition has no name");
   is(state.duration, 5000, "Transition duration is correct");
   // transitions run only once
   is(state.iterationCount, 1, "Transition iteration count is correct");
   is(state.playState, "running", "Transition playState is correct");
+  is(state.playbackRate, 1, "Transition playbackRate is correct");
 
   info("Checking the state of one of multiple animations on a node");
 
   // Checking the 2nd player
   state = yield getAnimationStateForNode(walker, front, ".multiple-animations", 1);
   is(state.name, "glow", "The 2nd animation's name is correct");
   is(state.duration, 1000, "The 2nd animation's duration is correct");
   is(state.iterationCount, 5, "The 2nd animation's iteration count is correct");
   is(state.playState, "running", "The 2nd animation's playState is correct");
+  is(state.playbackRate, 1, "The 2nd animation's playbackRate is correct");
 
   info("Checking the state of an animation with delay");
 
   state = yield getAnimationStateForNode(walker, front, ".delayed-animation", 0);
   is(state.delay, 5000, "The animation delay is correct");
 
   info("Checking the state of an transition with delay");
 
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/browser/browser_animation_actors_12.js
@@ -0,0 +1,46 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Check that a player's playbackRate can be changed.
+
+const {AnimationsFront} = require("devtools/server/actors/animation");
+const {InspectorFront} = require("devtools/server/actors/inspector");
+
+add_task(function*() {
+  let doc = yield addTab(MAIN_DOMAIN + "animation.html");
+
+  initDebuggerServer();
+  let client = new DebuggerClient(DebuggerServer.connectPipe());
+  let form = yield connectDebuggerClient(client);
+  let inspector = InspectorFront(client, form);
+  let walker = yield inspector.getWalker();
+  let animations = AnimationsFront(client, form);
+
+  info("Retrieve an animated node");
+  let node = yield walker.querySelector(walker.rootNode, ".simple-animation");
+
+  info("Retrieve the animation player for the node");
+  let [player] = yield animations.getAnimationPlayersForNode(node);
+
+  ok(player.setPlaybackRate, "Player has the setPlaybackRate method");
+
+  info("Change the rate to 10");
+  yield player.setPlaybackRate(10);
+
+  info("Query the state again");
+  let state = yield player.getCurrentState();
+  is(state.playbackRate, 10, "The playbackRate was updated");
+
+  info("Change the rate back to 1");
+  yield player.setPlaybackRate(1);
+
+  info("Query the state again");
+  state = yield player.getCurrentState();
+  is(state.playbackRate, 1, "The playbackRate was changed back");
+
+  yield closeDebuggerClient(client);
+  gBrowser.removeCurrentTab();
+});