font-parse-numeric-stretch-style-weight.html (4171B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 </head> 8 <body> 9 <script> 10 setup({explicit_done : true}); 11 12 var styleValidTests = { 13 'weight': [ 14 'bold', 15 '700', 16 '900', 17 '850', 18 '850.3', 19 'calc(100 + 300)', 20 'calc(0.2 + 205.5)', 21 'calc(0 - 100)', 22 'calc(200 + 801)', 23 ], 24 'stretch': ['51%', '199%', 'calc(10% + 20%)', '0%'], 25 'style' : [ 'normal', 'italic', 'oblique', 'oblique 50deg', 'oblique -90deg', 'oblique 90deg', 26 'oblique calc(90deg + 20deg)', 'oblique calc(30deg + 20deg)' ] 27 }; 28 29 var styleInvalidTests = { 30 'weight': ['100 400'], 31 'stretch': ['100% 110%', '100% 150%', 'calc(1 + 10%)'], 32 'style' : [ 'normal 10deg', 'italic 10deg', 'oblique -91deg', 'oblique 91deg' ] 33 }; 34 35 function testParseStyle() { 36 for (validStyleTestCategory of Object.keys(styleValidTests)) { 37 for (validStyleTest of styleValidTests[validStyleTestCategory]) { 38 test( 39 function() { 40 assert_true( 41 CSS.supports('font-' + validStyleTestCategory, validStyleTest)); 42 }, 43 'Valid value ' + validStyleTest + ' for font property ' + 44 validStyleTestCategory + ' used for styling.') 45 } 46 } 47 for (invalidStyleTestCategory of Object.keys(styleInvalidTests)) { 48 for (invalidStyleTest of styleInvalidTests[invalidStyleTestCategory]) { 49 test( 50 function() { 51 assert_false(CSS.supports( 52 'font-' + invalidStyleTestCategory, invalidStyleTest)); 53 }, 54 'Invalid value ' + invalidStyleTest + ' for font property ' + 55 invalidStyleTestCategory + ' used for styling.') 56 } 57 } 58 } 59 60 var faceTests = { 61 'weight': [ 62 ['100', '100'], ['700', '700'], ['900', '900'], ['bold', 'bold'], 63 ['normal', 'normal'], ['100 400', '100 400'], ['100 101.5', '100 101.5'], 64 ['999.8 999.9', '999.8 999.9'], 65 [ '500 400', '500 400'] 66 ], 67 'stretch': [ 68 ['0%', '0%'], 69 ['calc(0% - 10%)', 'calc(-10%)' ], 70 ['100%', '100%'], 71 ['110%', '110%'], 72 ['111.5%', '111.5%'], 73 [ "50% 200%", "50% 200%" ], 74 [ "0.1% 1%", "0.1% 1%" ], 75 [ "900% 901%", "900% 901%" ], 76 ['ultra-condensed', 'ultra-condensed'], 77 ['ultra-expanded', 'ultra-expanded'], 78 ], 79 'style' : [ 80 [ "normal", "normal" ], 81 [ "italic", "italic" ], 82 [ "oblique", "oblique" ], 83 [ "oblique 10deg", "oblique 10deg" ], 84 [ "oblique 10deg 20deg", "oblique 10deg 20deg" ] 85 ] 86 }; 87 88 var faceInvalidTests = { 89 'weight': [ 90 '0', 91 '0.9', 92 '-100 200', 93 '100 -200', 94 '100 1001', 95 '1001', 96 '1000.5', 97 '100 200 300', 98 'a', 99 'a b c', 100 ], 101 'stretch': [ 102 '-0.5%', '-1%', '60% 70% 80%', 'a%', 'a b c', '0.1', 103 '-60% 80%', 'ultra-expannnned', '50% 0' 104 ], 105 'style' : [ 'oblique 100deg', 'oblique italic', 'oblique -91deg', 'oblique 0', 106 'oblique 10', 'iiitalic', '90deg', '11', 'italic 90deg' ] 107 }; 108 109 function testParseFace() { 110 for (var theProperty of Object.keys(faceTests)) { 111 for (var faceTest of faceTests[theProperty]) { 112 test( 113 () => { 114 var fontFace = new FontFace('testfont', 'url()'); 115 assert_equals(fontFace[theProperty], 'normal'); 116 fontFace[theProperty] = faceTest[0]; 117 assert_equals(fontFace[theProperty], faceTest[1]); 118 }, 119 'Valid value ' + faceTest[0] + ' matches ' + faceTest[1] + ' for ' + 120 theProperty + ' in @font-face.'); 121 } 122 } 123 124 for (var theProperty of Object.keys(faceInvalidTests)) { 125 for (var faceTest of faceInvalidTests[theProperty]) { 126 test( 127 () => { 128 var fontFace = new FontFace('testfont', 'url()'); 129 assert_throws_dom('SyntaxError', () => { 130 fontFace[theProperty] = faceTest; 131 }, 'Value must not be accepted as weight value.'); 132 }, 133 'Value ' + faceTest + ' must not be accepted as ' + theProperty + 134 ' in @font-face.') 135 } 136 } 137 } 138 139 window.addEventListener('load', function() { 140 testParseStyle(); 141 testParseFace(); 142 done(); 143 }); 144 </script> 145 </body> 146 </html>