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
|
<!DOCTYPE html>
<title>Test for Bug 922669</title>
<script src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<iframe srcdoc="<!DOCTYPE html><style></style><div></div>"></iframe>
<script>
var gIsAndroid = navigator.appVersion.includes("Android");
var gTests = [
// Interact with the ::-moz-progress-bar.
{ markup: '<progress value="75" max="100"></progress>',
pseudoelement: '::-moz-progress-bar',
common_style: 'progress { -moz-appearance: none; } progress::-moz-progress-bar { background: black; }',
hover_test_style: 'progress::-moz-progress-bar:hover { background: green; }',
hover_reference_style: 'progress::-moz-progress-bar { background: green; }',
active_test_style: 'progress::-moz-progress-bar:active { background: lime; }',
active_reference_style: 'progress::-moz-progress-bar { background: lime; }' },
// Interact with the part of the <progress> not covered by the ::-moz-progress-bar.
{ markup: '<progress value="25" max="100"></progress>',
pseudoelement: '::-moz-progress-bar',
common_style: 'progress { -moz-appearance: none; } progress::-moz-progress-bar { background: black; }',
hover_test_style: 'progress::-moz-progress-bar { background: green; } progress::-moz-progress-bar:hover { background: red; }',
hover_reference_style: 'progress::-moz-progress-bar { background: green; }',
active_test_style: 'progress::-moz-progress-bar { background: lime; } progress::-moz-progress-bar:active { background: red; }',
active_reference_style: 'progress::-moz-progress-bar { background: lime; }' },
// Interact with the ::-moz-range-thumb.
{ markup: '<input type="range" value="50" min="0" max="100">',
pseudoelement: '::-moz-range-thumb',
common_style: 'input { -moz-appearance: none; } input::-moz-range-thumb { background: black; }',
hover_test_style: 'input::-moz-range-thumb:hover { background: green; }',
hover_reference_style: 'input::-moz-range-thumb { background: green; }',
active_test_style: 'input::-moz-range-thumb:active { background: lime; }',
active_reference_style: 'input::-moz-range-thumb { background: lime; }' },
// Interact with the part of the <input type="range"> not covered by the ::-moz-range-thumb.
{ markup: '<input type="range" value="25" min="0" max="100">',
pseudoelement: '::-moz-range-thumb',
common_style: 'input { -moz-appearance: none; } input::-moz-range-thumb { background: black; }',
hover_test_style: 'input::-moz-range-thumb { background: green; } input::-moz-range-thumb:hover { background: red; }',
hover_reference_style: 'input::-moz-range-thumb { background: green; }',
active_test_style: 'input::-moz-range-thumb { background: lime; } input::-moz-range-thumb:active { background: red; }',
active_reference_style: 'input::-moz-range-thumb { background: lime; }' },
// Interact with the ::-moz-meter-bar.
{ markup: '<meter value="75" min="0" max="100"></meter>',
pseudoelement: '::-moz-meter-bar',
common_style: 'meter { -moz-appearance: none; } meter::-moz-meter-bar { background: black; }',
hover_test_style: 'meter::-moz-meter-bar:hover { background: green; }',
hover_reference_style: 'meter::-moz-meter-bar { background: green; }',
active_test_style: 'meter::-moz-meter-bar:active { background: lime; }',
active_reference_style: 'meter::-moz-meter-bar { background: lime; }' },
// Interact with the part of the <meter> not covered by the ::-moz-meter-bar.
{ markup: '<meter value="25" min="0" max="100"></meter>',
pseudoelement: '::-moz-meter-bar',
common_style: 'meter { -moz-appearance: none; } meter::-moz-meter-bar { background: black; }',
hover_test_style: 'meter::-moz-meter-bar { background: green; } meter::-moz-meter-bar:hover { background: red; }',
hover_reference_style: 'meter::-moz-meter-bar { background: green; }',
active_test_style: 'meter::-moz-meter-bar { background: lime; } meter::-moz-meter-bar:active { background: red; }',
active_reference_style: 'meter::-moz-meter-bar { background: lime; }' },
// Do the same as the "Interact with the ::-moz-range-thumb" subtest above,
// but with selectors that include descendant operators.
{ markup: '<input type="range" value="50" min="0" max="100">',
pseudoelement: '::-moz-range-thumb',
common_style: 'body input { -moz-appearance: none; } input::-moz-range-thumb { background: black; }',
hover_test_style: 'body input::-moz-range-thumb:hover { background: green; }',
hover_reference_style: 'body input::-moz-range-thumb { background: green; }',
active_test_style: 'body input::-moz-range-thumb:active { background: lime; }',
active_reference_style: 'body input::-moz-range-thumb { background: lime; }' },
// Do the same as above, but using :is instead.
{ markup: '<input type="range" value="50" min="0" max="100">',
pseudoelement: '::-moz-range-thumb',
common_style: 'body input { -moz-appearance: none; } input::-moz-range-thumb { background: black; }',
hover_test_style: 'body input::-moz-range-thumb:is(:hover) { background: green; }',
hover_reference_style: 'body input::-moz-range-thumb { background: green; }',
active_test_style: 'body input::-moz-range-thumb:is(:active) { background: lime; }',
active_reference_style: 'body input::-moz-range-thumb { background: lime; }' },
// Do the same as above, but using :not instead.
{ markup: '<input type="range" value="50" min="0" max="100">',
pseudoelement: '::-moz-range-thumb',
common_style: 'input { -moz-appearance: none; } input::-moz-range-thumb { background: green } input::-moz-range-thumb:not(:hover) { background: black; }',
hover_test_style: '',
hover_reference_style: 'input::-moz-range-thumb { background: green !important; }',
active_test_style: 'input::-moz-range-thumb:active { background: lime !important; }',
active_reference_style: 'input::-moz-range-thumb { background: lime !important; }' },
// ::placeholder can't be tested, since the UA style sheet sets it to
// be pointer-events:none.
];
function countPixelDifferences(aCanvas1, aCanvas2) {
var ctx1 = aCanvas1.getContext("2d");
var ctx2 = aCanvas2.getContext("2d");
var data1 = ctx1.getImageData(0, 0, aCanvas1.width, aCanvas1.height);
var data2 = ctx2.getImageData(0, 0, aCanvas2.width, aCanvas2.height);
var n = 0;
for (var i = 0; i < data1.width * data2.height * 4; i += 4) {
if (data1.data[i] != data2.data[i] ||
data1.data[i + 1] != data2.data[i + 1] ||
data1.data[i + 2] != data2.data[i + 2] ||
data1.data[i + 3] != data2.data[i + 3]) {
n++;
}
}
return n;
}
function runTests() {
var iframe = document.querySelector("iframe");
var style = iframe.contentDocument.querySelector("style");
var div = iframe.contentDocument.querySelector("div");
var canvas1, canvas2;
function runTestPart1(aIndex) {
var test = gTests[aIndex];
div.innerHTML = test.markup;
style.textContent = test.common_style;
is(getComputedStyle(div.firstChild, test.pseudoelement).backgroundColor, "rgb(0, 0, 0)", "subtest #" + aIndex + ", computed style");
style.textContent += test.hover_test_style;
synthesizeMouseAtCenter(div.lastChild, { type: 'mouseover' }, iframe.contentWindow);
}
function runTestPart2(aIndex) {
var test = gTests[aIndex];
canvas1 = SpecialPowers.snapshotWindow(iframe.contentWindow, false);
style.textContent = test.common_style + test.hover_reference_style;
}
function runTestPart3(aIndex) {
var test = gTests[aIndex];
canvas2 = SpecialPowers.snapshotWindow(iframe.contentWindow, false);
ok(canvas1.width == canvas2.width && canvas1.height == canvas2.height, "hover subtest #" + aIndex + ", canvas sizes equal");
is(countPixelDifferences(canvas1, canvas2), 0, "hover subtest #" + aIndex + ", number of different pixels");
is(getComputedStyle(div.firstChild, test.pseudoelement).backgroundColor, "rgb(0, 128, 0)", "hover subtest #" + aIndex + ", computed style");
if (!gIsAndroid) {
style.textContent = test.common_style + test.active_test_style;
synthesizeMouseAtCenter(div.lastChild, { type: 'mousedown' }, iframe.contentWindow);
}
}
function runTestPart4(aIndex) {
if (!gIsAndroid) {
var test = gTests[aIndex];
canvas1 = SpecialPowers.snapshotWindow(iframe.contentWindow, false);
synthesizeMouseAtCenter(div.lastChild, { type: 'mouseup' }, iframe.contentWindow);
style.textContent = test.common_style + test.active_reference_style;
}
}
function runTestPart5(aIndex) {
if (!gIsAndroid) {
var test = gTests[aIndex];
canvas2 = SpecialPowers.snapshotWindow(iframe.contentWindow, false);
ok(canvas1.width == canvas2.width && canvas1.height == canvas2.height, "active subtest #" + aIndex + ", canvas sizes equal");
is(countPixelDifferences(canvas1, canvas2), 0, "active subtest #" + aIndex + ", number of different pixels");
is(getComputedStyle(div.firstChild, test.pseudoelement).backgroundColor, "rgb(0, 255, 0)", "active subtest #" + aIndex + ", computed style");
}
}
for (var i = 0; i < gTests.length; i++) {
setTimeout(runTestPart1, 0, i);
setTimeout(runTestPart2, 0, i);
setTimeout(runTestPart3, 0, i);
setTimeout(runTestPart4, 0, i);
setTimeout(runTestPart5, 0, i);
}
setTimeout(function() { SimpleTest.finish(); }, 0);
}
SimpleTest.waitForExplicitFinish();
window.addEventListener("load", async function() {
await SpecialPowers.contentTransformsReceived(window);
runTests();
});
</script>
|