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

"use strict";

// Test that the AnimationsActor emits events about changed animations on a
// node after getAnimationPlayersForNode was called on that node.

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

  info("Retrieve a non-animated node");
  const node = await walker.querySelector(walker.rootNode, ".not-animated");

  info("Retrieve the animation player for the node");
  const players = await animations.getAnimationPlayersForNode(node);
  is(players.length, 0, "The node has no animation players");

  info("Listen for new animations");
  let onMutations = once(animations, "mutations");

  info("Add a couple of animation on the node");
  await node.modifyAttributes([
    { attributeName: "class", newValue: "multiple-animations" },
  ]);
  let changes = await onMutations;

  ok(true, "The mutations event was emitted");
  is(changes.length, 2, "There are 2 changes in the mutation event");
  ok(
    changes.every(({ type }) => type === "added"),
    "Both changes are additions"
  );

  const names = changes.map(c => c.player.initialState.name).sort();
  is(names[0], "glow", "The animation 'glow' was added");
  is(names[1], "move", "The animation 'move' was added");

  info("Store the 2 new players for comparing later");
  const p1 = changes[0].player;
  const p2 = changes[1].player;

  info("Listen for removed animations");
  onMutations = once(animations, "mutations");

  info("Remove the animation css class on the node");
  await node.modifyAttributes([
    { attributeName: "class", newValue: "not-animated" },
  ]);

  changes = await onMutations;

  ok(true, "The mutations event was emitted");
  is(changes.length, 2, "There are 2 changes in the mutation event");
  ok(
    changes.every(({ type }) => type === "removed"),
    "Both are removals"
  );
  ok(
    changes[0].player === p1 || changes[0].player === p2,
    "The first removed player was one of the previously added players"
  );
  ok(
    changes[1].player === p1 || changes[1].player === p2,
    "The second removed player was one of the previously added players"
  );

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