summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-geometry_05.js
blob: 7b68fd1042ed33fb4503377df1b0f39c37796479 (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
/* 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/. */

/* Globals defined in: devtools/client/inspector/test/head.js */

"use strict";

// Test that the arrows/handlers and offsetparent and currentnode elements of
// the geometry highlighter only appear when needed.

const TEST_URL = URL_ROOT + "doc_inspector_highlighter-geometry_02.html";
const ID = "geometry-editor-";
const HIGHLIGHTER_TYPE = "GeometryEditorHighlighter";

const TEST_DATA = [
  {
    selector: "body",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: false,
    hasVisibleArrowsAndHandlers: false,
  },
  {
    selector: "h1",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: false,
    hasVisibleArrowsAndHandlers: false,
  },
  {
    selector: ".absolute",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
  {
    selector: "#absolute-container",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: false,
  },
  {
    selector: ".absolute-bottom-right",
    isOffsetParentVisible: true,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
  {
    selector: ".absolute-width-margin",
    isOffsetParentVisible: true,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
  {
    selector: ".absolute-all-4",
    isOffsetParentVisible: true,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
  {
    selector: ".relative",
    isOffsetParentVisible: true,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
  {
    selector: ".static",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: false,
    hasVisibleArrowsAndHandlers: false,
  },
  {
    selector: ".static-size",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: false,
  },
  {
    selector: ".fixed",
    isOffsetParentVisible: false,
    isCurrentNodeVisible: true,
    hasVisibleArrowsAndHandlers: true,
  },
];

add_task(async function () {
  const helper = await openInspectorForURL(TEST_URL).then(
    getHighlighterHelperFor(HIGHLIGHTER_TYPE)
  );

  helper.prefix = ID;

  const { hide, finalize } = helper;

  for (const data of TEST_DATA) {
    await testNode(helper, data);
  }

  info("Hiding the highlighter");
  await hide();
  await finalize();
});

async function testNode(helper, data) {
  const { selector } = data;
  await helper.show(data.selector);

  is(
    await isOffsetParentVisible(helper),
    data.isOffsetParentVisible,
    "The offset-parent highlighter visibility is correct for node " + selector
  );
  is(
    await isCurrentNodeVisible(helper),
    data.isCurrentNodeVisible,
    "The current-node highlighter visibility is correct for node " + selector
  );
  is(
    await hasVisibleArrowsAndHandlers(helper),
    data.hasVisibleArrowsAndHandlers,
    "The arrows visibility is correct for node " + selector
  );
}

async function isOffsetParentVisible({ isElementHidden }) {
  return !(await isElementHidden("offset-parent"));
}

async function isCurrentNodeVisible({ isElementHidden }) {
  return !(await isElementHidden("current-node"));
}

async function hasVisibleArrowsAndHandlers({ isElementHidden }) {
  for (const side of ["top", "left", "bottom", "right"]) {
    const hidden = await isElementHidden("arrow-" + side);
    if (!hidden) {
      return !(await isElementHidden("handler-" + side));
    }
  }
  return false;
}