gecko/layout/style/test/test_font_face_parser.html

207 lines
8.1 KiB
HTML

<!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 type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" 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 _(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\") format(\"truetype\", \"opentype\");"),
d: { "src" : "url(\"/fonts/Mouse\") format(\"truetype\", \"opentype\")" } },
{ 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\")" } },
// Correct but unusual src:
{ rule: _("src: local(Hoefler Text);"),
d: {"src" : "local(\"Hoefler Text\")"}, noncanonical: true },
// Incorrect src:
{ rule: _("src: \"/fonts/Mouse\";"), d: {} },
{ rule: _("src: /fonts/Mouse;"), d: {} },
{ rule: _("src: url(\"/fonts/Mouse\") format(truetype);"), 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: {} }
// unicode-range is not implemented (bug 443976).
// tests for that omitted for now.
];
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 if e instanceof DOMException) {
ok(e.code == DOMException.SYNTAX_ERR
&& !('d' in testset[curTest]),
testset[curTest].rule + " syntax error thrown", e);
} catch (e) {
ok(false, testset[curTest].rule, "During prep: " + 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;
// 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);
}
}
</script>
</body>
</html>