summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_keyframes-rule_01.js
blob: 8d4b436c54e4dcc7cb2cd5b070fc8dfc82f00c44 (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
95
96
97
98
99
100
101
102
103
104
105
106
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that keyframe rules and gutters are displayed correctly in the
// rule view.

const TEST_URI = URL_ROOT + "doc_keyframeanimation.html";

add_task(function* () {
  yield addTab(TEST_URI);
  let {inspector, view} = yield openRuleView();
  yield testPacman(inspector, view);
  yield testBoxy(inspector, view);
  yield testMoxy(inspector, view);
});

function* testPacman(inspector, view) {
  info("Test content and gutter in the keyframes rule of #pacman");

  yield assertKeyframeRules("#pacman", inspector, view, {
    elementRulesNb: 2,
    keyframeRulesNb: 2,
    keyframesRules: ["pacman", "pacman"],
    keyframeRules: ["100%", "100%"]
  });

  assertGutters(view, {
    guttersNbs: 2,
    gutterHeading: ["Keyframes pacman", "Keyframes pacman"]
  });
}

function* testBoxy(inspector, view) {
  info("Test content and gutter in the keyframes rule of #boxy");

  yield assertKeyframeRules("#boxy", inspector, view, {
    elementRulesNb: 3,
    keyframeRulesNb: 3,
    keyframesRules: ["boxy", "boxy", "boxy"],
    keyframeRules: ["10%", "20%", "100%"]
  });

  assertGutters(view, {
    guttersNbs: 1,
    gutterHeading: ["Keyframes boxy"]
  });
}

function* testMoxy(inspector, view) {
  info("Test content and gutter in the keyframes rule of #moxy");

  yield assertKeyframeRules("#moxy", inspector, view, {
    elementRulesNb: 3,
    keyframeRulesNb: 4,
    keyframesRules: ["boxy", "boxy", "boxy", "moxy"],
    keyframeRules: ["10%", "20%", "100%", "100%"]
  });

  assertGutters(view, {
    guttersNbs: 2,
    gutterHeading: ["Keyframes boxy", "Keyframes moxy"]
  });
}

function* assertKeyframeRules(selector, inspector, view, expected) {
  yield selectNode(selector, inspector);
  let elementStyle = view._elementStyle;

  let rules = {
    elementRules: elementStyle.rules.filter(rule => !rule.keyframes),
    keyframeRules: elementStyle.rules.filter(rule => rule.keyframes)
  };

  is(rules.elementRules.length, expected.elementRulesNb, selector +
    " has the correct number of non keyframe element rules");
  is(rules.keyframeRules.length, expected.keyframeRulesNb, selector +
    " has the correct number of keyframe rules");

  let i = 0;
  for (let keyframeRule of rules.keyframeRules) {
    ok(keyframeRule.keyframes.name == expected.keyframesRules[i],
      keyframeRule.keyframes.name + " has the correct keyframes name");
    ok(keyframeRule.domRule.keyText == expected.keyframeRules[i],
      keyframeRule.domRule.keyText + " selector heading is correct");
    i++;
  }
}

function assertGutters(view, expected) {
  let gutters = view.element.querySelectorAll(".theme-gutter");

  is(gutters.length, expected.guttersNbs,
    "There are " + gutters.length + " gutter headings");

  let i = 0;
  for (let gutter of gutters) {
    is(gutter.textContent, expected.gutterHeading[i],
      "Correct " + gutter.textContent + " gutter headings");
    i++;
  }

  return gutters;
}