summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-geometry_02.js
blob: e0681c6f9b531db765322e9b5450f233927eb9e3 (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
/* 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 geometry highlighter labels are correct.

const TEST_URL = `data:text/html;charset=utf-8,
                  <div id='positioned' style='
                    background:yellow;
                    position:absolute;
                    left:5rem;
                    top:30px;
                    right:300px;
                    bottom:10em;'></div>
                  <div id='positioned2' style='
                    background:blue;
                    position:absolute;
                    right:10%;
                    top:5vmin;'>test element</div>
                 <div id='relative' style='
                    background:green;
                    position:relative;
                    top:10px;
                    left:20px;
                    bottom:30px;
                    right:40px;
                    width:100px;
                    height:100px;'></div>
                 <div id='relative2' style='
                    background:grey;
                    position:relative;
                    top:0;bottom:-50px;
                    height:3em;'>relative</div>`;

const ID = "geometry-editor-";
const HIGHLIGHTER_TYPE = "GeometryEditorHighlighter";

const POSITIONED_ELEMENT_TESTS = [{
  selector: "#positioned",
  expectedLabels: [
    {side: "left", visible: true, label: "5rem"},
    {side: "top", visible: true, label: "30px"},
    {side: "right", visible: true, label: "300px"},
    {side: "bottom", visible: true, label: "10em"}
  ]
}, {
  selector: "#positioned2",
  expectedLabels: [
    {side: "left", visible: false},
    {side: "top", visible: true, label: "5vmin"},
    {side: "right", visible: true, label: "10%"},
    {side: "bottom", visible: false}
  ]
}, {
  selector: "#relative",
  expectedLabels: [
    {side: "left", visible: true, label: "20px"},
    {side: "top", visible: true, label: "10px"},
    {side: "right", visible: false},
    {side: "bottom", visible: false}
  ]
}, {
  selector: "#relative2",
  expectedLabels: [
    {side: "left", visible: false},
    {side: "top", visible: true, label: "0px"},
    {side: "right", visible: false},
    {side: "bottom", visible: false}
  ]
}];

add_task(function* () {
  let helper = yield openInspectorForURL(TEST_URL)
                       .then(getHighlighterHelperFor(HIGHLIGHTER_TYPE));

  helper.prefix = ID;

  let { finalize } = helper;

  yield positionLabelsAreCorrect(helper);

  yield finalize();
});

function* positionLabelsAreCorrect(
  {show, hide, isElementHidden, getElementTextContent}
) {
  info("Highlight nodes and check position labels");

  for (let {selector, expectedLabels} of POSITIONED_ELEMENT_TESTS) {
    info("Testing node " + selector);

    yield show(selector);

    for (let {side, visible, label} of expectedLabels) {
      let id = "label-" + side;

      let hidden = yield isElementHidden(id);
      if (visible) {
        ok(!hidden, "The " + side + " label is visible");

        let value = yield getElementTextContent(id);
        is(value, label, "The " + side + " label textcontent is correct");
      } else {
        ok(hidden, "The " + side + " label is hidden");
      }
    }

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