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-drawImage-shadow.js"></script> | 4 <script> |
| 5 // Create auxiliary canvas to draw to and create an image from. | |
| 6 // This is done instead of simply loading an image from the file system | |
| 7 // because that would throw a SECURITY_ERR DOM Exception. | |
| 8 var aCanvas = document.createElement('canvas'); | |
| 9 aCanvas.setAttribute('width', '200'); | |
| 10 aCanvas.setAttribute('height', '200'); | |
| 11 var aCtx = aCanvas.getContext('2d'); | |
| 12 | |
| 13 // Draw a circle on the same canvas. | |
| 14 aCtx.beginPath(); | |
| 15 aCtx.fillStyle = 'green'; | |
| 16 aCtx.arc(100, 100, 150, 0, -Math.PI/2, false); | |
| 17 aCtx.fill(); | |
| 18 | |
| 19 // Create the image object to be drawn on the master canvas. | |
| 20 var img = new Image(); | |
| 21 img.src = aCanvas.toDataURL(); // set a data URI of the base64 enconded image as the source | |
| 22 | |
| 23 // Create master canvas. | |
| 24 var canvas = document.createElement('canvas'); | |
| 25 document.body.appendChild(canvas); | |
| 26 canvas.setAttribute('width', '600'); | |
| 27 canvas.setAttribute('height', '600'); | |
| 28 var ctx = canvas.getContext('2d'); | |
| 29 | |
| 30 var testScenarios = [ | |
| 31 ['Test solid shadow 1', 260, 300, [0, 0, 0, 0]], | |
| 32 ['Test solid shadow 2', 350, 100, [240, 50, 50, 255]], | |
| 33 ['Test solid shadow 3', 400, 200, [240, 50, 50, 255]], | |
| 34 ['Test solid shadow 4', 490, 65, [0, 0, 0, 0]], | |
| 35 ['Test solid shadow 5', 485, 65, [0, 0, 0, 0]], | |
| 36 | |
| 37 ['Test blurry shadow 1', 260, 400, [0, 0, 0, 0]], | |
| 38 ['Test blurry shadow 2', 350, 300, [0, 0, 255, 'neq', 255]], | |
| 39 ['Test blurry shadow 3', 300, 400, [0, 0, 255, 'neq', 255]], | |
| 40 ['Test blurry shadow 4', 300, 500, [0, 0, 255, 'neq', 255]], | |
| 41 ['Test blurry shadow 5', 400, 500, [0, 0, 255, 'neq', 255]], | |
| 42 ['Test blurry shadow 6', 400, 400, [0, 0, 255]], | |
| 43 ['Test blurry shadow 7', 490, 315, [0, 0, 0, 0]], | |
| 44 ['Test blurry shadow 8', 485, 320, [0, 0, 0, 0]], | |
| 45 ]; | |
| 46 | |
| 47 function runTestScenario(x, y, expectedColor) | |
| 48 { | |
| 49 imageData = ctx.getImageData(x, y, 1, 1).data; | |
| 50 if (expectedColor.length == 5) { | |
| 51 assert_array_equals(imageData.slice(0,3), expectedColor.slice(0,3)); | |
| 52 assert_not_equals(imageData[3], expectedColor[4]); | |
| 53 } else { | |
| 54 assert_array_equals(imageData.slice(0, expectedColor.length), expectedCo lor); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 function drawImageToCanvasAndCheckPixels() { | |
| 59 ctx.shadowOffsetX = 250; | |
| 60 ctx.shadowColor = 'rgba(240, 50, 50, 1.0)'; | |
| 61 ctx.drawImage(img, 50, 50); | |
| 62 | |
| 63 ctx.shadowOffsetX = 250; | |
| 64 ctx.shadowBlur = 6; | |
| 65 ctx.shadowColor = 'rgba(50, 50, 200, 0.9)'; | |
| 66 ctx.shadowColor = 'rgba(0, 0, 255, 1.0)'; | |
| 67 ctx.drawImage(img, 50, 300); | |
| 68 | |
| 69 generate_tests(runTestScenario, testScenarios); | |
| 70 } | |
| 71 | |
| 72 async_test(t => { | |
| 73 img.onload = function() { | |
| 74 t.step(drawImageToCanvasAndCheckPixels); | |
|
Justin Novosad
2017/02/16 15:59:28
Are you sure this works correctly?
zakerinasab
2017/02/16 20:11:28
generate_tests replaced with a loop.
| |
| 75 t.done(); | |
| 76 } | |
| 77 }, "Ensure correct behavior of canvas with image shadow. A square with a cut-out top-right corner should be displayed with solid shadow (top) and blur shadow (b ottom)."); | |
| 78 </script> | |
| 8 </body> | 79 </body> |
| 9 </html> | |
| OLD | NEW |