summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/animation/test/browser_animation_logic_auto-stop.js
blob: fdf1867ffa86e6bb137bfe93e7c12fd8580825f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Animation inspector makes the current time to stop
// after end of animation duration except iterations infinity.
// Test followings:
// * state of animations and UI components after end of animation duration
// * state of animations and UI components after end of animation duration
//   but iteration count is infinity

add_task(async function () {
  await addTab(URL_ROOT + "doc_simple_animation.html");
  await removeAnimatedElementsExcept([".compositor-all", ".long"]);
  const { animationInspector, inspector, panel } =
    await openAnimationInspector();

  info("Checking state after end of animation duration");
  await selectNode(".long", inspector);
  await waitUntil(() => panel.querySelectorAll(".animation-item").length === 1);
  const pixelsData = getDurationAndRate(animationInspector, panel, 5);
  clickOnCurrentTimeScrubberController(
    animationInspector,
    panel,
    1 - pixelsData.rate
  );
  await waitUntilAnimationsPlayState(animationInspector, "paused");
  clickOnPauseResumeButton(animationInspector, panel);
  await assertStates(animationInspector, panel, false);

  info(
    "Checking state after end of animation duration and infinity iterations"
  );
  clickOnPauseResumeButton(animationInspector, panel);
  await waitUntilAnimationsPlayState(animationInspector, "paused");
  await selectNode(".compositor-all", inspector);
  await waitUntil(() => panel.querySelectorAll(".animation-item").length === 1);
  clickOnCurrentTimeScrubberController(animationInspector, panel, 1);
  await waitUntilAnimationsPlayState(animationInspector, "paused");
  clickOnPauseResumeButton(animationInspector, panel);
  await assertStates(animationInspector, panel, true);
});

async function assertStates(animationInspector, panel, shouldRunning) {
  const buttonEl = panel.querySelector(".pause-resume-button");
  const labelEl = panel.querySelector(".current-time-label");
  const scrubberEl = panel.querySelector(".current-time-scrubber");

  const previousLabelContent = labelEl.textContent;
  const previousScrubberX = scrubberEl.getBoundingClientRect().x;

  await waitUntilAnimationsPlayState(
    animationInspector,
    shouldRunning ? "running" : "paused"
  );

  const currentLabelContent = labelEl.textContent;
  const currentScrubberX = scrubberEl.getBoundingClientRect().x;

  if (shouldRunning) {
    isnot(
      previousLabelContent,
      currentLabelContent,
      "Current time label content should change"
    );
    isnot(
      previousScrubberX,
      currentScrubberX,
      "Current time scrubber position should change"
    );
    ok(
      !buttonEl.classList.contains("paused"),
      "State of button should be running"
    );
    assertAnimationsRunning(animationInspector);
  } else {
    is(
      previousLabelContent,
      currentLabelContent,
      "Current time label Content should not change"
    );
    is(
      previousScrubberX,
      currentScrubberX,
      "Current time scrubber position should not change"
    );
    ok(
      buttonEl.classList.contains("paused"),
      "State of button should be paused"
    );
    assertAnimationsPausing(animationInspector);
  }
}