1 description("This test ensures that Canvas and CanvasRenderingContext2D work correctly if the rendering context outlives the canvas element");
3 function dataToArray(data
) {
4 var result
= new Array(data
.length
)
5 for (var i
= 0; i
< data
.length
; i
++)
10 function getPixel(x
, y
) {
11 var data
= context
.getImageData(x
,y
,1,1);
12 if (!data
) // getImageData failed, which should never happen
14 return dataToArray(data
.data
);
17 function pixelShouldBe(x
, y
, colour
) {
18 shouldBe("getPixel(" + [x
, y
] +")", "["+colour
+"]");
21 function prepareCanvas() {
22 var context
= document
.createElement("canvas").getContext("2d");
23 context
.fillStyle
= "green";
24 context
.fillRect(0,0,100,100);
28 function clobberGC(count
) {
29 for (var i
= 0; i
< 5000; ++i
)
30 ({a
: i
*i
*i
*0.5+"str", b
: i
/Math
.sqrt(i
)});
36 context
= prepareCanvas();
38 pixelShouldBe(50, 50, [0, 128, 0, 255]);