Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <script src="../../resources/testharness.js"></script> | |
| 2 <script src="../../resources/testharnessreport.js"></script> | |
| 3 <script> | |
| 4 test(function() { | |
| 5 function assertPixelApprox(ctx, x, y, r, g, b, a, pos, colour, tolerance) { | |
| 6 var imgdata = ctx.getImageData(x, y, 1, 1); | |
| 7 var diff = Math.max(Math.abs(r-imgdata.data[0]), Math.abs(g-imgdata.data [1]), Math.abs(b-imgdata.data[2]), Math.abs(a-imgdata.data[3])); | |
| 8 assert_less_than_equal(diff, tolerance); | |
| 9 } | |
| 10 var offscreenCanvas = new OffscreenCanvas(100, 100); | |
| 11 var ctx = offscreenCanvas.getContext('2d'); | |
| 12 ctx.fillStyle = '#0f0'; | |
| 13 ctx.fillRect(0, 0, 100, 100); | |
| 14 ctx.globalAlpha = 0.01; // avoid any potential alpha = 0 optimisations. | |
|
xlai (Olivia)
2016/11/23 17:26:43
Could you use a more obvious number like 0.2, 0.7
| |
| 15 ctx.beginPath(); | |
| 16 ctx.fillStyle = '#f00'; | |
| 17 ctx.rect(0, 0, 100, 100); | |
| 18 ctx.fill(); | |
| 19 assertPixelApprox(ctx, 50, 25, 2, 253, 0, 255, "50,25", "2,253,0,255", 2); | |
| 20 }); | |
| 21 </script> | |
| OLD | NEW |