File: font-face-src-list.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (45 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download | duplicates (12)
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
<!DOCTYPE html>
<title>CSS Fonts 4 test: parsing the src descriptor list</title>
<meta name="assert" content="A parse error in one component of the source list does not invalidate the entire descriptor">
<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 = [
    // A component with a parse error does not invalidate the entire descriptor
    // if there's some other valid component present.
    { src: 'local(inherit), url(foo.ttf)', valid: true },
    { src: 'local("myfont"), local(unset)', valid: true },
    { src: 'local(), url(foo.ttf)', valid: true },
    { src: 'local(12px monospace), url(foo.ttf)', valid: true },
    { src: 'local("myfont") format(opentype), url(foo.ttf)', valid: true },
    { src: 'url(not a valid url/bar.ttf), url(foo.ttf)', valid: true },
    { src: 'url(foo.ttf) format(bad), url(foo.ttf)', valid: true },
    { src: 'url(foo.ttf) tech(unknown), url(foo.ttf)', valid: true },
    { src: 'url(foo.ttf) tech(color-COLRv0) otherfunc(othervalue), url(foo.ttf)', valid: true },
    { src: 'url(foo.ttf), url(something.ttf) format(broken)', valid: true },
    { src: '/* an empty component */, url(foo.ttf)', valid: true },
    { src: 'local(""), url(foo.ttf), unparseable-garbage, local("another font name")', valid: true },
    // But if all components are bad, the descriptor is invalid.
    { src: 'local(), local(initial)', valid: false },
    { src: 'local("textfont") format(opentype), local("emoji") tech(color-COLRv0)', valid: false },
    { src: 'local(), /*empty*/, url(should be quoted.ttf), junk', valid: false },
    { src: 'url(foo.ttf) format(unknown), url(bar.ttf) tech(broken)', valid: false },
    { src: 'url(foo.ttf) tech(color-COLRv0) otherfunc(othervalue), junk', 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>