tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

font-face-src-list.html (2394B)


      1 <!DOCTYPE html>
      2 <title>CSS Fonts 4 test: parsing the src descriptor list</title>
      3 <meta name="assert" content="A parse error in one component of the source list does not invalidate the entire descriptor">
      4 <link rel="help" href="https://drafts.csswg.org/css-fonts/#font-face-src-parsing">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <style id="testStyle">
      8 </style>
      9 <script>
     10  const sheet = testStyle.sheet;
     11  tests = [
     12    // A component with a parse error does not invalidate the entire descriptor
     13    // if there's some other valid component present.
     14    { src: 'local(inherit), url(foo.ttf)', valid: true },
     15    { src: 'local("myfont"), local(unset)', valid: true },
     16    { src: 'local(), url(foo.ttf)', valid: true },
     17    { src: 'local(12px monospace), url(foo.ttf)', valid: true },
     18    { src: 'local("myfont") format(opentype), url(foo.ttf)', valid: true },
     19    { src: 'url(not a valid url/bar.ttf), url(foo.ttf)', valid: true },
     20    { src: 'url(foo.ttf) format(bad), url(foo.ttf)', valid: true },
     21    { src: 'url(foo.ttf) tech(unknown), url(foo.ttf)', valid: true },
     22    { src: 'url(foo.ttf) tech(color-COLRv0) otherfunc(othervalue), url(foo.ttf)', valid: true },
     23    { src: 'url(foo.ttf), url(something.ttf) format(broken)', valid: true },
     24    { src: '/* an empty component */, url(foo.ttf)', valid: true },
     25    { src: 'local(""), url(foo.ttf), unparseable-garbage, local("another font name")', valid: true },
     26    // But if all components are bad, the descriptor is invalid.
     27    { src: 'local(), local(initial)', valid: false },
     28    { src: 'local("textfont") format(opentype), local("emoji") tech(color-COLRv0)', valid: false },
     29    { src: 'local(), /*empty*/, url(should be quoted.ttf), junk', valid: false },
     30    { src: 'url(foo.ttf) format(unknown), url(bar.ttf) tech(broken)', valid: false },
     31    { src: 'url(foo.ttf) tech(color-COLRv0) otherfunc(othervalue), junk', valid: false },
     32  ];
     33 
     34  for (let t of tests) {
     35    test(() => {
     36      assert_equals(sheet.cssRules.length, 0, "testSheet should initially be empty");
     37      sheet.insertRule("@font-face { src: " + t.src + "}");
     38      try {
     39        assert_equals(sheet.cssRules[0].style.getPropertyValue("src") != "", t.valid);
     40      } finally {
     41        sheet.deleteRule(0);
     42      }
     43    }, "Check that src: " + t.src + " is " + (t.valid ? "valid" : "invalid"));
     44  }
     45 </script>