Bug 1134500 - Fix multiple browser/devtools/animationinspector intermittent tests. r=bgrins, a=test-only
💩💩 backed out by 88bda8094530 💩 💩
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 03 Apr 2015 10:32:48 +0200
changeset 258319 589aafc2bb13
parent 258318 484a6aef6a4f
child 258320 98ac0c020205
push id4645
push userryanvm@gmail.com
push date2015-04-07 15:05 +0000
treeherdermozilla-beta@8f0271f2c153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, test-only
bugs1134500, 1149711
milestone38.0
Bug 1134500 - Fix multiple browser/devtools/animationinspector intermittent tests. r=bgrins, a=test-only This changes a few animationinspector tests by making them wait until the expected animation state is reached rather than just waiting for the next animation auto-refresh update, which might, in some cases, not be enough. This is a re-landing of bug 1134500 and bug 1149711.
browser/devtools/animationinspector/test/browser_animation_playerWidgets_disables_on_finished.js
browser/devtools/animationinspector/test/browser_animation_playerWidgets_dont_show_time_after_duration.js
browser/devtools/animationinspector/test/browser_animation_toggle_button_updates_playerWidgets.js
browser/devtools/animationinspector/test/browser_animation_ui_updates_when_animation_changes.js
browser/devtools/animationinspector/test/head.js
--- a/browser/devtools/animationinspector/test/browser_animation_playerWidgets_disables_on_finished.js
+++ b/browser/devtools/animationinspector/test/browser_animation_playerWidgets_disables_on_finished.js
@@ -16,25 +16,17 @@ add_task(function*() {
   info("Select the test node");
   yield selectNode(".still", inspector);
 
   is(controller.animationPlayers.length, 2, "2 animation players exist");
 
   info("Wait for both animations to end");
 
   let promises = controller.animationPlayers.map(front => {
-    let def = promise.defer();
-    let onStateChanged = () => {
-      if (front.state.playState === "finished") {
-        front.off(front.AUTO_REFRESH_EVENT, onStateChanged);
-        def.resolve();
-      }
-    };
-    front.on(front.AUTO_REFRESH_EVENT, onStateChanged);
-    return def.promise;
+    return waitForPlayState(front, "finished");
   });
 
   yield promise.all(promises);
 
   for (let widgetEl of panel.playersEl.querySelectorAll(".player-widget")) {
     ok(widgetEl.classList.contains("finished"), "The player widget has the right class");
   }
 });
--- a/browser/devtools/animationinspector/test/browser_animation_playerWidgets_dont_show_time_after_duration.js
+++ b/browser/devtools/animationinspector/test/browser_animation_playerWidgets_dont_show_time_after_duration.js
@@ -19,24 +19,16 @@ add_task(function*() {
 
   info("Select the node");
   yield selectNode(".still", inspector);
 
   info("Wait until the animation ends");
   let widget = panel.playerWidgets[0];
   let front = widget.player;
 
-  let def = promise.defer();
-  let onStateChanged = () => {
-    if (front.state.playState === "finished") {
-      front.off(front.AUTO_REFRESH_EVENT, onStateChanged);
-      def.resolve();
-    }
-  };
-  front.on(front.AUTO_REFRESH_EVENT, onStateChanged);
-  yield def.promise;
+  yield waitForPlayState(front, "finished");
 
   is(widget.currentTimeEl.value, front.state.duration,
     "The timeline slider has the right value");
   is(widget.timeDisplayEl.textContent,
     L10N.numberWithDecimals(front.state.duration / 1000, 2) + "s",
     "The timeline slider has the right value");
 });
--- a/browser/devtools/animationinspector/test/browser_animation_toggle_button_updates_playerWidgets.js
+++ b/browser/devtools/animationinspector/test/browser_animation_toggle_button_updates_playerWidgets.js
@@ -9,27 +9,30 @@
 
 add_task(function*() {
   yield addTab(TEST_URL_ROOT + "doc_simple_animation.html");
   let {inspector, panel} = yield openAnimationInspector();
 
   info("Select an animated node");
   yield selectNode(".animated", inspector);
   let widget = panel.playerWidgets[0];
+  let player = widget.player;
 
-  info("Click the toggle button to pause all animations");
-  let onRefresh = widget.player.once(widget.player.AUTO_REFRESH_EVENT);
+  info("Listen to animation state changes and click the toggle button to " +
+    "pause all animations");
+  let onPaused = waitForPlayState(player, "paused");
   yield panel.toggleAll();
-  yield onRefresh;
+  yield onPaused;
 
   info("Checking the selected node's animation player widget's state");
-  is(widget.player.state.playState, "paused", "The player front's state is paused");
+  is(player.state.playState, "paused", "The player front's state is paused");
   ok(widget.el.classList.contains("paused"), "The widget's UI is in paused state");
 
-  info("Click the toggle button to play all animations");
-  onRefresh = widget.player.once(widget.player.AUTO_REFRESH_EVENT);
+  info("Listen to animation state changes and click the toggle button to " +
+    "play all animations");
+  let onRunning = waitForPlayState(player, "running");
   yield panel.toggleAll();
-  yield onRefresh;
+  yield onRunning;
 
   info("Checking the selected node's animation player widget's state again");
-  is(widget.player.state.playState, "running", "The player front's state is running");
+  is(player.state.playState, "running", "The player front's state is running");
   ok(widget.el.classList.contains("running"), "The widget's UI is in running state");
 });
--- a/browser/devtools/animationinspector/test/browser_animation_ui_updates_when_animation_changes.js
+++ b/browser/devtools/animationinspector/test/browser_animation_ui_updates_when_animation_changes.js
@@ -11,39 +11,44 @@ add_task(function*() {
   yield addTab(TEST_URL_ROOT + "doc_simple_animation.html");
   let {panel, inspector} = yield openAnimationInspector();
 
   info("Select the test node");
   yield selectNode(".animated", inspector);
 
   info("Get the player widget");
   let widget = panel.playerWidgets[0];
+  let player = widget.player;
+
+  info("Wait for paused playState");
+  let onPaused = waitForPlayState(player, "paused");
 
   info("Pause the animation via the content DOM");
   yield executeInContent("Test:ToggleAnimationPlayer", {
     animationIndex: 0,
     pause: true
   }, {
     node: getNode(".animated")
   });
 
-  info("Wait for the next state update");
-  yield widget.player.once(widget.player.AUTO_REFRESH_EVENT);
+  yield onPaused;
 
-  is(widget.player.state.playState, "paused", "The AnimationPlayerFront is paused");
+  is(player.state.playState, "paused", "The AnimationPlayerFront is paused");
   ok(widget.el.classList.contains("paused"), "The button's state has changed");
   ok(!widget.rafID, "The smooth timeline animation has been stopped");
 
+  info("Wait for running playState");
+  let onRunning = waitForPlayState(player, "running");
+
   info("Play the animation via the content DOM");
   yield executeInContent("Test:ToggleAnimationPlayer", {
     animationIndex: 0,
     pause: false
   }, {
     node: getNode(".animated")
   });
 
-  info("Wait for the next state update");
-  yield widget.player.once(widget.player.AUTO_REFRESH_EVENT);
+  yield onRunning;
 
-  is(widget.player.state.playState, "running", "The AnimationPlayerFront is running");
+  is(player.state.playState, "running", "The AnimationPlayerFront is running");
   ok(widget.el.classList.contains("running"), "The button's state has changed");
   ok(widget.rafID, "The smooth timeline animation has been started");
 });
--- a/browser/devtools/animationinspector/test/head.js
+++ b/browser/devtools/animationinspector/test/head.js
@@ -287,20 +287,18 @@ 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 waitForStateCondition(widget.player, state => {
-    return state.playState === nextState;
-  }, "after clicking the toggle button");
+  // Wait until the state changes.
+  yield waitForPlayState(widget.player, nextState);
 });
 
 /**
  * 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
@@ -321,16 +319,47 @@ let waitForStateCondition = Task.async(f
       player.off(player.AUTO_REFRESH_EVENT, onNewState);
       def.resolve();
     }
   });
   return def.promise;
 });
 
 /**
+ * Wait for a player's auto-refresh events and stop when the playState is the
+ * provided string.
+ * @param {AnimationPlayerFront} player
+ * @param {String} playState The playState to expect.
+ * @return {Promise} Resolves when the playState has changed to the expected value.
+ */
+function waitForPlayState(player, playState) {
+  return waitForStateCondition(player, state => {
+    return state.playState === playState;
+  }, "Waiting for animation to be " + playState);
+}
+
+/**
+ * Wait for the player's auto-refresh events until the animation is paused.
+ * When done, check its currentTime.
+ * @param {PlayerWidget} widget.
+ * @param {Numer} time.
+ * @return {Promise} Resolves when the animation is paused and tests have ran.
+ */
+let checkPausedAt = Task.async(function*(widget, time) {
+  info("Wait for the next auto-refresh");
+
+  yield waitForPlayState(widget.player, "paused");
+
+  ok(widget.el.classList.contains("paused"), "The widget is in paused mode");
+  is(widget.player.state.currentTime, time,
+    "The player front's currentTime was set to " + time);
+  is(widget.currentTimeEl.value, time, "The input's value was set to " + time);
+});
+
++/**
  * 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},
                                          {node: getNode(selector)});
   return playState;
 });