upload webkit/tizen 2.0_beta source.
[framework/web/webkit-efl.git] / LayoutTests / fast / canvas / canvas-longlived-context.js
1 description("This test ensures that Canvas and CanvasRenderingContext2D work correctly if the rendering context outlives the canvas element");
2
3 function dataToArray(data) {
4     var result = new Array(data.length)
5     for (var i = 0; i < data.length; i++)
6         result[i] = data[i];
7     return result;
8 }
9
10 function getPixel(x, y) {
11     var data = context.getImageData(x,y,1,1);
12     if (!data) // getImageData failed, which should never happen
13         return [-1,-1,-1,-1];
14     return dataToArray(data.data);
15 }
16
17 function pixelShouldBe(x, y, colour) {
18     shouldBe("getPixel(" + [x, y] +")", "["+colour+"]");
19 }
20
21 function prepareCanvas() {
22     var context = document.createElement("canvas").getContext("2d");
23     context.fillStyle = "green";
24     context.fillRect(0,0,100,100);
25     return context;
26 }
27
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)});
31     if (count > 0)
32         clobberGC(count-1);
33 }
34
35 function test() {
36     context = prepareCanvas();
37     clobberGC(40);
38     pixelShouldBe(50, 50, [0, 128, 0, 255]);
39 }
40 test();