1 <canvas width=
"200" height=
"200" id=
"canvas">FAIL: no canvas support
</canvas>
5 testRunner
.dumpAsText();
7 var canvas
= document
.getElementById("canvas").getContext("2d");
9 // 1. Infinite dimensions to fillRect
10 canvas
.fillStyle
= "green";
11 canvas
.fillRect(0, 0, 100, 100);
12 canvas
.fillStyle
= "red";
14 canvas
.fillRect(0, 0, Infinity
, Infinity
);
16 canvas
.fillRect(0, 0, 100, 100);
19 // 2. Infinite dimensions to rect
20 canvas
.fillStyle
= "green";
21 canvas
.fillRect(100, 0, 100, 100);
22 canvas
.fillStyle
= "red";
24 canvas
.rect(100, 0, Infinity
, Infinity
);
27 canvas
.fillRect(100, 0, 100, 100);
30 // 3. Infinite argument to moveTo
31 canvas
.translate(0, 100);
32 canvas
.fillStyle
= "red";
33 canvas
.fillRect(0, 0, 100, 100);
34 canvas
.fillStyle
= "green";
37 canvas
.moveTo(Infinity
, Infinity
);
38 canvas
.rect(0, 0, 100, 100);
44 // 4. Infinite argument to lineTo
45 canvas
.translate(100, 0);
46 canvas
.fillStyle
= "red";
47 canvas
.fillRect(0, 0, 100, 100);
48 canvas
.fillStyle
= "green";
52 canvas
.lineTo(100, 0);
53 canvas
.lineTo(100, 100);
54 canvas
.lineTo(0, 100);
55 canvas
.lineTo(Infinity
, 100);
61 document
.getElementById("log").innerHTML
+= msg
+ "<br/>";
64 function dataToArray(data
) {
65 var result
= new Array(data
.length
)
66 for (var i
= 0; i
< data
.length
; i
++)
71 function getPixel(ctx
, x
, y
) {
72 var data
= ctx
.getImageData(x
,y
,1,1);
73 if (!data
) // getImageData failed, which should never happen
75 return dataToArray(data
.data
);
78 function pixelShouldBe(ctx
, x
, y
, colour
) {
79 var ctxColour
= getPixel(ctx
, x
, y
);
81 for (var i
= 0; i
< 4; i
++)
82 if (colour
[i
] != ctxColour
[i
]) {
87 log("PASS: pixel at ("+[x
,y
]+") was ["+colour
+"]");
89 log("FAIL: pixel at ("+[x
,y
]+") was ["+ctxColour
+"], expected ["+colour
+"]");
92 var points
= [25, 50, 75, 125, 150, 175];
93 for (var x
= 0; x
< points
.length
; x
++) {
94 for (var y
= 0; y
< points
.length
; y
++) {
95 pixelShouldBe(canvas
, points
[x
], points
[y
], [0, 128, 0, 255]);