1 description("Ensure correct behavior of canvas with path fill + 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', '1000');
31 canvas.setAttribute('height', '1000');
32 var ctx = canvas.getContext('2d');
35 ctx.shadowOffsetX = 100;
36 ctx.shadowOffsetY = 100;
37 ctx.fillStyle = 'rgba(0, 0, 255, 1)';
39 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
47 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
55 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
64 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
72 var d; // imageData.data
74 // Verify solid shadow.
75 d = ctx.getImageData(201, 205, 1, 1).data;
76 shouldBe('d[0]', '255');
77 shouldBe('d[1]', '0');
78 shouldBe('d[2]', '0');
79 shouldBe('d[3]', '255');
81 d = ctx.getImageData(298, 295, 1, 1).data;
82 shouldBe('d[0]', '255');
83 shouldBe('d[1]', '0');
84 shouldBe('d[2]', '0');
85 shouldBe('d[3]', '255');
87 d = ctx.getImageData(201, 298, 1, 1).data;
88 shouldBe('d[0]', '255');
89 shouldBe('d[1]', '0');
90 shouldBe('d[2]', '0');
91 shouldBe('d[3]', '255');
93 // Verify solid alpha shadow.
94 d = ctx.getImageData(201, 405, 1, 1).data;
95 shouldBe('d[0]', '255');
96 shouldBe('d[1]', '0');
97 shouldBe('d[2]', '0');
98 shouldBeAround('d[3]', '76');
100 d = ctx.getImageData(298, 405, 1, 1).data;
101 shouldBe('d[0]', '255');
102 shouldBe('d[1]', '0');
103 shouldBe('d[2]', '0');
104 shouldBeAround('d[3]', '76');
106 d = ctx.getImageData(205, 498, 1, 1).data;
107 shouldBe('d[0]', '255');
108 shouldBe('d[1]', '0');
109 shouldBe('d[2]', '0');
110 shouldBeAround('d[3]', '76');
112 // Verify blurry shadow.
113 d = ctx.getImageData(398, 205, 1, 1).data;
114 shouldBe('d[0]', '255');
115 shouldBe('d[1]', '0');
116 shouldBe('d[2]', '0');
117 shouldBeAround('d[3]', '83');
119 d = ctx.getImageData(501, 205, 1, 1).data;
120 shouldBe('d[0]', '255');
121 shouldBe('d[1]', '0');
122 shouldBe('d[2]', '0');
123 shouldBeAround('d[3]', '83');
125 d = ctx.getImageData(500, 300, 1, 1).data;
126 shouldBe('d[0]', '255');
127 shouldBe('d[1]', '0');
128 shouldBe('d[2]', '0');
129 shouldBeAround('d[3]', '53');
131 // Verify blurry alpha shadow.
132 d = ctx.getImageData(398, 405, 1, 1).data;
133 shouldBe('d[0]', '255');
134 shouldBe('d[1]', '0');
135 shouldBe('d[2]', '0');
136 shouldBeAround('d[3]', '24');
138 d = ctx.getImageData(405, 501, 1, 1).data;
139 shouldBe('d[0]', '255');
140 shouldBe('d[1]', '0');
141 shouldBe('d[2]', '0');
142 shouldBeAround('d[3]', '24');
144 d = ctx.getImageData(405, 501, 1, 1).data;
145 shouldBe('d[0]', '255');
146 shouldBe('d[1]', '0');
147 shouldBe('d[2]', '0');
148 shouldBeAround('d[3]', '24');