Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / canvas-longlived-context.js
blob1b2a756ea2e0b365a56b82aa7e1d08d0753806af
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++)
6 result[i] = data[i];
7 return result;
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);
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);
25 return context;
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);
35 function test() {
36 context = prepareCanvas();
37 clobberGC(40);
38 pixelShouldBe(50, 50, [0, 128, 0, 255]);
40 test();