1 description("This test ensures that paths are correctly handled over save/restore boundaries");
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 var canvas = document.createElement("canvas");
25 var context = canvas.getContext("2d");
26 context.fillStyle = "red";
27 context.fillRect(0,0,100,100);
28 context.fillStyle = "green";
33 context.translate(100, 100);
34 context.rect(-100, -100, 50, 50);
37 pixelShouldBe(25, 25, [0, 128, 0, 255]);
43 context.rect(25, 0,25,25);
46 pixelShouldBe(75, 25, [0, 128, 0, 255]);
47 pixelShouldBe(75, 75, [255, 0, 0, 255]);
52 context.rotate(90/180 * Math.PI);
53 context.rect(50, -50, 50, 50);
56 pixelShouldBe(25, 75, [0, 128, 0, 255]);
57 pixelShouldBe(75, 75, [255, 0, 0, 255]);
62 context.transform(1, 0, 0, 1, 50, 50);
63 context.rect(0, 0, 50, 50);
66 pixelShouldBe(75, 75, [0, 128, 0, 255]);