tor-browser

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

font-face-src-format.html (3922B)


      1 <!DOCTYPE html>
      2 <title>CSS Fonts 4 test: parsing the format() function in the src descriptor</title>
      3 <link rel="help" href="https://drafts.csswg.org/css-fonts/#font-face-src-parsing">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <style id="testStyle">
      7 </style>
      8 <script>
      9  const sheet = testStyle.sheet;
     10  tests = [
     11    // No format() function
     12    { src: 'url("foo.ttf")', valid: true },
     13    { src: 'url("foo.ttf"), url("bar.ttf")', valid: true },
     14    // Empty format() is not valid
     15    { src: 'url("foo.ttf") format()', valid: false },
     16    // Garbage data instead of format() is not valid
     17    { src: 'url("foo.ttf") dummy()', valid: false },
     18    // Garbage data following valid format() is not valid
     19    { src: 'url("foo.ttf") format("woff") dummy()', valid: false },
     20    // Garbage data preceding valid format() is not valid
     21    { src: 'url("foo.ttf") dummy() format("woff")', valid: false },
     22    // Quoted strings in format()
     23    { src: 'url("foo.ttf") format("collection")', valid: true },
     24    { src: 'url("foo.ttf") format("opentype")', valid: true },
     25    { src: 'url("foo.ttf") format("truetype")', valid: true },
     26    { src: 'url("foo.ttf") format("woff")', valid: true },
     27    { src: 'url("foo.ttf") format("woff2")', valid: true },
     28    // Multiple strings (was valid in CSS Fonts 3, but not allowed in Fonts 4)
     29    { src: 'url("foo.ttf") format("opentype", "truetype")', valid: false },
     30    // Keywords (new in Fonts 4)
     31    { src: 'url("foo.ttf") format(collection)', valid: true },
     32    { src: 'url("foo.ttf") format(opentype)', valid: true },
     33    { src: 'url("foo.ttf") format(truetype)', valid: true },
     34    { src: 'url("foo.ttf") format(woff)', valid: true },
     35    { src: 'url("foo.ttf") format(woff2)', valid: true },
     36    // Multiple keywords are not accepted
     37    { src: 'url("foo.ttf") format(opentype, truetype)', valid: false },
     38    { src: 'url("foo.ttf") format(opentype truetype)', valid: false },
     39    // Invalid format keywords should be a parse error
     40    { src: 'url("foo.ttf") format(auto)', valid: false },
     41    { src: 'url("foo.ttf") format(default)', valid: false },
     42    { src: 'url("foo.ttf") format(inherit)', valid: false },
     43    { src: 'url("foo.ttf") format(initial)', valid: false },
     44    { src: 'url("foo.ttf") format(none)', valid: false },
     45    { src: 'url("foo.ttf") format(normal)', valid: false },
     46    { src: 'url("foo.ttf") format(xyzzy)', valid: false },
     47    // Unknown format string still matches the grammar, although it won't be
     48    // loaded. UAs may choose to either not load it, or not add unsupported
     49    // entries to the list, ensure that subsequent component of the list are
     50    // still recognized.
     51    { src: 'url("foo.ttf") format("embedded-opentype"), url("bar.html")', valid: true },
     52    { src: 'url("foo.ttf") format(embedded-opentype), url("bar.html")', valid: true },
     53    { src: 'url("foo.ttf") format("svg"), url("bar.html")', valid: true },
     54    { src: 'url("foo.ttf") format(svg), url("bar.html")', valid: true },
     55    // A parsing error in one component does not make the entire descriptor invalid.
     56    { src: 'url("foo.ttf") format(xyzz 200px), url("bar.html")', valid: true },
     57    { src: 'url("foo.ttf") format(xyzz), url("bar.html")', valid: true },
     58    { src: 'url("foo.ttf") dummy(xyzzy), url("bar.html")', valid: true },
     59    { src: 'url("foo.ttf") format(), url("bar.html")', valid: true },
     60    { src: 'url("foo.ttf") format(none), url("bar.html")', valid: true },
     61  ];
     62 
     63  for (let t of tests) {
     64    test(() => {
     65      assert_equals(sheet.cssRules.length, 0, "testSheet should initially be empty");
     66      sheet.insertRule("@font-face { src: " + t.src + "}");
     67      try {
     68        assert_equals(sheet.cssRules[0].style.getPropertyValue("src") != "", t.valid);
     69      } finally {
     70        sheet.deleteRule(0);
     71      }
     72    }, "Check that src: " + t.src + " is " + (t.valid ? "valid" : "invalid"));
     73  }
     74 </script>