summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_flex_display_badge.js
blob: fb16ffe3612ef4b18a50dc13f420bb381c04ade2 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the flex display badge toggles on the flexbox highlighter.

const TEST_URI = `
  <style type="text/css">
    #flex {
      display: flex;
    }
  </style>
  <div id="flex"></div>
`;

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector } = await openLayoutView();
  const { store } = inspector;
  const HIGHLIGHTER_TYPE = inspector.highlighters.TYPES.FLEXBOX;
  const {
    getActiveHighlighter,
    getNodeForActiveHighlighter,
    waitForHighlighterTypeShown,
    waitForHighlighterTypeHidden,
  } = getHighlighterTestHelpers(inspector);

  info("Check the flex display badge is shown and not active.");
  await selectNode("#flex", inspector);

  info("Wait until the flexbox store has been updated");
  await waitUntilState(
    store,
    state =>
      state.flexbox.flexContainer.nodeFront === inspector.selection.nodeFront
  );

  const flexContainer = await getContainerForSelector("#flex", inspector);
  const flexDisplayBadge = flexContainer.elt.querySelector(
    ".inspector-badge.interactive[data-display]"
  );
  ok(
    !flexDisplayBadge.classList.contains("active"),
    "flex display badge is not active."
  );
  is(
    flexDisplayBadge.getAttribute("aria-pressed"),
    "false",
    "flex display badge is not pressed."
  );
  ok(
    flexDisplayBadge.classList.contains("interactive"),
    "flex display badge is interactive."
  );

  info("Check the initial state of the flex highlighter.");
  ok(
    !getActiveHighlighter(HIGHLIGHTER_TYPE),
    "No flexbox highlighter exists in the highlighters overlay."
  );
  ok(
    !getNodeForActiveHighlighter(HIGHLIGHTER_TYPE),
    "No flexbox highlighter is shown."
  );

  info("Toggling ON the flexbox highlighter from the flex display badge.");
  let onHighlighterShown = waitForHighlighterTypeShown(HIGHLIGHTER_TYPE);
  let onCheckboxChange = waitUntilState(
    store,
    state => state.flexbox.highlighted
  );
  flexDisplayBadge.click();
  await onHighlighterShown;
  await onCheckboxChange;

  info(
    "Check the flexbox highlighter is created and flex display badge state."
  );
  ok(
    getActiveHighlighter(HIGHLIGHTER_TYPE),
    "Flexbox highlighter is created in the highlighters overlay."
  );
  ok(
    getNodeForActiveHighlighter(HIGHLIGHTER_TYPE),
    "Flexbox highlighter is shown."
  );
  ok(
    flexDisplayBadge.classList.contains("active"),
    "flex display badge is active."
  );
  is(
    flexDisplayBadge.getAttribute("aria-pressed"),
    "true",
    "flex display badge is pressed."
  );
  ok(
    flexDisplayBadge.classList.contains("interactive"),
    "flex display badge is interactive."
  );

  info("Toggling OFF the flexbox highlighter from the flex display badge.");
  let onHighlighterHidden = waitForHighlighterTypeHidden(HIGHLIGHTER_TYPE);
  onCheckboxChange = waitUntilState(store, state => !state.flexbox.highlighted);
  flexDisplayBadge.click();
  await onHighlighterHidden;
  await onCheckboxChange;

  ok(
    !flexDisplayBadge.classList.contains("active"),
    "flex display badge is not active."
  );
  is(
    flexDisplayBadge.getAttribute("aria-pressed"),
    "false",
    "flex display badge is no longer pressed."
  );
  ok(
    flexDisplayBadge.classList.contains("interactive"),
    "flex display badge is interactive."
  );

  info("Toggling ON the flexbox highlighter from the keyboard.");
  onHighlighterShown = waitForHighlighterTypeShown(HIGHLIGHTER_TYPE);
  onCheckboxChange = waitUntilState(store, state => state.flexbox.highlighted);

  flexDisplayBadge.focus();
  EventUtils.synthesizeKey("VK_RETURN", {}, flexDisplayBadge.ownerGlobal);
  await onHighlighterShown;
  await onCheckboxChange;

  ok(
    getNodeForActiveHighlighter(HIGHLIGHTER_TYPE),
    "Flexbox highlighter was displayed from the keyboard."
  );
  ok(
    flexDisplayBadge.classList.contains("active"),
    "flex display badge is active."
  );
  is(
    flexDisplayBadge.getAttribute("aria-pressed"),
    "true",
    "flex display badge is pressed."
  );

  info("Toggling OFF the flexbox highlighter from the keyboard.");
  onHighlighterHidden = waitForHighlighterTypeHidden(HIGHLIGHTER_TYPE);
  onCheckboxChange = waitUntilState(store, state => !state.flexbox.highlighted);
  EventUtils.synthesizeKey("VK_RETURN", {}, flexDisplayBadge.ownerGlobal);
  await onHighlighterHidden;
  await onCheckboxChange;

  ok(true, "Highlighter was hidden from the keyboard");
  ok(
    !flexDisplayBadge.classList.contains("active"),
    "flex display badge was deactivated from the keyboard"
  );
  is(
    flexDisplayBadge.getAttribute("aria-pressed"),
    "false",
    "flex display badge is no longer pressed."
  );
});