Bug 1137771 - Intermittent browser_animation_play_pause_button.js. r=miker, a=test-only
authorPatrick Brosset <pbrosset@mozilla.com>
Tue, 31 Mar 2015 16:18:02 +0200
changeset 258230 b228af82453b
parent 258229 e98a992238e2
child 258231 cf89394816b1
push id4623
push userryanvm@gmail.com
push date2015-04-03 01:49 +0000
treeherdermozilla-beta@9c755cdc241c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker, test-only
bugs1137771
milestone38.0
Bug 1137771 - Intermittent browser_animation_play_pause_button.js. r=miker, a=test-only Instead of waiting for the next auto-refresh event only (which could be a response to an older request, therefore not having the expected state yet), wait until the state changes to what we expect in the test. This means that if the play/pause button doesn't work anymore, then the test will timeout, but at least it won't intermittently fail as it was doing until now.
browser/devtools/animationinspector/test/head.js
--- a/browser/devtools/animationinspector/test/head.js
+++ b/browser/devtools/animationinspector/test/head.js
@@ -288,17 +288,46 @@ let togglePlayPauseButton = Task.async(f
   // Verify that the button's state is changed immediately, even if it will be
   // changed anyway with the next auto-refresh.
   ok(widget.el.classList.contains(nextState),
     "The button's state was changed in the UI before the request was sent");
 
   yield onClicked;
 
   // Wait for the next sate change event to make sure the state is updated
-  yield widget.player.once(widget.player.AUTO_REFRESH_EVENT);
+  yield waitForStateCondition(widget.player, state => {
+    return state.playState === nextState;
+  }, "after clicking the toggle button");
+});
+
+/**
+ * Wait for a player's auto-refresh events and stop when a condition becomes
+ * truthy.
+ * @param {AnimationPlayerFront} player
+ * @param {Function} conditionCheck Will be called over and over again when the
+ * player state changes, passing the state as argument. This method must return
+ * a truthy value to stop waiting.
+ * @param {String} desc If provided, this will be logged with info(...) every
+ * time the state is refreshed, until the condition passes.
+ * @return {Promise} Resolves when the condition passes.
+ */
+let waitForStateCondition = Task.async(function*(player, conditionCheck, desc="") {
+  if (desc) {
+    desc = "(" + desc + ")";
+  }
+  info("Waiting for a player's auto-refresh event " + desc);
+  let def = promise.defer();
+  player.on(player.AUTO_REFRESH_EVENT, function onNewState() {
+    info("State refreshed, checking condition ... " + desc);
+    if (conditionCheck(player.state)) {
+      player.off(player.AUTO_REFRESH_EVENT, onNewState);
+      def.resolve();
+    }
+  });
+  return def.promise;
 });
 
 /**
  * Get the current playState of an animation player on a given node.
  */
 let getAnimationPlayerState = Task.async(function*(selector, animationIndex=0) {
   let playState = yield executeInContent("Test:GetAnimationPlayerState",
                                          {animationIndex},