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-strokeRect-alpha-shadow.js"></script> | 4 <script> |
| 5 // Ensure correct behavior of canvas with strokeRect using a semi-transparent so
lid strokeStyle and a shadow. |
| 6 |
| 7 var canvas = document.createElement('canvas'); |
| 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.strokeStyle = 'rgba(0, 0, 255, 0.5)'; |
| 15 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)'; |
| 16 ctx.shadowOffsetX = 250; |
| 17 ctx.lineWidth = 25; |
| 18 |
| 19 var side = 200; |
| 20 |
| 21 // Alpha shadow. |
| 22 ctx.shadowBlur = 0; |
| 23 ctx.strokeRect(50, 50, side, side); |
| 24 |
| 25 // Blurry shadow. |
| 26 ctx.shadowBlur = 10; |
| 27 ctx.strokeRect(50, 300, side, side); |
| 28 |
| 29 ctx.rotate(Math.PI / 2); |
| 30 |
| 31 // Rotated alpha shadow. |
| 32 ctx.shadowBlur = 0; |
| 33 ctx.strokeRect(550, -250, side, side); |
| 34 |
| 35 // Rotated blurry shadow. |
| 36 ctx.shadowBlur = 10; |
| 37 ctx.strokeRect(800, -250, side, side); |
| 38 |
| 39 ctx.restore(); |
| 40 |
| 41 var imageData, data; |
| 42 ctx.fillStyle = 'black'; |
| 43 |
| 44 function testPixelAlphaShadow(x, y, color) |
| 45 { |
| 46 if (color.length == 4) { |
| 47 assert_array_equals(ctx.getImageData(x, y, 1, 1).data, color); |
| 48 } else { // we expect to have [r, g, b, a, alphaApprox] |
| 49 var data = ctx.getImageData(x, y, 1, 1).data; |
| 50 assert_array_equals(data.slice(0,3), color.slice(0,3)); |
| 51 assert_approx_equals(data[3], color[3], color[4]); |
| 52 } |
| 53 // Plot test point. |
| 54 ctx.fillRect(x, y, 3, 3); |
| 55 } |
| 56 |
| 57 var alphaTolerance = 15; |
| 58 var testScenarios = [ |
| 59 ['Verify alpha shadow 1' , 400, 150, [0, 0, 0, 0]], |
| 60 ['Verify alpha shadow 2' , 400, 75, [0, 0, 0, 0]], |
| 61 ['Verify alpha shadow 3' , 400, 225, [0, 0, 0, 0]], |
| 62 ['Verify alpha shadow 4' , 325, 150, [0, 0, 0, 0]], |
| 63 ['Verify alpha shadow 5' , 475, 150, [0, 0, 0, 0]], |
| 64 ['Verify alpha shadow 6' , 400, 50, [255, 0, 0, 64, alphaTolerance]], |
| 65 ['Verify alpha shadow 7' , 500, 150, [255, 0, 0, 64, alphaTolerance]], |
| 66 ['Verify alpha shadow 8' , 400, 250, [255, 0, 0, 64, alphaTolerance]], |
| 67 ['Verify alpha shadow 9' , 300, 150, [255, 0, 0, 64, alphaTolerance]], |
| 68 ['Verify alpha shadow 10' , 400, 25, [0, 0, 0, 0]], |
| 69 ['Verify alpha shadow 11' , 525, 150, [0, 0, 0, 0]], |
| 70 ['Verify alpha shadow 12' , 400, 275, [0, 0, 0, 0]], |
| 71 ['Verify alpha shadow 13' , 275, 150, [0, 0, 0, 0]], |
| 72 |
| 73 ['Verify blurry shadow 1' , 400, 400, [0, 0, 0, 0]], |
| 74 ['Verify blurry shadow 2' , 400, 325, [0, 0, 0, 0]], |
| 75 ['Verify blurry shadow 3' , 475, 400, [0, 0, 0, 0]], |
| 76 ['Verify blurry shadow 4' , 400, 475, [0, 0, 0, 0]], |
| 77 ['Verify blurry shadow 5' , 325, 400, [0, 0, 0, 0]], |
| 78 ['Verify blurry shadow 6' , 400, 300, [255, 0, 0, 64, alphaTolerance]], |
| 79 ['Verify blurry shadow 7' , 400, 500, [255, 0, 0, 64, alphaTolerance]], |
| 80 ['Verify blurry shadow 8' , 300, 400, [255, 0, 0, 64, alphaTolerance]], |
| 81 ['Verify blurry shadow 9' , 500, 400, [255, 0, 0, 64, alphaTolerance]], |
| 82 ['Verify blurry shadow 10' , 525, 400, [0, 0, 0, 0]], |
| 83 ['Verify blurry shadow 11' , 275, 400, [0, 0, 0, 0]], |
| 84 |
| 85 ['Verify rotated alpha shadow 1' , 400, 650, [0, 0, 0, 0]], |
| 86 ['Verify rotated alpha shadow 2' , 400, 575, [0, 0, 0, 0]], |
| 87 ['Verify rotated alpha shadow 3' , 400, 725, [0, 0, 0, 0]], |
| 88 ['Verify rotated alpha shadow 4' , 325, 650, [0, 0, 0, 0]], |
| 89 ['Verify rotated alpha shadow 5' , 475, 650, [0, 0, 0, 0]], |
| 90 ['Verify rotated alpha shadow 6' , 400, 550, [255, 0, 0, 64, alphaTolerance]
], |
| 91 ['Verify rotated alpha shadow 7' , 500, 650, [255, 0, 0, 64, alphaTolerance]
], |
| 92 ['Verify rotated alpha shadow 8' , 400, 750, [255, 0, 0, 64, alphaTolerance]
], |
| 93 ['Verify rotated alpha shadow 9' , 300, 650, [255, 0, 0, 64, alphaTolerance]
], |
| 94 ['Verify rotated alpha shadow 10' , 400, 525, [0, 0, 0, 0]], |
| 95 ['Verify rotated alpha shadow 11' , 525, 650, [0, 0, 0, 0]], |
| 96 ['Verify rotated alpha shadow 12' , 400, 775, [0, 0, 0, 0]], |
| 97 ['Verify rotated alpha shadow 13' , 275, 650, [0, 0, 0, 0]], |
| 98 |
| 99 ['Verify rotated blurry shadow 1' , 400, 900, [0, 0, 0, 0]], |
| 100 ['Verify rotated blurry shadow 2' , 400, 825, [0, 0, 0, 0]], |
| 101 ['Verify rotated blurry shadow 3' , 475, 900, [0, 0, 0, 0]], |
| 102 ['Verify rotated blurry shadow 4' , 400, 975, [0, 0, 0, 0]], |
| 103 ['Verify rotated blurry shadow 5' , 325, 900, [0, 0, 0, 0]], |
| 104 ['Verify rotated blurry shadow 6' , 400, 800, [255, 0, 0, 64, alphaTolerance
]], |
| 105 ['Verify rotated blurry shadow 7' , 400, 1000, [255, 0, 0, 64, alphaToleranc
e]], |
| 106 ['Verify rotated blurry shadow 8' , 300, 900, [255, 0, 0, 64, alphaTolerance
]], |
| 107 ['Verify rotated blurry shadow 9' , 500, 900, [255, 0, 0, 64, alphaTolerance
]], |
| 108 ['Verify rotated blurry shadow 10' , 525, 900, [0, 0, 0, 0]], |
| 109 ['Verify rotated blurry shadow 11' , 275, 900, [0, 0, 0, 0]], |
| 110 ['Verify rotated blurry shadow 12' , 400, 1025, [0, 0, 0, 0]], |
| 111 ]; |
| 112 |
| 113 generate_tests(testPixelAlphaShadow, testScenarios); |
| 114 |
| 115 </script> |
8 </body> | 116 </body> |
9 </html> | |
OLD | NEW |