summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-cssshape_02.js
blob: 1cb72c7b4d8c0d225c138f5026824d2cd40171e7 (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
/* 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";

// Make sure that the CSS shapes highlighters have the correct attributes.

const TEST_URL = URL_ROOT + "doc_inspector_highlighter_cssshapes.html";
const HIGHLIGHTER_TYPE = "ShapesHighlighter";

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

  await polygonHasCorrectAttrs(highlighterTestFront, inspector, highlighter);
  await circleHasCorrectAttrs(highlighterTestFront, inspector, highlighter);
  await ellipseHasCorrectAttrs(highlighterTestFront, inspector, highlighter);
  await insetHasCorrectAttrs(highlighterTestFront, inspector, highlighter);

  await highlighter.finalize();
});

async function polygonHasCorrectAttrs(
  highlighterTestFront,
  inspector,
  highlighterFront
) {
  info("Checking polygon highlighter has correct points");

  const polygonNode = await getNodeFront("#polygon", inspector);
  await highlighterFront.show(polygonNode, { mode: "cssClipPath" });

  const points = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-polygon",
    "points",
    highlighterFront
  );
  const realPoints =
    "0,0 12.5,50 25,0 37.5,50 50,0 62.5,50 " +
    "75,0 87.5,50 100,0 90,100 50,60 10,100";
  is(points, realPoints, "Polygon highlighter has correct points");
}

async function circleHasCorrectAttrs(
  highlighterTestFront,
  inspector,
  highlighterFront
) {
  info("Checking circle highlighter has correct attributes");

  const circleNode = await getNodeFront("#circle", inspector);
  await highlighterFront.show(circleNode, { mode: "cssClipPath" });

  const rx = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "rx",
    highlighterFront
  );
  const ry = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "ry",
    highlighterFront
  );
  const cx = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "cx",
    highlighterFront
  );
  const cy = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "cy",
    highlighterFront
  );

  is(rx, "25", "Circle highlighter has correct rx");
  is(ry, "25", "Circle highlighter has correct ry");
  is(cx, "30", "Circle highlighter has correct cx");
  is(cy, "40", "Circle highlighter has correct cy");
}

async function ellipseHasCorrectAttrs(
  highlighterTestFront,
  inspector,
  highlighterFront
) {
  info("Checking ellipse highlighter has correct attributes");

  const ellipseNode = await getNodeFront("#ellipse", inspector);
  await highlighterFront.show(ellipseNode, { mode: "cssClipPath" });

  const rx = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "rx",
    highlighterFront
  );
  const ry = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "ry",
    highlighterFront
  );
  const cx = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "cx",
    highlighterFront
  );
  const cy = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-ellipse",
    "cy",
    highlighterFront
  );

  is(rx, "40", "Ellipse highlighter has correct rx");
  is(ry, "30", "Ellipse highlighter has correct ry");
  is(cx, "25", "Ellipse highlighter has correct cx");
  is(cy, "30", "Ellipse highlighter has correct cy");
}

async function insetHasCorrectAttrs(
  highlighterTestFront,
  inspector,
  highlighterFront
) {
  info("Checking rect highlighter has correct attributes");

  const insetNode = await getNodeFront("#inset", inspector);
  await highlighterFront.show(insetNode, { mode: "cssClipPath" });

  const x = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-rect",
    "x",
    highlighterFront
  );
  const y = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-rect",
    "y",
    highlighterFront
  );
  const width = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-rect",
    "width",
    highlighterFront
  );
  const height = await highlighterTestFront.getHighlighterNodeAttribute(
    "shapes-rect",
    "height",
    highlighterFront
  );

  is(x, "15", "Rect highlighter has correct x");
  is(y, "25", "Rect highlighter has correct y");
  is(width, "72.5", "Rect highlighter has correct width");
  is(height, "45", "Rect highlighter has correct height");
}