Bug 1113091 - Make the AnimationPlayerActor aware of the player ready promise; r=bgrins
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 09 Jan 2015 15:21:05 +0100
changeset 248788 2684f09cf98595a55f987bb4ae801000c7e5eb2b
parent 248787 46822560ac5394d889a058d711db1f3bff3cf620
child 248789 6d2c3bd2ccc1a95233d371a64442307c16f92883
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1113091
milestone37.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 1113091 - Make the AnimationPlayerActor aware of the player ready promise; r=bgrins
toolkit/devtools/server/actors/animation.js
toolkit/devtools/server/tests/browser/browser_animation_actors_04.js
--- a/toolkit/devtools/server/actors/animation.js
+++ b/toolkit/devtools/server/actors/animation.js
@@ -22,19 +22,18 @@
  *   http://w3c.github.io/web-animations/
  * - WebAnimation WebIDL files:
  *   /dom/webidl/Animation*.webidl
  */
 
 const {Cu} = require("chrome");
 const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
 const {setInterval, clearInterval} = require("sdk/timers");
-const {ActorClass, Actor,
-       FrontClass, Front,
-       Arg, method, RetVal} = require("devtools/server/protocol");
+const protocol = require("devtools/server/protocol");
+const {ActorClass, Actor, FrontClass, Front, Arg, method, RetVal} = protocol;
 const {NodeActor} = require("devtools/server/actors/inspector");
 const EventEmitter = require("devtools/toolkit/event-emitter");
 
 const PLAYER_DEFAULT_AUTO_REFRESH_TIMEOUT = 500; // ms
 
 /**
  * The AnimationPlayerActor provides information about a given animation: its
  * startTime, currentTime, current state, etc.
@@ -52,21 +51,22 @@ let AnimationPlayerActor = ActorClass({
    * @param {AnimationPlayer} The player object returned by getAnimationPlayers
    * @param {DOMNode} The node targeted by this player
    * @param {Number} Temporary work-around used to retrieve duration and
    * iteration count from computed-style rather than from waapi. This is needed
    * to know which duration to get, in case there are multiple css animations
    * applied to the same node.
    */
   initialize: function(animationsActor, player, node, playerIndex) {
+    Actor.prototype.initialize.call(this, animationsActor.conn);
+
     this.player = player;
     this.node = node;
     this.playerIndex = playerIndex;
     this.styles = node.ownerDocument.defaultView.getComputedStyle(node);
-    Actor.prototype.initialize.call(this, animationsActor.conn);
   },
 
   destroy: function() {
     this.player = this.node = this.styles = null;
     Actor.prototype.destroy.call(this);
   },
 
   /**
@@ -170,23 +170,42 @@ let AnimationPlayerActor = ActorClass({
     this.player.pause();
   }, {
     request: {},
     response: {}
   }),
 
   /**
    * Play the player.
+   * This method only returns when the animation has left its pending state.
    */
   play: method(function() {
     this.player.play();
     return this.player.ready;
   }, {
     request: {},
     response: {}
+  }),
+
+  /**
+   * Simply exposes the player ready promise.
+   *
+   * When an animation is created/paused then played, there's a short time
+   * during which its playState is pending, before being set to running.
+   *
+   * If you either created a new animation using the Web Animations API or
+   * paused/played an existing one, and then want to access the playState, you
+   * might be interested to call this method.
+   * This is especially important for tests.
+   */
+  ready: method(function() {
+    return this.player.ready;
+  }, {
+    request: {},
+    response: {}
   })
 });
 
 let AnimationPlayerFront = FrontClass(AnimationPlayerActor, {
   AUTO_REFRESH_EVENT: "updated-state",
 
   initialize: function(conn, form, detail, ctx) {
     EventEmitter.decorate(this);
--- a/toolkit/devtools/server/tests/browser/browser_animation_actors_04.js
+++ b/toolkit/devtools/server/tests/browser/browser_animation_actors_04.js
@@ -33,26 +33,26 @@ function* playStateIsUpdatedDynamically(
   // using the CPOW.
   let cpow = content.document.querySelector(".short-animation");
   cpow.classList.remove("short-animation");
   let reflow = cpow.offsetWidth;
   cpow.classList.add("short-animation");
 
   let [player] = yield front.getAnimationPlayersForNode(node);
 
-  // Bug 1113091 - We should wait for the player to become ready then
-  // test for the "running" state only
-  ok(player.initialState.playState == "running" ||
-     player.initialState.playState == "pending",
-    "The playState is running or pending while the transition is running");
+  yield player.ready();
+  let state = yield player.getCurrentState();
+
+  is(state.playState, "running",
+    "The playState is running while the transition is running");
 
   info("Wait until the animation stops (more than 1000ms)");
   yield wait(1500); // Waiting 1.5sec for good measure
 
-  let state = yield player.getCurrentState();
+  state = yield player.getCurrentState();
   is(state.playState, "finished",
     "The animation has ended and the state has been updated");
   ok(state.currentTime > player.initialState.currentTime,
     "The currentTime has been updated");
 }
 
 function wait(ms) {
   return new Promise(resolve => {