summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-constructors.js
blob: 487287f4d8f67af90c207bf78766efbcb4c62fc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
description("Test different constructors of Path.");
var ctx = document.createElement('canvas').getContext('2d');

debug("Test constructor Path().")
ctx.beginPath();
var p1 = new Path();
p1.rect(0,0,100,100);
ctx.fillStyle = 'yellow';
ctx.currentPath = p1;
ctx.fill();
var imageData = ctx.getImageData(0, 0, 100, 100);
var imgdata = imageData.data;
shouldBe("imgdata[4]", "255");
shouldBe("imgdata[5]", "255");
shouldBe("imgdata[6]", "0");
shouldBe("imgdata[7]", "255");
debug("");

debug("Test constructor Path(DOMString) which takes a SVG data string.")
ctx.beginPath();
var p2 = new Path("M100,0L200,0L200,100L100,100z");
ctx.currentPath = p2;
ctx.fillStyle = 'blue';
ctx.fill();
imageData = ctx.getImageData(100, 0, 100, 100);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "0");
shouldBe("imgdata[6]", "255");
shouldBe("imgdata[7]", "255");
debug("");

debug("Test constructor Path(Path) which takes another Path object.")
ctx.beginPath();
var p3 = new Path(p1);
ctx.translate(200,0);
ctx.currentPath = p3;
ctx.fillStyle = 'green';
ctx.translate(-200,0);
ctx.fill();
imageData = ctx.getImageData(200, 0, 100, 100);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");
shouldBe("imgdata[7]", "255");
debug("");