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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests that the rule view's highlightProperty scrolls to the specified declaration.
const TEST_URI = `
<style type="text/css">
.test {
margin: 5px;
font-size: 12px;
border: 1px solid blue;
margin-top: 20px;
}
.test::after {
content: "!";
color: red;
}
</style>
<div class="test">Hello this is a test</div>
`;
add_task(async function () {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view } = await openRuleView();
await selectNode(".test", inspector);
const { rules, styleWindow } = view;
info(
"Highlight the computed border-left-width declaration in the rule view."
);
const borderLeftWidthStyle = rules[2].textProps[2].computed.find(
({ name }) => name === "border-left-width"
);
let onHighlightProperty = view.once("scrolled-to-element");
let isHighlighted = view.highlightProperty("border-left-width");
await onHighlightProperty;
ok(isHighlighted, "border-left-property is highlighted.");
ok(
isInViewport(borderLeftWidthStyle.element, styleWindow),
"border-left-width is in view."
);
info("Highlight the font-size declaration in the rule view.");
const fontSize = rules[2].textProps[1].editor;
info("Wait for the view to scroll to the property.");
onHighlightProperty = view.once("scrolled-to-element");
isHighlighted = view.highlightProperty("font-size");
await onHighlightProperty;
ok(isHighlighted, "font-size property is highlighted.");
ok(isInViewport(fontSize.element, styleWindow), "font-size is in view.");
info("Highlight the pseudo-element's color declaration in the rule view.");
const color = rules[0].textProps[1].editor;
info("Wait for the view to scroll to the property.");
onHighlightProperty = view.once("scrolled-to-element");
isHighlighted = view.highlightProperty("color");
await onHighlightProperty;
ok(isHighlighted, "color property is highlighted.");
ok(isInViewport(color.element, styleWindow), "color property is in view.");
info("Highlight margin-top declaration in the rules view.");
const marginTop = rules[2].textProps[3].editor;
info("Wait for the view to scroll to the property.");
onHighlightProperty = view.once("scrolled-to-element");
isHighlighted = view.highlightProperty("margin-top");
await onHighlightProperty;
ok(isHighlighted, "margin-top property is highlighted.");
ok(
isInViewport(marginTop.element, styleWindow),
"margin-top property is in view."
);
});
function isInViewport(element, win) {
const { top, left, bottom, right } = element.getBoundingClientRect();
return (
top >= 0 &&
bottom <= win.innerHeight &&
left >= 0 &&
right <= win.innerWidth
);
}
|