Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <head> | |
| 4 <script src="../../resources/js-test.js"></script> | |
| 5 </head> | |
| 6 <body> | 3 <body> |
| 7 <script src="script-tests/canvas-fillPath-alpha-shadow.js"></script> | 4 <script> |
| 5 test(function(t) { | |
| 6 | |
| 7 var canvas = document.createElement('canvas'); | |
|
Justin Novosad
2017/02/06 20:04:23
indent
zakerinasab
2017/02/09 18:02:00
Done.
| |
| 8 document.body.appendChild(canvas); | |
| 9 canvas.setAttribute('width', '600'); | |
| 10 canvas.setAttribute('height', '1100'); | |
| 11 var ctx = canvas.getContext('2d'); | |
| 12 | |
| 13 ctx.save(); | |
| 14 ctx.fillStyle = 'rgba(0, 0, 255, 0.5)'; | |
| 15 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)'; | |
| 16 ctx.shadowOffsetX = 250; | |
| 17 | |
| 18 function fillShape(x, y) { | |
| 19 ctx.beginPath(); | |
| 20 ctx.arc(x, y, 100, 0, Math.PI*2, true); | |
| 21 ctx.arc(x, y, 50, 0, Math.PI*2, false); | |
| 22 ctx.fill(); | |
| 23 } | |
| 24 | |
| 25 // Alpha shadow. | |
| 26 ctx.shadowBlur = 0; | |
| 27 fillShape(150, 150); | |
| 28 | |
| 29 // Blurry shadow. | |
| 30 ctx.shadowBlur = 10; | |
| 31 fillShape(150, 400); | |
| 32 | |
| 33 ctx.rotate(Math.PI/2); | |
| 34 | |
| 35 // Rotated alpha shadow. | |
| 36 ctx.shadowBlur = 0; | |
| 37 fillShape(650, -150); | |
| 38 | |
| 39 // Rotated blurry shadow. | |
| 40 ctx.shadowBlur = 10; | |
| 41 fillShape(900, -150); | |
| 42 | |
| 43 ctx.restore(); | |
| 44 | |
| 45 var imageData, data; | |
| 46 ctx.fillStyle = 'black'; | |
| 47 | |
| 48 function test(x, y, r, g, b, a, alphaApprox) { | |
|
Justin Novosad
2017/02/06 20:04:23
call this something else. It has a name conflict w
zakerinasab
2017/02/09 18:02:00
Done.
| |
| 49 // Get pixel. | |
| 50 imageData = ctx.getImageData(x, y, 1, 1); | |
| 51 data = imageData.data; | |
| 52 // Test pixel color components. | |
| 53 assert_equals(data[0], r); | |
| 54 assert_equals(data[1], g); | |
| 55 assert_equals(data[2], b); | |
| 56 if (alphaApprox === undefined) | |
| 57 alphaApprox = 15; | |
| 58 assert_approx_equals(data[3], a, alphaApprox); | |
| 59 // Plot test point. | |
| 60 ctx.fillRect(x, y, 3, 3); | |
| 61 } | |
| 62 | |
| 63 // Verifying alpha shadow... | |
| 64 test(400, 150, 0, 0, 0, 0, 0); | |
|
Justin Novosad
2017/02/06 20:04:23
Should use generate_tests() here
zakerinasab
2017/02/09 18:02:00
Done.
| |
| 65 test(400, 75, 255, 0, 0, 64); | |
| 66 test(400, 225, 255, 0, 0, 64); | |
| 67 test(325, 150, 255, 0, 0, 64); | |
| 68 test(475, 150, 255, 0, 0, 64); | |
| 69 | |
| 70 // Verifying blurry shadow... | |
| 71 test(400, 400, 0, 0, 0, 0, 0); | |
| 72 test(400, 300, 255, 0, 0, 31); | |
| 73 test(400, 500, 255, 0, 0, 31); | |
| 74 test(300, 400, 255, 0, 0, 31); | |
| 75 test(500, 400, 255, 0, 0, 31); | |
| 76 | |
| 77 // Verifying rotated alpha shadow... | |
| 78 test(400, 650, 0, 0, 0, 0, 0); | |
| 79 test(400, 575, 255, 0, 0, 64); | |
| 80 test(400, 725, 255, 0, 0, 64); | |
| 81 test(325, 650, 255, 0, 0, 64); | |
| 82 test(475, 650, 255, 0, 0, 64); | |
| 83 | |
| 84 // Verifying rotated blurry shadow... | |
| 85 test(400, 900, 0, 0, 0, 0, 0); | |
| 86 test(400, 800, 255, 0, 0, 31); | |
| 87 test(400, 1000, 255, 0, 0, 31); | |
| 88 test(300, 900, 255, 0, 0, 31); | |
| 89 test(500, 900, 255, 0, 0, 31); | |
| 90 | |
| 91 }, "Ensure correct behavior of canvas with fillPath using a fillStyle color with alpha and a shadow"); | |
| 92 </script> | |
| 8 </body> | 93 </body> |
| 9 </html> | |
| OLD | NEW |