2d.text.measure.actualBoundingBox.whitespace.worker.js (1771B)
1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. 2 // OffscreenCanvas test in a worker:2d.text.measure.actualBoundingBox.whitespace 3 // Description:Testing actualBoundingBox with leading/trailing whitespace 4 // Note: 5 6 importScripts("/resources/testharness.js"); 7 importScripts("/html/canvas/resources/canvas-tests.js"); 8 9 promise_test(async t => { 10 var canvas = new OffscreenCanvas(100, 50); 11 var ctx = canvas.getContext('2d'); 12 13 var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')"); 14 f.load(); 15 self.fonts.add(f); 16 await self.fonts.ready; 17 ctx.font = '50px CanvasTest'; 18 ctx.direction = 'ltr'; 19 ctx.align = 'left' 20 ctx.baseline = 'alphabetic' 21 // Different platforms may render text slightly different. 22 // Values that are nominally expected to be zero might actually vary by a 23 // pixel or so if the UA accounts for antialiasing at glyph edges, so we 24 // allow a slight deviation. 25 var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000]; 26 for (var codepoint of whitespaces) { 27 let whitespace = String.fromCharCode(codepoint); 28 29 _assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1"); 30 _assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50"); 31 32 _assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49"); 33 _assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101"); 34 } 35 }, "Testing actualBoundingBox with leading/trailing whitespace"); 36 done();