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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
<!DOCTYPE HTML>
<html>
<head>
<title>Test for CSS EOF handling</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p><a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=311616">bug 311616</a>,
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=325064">bug 325064</a></p>
<iframe id="display"></iframe>
<p id="log"></p>
<pre id="test">
<script class="testbody" type="text/javascript">
const tests = [
{
name: "basic rule",
ref: "#r {background-color : orange}",
tst: "#t {background-color : orange",
prop: "background-color", pseudo: ""
},
{
name: "function",
ref: "#r {background-color: rgb(0,255,0)}",
tst: "#t {background-color: rgb(0,255,0",
prop: "background-color", pseudo: ""
},
{
name: "comment",
ref: "#r {background-color: aqua/*marine*/}",
tst: "#t {background-color: aqua/*marine",
prop: "background-color", pseudo: ""
},
{
name: "@media 1",
ref: "@media all { #r { background-color: yellow } }",
tst: "@media all { #t { background-color: yellow }",
prop: "background-color", pseudo: ""
},
{
name: "@media 2",
ref: "@media all { #r { background-color: magenta } }",
tst: "@media all { #t { background-color: magenta",
prop: "background-color", pseudo: ""
},
{
name: "@import 1",
ref: "@import 'data:text/css,%23r%7Bbackground-color%3Agray%7D';",
tst: "@import 'data:text/css,%23t%7Bbackground-color%3Agray%7D",
prop: "background-color", pseudo: ""
},
{
name: "@import 2",
ref: "@import 'data:text/css,%23r%7Bbackground-color%3Ablack%7D' all;",
tst: "@import 'data:text/css,%23t%7Bbackground-color%3Ablack%7D' all",
prop: "background-color", pseudo: ""
},
{
name: "url-token 1",
ref: "#r { background-image: url(data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAADklEQVQI12NI" +
"YJgAhAkAB4gB4Ry+pcoAAAAASUVORK5CYII=) }",
tst: "#t { background-image: url(data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAADklEQVQI12NI" +
"YJgAhAkAB4gB4Ry+pcoAAAAASUVORK5CYII=",
prop: "background-image", pseudo: ""
},
{
name: "url-token 2",
ref: "#r { background-image: url('data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAAEElEQVQI12Mo" +
"YNjAcIHhAQAJ2ALR4kRk1gAAAABJRU5ErkJggg==') }",
tst: "#t { background-image: url('data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAAEElEQVQI12Mo" +
"YNjAcIHhAQAJ2ALR4kRk1gAAAABJRU5ErkJggg==",
prop: "background-image", pseudo: ""
},
{
name: "url-token 3",
ref: "#r { background-image: url('data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAAEElEQVQI12N4" +
"wHCBYQNDAQAMuALRrGb97AAAAABJRU5ErkJggg==') }",
tst: "#t { background-image: url('data:image/png;base64," +
"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAEAQAAAACBiqPTAAAAEElEQVQI12N4" +
"wHCBYQNDAQAMuALRrGb97AAAAABJRU5ErkJggg=='",
prop: "background-image", pseudo: ""
},
{
name: "url-token 4", /*Bug 751939*/
ref: "#r { background-image: url( )}",
tst: "#t { background-image: url(" ,
prop: "background-image", pseudo: ""
},
{
name: "counter",
ref: "#r::before { content: counter(tr, upper-alpha) }",
tst: "#t::before { content: counter(tr, upper-alpha",
prop: "content", pseudo: "::before"
},
{
name: "string",
ref: "#r::before { content: 'B' }",
tst: "#t::before { content: 'B",
prop: "content", pseudo: "::before"
},
/* For these tests, there is no visible effect on computed style;
instead we have to audit the DOM stylesheet object. */
{
todo: 1, /* bug 446226 */
name: "selector 1",
ref: "td[colspan='3'] {}",
tst: "td[colspan='3"
},
{
todo: 1, /* bug 446226 */
name: "selector 2",
ref: "td[colspan='3'] {}",
tst: "td[colspan='3'"
},
{
todo: 1, /* bug 446226 */
name: "selector 3",
ref: "td:lang(en) {}",
tst: "td:lang(en"
},
{
name: "@media 3",
ref: "@media all {}",
tst: "@media all {",
},
{
name: "@namespace 1a",
ref: "@namespace foo url('http://foo.example.com/');",
tst: "@namespace foo url('http://foo.example.com/')"
},
{
name: "@namespace 1b",
ref: "@namespace foo url(http://foo.example.com/);",
tst: "@namespace foo url(http://foo.example.com/"
},
{
name: "@namespace 1c",
ref: "@namespace foo url('http://foo.example.com/');",
tst: "@namespace foo url('http://foo.example.com/"
},
{
name: "@namespace 1d",
ref: "@namespace foo 'http://foo.example.com/';",
tst: "@namespace foo 'http://foo.example.com/'"
},
{
name: "@namespace 1e",
ref: "@namespace foo 'http://foo.example.com/';",
tst: "@namespace foo 'http://foo.example.com/"
},
{
name: "@namespace 2a",
ref: "@namespace url('http://foo.example.com/');",
tst: "@namespace url('http://foo.example.com/')"
},
{
name: "@namespace 2b",
ref: "@namespace url('http://foo.example.com/');",
tst: "@namespace url('http://foo.example.com/'"
},
{
name: "@namespace 2c",
ref: "@namespace url('http://foo.example.com/');",
tst: "@namespace url('http://foo.example.com/"
},
{
name: "@namespace 2d",
ref: "@namespace 'http://foo.example.com/';",
tst: "@namespace 'http://foo.example.com/'"
},
{
name: "@namespace 2e",
ref: "@namespace 'http://foo.example.com/';",
tst: "@namespace 'http://foo.example.com/"
}
];
const basestyle = ("table {\n"+
" border-collapse: collapse;\n"+
"}\n"+
"td {\n"+
" width: 1.5em;\n"+
" height: 1.5em;\n"+
" border: 1px solid black;\n"+
" text-align: center;\n"+
" margin: 0;\n"+
"}\n"+
"tr { counter-increment: tr }\n");
/* This is more complicated than it might look like it needs to be,
because for each subtest we have to splat stuff into the iframe,
allow the renderer to run, and only then interrogate the computed
styles. */
SimpleTest.waitForExplicitFinish();
window.onload = function() {
const frame = document.getElementById("display");
var curTest = 0;
const prepareTest = function() {
var cd = frame.contentDocument;
cd.open();
cd.write('<!DOCTYPE HTML><html><head>' +
'<style>\n' + basestyle + '</style>\n' +
'<style>\n' + tests[curTest].ref + '</style>\n' +
'<style>\n' + tests[curTest].tst + '</style>\n' +
'</head><body>\n' +
'<table><tr><td id="r"><td id="t"></table>' +
'</body></html>');
cd.close();
};
const checkTest = function() {
var cd = frame.contentDocument;
var _is = tests[curTest].todo ? todo_is : is;
var _ok = tests[curTest].todo ? todo : ok;
if (cd.styleSheets[1].cssRules.length == 1 &&
cd.styleSheets[2].cssRules.length == 1) {
// If we have a .prop for this test, the .cssText of the reference
// and test rules will differ in the selector. Change #t to #r
// in the test rule.
var ref_canon = cd.styleSheets[1].cssRules[0].cssText;
var tst_canon = cd.styleSheets[2].cssRules[0].cssText;
tst_canon = tst_canon.replace(/(#|%23)t\b/, "$1r");
_is(tst_canon, ref_canon,
tests[curTest].name + " (canonicalized rule)");
} else {
_ok(false, tests[curTest].name + " (rule missing)");
}
if (tests[curTest].prop) {
var prop = tests[curTest].prop;
var pseudo = tests[curTest].pseudo;
var refElt = cd.getElementById("r");
var tstElt = cd.getElementById("t");
var refStyle = cd.defaultView.getComputedStyle(refElt, pseudo);
var tstStyle = cd.defaultView.getComputedStyle(tstElt, pseudo);
_is(tstStyle.getPropertyValue(prop),
refStyle.getPropertyValue(prop),
tests[curTest].name + " (computed style)");
}
curTest++;
if (curTest < tests.length) {
prepareTest();
} else {
SimpleTest.finish();
}
};
frame.onload = function(){setTimeout(checkTest, 0);};
prepareTest();
};
</script>
</pre>
</body>
</html>
|