canvas.2d.offscreen.worker.direction.html (1694B)
1 <!doctype HTML> 2 <html class="reftest-wait"> 3 <meta charset="utf-8"> 4 <title>HTML5 Canvas Test: The direction attribute is respected in offscreen worker canvas</title> 5 <link rel="match" href="canvas.2d.offscreen.worker.direction-ref.html" /> 6 <link rel="author" href="mailto:schenney@chromium.org"/> 7 <link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/> 8 <meta name="assert" content="An offscreen canvas in a worker respects the direction text attribute." /> 9 <script src="/common/reftest-wait.js"></script> 10 <script type="text/javascript"> 11 function runTest() { 12 const placeholder_canvas = document.createElement('canvas'); 13 placeholder_canvas.setAttribute('width', '300'); 14 placeholder_canvas.setAttribute('height', '150'); 15 const offscreen = placeholder_canvas.transferControlToOffscreen(); 16 17 const worker = new Worker('text-direction-worker.js'); 18 worker.postMessage({canvas: offscreen}, [offscreen]); 19 20 const canvas = document.getElementById('canvas1'); 21 const ctx = canvas.getContext('2d', {willReadFrequently: true}); 22 function checkResult() { 23 // Wait until frame propagates. 24 ctx.drawImage(placeholder_canvas, 0, 0); 25 const pixel = ctx.getImageData(0, 0, 1, 1).data; 26 27 if (pixel[3] == 0) { 28 // Result not available, wait longer. 29 requestAnimationFrame(checkResult); 30 } else { 31 takeScreenshot(); 32 } 33 } 34 requestAnimationFrame(checkResult); 35 } 36 </script> 37 <body onload="runTest()"> 38 <canvas id="canvas1" width="300" height="150"> 39 Browser does not support HTML5 Canvas. 40 </canvas> 41 </body> 42 </html>