summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-rulers_02.js
blob: 44bd1514b3ece04bfc3675f5b421f99ba59fde90 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* 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 geometry highlighter elements.

const TEST_URL =
  "data:text/html;charset=utf-8," +
  "<div style='position:absolute;left: 0; top: 0; " +
  "width: 40000px; height: 8000px'></div>";

const ID = "rulers-highlighter-";

add_task(async function () {
  const { inspector, highlighterTestFront } = await openInspectorForURL(
    TEST_URL
  );
  const front = inspector.inspectorFront;

  const highlighter = await front.getHighlighterByType("RulersHighlighter");

  // the rulers doesn't need any node, but as highligher it seems mandatory
  // ones, so the body is given
  const body = await getNodeFront("body", inspector);
  await highlighter.show(body);

  await isUpdatedAfterScroll(highlighter, inspector, highlighterTestFront);

  await highlighter.finalize();
});

async function isUpdatedAfterScroll(
  highlighterFront,
  inspector,
  highlighterTestFront
) {
  info("Check the rulers' position by default");

  let xAxisRulerTransform =
    await highlighterTestFront.getHighlighterNodeAttribute(
      `${ID}x-axis-ruler`,
      "transform",
      highlighterFront
    );
  let xAxisTextTransform =
    await highlighterTestFront.getHighlighterNodeAttribute(
      `${ID}x-axis-text`,
      "transform",
      highlighterFront
    );
  let yAxisRulerTransform =
    await highlighterTestFront.getHighlighterNodeAttribute(
      `${ID}y-axis-ruler`,
      "transform",
      highlighterFront
    );
  let yAxisTextTransform =
    await highlighterTestFront.getHighlighterNodeAttribute(
      `${ID}y-axis-text`,
      "transform",
      highlighterFront
    );

  is(xAxisRulerTransform, null, "x axis ruler is positioned properly");
  is(xAxisTextTransform, null, "x axis text are positioned properly");
  is(yAxisRulerTransform, null, "y axis ruler is positioned properly");
  is(yAxisTextTransform, null, "y axis text are positioned properly");

  info("Ask the content window to scroll to specific coords");

  const x = 200,
    y = 300;

  let data = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [x, y],
    (_x, _y) => {
      return new Promise(resolve => {
        content.addEventListener(
          "scroll",
          () => resolve({ x: content.scrollX, y: content.scrollY }),
          { once: true }
        );
        content.scrollTo(_x, _y);
      });
    }
  );

  is(data.x, x, "window scrolled properly horizontally");
  is(data.y, y, "window scrolled properly vertically");

  info("Check the rulers are properly positioned after the scrolling");

  xAxisRulerTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}x-axis-ruler`,
    "transform",
    highlighterFront
  );
  xAxisTextTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}x-axis-text`,
    "transform",
    highlighterFront
  );
  yAxisRulerTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}y-axis-ruler`,
    "transform",
    highlighterFront
  );
  yAxisTextTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}y-axis-text`,
    "transform",
    highlighterFront
  );

  is(
    xAxisRulerTransform,
    `translate(-${x})`,
    "x axis ruler is positioned properly"
  );
  is(
    xAxisTextTransform,
    `translate(-${x})`,
    "x axis text are positioned properly"
  );
  is(
    yAxisRulerTransform,
    `translate(0, -${y})`,
    "y axis ruler is positioned properly"
  );
  is(
    yAxisTextTransform,
    `translate(0, -${y})`,
    "y axis text are positioned properly"
  );

  info("Ask the content window to scroll relative to the current position");

  data = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [-50, -60],
    (_deltaX, _deltaY) => {
      return new Promise(resolve => {
        content.addEventListener(
          "scroll",
          () => resolve({ x: content.scrollX, y: content.scrollY }),
          { once: true }
        );
        content.scrollBy(_deltaX, _deltaY);
      });
    }
  );

  is(data.x, x - 50, "window scrolled properly horizontally");
  is(data.y, y - 60, "window scrolled properly vertically");

  info("Check the rulers are properly positioned after the relative scrolling");

  xAxisRulerTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}x-axis-ruler`,
    "transform",
    highlighterFront
  );
  xAxisTextTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}x-axis-text`,
    "transform",
    highlighterFront
  );
  yAxisRulerTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}y-axis-ruler`,
    "transform",
    highlighterFront
  );
  yAxisTextTransform = await highlighterTestFront.getHighlighterNodeAttribute(
    `${ID}y-axis-text`,
    "transform",
    highlighterFront
  );

  is(
    xAxisRulerTransform,
    `translate(-${x - 50})`,
    "x axis ruler is positioned properly"
  );
  is(
    xAxisTextTransform,
    `translate(-${x - 50})`,
    "x axis text are positioned properly"
  );
  is(
    yAxisRulerTransform,
    `translate(0, -${y - 60})`,
    "y axis ruler is positioned properly"
  );
  is(
    yAxisTextTransform,
    `translate(0, -${y - 60})`,
    "y axis text are positioned properly"
  );
}