mdelaney@apple.com | b827a4e | 2011-01-12 23:35:54 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <title>Canvas test: test large width/height values</title> |
mark.lam@apple.com | 104d993 | 2013-09-07 22:20:15 +0000 | [diff] [blame] | 3 | <script src="../../resources/js-test-pre.js"></script> |
mdelaney@apple.com | b827a4e | 2011-01-12 23:35:54 +0000 | [diff] [blame] | 4 | <body> |
| 5 | <p>Tests that using reasonably large values for canvas.height and canvas.height don't cause a crash"</p> |
| 6 | <pre id="console"></pre> |
| 7 | <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> |
| 8 | <script> |
| 9 | var canvas = document.getElementById("c"); |
| 10 | var x, y, w=1, h=1; |
| 11 | |
| 12 | testHeight(canvas, 1000); |
| 13 | testHeight(canvas, 10000); |
mdelaney@apple.com | 53c870c2 | 2011-01-13 20:36:06 +0000 | [diff] [blame] | 14 | testHeight(canvas, 32000); |
mdelaney@apple.com | b827a4e | 2011-01-12 23:35:54 +0000 | [diff] [blame] | 15 | |
mdelaney@apple.com | b827a4e | 2011-01-12 23:35:54 +0000 | [diff] [blame] | 16 | testWidth(canvas, 1000); |
| 17 | testWidth(canvas, 10000); |
mdelaney@apple.com | 53c870c2 | 2011-01-13 20:36:06 +0000 | [diff] [blame] | 18 | testWidth(canvas, 32000); |
mdelaney@apple.com | b827a4e | 2011-01-12 23:35:54 +0000 | [diff] [blame] | 19 | |
| 20 | function testHeight(canvas, height) { |
| 21 | canvas.width = 50; |
| 22 | canvas.height = height; |
| 23 | var ctx = canvas.getContext("2d"); |
| 24 | ctx.fillStyle = "rgba(255, 255, 255, 1)"; |
| 25 | var msg = "height == "+height; |
| 26 | if (canvas.height == height) |
| 27 | testPassed(msg); |
| 28 | else |
| 29 | testFailed(msg); |
| 30 | x = canvas.width-2; |
| 31 | y = canvas.height-2; |
| 32 | ctx.fillRect(x,y,w,h); |
| 33 | var data = ctx.getImageData(x,y,w,h); |
| 34 | for (var x = 0; x < 4; x++) { |
| 35 | var msg = "Actual: " + data.data[x] + " Expected: 255"; |
| 36 | if (data.data[x] == 255) |
| 37 | testPassed(msg); |
| 38 | else |
| 39 | testFailed(msg); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | function testWidth(canvas, width) { |
| 44 | canvas.height = 50; |
| 45 | canvas.width = width; |
| 46 | var ctx = canvas.getContext("2d"); |
| 47 | ctx.fillStyle = "rgba(255, 255, 255, 1)"; |
| 48 | var msg = "width == "+width; |
| 49 | if (canvas.width == width) |
| 50 | testPassed(msg); |
| 51 | else |
| 52 | testFailed(msg); |
| 53 | x = canvas.width-2; |
| 54 | y = canvas.height-2; |
| 55 | ctx.fillRect(x,y,w,h); |
| 56 | var data = ctx.getImageData(x,y,w,h); |
| 57 | for (var x = 0; x < 4; x++) { |
| 58 | var msg = "Actual: " + data.data[x] + " Expected: 255"; |
| 59 | if (data.data[x] == 255) |
| 60 | testPassed(msg); |
| 61 | else |
| 62 | testFailed(msg); |
| 63 | } |
| 64 | } |
| 65 | </script> |
| 66 | |