Bug 1784058 - Add WPT test for @font-face format() parsing issues. r=emilio

I notice there's a lack of test coverage here, so before making changes I'd like to
add a simple set of tests so that we can see the effect of the upcoming fix.

Differential Revision: https://phabricator.services.mozilla.com/D154234
This commit is contained in:
Jonathan Kew 2022-08-11 13:10:01 +00:00
Родитель 4a3e629847
Коммит 481afa5a20
2 изменённых файлов: 83 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,24 @@
[font-face-src-format.html]
[Check that src: url("foo.ttf") format("opentype", "truetype") is invalid]
expected: FAIL
[Check that src: url("foo.ttf") format(collection) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(embedded-opentype) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(opentype) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(svg) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(truetype) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(woff) is valid]
expected: FAIL
[Check that src: url("foo.ttf") format(woff2) is valid]
expected: FAIL

Просмотреть файл

@ -0,0 +1,59 @@
<!DOCTYPE html>
<title>CSS Fonts 4 test: parsing the format() function in the src descriptor</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-face-src-parsing">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style id="testStyle">
</style>
<script>
const sheet = testStyle.sheet;
tests = [
// No format() function
{ src: 'url("foo.ttf")', valid: true },
// Empty format() is not valid
{ src: 'url("foo.ttf") format()', valid: false },
// Quoted strings in format()
{ src: 'url("foo.ttf") format("collection")', valid: true },
{ src: 'url("foo.ttf") format("embedded-opentype")', valid: true },
{ src: 'url("foo.ttf") format("opentype")', valid: true },
{ src: 'url("foo.ttf") format("svg")', valid: true },
{ src: 'url("foo.ttf") format("truetype")', valid: true },
{ src: 'url("foo.ttf") format("woff")', valid: true },
{ src: 'url("foo.ttf") format("woff2")', valid: true },
// Multiple strings (was valid in CSS Fonts 3, but not allowed in Fonts 4)
{ src: 'url("foo.ttf") format("opentype", "truetype")', valid: false },
// Unknown format string still matches the grammar, although it won't be loaded
{ src: 'url("foo.ttf") format("xyzzy")', valid: true },
// Keywords (new in Fonts 4)
{ src: 'url("foo.ttf") format(collection)', valid: true },
{ src: 'url("foo.ttf") format(embedded-opentype)', valid: true },
{ src: 'url("foo.ttf") format(opentype)', valid: true },
{ src: 'url("foo.ttf") format(svg)', valid: true },
{ src: 'url("foo.ttf") format(truetype)', valid: true },
{ src: 'url("foo.ttf") format(woff)', valid: true },
{ src: 'url("foo.ttf") format(woff2)', valid: true },
// Multiple keywords are not accepted
{ src: 'url("foo.ttf") format(opentype, truetype)', valid: false },
{ src: 'url("foo.ttf") format(opentype truetype)', valid: false },
// Invalid format keywords should be a parse error
{ src: 'url("foo.ttf") format(auto)', valid: false },
{ src: 'url("foo.ttf") format(default)', valid: false },
{ src: 'url("foo.ttf") format(inherit)', valid: false },
{ src: 'url("foo.ttf") format(initial)', valid: false },
{ src: 'url("foo.ttf") format(none)', valid: false },
{ src: 'url("foo.ttf") format(normal)', valid: false },
{ src: 'url("foo.ttf") format(xyzzy)', valid: false },
];
for (let t of tests) {
test(() => {
assert_equals(sheet.cssRules.length, 0, "testSheet should initially be empty");
sheet.insertRule("@font-face { src: " + t.src + "}");
try {
assert_equals(sheet.cssRules[0].style.getPropertyValue("src") != "", t.valid);
} finally {
sheet.deleteRule(0);
}
}, "Check that src: " + t.src + " is " + (t.valid ? "valid" : "invalid"));
}
</script>