1 description("Ensure correct behavior of canvas with path stroke + shadow after scaling. A blue and red checkered pattern should be displayed.");
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 function shouldBeAround(a, b)
22 if (Math.abs(evalA - b) < 20)
23 print("PASS " + a + " is around " + b , "green")
25 print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red");
28 var canvas = document.createElement('canvas');
29 document.body.appendChild(canvas);
30 canvas.setAttribute('width', '600');
31 canvas.setAttribute('height', '600');
32 var ctx = canvas.getContext('2d');
35 ctx.shadowOffsetX = 100;
36 ctx.shadowOffsetY = 100;
37 ctx.strokeStyle = 'rgba(0, 0, 255, 1)';
40 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
49 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
58 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
68 ctx.shadowColor = 'rgba(255, 0, 0, 0.6)';
77 var d; // imageData.data
79 // Verify solid shadow.
80 d = ctx.getImageData(250, 200, 1, 1).data;
81 shouldBe('d[0]', '255');
82 shouldBe('d[1]', '0');
83 shouldBe('d[2]', '0');
84 shouldBe('d[3]', '255');
86 d = ctx.getImageData(300, 290, 1, 1).data;
87 shouldBe('d[0]', '255');
88 shouldBe('d[1]', '0');
89 shouldBe('d[2]', '0');
90 shouldBe('d[3]', '255');
92 d = ctx.getImageData(200, 250, 1, 1).data;
93 shouldBe('d[0]', '255');
94 shouldBe('d[1]', '0');
95 shouldBe('d[2]', '0');
96 shouldBe('d[3]', '255');
98 // Verify solid alpha shadow.
99 d = ctx.getImageData(201, 405, 1, 1).data;
100 shouldBe('d[0]', '255');
101 shouldBe('d[1]', '0');
102 shouldBe('d[2]', '0');
103 shouldBeAround('d[3]', '76');
105 d = ctx.getImageData(201, 500, 1, 1).data;
106 shouldBe('d[0]', '255');
107 shouldBe('d[1]', '0');
108 shouldBe('d[2]', '0');
109 shouldBeAround('d[3]', '76');
111 d = ctx.getImageData(300, 499, 1, 1).data;
112 shouldBe('d[0]', '255');
113 shouldBe('d[1]', '0');
114 shouldBe('d[2]', '0');
115 shouldBeAround('d[3]', '76');
117 // Verify blurry shadow.
118 d = ctx.getImageData(398, 210, 1, 1).data;
119 shouldBe('d[0]', '255');
120 shouldBe('d[1]', '0');
121 shouldBe('d[2]', '0');
122 shouldBeAround('d[3]', '200');
124 d = ctx.getImageData(508, 250, 1, 1).data;
125 shouldBe('d[0]', '255');
126 shouldBe('d[1]', '0');
127 shouldBe('d[2]', '0');
128 shouldBeAround('d[3]', '49');
130 d = ctx.getImageData(450, 198, 1, 1).data;
131 shouldBe('d[0]', '255');
132 shouldBe('d[1]', '0');
133 shouldBe('d[2]', '0');
134 shouldBeAround('d[3]', '199');
136 // Verify blurry alpha shadow.
137 d = ctx.getImageData(505, 450, 1, 1).data;
138 shouldBe('d[0]', '255');
139 shouldBe('d[1]', '0');
140 shouldBe('d[2]', '0');
141 shouldBeAround('d[3]', '70');
143 d = ctx.getImageData(505, 450, 1, 1).data;
144 shouldBe('d[0]', '255');
145 shouldBe('d[1]', '0');
146 shouldBe('d[2]', '0');
147 shouldBeAround('d[3]', '70');
149 d = ctx.getImageData(450, 405, 1, 1).data;
150 shouldBe('d[0]', '255');
151 shouldBe('d[1]', '0');
152 shouldBe('d[2]', '0');
153 shouldBeAround('d[3]', '69');