format-specifiers-variations.html (1927B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>CSS Test: Supported format specifiers should load</title> 5 <link rel="help" href="https://drafts.csswg.org/css-fonts-4/#src-desc"/> 6 <meta name="assert" content="Supported format specifiers should load"/> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 </head> 11 <body> 12 <script> 13 setup({ 14 explicit_done: true 15 }); 16 17 var formatSpecifiers = [ 18 "woff", 19 "truetype", 20 "opentype", 21 "woff2", 22 "woff-variations", 23 "truetype-variations", 24 "opentype-variations", 25 "woff2-variations" 26 ]; 27 28 var defaultAhemSrc = 'url("/fonts/Ahem.ttf") format("INSERT_FORMAT")'; 29 30 function runTestOnFormatSpecifiers(formats, expectFail) { 31 for (var i = 0; i < formats.length; ++i) { 32 promise_test((testDetails) => { 33 var familyName = "load_ahem_" + i; 34 var ahemSrcFormat = defaultAhemSrc.replace("INSERT_FORMAT", testDetails.properties.format); 35 var fontFace = new FontFace(familyName, ahemSrcFormat); 36 if (!expectFail) { 37 return fontFace.load(); 38 } else { 39 return promise_rejects_dom(testDetails, "SyntaxError", fontFace.load()); 40 } 41 }, (expectFail ? "Do not load" : "Load") + " Ahem with format " + formats[i], { 42 "format": formats[i] 43 }); 44 } 45 } 46 47 runTestOnFormatSpecifiers(formatSpecifiers, false); 48 runTestOnFormatSpecifiers(formatSpecifiers.map(x => "xyz" + x), true); 49 runTestOnFormatSpecifiers(formatSpecifiers.map(x => x + "xyz"), true); 50 runTestOnFormatSpecifiers(formatSpecifiers.map(x => x.slice(0, -2)), true); 51 runTestOnFormatSpecifiers(formatSpecifiers.map(x => x.slice(2)), true); 52 runTestOnFormatSpecifiers(formatSpecifiers.map(x => x.slice(0, x.length / 3) + x.slice(x.length / 3 + 1)), true); 53 54 done(); 55 </script> 56 </body> 57 </html>