summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-geometry_05.js
blob: 649a4be3be3f0eb364b06fd032745c3c8beb66a7 (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
/* 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(function* () {
  let helper = yield openInspectorForURL(TEST_URL)
                       .then(getHighlighterHelperFor(HIGHLIGHTER_TYPE));

  helper.prefix = ID;

  let { hide, finalize } = helper;

  for (let data of TEST_DATA) {
    yield testNode(helper, data);
  }

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

function* testNode(helper, data) {
  let { selector } = data;
  yield helper.show(data.selector);

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

function* isOffsetParentVisible({isElementHidden}) {
  return !(yield isElementHidden("offset-parent"));
}

function* isCurrentNodeVisible({isElementHidden}) {
  return !(yield isElementHidden("current-node"));
}

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