OLD | NEW |
1 <!DOCTYPE html> | 1 <script src='../../resources/testharness.js'></script> |
2 <title>Canvas test: test large width/height values</title> | 2 <script src='../../resources/testharnessreport.js'></script> |
3 <script src="../../resources/js-test.js"></script> | 3 <canvas id='c' width='100' height='50'></canvas> |
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> | 4 <script> |
9 var canvas = document.getElementById("c"); | 5 // Tests that using reasonably large values for canvas.height and canvas.height
do not cause a crash |
10 var x, y, w=1, h=1; | 6 var canvas = document.getElementById('c'); |
| 7 var x, y, w = 1, h = 1; |
11 | 8 |
12 testHeight(canvas, 1000); | 9 function testLargeDimension(size, isWidth) { |
13 testHeight(canvas, 10000); | 10 canvas.width = (isWidth ? size : 50); |
14 testHeight(canvas, 32000); | 11 canvas.height = (isWidth ? 50 : size); |
15 | 12 var ctx = canvas.getContext('2d'); |
16 testWidth(canvas, 1000); | 13 ctx.fillStyle = 'rgba(255, 255, 255, 1)'; |
17 testWidth(canvas, 10000); | 14 assert_equals((isWidth ? canvas.width : canvas.height), size); |
18 testWidth(canvas, 32000); | 15 x = canvas.width - 2; |
19 | 16 y = canvas.height - 2; |
20 function testHeight(canvas, height) { | 17 ctx.fillRect(x, y, w, h); |
21 canvas.width = 50; | 18 var data = ctx.getImageData(x, y, w, h).data; |
22 canvas.height = height; | 19 for (var i = 0; i < 4; i++) |
23 var ctx = canvas.getContext("2d"); | 20 assert_equals(data[i], 255); |
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 } | 21 } |
42 | 22 |
43 function testWidth(canvas, width) { | 23 testScenarios = [['Test Width = 1000', 1000, true], |
44 canvas.height = 50; | 24 ['Test Width = 10000', 10000, true], |
45 canvas.width = width; | 25 ['Test Width = 32000', 32000, true], |
46 var ctx = canvas.getContext("2d"); | 26 |
47 ctx.fillStyle = "rgba(255, 255, 255, 1)"; | 27 ['Test Height = 1000', 1000, false], |
48 var msg = "width == "+width; | 28 ['Test Height = 10000', 10000, false], |
49 if (canvas.width == width) | 29 ['Test Height = 32000', 32000, false]]; |
50 testPassed(msg); | 30 |
51 else | 31 generate_tests(testLargeDimension, testScenarios); |
52 testFailed(msg); | 32 |
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> | 33 </script> |
66 | 34 |
OLD | NEW |