summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-cssgrid_01.js
blob: cbc10c8843dee469f376317ca3c104e6bdd58902 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// Test the creation of the canvas highlighter element of the css grid highlighter.

const TEST_URL = `
  <style type='text/css'>
    #grid {
      display: grid;
    }
    #cell1 {
      grid-column: 1;
      grid-row: 1;
    }
    #cell2 {
      grid-column: 2;
      grid-row: 1;
    }
    #cell3 {
      grid-column: 1;
      grid-row: 2;
    }
    #cell4 {
      grid-column: 2;
      grid-row: 2;
    }
  </style>
  <div id="grid">
    <div id="cell1">cell1</div>
    <div id="cell2">cell2</div>
    <div id="cell3">cell3</div>
    <div id="cell4">cell4</div>
  </div>
`;

const HIGHLIGHTER_TYPE = "CssGridHighlighter";

add_task(async function () {
  const { inspector, highlighterTestFront } = await openInspectorForURL(
    "data:text/html;charset=utf-8," + encodeURIComponent(TEST_URL)
  );
  const front = inspector.inspectorFront;
  const highlighter = await front.getHighlighterByType(HIGHLIGHTER_TYPE);

  await isHiddenByDefault(highlighterTestFront, highlighter);
  await isVisibleWhenShown(highlighterTestFront, inspector, highlighter);

  await highlighter.finalize();
});

async function isHiddenByDefault(highlighterTestFront, highlighterFront) {
  info("Checking that the highlighter is hidden by default");

  const hidden = await highlighterTestFront.getHighlighterNodeAttribute(
    "css-grid-canvas",
    "hidden",
    highlighterFront
  );
  ok(hidden, "The highlighter is hidden by default");
}

async function isVisibleWhenShown(
  highlighterTestFront,
  inspector,
  highlighterFront
) {
  info("Asking to show the highlighter on the test node");

  const node = await getNodeFront("#grid", inspector);
  await highlighterFront.show(node);

  let hidden = await highlighterTestFront.getHighlighterNodeAttribute(
    "css-grid-canvas",
    "hidden",
    highlighterFront
  );
  ok(!hidden, "The highlighter is visible");

  info("Hiding the highlighter");
  await highlighterFront.hide();

  hidden = await highlighterTestFront.getHighlighterNodeAttribute(
    "css-grid-canvas",
    "hidden",
    highlighterFront
  );
  ok(hidden, "The highlighter is hidden");
}