Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-path-addpath.js
1 description("Test addPath() method.");
2 var canvas = document.createElement('canvas');
3 var ctx = canvas.getContext('2d');
4
5 debug("Test addPath() with transform as identity matrix.");
6 ctx.clearRect(0, 0, canvas.width, canvas.height);
7 ctx.beginPath();
8 var p1 = new Path2D();
9 p1.rect(0,0,100,100);
10 var p2 = new Path2D();
11 p2.rect(0,100,100,100);
12 var m = ctx.currentTransform;
13 p1.addPath(p2, m);
14 ctx.fillStyle = 'yellow';
15 ctx.fill(p1);
16 var imageData = ctx.getImageData(0, 100, 100, 100);
17 var imgdata = imageData.data;
18 shouldBe("imgdata[4]", "255");
19 shouldBe("imgdata[5]", "255");
20 shouldBe("imgdata[6]", "0");
21 shouldBe("imgdata[7]", "255");
22 debug("");
23
24 debug("Test addPath() with transform as translate(100, -100).");
25 ctx.clearRect(0, 0, canvas.width, canvas.height);
26 ctx.beginPath();
27 var p3 = new Path2D();
28 p3.rect(0,0,100,100);
29 var p4 = new Path2D();
30 p4.rect(0,100,100,100);
31 m.a = 1; m.b = 0;
32 m.c = 0; m.d = 1;
33 m.e = 100; m.f = -100;
34 p3.addPath(p4, m);
35 ctx.fillStyle = 'yellow';
36 ctx.fill(p3);
37 imageData = ctx.getImageData(100, 0, 100, 100);
38 imgdata = imageData.data;
39 shouldBe("imgdata[4]", "255");
40 shouldBe("imgdata[5]", "255");
41 shouldBe("imgdata[6]", "0");
42 shouldBe("imgdata[7]", "255");
43 debug("");
44
45 debug("Test addPath() with non-invertible transform.");
46 ctx.clearRect(0, 0, canvas.width, canvas.height);
47 ctx.beginPath();
48 var p5 = new Path2D();
49 p5.rect(0,0,100,100);
50 var p6 = new Path2D();
51 p6.rect(100,100,100,100);
52 m.a = 0; m.b = 0;
53 m.c = 0; m.d = 0;
54 m.e = 0; m.f = 0;
55 p5.addPath(p6, m);
56 ctx.fillStyle = 'yellow';
57 ctx.fill(p5);
58 imageData = ctx.getImageData(100, 100, 100, 100);
59 imgdata = imageData.data;
60 shouldNotBe("imgdata[4]", "255");
61 shouldNotBe("imgdata[5]", "255");
62 shouldBe("imgdata[6]", "0");
63 shouldNotBe("imgdata[7]", "255");
64 debug("");
65
66 debug("Test addPath() with transform as null or invalid type.");
67 ctx.clearRect(0, 0, canvas.width, canvas.height);
68 ctx.beginPath();
69 var p7 = new Path2D();
70 p7.rect(0,0,100,100);
71 var p8 = new Path2D();
72 p8.rect(100,100,100,100);
73 p7.addPath(p8, null);
74 shouldThrow("p7.addPath(p8, [])");
75 shouldThrow("p7.addPath(p8, {})");
76 ctx.fillStyle = 'red';
77 ctx.fill(p7);
78 imageData = ctx.getImageData(100, 100, 100, 100);
79 imgdata = imageData.data;
80 shouldBe("imgdata[4]", "255");
81 shouldBe("imgdata[5]", "0");
82 shouldBe("imgdata[6]", "0");
83 shouldBe("imgdata[7]", "255");
84 debug("");
85
86 debug("Test addPath() with transform omitted.");
87 ctx.clearRect(0, 0, canvas.width, canvas.height);
88 ctx.beginPath();
89 var p9 = new Path2D();
90 var p10 = new Path2D();
91 p9.rect(0,0,10,10);
92 p10.addPath(p9);
93 ctx.fillStyle = 'red';
94 ctx.fill(p10);
95 imageData = ctx.getImageData(1, 1, 1, 1);
96 imgdata = imageData.data;
97 shouldBe("imgdata[0]", "255");
98 shouldBe("imgdata[1]", "0");
99 shouldBe("imgdata[2]", "0");
100 shouldBe("imgdata[3]", "255");
101 debug("");
102
103 debug("Test addPath() with path as null and invalid type");
104 var p9 = new Path2D();
105 p9.rect(0,0,100,100);
106 shouldThrow("p7.addPath(null, m)");
107 shouldThrow("p7.addPath([], m)");
108 shouldThrow("p7.addPath({}, m)");
109 debug("");