Bug 1205681 - 3 - Tests for the timeline rewind button; r=tromey
authorPatrick Brosset <pbrosset@mozilla.com>
Mon, 12 Oct 2015 11:39:21 +0200
changeset 267499 d42f330611b58b77c36ac176796aedad57e8c499
parent 267498 84e437888ab4663b1d392fe1713994d9ccd8887b
child 267500 e1273c74b4838bab1d4998ecb4c8485c4df8cb9c
push id18051
push usercbook@mozilla.com
push dateWed, 14 Oct 2015 10:50:45 +0000
treeherderb2g-inbound@3f15abe61a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1205681
milestone44.0a1
Bug 1205681 - 3 - Tests for the timeline rewind button; r=tromey
devtools/client/animationinspector/test/browser.ini
devtools/client/animationinspector/test/browser_animation_timeline_pause_button.js
devtools/client/animationinspector/test/browser_animation_timeline_rewind_button.js
devtools/client/animationinspector/test/head.js
--- a/devtools/client/animationinspector/test/browser.ini
+++ b/devtools/client/animationinspector/test/browser.ini
@@ -21,16 +21,17 @@ support-files =
 [browser_animation_refresh_on_removed_animation.js]
 [browser_animation_refresh_when_active.js]
 [browser_animation_same_nb_of_playerWidgets_and_playerFronts.js]
 [browser_animation_shows_player_on_valid_node.js]
 [browser_animation_target_highlight_select.js]
 [browser_animation_target_highlighter_lock.js]
 [browser_animation_timeline_header.js]
 [browser_animation_timeline_pause_button.js]
+[browser_animation_timeline_rewind_button.js]
 [browser_animation_timeline_scrubber_exists.js]
 [browser_animation_timeline_scrubber_movable.js]
 [browser_animation_timeline_scrubber_moves.js]
 [browser_animation_timeline_shows_delay.js]
 [browser_animation_timeline_shows_iterations.js]
 [browser_animation_timeline_shows_time_info.js]
 [browser_animation_timeline_takes_rate_into_account.js]
 [browser_animation_timeline_ui.js]
--- a/devtools/client/animationinspector/test/browser_animation_timeline_pause_button.js
+++ b/devtools/client/animationinspector/test/browser_animation_timeline_pause_button.js
@@ -15,53 +15,21 @@ add_task(function*() {
   let {panel} = yield openAnimationInspector();
   let btn = panel.playTimelineButtonEl;
 
   ok(btn, "The play/pause button exists");
   ok(!btn.classList.contains("paused"),
      "The play/pause button is in its playing state");
 
   info("Click on the button to pause all timeline animations");
-  yield clickPlayPauseButton(panel);
+  yield clickTimelinePlayPauseButton(panel);
 
   ok(btn.classList.contains("paused"),
      "The play/pause button is in its paused state");
-  yield checkIfScrubberMoving(panel, false);
+  yield assertScrubberMoving(panel, false);
 
   info("Click again on the button to play all timeline animations");
-  yield clickPlayPauseButton(panel);
+  yield clickTimelinePlayPauseButton(panel);
 
   ok(!btn.classList.contains("paused"),
      "The play/pause button is in its playing state again");
-  yield checkIfScrubberMoving(panel, true);
+  yield assertScrubberMoving(panel, true);
 });
-
-function* clickPlayPauseButton(panel) {
-  let onUiUpdated = panel.once(panel.UI_UPDATED_EVENT);
-
-  let btn = panel.playTimelineButtonEl;
-  let win = btn.ownerDocument.defaultView;
-  EventUtils.sendMouseEvent({type: "click"}, btn, win);
-
-  yield onUiUpdated;
-  yield waitForAllAnimationTargets(panel);
-}
-
-function* checkIfScrubberMoving(panel, isMoving) {
-  let timeline = panel.animationsTimelineComponent;
-  let scrubberEl = timeline.scrubberEl;
-
-  if (isMoving) {
-    // If we expect the scrubber to move, just wait for a couple of
-    // timeline-data-changed events and compare times.
-    let {time: time1} = yield timeline.once("timeline-data-changed");
-    let {time: time2} = yield timeline.once("timeline-data-changed");
-    ok(time2 > time1, "The scrubber is moving");
-  } else {
-    // If instead we expect the scrubber to remain at its position, just wait
-    // for some time. A relatively long timeout is used because the test page
-    // has long running animations, so the scrubber doesn't move that quickly.
-    let startOffset = scrubberEl.offsetLeft;
-    yield new Promise(r => setTimeout(r, 2000));
-    let endOffset = scrubberEl.offsetLeft;
-    is(startOffset, endOffset, "The scrubber is not moving");
-  }
-}
new file mode 100644
--- /dev/null
+++ b/devtools/client/animationinspector/test/browser_animation_timeline_rewind_button.js
@@ -0,0 +1,48 @@
+/* vim: set 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 the timeline toolbar contains a rewind button and that it can be
+// clicked. Check that when it is, the current animations displayed in the
+// timeline get their playstates changed to paused, and their currentTimes
+// reset to 0, and that the scrubber stops moving and is positioned to the
+// start.
+
+add_task(function*() {
+  yield addTab(TEST_URL_ROOT + "doc_simple_animation.html");
+
+  let {panel, controller} = yield openAnimationInspector();
+  let btn = panel.rewindTimelineButtonEl;
+
+  ok(btn, "The rewind button exists");
+
+  info("Click on the button to rewind all timeline animations");
+  yield clickTimelineRewindButton(panel);
+
+  info("Check that the scrubber has stopped moving");
+  yield assertScrubberMoving(panel, false);
+
+  ok(controller.animationPlayers.every(({state}) => state.currentTime === 0),
+     "All animations' currentTimes have been set to 0");
+  ok(controller.animationPlayers.every(({state}) => state.playState === "paused"),
+     "All animations have been paused");
+
+  info("Play the animations again");
+  yield clickTimelinePlayPauseButton(panel);
+
+  info("And pause them after a short while");
+  yield new Promise(r => setTimeout(r, 200));
+
+  info("Check that rewinding when animations are paused works too");
+  yield clickTimelineRewindButton(panel);
+
+  info("Check that the scrubber has stopped moving");
+  yield assertScrubberMoving(panel, false);
+
+  ok(controller.animationPlayers.every(({state}) => state.currentTime === 0),
+     "All animations' currentTimes have been set to 0");
+  ok(controller.animationPlayers.every(({state}) => state.playState === "paused"),
+     "All animations have been paused");
+});
--- a/devtools/client/animationinspector/test/head.js
+++ b/devtools/client/animationinspector/test/head.js
@@ -444,8 +444,55 @@ var waitForAllAnimationTargets = Task.as
   yield promise.all(targets.map(t => {
     if (!t.nodeFront) {
       return t.once("target-retrieved");
     }
     return false;
   }));
   return targets;
 });
+
+/**
+ * Check the scrubber element in the timeline is moving.
+ * @param {AnimationPanel} panel
+ * @param {Boolean} isMoving
+ */
+function* assertScrubberMoving(panel, isMoving) {
+  let timeline = panel.animationsTimelineComponent;
+  let scrubberEl = timeline.scrubberEl;
+
+  if (isMoving) {
+    // If we expect the scrubber to move, just wait for a couple of
+    // timeline-data-changed events and compare times.
+    let {time: time1} = yield timeline.once("timeline-data-changed");
+    let {time: time2} = yield timeline.once("timeline-data-changed");
+    ok(time2 > time1, "The scrubber is moving");
+  } else {
+    // If instead we expect the scrubber to remain at its position, just wait
+    // for some time and make sure timeline-data-changed isn't emitted.
+    let hasMoved = false;
+    timeline.once("timeline-data-changed", () => hasMoved = true);
+    yield new Promise(r => setTimeout(r, 500));
+    ok(!hasMoved, "The scrubber is not moving");
+  }
+}
+
+function* clickTimelinePlayPauseButton(panel) {
+  let onUiUpdated = panel.once(panel.UI_UPDATED_EVENT);
+
+  let btn = panel.playTimelineButtonEl;
+  let win = btn.ownerDocument.defaultView;
+  EventUtils.sendMouseEvent({type: "click"}, btn, win);
+
+  yield onUiUpdated;
+  yield waitForAllAnimationTargets(panel);
+}
+
+function* clickTimelineRewindButton(panel) {
+  let onUiUpdated = panel.once(panel.UI_UPDATED_EVENT);
+
+  let btn = panel.rewindTimelineButtonEl;
+  let win = btn.ownerDocument.defaultView;
+  EventUtils.sendMouseEvent({type: "click"}, btn, win);
+
+  yield onUiUpdated;
+  yield waitForAllAnimationTargets(panel);
+}