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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
<!DOCTYPE HTML><html>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=441469 -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test of @font-face parser</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>
<p>@font-face parsing (<a
target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=441469"
>bug 441469</a>)</p>
<pre id="display"></pre>
<style type="text/css" id="testbox"></style>
<script class="testbody" type="text/javascript">
function runTest() {
function _(b) { return "@font-face { " + b + " }"; };
var testset = [
// Complete nonsense - shouldn't make a font-face rule at all.
{ rule: "@font-face;" },
{ rule: "font-face { }" },
{ rule: "@fontface { }" },
{ rule: "@namespace foo url(http://example.com/foo);" },
// Empty rule.
{ rule: "@font-face { }", d: {} },
{ rule: "@font-face {", d: {} },
{ rule: "@font-face { ; }", d: {}, noncanonical: true },
// Correct font-family.
{ rule: _("font-family: \"Mouse\";"), d: {"font-family" : "\"Mouse\""} },
{ rule: _("font-family: \"Mouse\""), d: {"font-family" : "\"Mouse\""},
noncanonical: true },
{ rule: _("font-family: Mouse;"), d: {"font-family" : "Mouse" },
noncanonical: true },
{ rule: _("font-family: Mouse"), d: {"font-family" : "Mouse" },
noncanonical: true },
// Correct but unusual font-family.
{ rule: _("font-family: Hoefler Text;"),
d: {"font-family" : "Hoefler Text"},
noncanonical: true },
// Incorrect font-family.
{ rule: _("font-family:"), d: {} },
{ rule: _("font-family \"Mouse\""), d: {} },
{ rule: _("font-family: *"), d: {} },
{ rule: _("font-family: Mouse, Rat"), d: {} },
{ rule: _("font-family: sans-serif"), d: {} },
// Correct font-style.
{ rule: _("font-style: normal;"), d: {"font-style" : "normal"} },
{ rule: _("font-style: italic;"), d: {"font-style" : "italic"} },
{ rule: _("font-style: oblique;"), d: {"font-style" : "oblique"} },
// Correct font-weight.
{ rule: _("font-weight: 100;"), d: {"font-weight" : "100"} },
{ rule: _("font-weight: 200;"), d: {"font-weight" : "200"} },
{ rule: _("font-weight: 300;"), d: {"font-weight" : "300"} },
{ rule: _("font-weight: 400;"), d: {"font-weight" : "400"} },
{ rule: _("font-weight: 500;"), d: {"font-weight" : "500"} },
{ rule: _("font-weight: 600;"), d: {"font-weight" : "600"} },
{ rule: _("font-weight: 700;"), d: {"font-weight" : "700"} },
{ rule: _("font-weight: 800;"), d: {"font-weight" : "800"} },
{ rule: _("font-weight: 900;"), d: {"font-weight" : "900"} },
{ rule: _("font-weight: normal;"), d: {"font-weight" : "normal"} },
{ rule: _("font-weight: bold;"), d: {"font-weight" : "bold"} },
// Incorrect font-weight.
{ rule: _("font-weight: bolder;"), d: {} },
{ rule: _("font-weight: lighter;"), d: {} },
// Correct font-stretch.
{ rule: _("font-stretch: ultra-condensed;"),
d: {"font-stretch" : "ultra-condensed"} },
{ rule: _("font-stretch: extra-condensed;"),
d: {"font-stretch" : "extra-condensed"} },
{ rule: _("font-stretch: condensed;"),
d: {"font-stretch" : "condensed"} },
{ rule: _("font-stretch: semi-condensed;"),
d: {"font-stretch" : "semi-condensed"} },
{ rule: _("font-stretch: normal;"),
d: {"font-stretch" : "normal"} },
{ rule: _("font-stretch: semi-expanded;"),
d: {"font-stretch" : "semi-expanded"} },
{ rule: _("font-stretch: expanded;"),
d: {"font-stretch" : "expanded"} },
{ rule: _("font-stretch: extra-expanded;"),
d: {"font-stretch" : "extra-expanded"} },
{ rule: _("font-stretch: ultra-expanded;"),
d: {"font-stretch" : "ultra-expanded"} },
// Incorrect font-stretch.
{ rule: _("font-stretch: wider;"), d: {} },
{ rule: _("font-stretch: narrower;"), d: {} },
// Correct src:
{ rule: _("src: url(\"/fonts/Mouse\");"),
d: { "src" : "url(\"/fonts/Mouse\")" } },
{ rule: _("src: url(/fonts/Mouse);"),
d: { "src" : "url(\"/fonts/Mouse\")" }, noncanonical: true },
{ rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\");"),
d: { "src" : "url(\"/fonts/Mouse\") format(\"truetype\")" } },
{ rule: _("src: url(\"/fonts/Mouse\"), url(\"/fonts/Rat\");"),
d: { "src" : "url(\"/fonts/Mouse\"), url(\"/fonts/Rat\")" } },
{ rule: _("src: local(Mouse), url(\"/fonts/Mouse\");"),
d: { "src" : "local(Mouse), url(\"/fonts/Mouse\")" },
noncanonical: true },
{ rule: _("src: local(\"老鼠\"), url(\"/fonts/Mouse\");"),
d: { "src" : "local(\"老鼠\"), url(\"/fonts/Mouse\")" } },
{ rule: _("src: local(\"老鼠\"), url(\"/fonts/Mouse\") format(\"truetype\");"),
d: { "src" : "local(\"老鼠\"), url(\"/fonts/Mouse\") format(\"truetype\")" } },
{ rule: _("src: url(\"/fonts/Mouse\") format(truetype);"),
d: { "src" : "url(\"/fonts/Mouse\") format(truetype)" } },
// Correct but unusual src:
{ rule: _("src: local(Hoefler Text);"),
d: {"src" : "local(Hoefler Text)"}, noncanonical: true },
// Incorrect src:
{ rule: _("src:"), d: {} },
{ rule: _("src: \"/fonts/Mouse\";"), d: {} },
{ rule: _("src: /fonts/Mouse;"), d: {} },
{ rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\",opentype);"), d: {} },
{ rule: _("src: local(*);"), d: {} },
{ rule: _("src: format(\"truetype\");"), d: {} },
{ rule: _("src: local(Mouse) format(\"truetype\");"), d: {} },
{ rule: _("src: local(Mouse, Rat);"), d: {} },
{ rule: _("src: local(sans-serif);"), d: {} },
{ rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\", \"opentype\");"), d: {} },
// Repeated descriptors
{ rule: _("font-weight: 700; font-weight: 200;"),
d: {"font-weight" : "200"},
noncanonical: true },
{ rule: _("src: url(\"/fonts/Cat\"); src: url(\"/fonts/Mouse\");"),
d: { "src" : "url(\"/fonts/Mouse\")" },
noncanonical: true },
{ rule: _("src: local(Cat); src: local(Mouse)"),
d: { "src" : "local(Mouse)" },
noncanonical: true },
// Correct parenthesis matching for local()
{ rule: _("src: local(Mouse); src: local(Cat(); src: local(Rat); )"),
d: { "src" : "local(Mouse)" },
noncanonical: true },
{ rule: _("src: local(Mouse); src: local(\"Cat\"; src: local(Rat); )"),
d: { "src" : "local(Mouse)" },
noncanonical: true },
// Correct parenthesis matching for format()
{ rule: _("src: url(\"/fonts/Mouse\"); " +
"src: url(\"/fonts/Cat\") format(Cat(); src: local(Rat); )"),
d: { "src" : "url(\"/fonts/Mouse\")" },
noncanonical: true },
{ rule: _("src: url(\"/fonts/Mouse\"); " +
"src: url(\"/fonts/Cat\") format(\"Cat\"; src: local(Rat); )"),
d: { "src" : "url(\"/fonts/Mouse\")" },
noncanonical: true },
{ rule: _("src: url(\"/fonts/Mouse\"); " +
"src: url(\"/fonts/Cat\") format((); src: local(Rat); )"),
d: { "src" : "url(\"/fonts/Mouse\")" },
noncanonical: true },
// Correct unicode-range:
{ rule: _("unicode-range: U+A5;"), d: { "unicode-range" : "U+A5" } },
{ rule: _("unicode-range: U+00A5;"),
d: { "unicode-range" : "U+A5" }, noncanonical: true },
{ rule: _("unicode-range: U+00a5;"),
d: { "unicode-range" : "U+A5" }, noncanonical: true },
{ rule: _("unicode-range: u+00a5;"),
d: { "unicode-range" : "U+A5" }, noncanonical: true },
{ rule: _("unicode-range: U+0-FF;"),
d: { "unicode-range" : "U+0-FF" } },
{ rule: _("unicode-range: U+00??;"),
d: { "unicode-range" : "U+0-FF" }, noncanonical: true },
{ rule: _("unicode-range: U+?"),
d: { "unicode-range" : "U+0-F" }, noncanonical: true },
{ rule: _("unicode-range: U+590-5ff;"),
d: { "unicode-range" : "U+590-5FF" }, noncanonical: true },
{ rule: _("unicode-range: U+A5, U+4E00-9FFF, U+30??, U+FF00-FF9F;"),
d: { "unicode-range" : "U+A5, U+4E00-9FFF, U+3000-30FF, U+FF00-FF9F" },
noncanonical: true },
{ rule: _("unicode-range: U+104??;"),
d: { "unicode-range" : "U+10400-104FF" }, noncanonical: true },
{ rule: _("unicode-range: U+320??, U+321??, U+322??, U+323??, U+324??, U+325??;"),
d: { "unicode-range" : "U+32000-320FF, U+32100-321FF, U+32200-322FF, U+32300-323FF, U+32400-324FF, U+32500-325FF" },
noncanonical: true },
{ rule: _("unicode-range: U+100000-10ABCD;"),
d: { "unicode-range" : "U+100000-10ABCD" } },
{ rule: _("unicode-range: U+0121 , U+1023"),
d: { "unicode-range" : "U+121, U+1023" }, noncanonical: true },
{ rule: _("unicode-range: U+0121/**/, U+1023"),
d: { "unicode-range" : "U+121, U+1023" }, noncanonical: true },
// Incorrect unicode-range:
{ rule: _("unicode-range:"), d: {} },
{ rule: _("unicode-range: U+"), d: {} },
{ rule: _("unicode-range: U+8FFFFFFF"), d: {} },
{ rule: _("unicode-range: U+8FFF-7000"), d: {} },
{ rule: _("unicode-range: U+8F??-9000"), d: {} },
{ rule: _("unicode-range: U+9000-9???"), d: {} },
{ rule: _("unicode-range: U+??00"), d: {} },
{ rule: _("unicode-range: U+12345678?"), d: {} },
{ rule: _("unicode-range: U+1????????"), d: {} },
{ rule: _("unicode-range: twelve"), d: {} },
{ rule: _("unicode-range: 1000"), d: {} },
{ rule: _("unicode-range: 13??"), d: {} },
{ rule: _("unicode-range: 1300-1377"), d: {} },
{ rule: _("unicode-range: U-1000"), d: {} },
{ rule: _("unicode-range: U+nnnn"), d: {} },
{ rule: _("unicode-range: U+0121 U+1023"), d: {} },
{ rule: _("unicode-range: U+ 0121"), d: {} },
{ rule: _("unicode-range: U +0121"), d: {} },
{ rule: _("unicode-range: U+0121-"), d: {} },
{ rule: _("unicode-range: U+0121- 1023"), d: {} },
{ rule: _("unicode-range: U+0121 -1023"), d: {} },
{ rule: _("unicode-range: U+012 ?"), d: {} },
{ rule: _("unicode-range: U+01 2?"), d: {} },
{ rule: _("unicode-range: U+A0000-12FFFF"), d: {} },
{ rule: _("unicode-range: U+??????"), d: {} },
// Thorough test of seven-digit rejection: all these are syntax errors
{ rule: _("unicode-range: U+1034560, U+A5"), d: {} },
{ rule: _("unicode-range: U+1034569, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456a, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456f, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456?, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456-1034560, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456-1034569, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456-103456a, U+A5"), d: {} },
{ rule: _("unicode-range: U+103456-103456f, U+A5"), d: {} },
// Syntactically invalid unicode-range tokens invalidate the
// entire descriptor
{ rule: _("unicode-range: U+1, U+2, U+X"), d: {} },
{ rule: _("unicode-range: U+A5, U+0?F"), d: {} },
{ rule: _("unicode-range: U+A5, U+0F?-E00"), d: {} },
// Descending ranges and ranges outside 0-10FFFF are invalid
{ rule: _("unicode-range: U+A5, U+90-30"), d: {} },
{ rule: _("unicode-range: U+A5, U+220043"), d: {} },
// font-feature-settings
{ rule: _("font-feature-settings: normal;"),
d: { "font-feature-settings" : "normal" } },
{ rule: _("font-feature-settings: \"dlig\";"),
d: { "font-feature-settings" : "\"dlig\"" } },
{ rule: _("font-feature-settings: \"dlig\" 1;"),
d: { "font-feature-settings" : "\"dlig\"" }, noncanonical: true },
{ rule: _("font-feature-settings: 'dlig' 1"),
d: { "font-feature-settings" : "\"dlig\"" }, noncanonical: true },
// incorrect font-feature-settings
{ rule: _("font-feature-settings: dlig 1"), d: {} },
{ rule: _("font-feature-settings: none;"), d: {} },
{ rule: _("font-feature-settings: 0;"), d: {} },
{ rule: _("font-feature-settings: 3.14;"), d: {} },
{ rule: _("font-feature-settings: 'blah' 3.14;"), d: {} },
{ rule: _("font-feature-settings: 'dlig' 1 'hist' 0;"), d: {} },
{ rule: _("font-feature-settings: 'dlig=1,hist=1'"), d: {} },
// font-language-override:
{ rule: _("font-language-override: normal;"),
d: { "font-language-override" : "normal" } },
{ rule: _("font-language-override: \"TRK\";"),
d: { "font-language-override" : "\"TRK\"" } },
{ rule: _("font-language-override: 'TRK'"),
d: { "font-language-override" : "\"TRK\"" }, noncanonical: true },
// incorrect font-language-override
{ rule: _("font-language-override: TRK"), d: {} },
{ rule: _("font-language-override: none;"), d: {} },
{ rule: _("font-language-override: 0;"), d: {} },
{ rule: _("font-language-override: #999;"), d: {} },
{ rule: _("font-language-override: 'TRK' 'SRB'"), d: {} },
{ rule: _("font-language-override: 'TRK', 'SRB'"), d: {} },
// font-display:
{ rule: _("font-display: auto;"),
d: { "font-display" : "auto" } },
{ rule: _("font-display: block;"),
d: { "font-display" : "block" } },
{ rule: _("font-display: swap;"),
d: { "font-display" : "swap" } },
{ rule: _("font-display: fallback;"),
d: { "font-display" : "fallback" } },
{ rule: _("font-display: optional;"),
d: { "font-display" : "optional" } },
// incorrect font-display
{ rule: _("font-display: hidden"), d: {} },
{ rule: _("font-display: swap 3"), d: {} },
{ rule: _("font-display: block 2 swap 0"), d: {} },
{ rule: _("font-display: all"), d: {} },
];
var display = document.getElementById("display");
var sheet = document.styleSheets[1];
for (var curTest = 0; curTest < testset.length; curTest++) {
try {
while(sheet.cssRules.length > 0)
sheet.deleteRule(0);
sheet.insertRule(testset[curTest].rule, 0);
} catch (e) {
ok(
e.name == "SyntaxError"
&& e instanceof DOMException
&& e.code == DOMException.SYNTAX_ERR
&& !('d' in testset[curTest]),
testset[curTest].rule + " syntax error thrown - " + e
);
}
try {
if (testset[curTest].d) {
is(sheet.cssRules.length, 1,
testset[curTest].rule + " rule count");
is(sheet.cssRules[0].type, 5 /*FONT_FACE_RULE*/,
testset[curTest].rule + " rule type");
var d = testset[curTest].d;
var s = sheet.cssRules[0].style;
var n = 0;
is(s.getPropertyValue("pointless"), "", "Unknown descriptors don't assert");
// everything is set that should be
for (var name in d) {
is(s.getPropertyValue(name), d[name],
testset[curTest].rule + " (prop " + name + ")");
n++;
}
// nothing else is set
is(s.length, n, testset[curTest].rule + "prop count");
for (var i = 0; i < s.length; i++) {
ok(
s[i] in d,
testset[curTest].rule +
" - Unexpected item #" + i + ": " + s[i]
);
}
// round-tripping of cssText
// this is a strong test; it's okay if the exact serialization
// changes in the future
if (n && !testset[curTest].noncanonical) {
is(sheet.cssRules[0].cssText.replace(/[ \n]+/g, " "),
testset[curTest].rule,
testset[curTest].rule + " rule text");
}
} else {
if (sheet.cssRules.length == 0) {
is(sheet.cssRules.length, 0,
testset[curTest].rule + " rule count (0)");
} else {
is(sheet.cssRules.length, 1,
testset[curTest].rule + " rule count (1 non-fontface)");
isnot(sheet.cssRules[0].type, 5 /*FONT_FACE_RULE*/,
testset[curTest].rule + " rule type (1 non-fontface)");
}
}
} catch (e) {
ok(false, testset[curTest].rule + " - During test: " + e);
}
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
runTest();
</script>
</body>
</html>
|