fontface-override-descriptor-getter-setter.sub.html (8033B)
1 <!DOCTYPE html> 2 <title>Tests getters and setters of the font metrics override descriptors of FontFace</title> 3 <link rel="author" href="mailto:xiaochengh@chromium.org"> 4 <link rel="help" href="https://drafts.csswg.org/css-font-loading/#fontface-interface"> 5 <link rel="help" href="https://drafts.csswg.org/css-fonts-4/#font-metrics-override-desc"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script> 9 function rejection(promise) { 10 return new Promise((resolve, reject) => promise.then(reject, resolve)); 11 } 12 13 // ascentOverride 14 15 test(() => { 16 const face = new FontFace( 17 'ascent-override-initial', 18 'url(https://{{host}}/font.woff)'); 19 assert_equals(face.ascentOverride, 'normal'); 20 }, "Initial value of ascentOverride should be 'normal'"); 21 22 test(() => { 23 const face = new FontFace( 24 'ascent-override-initialize-with-normal', 25 'url(https://{{host}}/font.woff)', 26 {ascentOverride: 'normal'}); 27 assert_equals(face.ascentOverride, 'normal'); 28 }, "Initialize ascentOverride with 'normal' should succeed"); 29 30 test(() => { 31 const face = new FontFace( 32 'ascent-override-initialize-with-percentage', 33 'url(https://{{host}}/font.woff)', 34 {ascentOverride: '50%'}); 35 assert_equals(face.ascentOverride, '50%'); 36 }, "Initialize ascentOverride with a percentage should succeed"); 37 38 promise_test(async () => { 39 const face = new FontFace( 40 'ascent-override-initialize-with-negative-percentage', 41 'url(https://{{host}}/font.woff)', 42 {ascentOverride: '-50%'}); 43 const error = await rejection(face.load()); 44 assert_equals('error', face.status); 45 assert_throws_dom('SyntaxError', () => {throw error}); 46 }, "Initialize ascentOverride with a negative percentage should fail"); 47 48 promise_test(async () => { 49 const face = new FontFace( 50 'ascent-override-initialize-with-non-percentage', 51 'url(https://{{host}}/font.woff)', 52 {ascentOverride: '10px'}); 53 const error = await rejection(face.load()); 54 assert_equals('error', face.status); 55 assert_throws_dom('SyntaxError', () => {throw error}); 56 }, "Initialize ascentOverride with a non-percentage should fail"); 57 58 test(() => { 59 const face = new FontFace( 60 'ascent-override-normal-to-percentage', 61 'url(https://{{host}}/font.woff)', 62 {ascentOverride: 'normal'}); 63 face.ascentOverride = '50%'; 64 assert_equals(face.ascentOverride, '50%'); 65 }, "Changing ascentOverride from 'normal' to percentage should succeed"); 66 67 test(() => { 68 const face = new FontFace( 69 'ascent-override-percentage-to-normal', 70 'url(https://{{host}}/font.woff)', 71 {ascentOverride: '50%'}); 72 face.ascentOverride = 'normal'; 73 assert_equals(face.ascentOverride, 'normal'); 74 }, "Changing ascentOverride from percentage to 'normal' should succeed"); 75 76 test(() => { 77 const face = new FontFace( 78 'ascent-override-set-to-invalid', 79 'url(https://{{host}}/font.woff)'); 80 assert_throws_dom('SyntaxError', () => {face.ascentOverride = '10px'}); 81 }, "Changing ascentOverride to invalid value should fail"); 82 83 // descentOverride 84 85 test(() => { 86 const face = new FontFace( 87 'descent-override-initial', 88 'url(https://{{host}}/font.woff)'); 89 assert_equals(face.descentOverride, 'normal'); 90 }, "Initial value of descentOverride should be 'normal'"); 91 92 test(() => { 93 const face = new FontFace( 94 'descent-override-initialize-with-normal', 95 'url(https://{{host}}/font.woff)', 96 {descentOverride: 'normal'}); 97 assert_equals(face.descentOverride, 'normal'); 98 }, "Initialize descentOverride with 'normal' should succeed"); 99 100 test(() => { 101 const face = new FontFace( 102 'descent-override-initialize-with-percentage', 103 'url(https://{{host}}/font.woff)', 104 {descentOverride: '50%'}); 105 assert_equals(face.descentOverride, '50%'); 106 }, "Initialize descentOverride with a percentage should succeed"); 107 108 promise_test(async () => { 109 const face = new FontFace( 110 'descent-override-initialize-with-negative-percentage', 111 'url(https://{{host}}/font.woff)', 112 {descentOverride: '-50%'}); 113 const error = await rejection(face.load()); 114 assert_equals('error', face.status); 115 assert_throws_dom('SyntaxError', () => {throw error}); 116 }, "Initialize descentOverride with a negative percentage should fail"); 117 118 promise_test(async () => { 119 const face = new FontFace( 120 'descent-override-initialize-with-non-percentage', 121 'url(https://{{host}}/font.woff)', 122 {descentOverride: '10px'}); 123 const error = await rejection(face.load()); 124 assert_equals('error', face.status); 125 assert_throws_dom('SyntaxError', () => {throw error}); 126 }, "Initialize descentOverride with a non-percentage should fail"); 127 128 test(() => { 129 const face = new FontFace( 130 'descent-override-normal-to-percentage', 131 'url(https://{{host}}/font.woff)', 132 {descentOverride: 'normal'}); 133 face.descentOverride = '50%'; 134 assert_equals(face.descentOverride, '50%'); 135 }, "Changing descentOverride from 'normal' to percentage should succeed"); 136 137 test(() => { 138 const face = new FontFace( 139 'descent-override-percentage-to-normal', 140 'url(https://{{host}}/font.woff)', 141 {descentOverride: '50%'}); 142 face.descentOverride = 'normal'; 143 assert_equals(face.descentOverride, 'normal'); 144 }, "Changing descentOverride from percentage to 'normal' should succeed"); 145 146 test(() => { 147 const face = new FontFace( 148 'descent-override-set-to-invalid', 149 'url(https://{{host}}/font.woff)'); 150 assert_throws_dom('SyntaxError', () => {face.descentOverride = '10px'}); 151 }, "Changing descentOverride to invalid value should fail"); 152 153 // lineGapOverride 154 155 test(() => { 156 const face = new FontFace( 157 'lineGap-override-initial', 158 'url(https://{{host}}/font.woff)'); 159 assert_equals(face.lineGapOverride, 'normal'); 160 }, "Initial value of lineGapOverride should be 'normal'"); 161 162 test(() => { 163 const face = new FontFace( 164 'lineGap-override-initialize-with-normal', 165 'url(https://{{host}}/font.woff)', 166 {lineGapOverride: 'normal'}); 167 assert_equals(face.lineGapOverride, 'normal'); 168 }, "Initialize lineGapOverride with 'normal' should succeed"); 169 170 test(() => { 171 const face = new FontFace( 172 'lineGap-override-initialize-with-percentage', 173 'url(https://{{host}}/font.woff)', 174 {lineGapOverride: '50%'}); 175 assert_equals(face.lineGapOverride, '50%'); 176 }, "Initialize lineGapOverride with a percentage should succeed"); 177 178 promise_test(async () => { 179 const face = new FontFace( 180 'lineGap-override-initialize-with-negative-percentage', 181 'url(https://{{host}}/font.woff)', 182 {lineGapOverride: '-50%'}); 183 const error = await rejection(face.load()); 184 assert_equals('error', face.status); 185 assert_throws_dom('SyntaxError', () => {throw error}); 186 }, "Initialize lineGapOverride with a negative percentage should fail"); 187 188 promise_test(async () => { 189 const face = new FontFace( 190 'lineGap-override-initialize-with-non-percentage', 191 'url(https://{{host}}/font.woff)', 192 {lineGapOverride: '10px'}); 193 const error = await rejection(face.load()); 194 assert_equals('error', face.status); 195 assert_throws_dom('SyntaxError', () => {throw error}); 196 }, "Initialize lineGapOverride with a non-percentage should fail"); 197 198 test(() => { 199 const face = new FontFace( 200 'lineGap-override-normal-to-percentage', 201 'url(https://{{host}}/font.woff)', 202 {lineGapOverride: 'normal'}); 203 face.lineGapOverride = '50%'; 204 assert_equals(face.lineGapOverride, '50%'); 205 }, "Changing lineGapOverride from 'normal' to percentage should succeed"); 206 207 test(() => { 208 const face = new FontFace( 209 'lineGap-override-percentage-to-normal', 210 'url(https://{{host}}/font.woff)', 211 {lineGapOverride: '50%'}); 212 face.lineGapOverride = 'normal'; 213 assert_equals(face.lineGapOverride, 'normal'); 214 }, "Changing lineGapOverride from percentage to 'normal' should succeed"); 215 216 test(() => { 217 const face = new FontFace( 218 'lineGap-override-set-to-invalid', 219 'url(https://{{host}}/font.woff)'); 220 assert_throws_dom('SyntaxError', () => {face.lineGapOverride = '10px'}); 221 }, "Changing lineGapOverride to invalid value should fail"); 222 </script>