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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that the rule and computed views refresh when style changes that impact the
// current selection occur.
// This test does not need to worry about the correctness of the styles and rules
// displayed in these views (other tests do this) but only cares that they do catch the
// change.
const TEST_URI = TEST_URL_ROOT + "doc_content_style_changes.html";
const TEST_DATA = [
{
target: "#test",
className: "green-class",
force: true,
},
{
target: "#test",
className: "green-class",
force: false,
},
{
target: "#parent",
className: "purple-class",
force: true,
},
{
target: "#parent",
className: "purple-class",
force: false,
},
{
target: "#sibling",
className: "blue-class",
force: true,
},
{
target: "#sibling",
className: "blue-class",
force: false,
},
];
add_task(async function () {
const tab = await addTab(TEST_URI);
const { inspector } = await openRuleView();
await selectNode("#test", inspector);
info("Run the test on the rule-view");
await runViewTest(inspector, tab, "rule");
info("Switch to the computed view");
const onComputedViewReady = inspector.once("computed-view-refreshed");
selectComputedView(inspector);
await onComputedViewReady;
info("Run the test again on the computed view");
await runViewTest(inspector, tab, "computed");
});
async function runViewTest(inspector, tab, viewName) {
for (const { target, className, force } of TEST_DATA) {
info(
(force ? "Adding" : "Removing") +
` class ${className} on ${target} and expecting a ${viewName}-view refresh`
);
await toggleClassAndWaitForViewChange(
{ target, className, force },
inspector,
tab,
`${viewName}-view-refreshed`
);
}
}
async function toggleClassAndWaitForViewChange(
whatToMutate,
inspector,
tab,
eventName
) {
const onRefreshed = inspector.once(eventName);
await SpecialPowers.spawn(
tab.linkedBrowser,
[whatToMutate],
function ({ target, className, force }) {
content.document.querySelector(target).classList.toggle(className, force);
}
);
await onRefreshed;
ok(true, "The view was refreshed after the class was changed");
}
|