1 description("Test addPath() method.");
2 var canvas = document.createElement('canvas');
3 var ctx = canvas.getContext('2d');
5 debug("Test addPath() with transform as identity matrix.");
6 ctx.clearRect(0, 0, canvas.width, canvas.height);
10 var p2 = new Path2D();
11 p2.rect(0,100,100,100);
12 var m = ctx.currentTransform;
14 ctx.fillStyle = 'yellow';
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");
24 debug("Test addPath() with transform as translate(100, -100).");
25 ctx.clearRect(0, 0, canvas.width, canvas.height);
27 var p3 = new Path2D();
29 var p4 = new Path2D();
30 p4.rect(0,100,100,100);
33 m.e = 100; m.f = -100;
35 ctx.fillStyle = 'yellow';
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");
45 debug("Test addPath() with non-invertible transform.");
46 ctx.clearRect(0, 0, canvas.width, canvas.height);
48 var p5 = new Path2D();
50 var p6 = new Path2D();
51 p6.rect(100,100,100,100);
56 ctx.fillStyle = 'yellow';
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");
66 debug("Test addPath() with transform as null or invalid type.");
67 ctx.clearRect(0, 0, canvas.width, canvas.height);
69 var p7 = new Path2D();
71 var p8 = new Path2D();
72 p8.rect(100,100,100,100);
74 shouldThrow("p7.addPath(p8, [])");
75 shouldThrow("p7.addPath(p8, {})");
76 ctx.fillStyle = 'red';
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");
86 debug("Test addPath() with transform omitted.");
87 ctx.clearRect(0, 0, canvas.width, canvas.height);
89 var p9 = new Path2D();
90 var p10 = new Path2D();
93 ctx.fillStyle = 'red';
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");
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)");