2011-01-11 Matthew Delaney <mdelaney@apple.com>
[WebKit-https.git] / LayoutTests / fast / canvas / canvas-large-dimensions.html
1 <!DOCTYPE html>
2 <title>Canvas test: test large width/height values</title>
3 <script src="../js/resources/js-test-pre.js"></script>
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);
14 testHeight(canvas, 100000);
15 testHeight(canvas, 1000000);
16
17 testWidth(canvas, 100);
18 testWidth(canvas, 1000);
19 testWidth(canvas, 10000);
20 testWidth(canvas, 100000);
21 testWidth(canvas, 1000000);
22
23 function testHeight(canvas, height) {
24     canvas.width = 50;
25     canvas.height = height;
26     var ctx = canvas.getContext("2d");
27     ctx.fillStyle = "rgba(255, 255, 255, 1)";
28     var msg = "height == "+height;
29     if (canvas.height == height)
30         testPassed(msg);
31     else
32         testFailed(msg);
33     x = canvas.width-2;
34     y = canvas.height-2;
35     ctx.fillRect(x,y,w,h);
36     var data = ctx.getImageData(x,y,w,h);
37     for (var x = 0; x < 4; x++) {
38         var msg = "Actual: " + data.data[x] + " Expected: 255";
39         if (data.data[x] == 255)
40             testPassed(msg);
41         else
42             testFailed(msg);
43     }
44 }
45
46 function testWidth(canvas, width) {
47     canvas.height = 50;
48     canvas.width = width;
49     var ctx = canvas.getContext("2d");
50     ctx.fillStyle = "rgba(255, 255, 255, 1)";
51     var msg = "width == "+width;
52     if (canvas.width == width)
53         testPassed(msg);
54     else
55         testFailed(msg);
56     x = canvas.width-2;
57     y = canvas.height-2;
58     ctx.fillRect(x,y,w,h);
59     var data = ctx.getImageData(x,y,w,h);
60     for (var x = 0; x < 4; x++) {
61         var msg = "Actual: " + data.data[x] + " Expected: 255";
62         if (data.data[x] == 255)
63             testPassed(msg);
64         else
65             testFailed(msg);
66     }
67 }
68 </script>
69