1 description("Ensure correct behavior of canvas with path stroke shadow");
3 function print(message, color)
5 var paragraph = document.createElement("div");
6 paragraph.appendChild(document.createTextNode(message));
7 paragraph.style.fontFamily = "monospace";
9 paragraph.style.color = color;
10 document.getElementById("console").appendChild(paragraph);
13 // Level of tolerance we expect of most pixel comparisons in this test.
14 function shouldBeAlmost(_a, _b)
16 shouldBeCloseTo(_a, _b, 2);
19 var canvas = document.createElement('canvas');
20 document.body.appendChild(canvas);
21 canvas.setAttribute('width', '700');
22 canvas.setAttribute('height', '700');
23 var ctx = canvas.getContext('2d');
28 ctx.bezierCurveTo(200, 40, 75, 150, 30, 30);
29 ctx.quadraticCurveTo(250, 75, 50, 300);
30 ctx.shadowOffsetX = 350;
31 ctx.shadowColor = 'rgba(255, 20, 0, 0.5)';
33 ctx.strokeStyle = 'rgba(0, 0, 255, 1)';
41 ctx.bezierCurveTo(200, 390, 75, 500, 30, 380);
42 ctx.quadraticCurveTo(250, 425, 50, 650);
43 ctx.shadowOffsetX = 350;
44 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
46 ctx.strokeStyle = 'rgba(0, 0, 255, 1)';
53 // Verify solid shadow.
54 imageData = ctx.getImageData(650, 300, 1, 1);
55 data = imageData.data;
56 shouldBeAlmost('data[0]', 255);
57 shouldBeAlmost('data[1]', 20);
58 shouldBeAlmost('data[2]', 0);
60 imageData = ctx.getImageData(650, 50, 1, 1);
61 data = imageData.data;
62 shouldBeAlmost('data[0]', 255);
63 shouldBeAlmost('data[1]', 20);
64 shouldBeAlmost('data[2]', 0);
66 imageData = ctx.getImageData(380, 30, 1, 1);
67 data = imageData.data;
68 shouldBeAlmost('data[0]', 255);
69 shouldBeAlmost('data[1]', 20);
70 shouldBeAlmost('data[2]', 0);
72 imageData = ctx.getImageData(400, 40, 1, 1);
73 data = imageData.data;
74 shouldBeAlmost('data[0]', 255);
75 shouldBeAlmost('data[1]', 20);
76 shouldBeAlmost('data[2]', 0);
78 // Verify blurry shadow.
79 imageData = ctx.getImageData(640, 640, 1, 1);
80 data = imageData.data;
81 shouldBeAlmost('data[0]', 255);
82 shouldBeAlmost('data[1]', 0);
83 shouldBeAlmost('data[2]', 0);
84 shouldNotBe('data[3]', '255');
86 imageData = ctx.getImageData(650, 400, 1, 1);
87 data = imageData.data;
88 shouldBeAlmost('data[0]', 255);
89 shouldBeAlmost('data[1]', 0);
90 shouldBeAlmost('data[2]', 0);
91 shouldNotBe('data[3]', '255');
93 imageData = ctx.getImageData(380, 380, 1, 1);
94 data = imageData.data;
95 shouldBeAlmost('data[0]', 255);
96 shouldBeAlmost('data[1]', 0);
97 shouldBeAlmost('data[2]', 0);
98 shouldNotBe('data[3]', '255');
100 imageData = ctx.getImageData(350, 380, 1, 1);
101 data = imageData.data;
102 shouldBeAlmost('data[0]', 255);
103 shouldBeAlmost('data[1]', 0);
104 shouldBeAlmost('data[2]', 0);
105 shouldNotBe('data[3]', '255');