3412c3389d462ff3e9b236f7e2965e571ff8c62e
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-path-constructors.js
1 description("Test different constructors of Path.");
2 var ctx = document.createElement('canvas').getContext('2d');
3
4 debug("Test constructor Path().")
5 ctx.beginPath();
6 var p1 = new Path2D();
7 p1.rect(0,0,100,100);
8 ctx.fillStyle = 'yellow';
9 ctx.currentPath = p1;
10 ctx.fill();
11 var imageData = ctx.getImageData(0, 0, 100, 100);
12 var imgdata = imageData.data;
13 shouldBe("imgdata[4]", "255");
14 shouldBe("imgdata[5]", "255");
15 shouldBe("imgdata[6]", "0");
16 shouldBe("imgdata[7]", "255");
17 debug("");
18
19 debug("Test constructor Path(DOMString) which takes a SVG data string.")
20 ctx.beginPath();
21 var p2 = new Path2D("M100,0L200,0L200,100L100,100z");
22 ctx.currentPath = p2;
23 ctx.fillStyle = 'blue';
24 ctx.fill();
25 imageData = ctx.getImageData(100, 0, 100, 100);
26 imgdata = imageData.data;
27 shouldBe("imgdata[4]", "0");
28 shouldBe("imgdata[5]", "0");
29 shouldBe("imgdata[6]", "255");
30 shouldBe("imgdata[7]", "255");
31 debug("");
32
33 debug("Test constructor Path(Path) which takes another Path object.")
34 ctx.beginPath();
35 var p3 = new Path2D(p1);
36 ctx.translate(200,0);
37 ctx.currentPath = p3;
38 ctx.fillStyle = 'green';
39 ctx.translate(-200,0);
40 ctx.fill();
41 imageData = ctx.getImageData(200, 0, 100, 100);
42 imgdata = imageData.data;
43 shouldBe("imgdata[4]", "0");
44 shouldBe("imgdata[5]", "128");
45 shouldBe("imgdata[6]", "0");
46 shouldBe("imgdata[7]", "255");
47 debug("");