2d.line.cap.round.worker.js (1844B)
1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. 2 // OffscreenCanvas test in a worker:2d.line.cap.round 3 // Description:lineCap 'round' is rendered correctly 4 // Note: 5 6 importScripts("/resources/testharness.js"); 7 importScripts("/html/canvas/resources/canvas-tests.js"); 8 9 var t = async_test("lineCap 'round' is rendered correctly"); 10 var t_pass = t.done.bind(t); 11 var t_fail = t.step_func(function(reason) { 12 throw reason; 13 }); 14 t.step(function() { 15 16 var canvas = new OffscreenCanvas(100, 50); 17 var ctx = canvas.getContext('2d'); 18 19 ctx.fillStyle = '#0f0'; 20 ctx.fillRect(0, 0, 100, 50); 21 22 var tol = 1; // tolerance to avoid antialiasing artifacts 23 24 ctx.lineCap = 'round'; 25 ctx.lineWidth = 20; 26 27 28 ctx.fillStyle = '#f00'; 29 ctx.strokeStyle = '#0f0'; 30 31 ctx.beginPath(); 32 ctx.moveTo(35-tol, 15); 33 ctx.arc(25, 15, 10-tol, 0, Math.PI, true); 34 ctx.arc(25, 35, 10-tol, Math.PI, 0, true); 35 ctx.fill(); 36 37 ctx.beginPath(); 38 ctx.moveTo(25, 15); 39 ctx.lineTo(25, 35); 40 ctx.stroke(); 41 42 43 ctx.fillStyle = '#0f0'; 44 ctx.strokeStyle = '#f00'; 45 46 ctx.beginPath(); 47 ctx.moveTo(75, 15); 48 ctx.lineTo(75, 35); 49 ctx.stroke(); 50 51 ctx.beginPath(); 52 ctx.moveTo(85+tol, 15); 53 ctx.arc(75, 15, 10+tol, 0, Math.PI, true); 54 ctx.arc(75, 35, 10+tol, Math.PI, 0, true); 55 ctx.fill(); 56 57 _assertPixel(canvas, 17,6, 0,255,0,255); 58 _assertPixel(canvas, 25,6, 0,255,0,255); 59 _assertPixel(canvas, 32,6, 0,255,0,255); 60 _assertPixel(canvas, 17,43, 0,255,0,255); 61 _assertPixel(canvas, 25,43, 0,255,0,255); 62 _assertPixel(canvas, 32,43, 0,255,0,255); 63 64 _assertPixel(canvas, 67,6, 0,255,0,255); 65 _assertPixel(canvas, 75,6, 0,255,0,255); 66 _assertPixel(canvas, 82,6, 0,255,0,255); 67 _assertPixel(canvas, 67,43, 0,255,0,255); 68 _assertPixel(canvas, 75,43, 0,255,0,255); 69 _assertPixel(canvas, 82,43, 0,255,0,255); 70 t.done(); 71 }); 72 done();