summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_animation_playPauseSeveral.js
blob: d478a801d0d97a28e46590fa31779bacb3d0276c (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check that the AnimationsActor can pause/play a given list of animations at once.

// List of selectors that match "all" animated nodes in the test page.
// This list misses a bunch of animated nodes on purpose. Only the ones that
// have infinite animations are listed. This is done to avoid intermittents
// caused when finite animations are already done playing by the time the test
// runs.
const ALL_ANIMATED_NODES = [
  ".simple-animation",
  ".multiple-animations",
  ".delayed-animation",
];

add_task(async function () {
  const { target, walker, animations } = await initAnimationsFrontForUrl(
    MAIN_DOMAIN + "animation.html"
  );

  info("Pause all animations in the test document");
  await toggleAndCheckStates(walker, animations, ALL_ANIMATED_NODES, "paused");

  info("Play all animations in the test document");
  await toggleAndCheckStates(walker, animations, ALL_ANIMATED_NODES, "running");

  await target.destroy();
  gBrowser.removeCurrentTab();
});

async function toggleAndCheckStates(walker, animations, selectors, playState) {
  info(
    "Checking the playState of all the nodes that have infinite running " +
      "animations"
  );

  for (const selector of selectors) {
    const players = await getPlayersFor(walker, animations, selector);

    if (playState === "paused") {
      await animations.pauseSome(players);
    } else {
      await animations.playSome(players);
    }

    info("Getting the AnimationPlayerFront for node " + selector);
    const player = players[0];
    await checkPlayState(player, selector, playState);
  }
}

async function getPlayersFor(walker, animations, selector) {
  const node = await walker.querySelector(walker.rootNode, selector);
  return animations.getAnimationPlayersForNode(node);
}

async function checkPlayState(player, selector, expectedState) {
  const state = await player.getCurrentState();
  is(
    state.playState,
    expectedState,
    "The playState of node " + selector + " is " + expectedState
  );
}