1 description("Ensure correct behavior of canvas with fillRect+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)';
40 ctx.fillRect(50, 50, 50, 50);
42 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
43 ctx.fillRect(50, 150, 50, 50);
45 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
47 ctx.fillRect(150, 50, 50, 50);
49 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
50 ctx.fillRect(150, 150, 50, 50);
52 var d; // imageData.data
54 // Verify solid shadow.
55 d = ctx.getImageData(201, 205, 1, 1).data;
56 shouldBe('d[0]', '255');
57 shouldBe('d[1]', '0');
58 shouldBe('d[2]', '0');
59 shouldBe('d[3]', '255');
61 d = ctx.getImageData(298, 298, 1, 1).data;
62 shouldBe('d[0]', '255');
63 shouldBe('d[1]', '0');
64 shouldBe('d[2]', '0');
65 shouldBe('d[3]', '255');
67 d = ctx.getImageData(201, 298, 1, 1).data;
68 shouldBe('d[0]', '255');
69 shouldBe('d[1]', '0');
70 shouldBe('d[2]', '0');
71 shouldBe('d[3]', '255');
73 // Verify solid alpha shadow.
74 d = ctx.getImageData(201, 405, 1, 1).data;
75 shouldBe('d[0]', '255');
76 shouldBe('d[1]', '0');
77 shouldBe('d[2]', '0');
78 shouldBeAround('d[3]', '76');
80 d = ctx.getImageData(298, 405, 1, 1).data;
81 shouldBe('d[0]', '255');
82 shouldBe('d[1]', '0');
83 shouldBe('d[2]', '0');
84 shouldBeAround('d[3]', '76');
86 d = ctx.getImageData(205, 498, 1, 1).data;
87 shouldBe('d[0]', '255');
88 shouldBe('d[1]', '0');
89 shouldBe('d[2]', '0');
90 shouldBeAround('d[3]', '76');
92 // Verify blurry shadow.
93 d = ctx.getImageData(398, 205, 1, 1).data;
94 shouldBe('d[0]', '255');
95 shouldBe('d[1]', '0');
96 shouldBe('d[2]', '0');
97 shouldBeAround('d[3]', '83');
99 d = ctx.getImageData(501, 205, 1, 1).data;
100 shouldBe('d[0]', '255');
101 shouldBe('d[1]', '0');
102 shouldBe('d[2]', '0');
103 shouldBeAround('d[3]', '83');
105 d = ctx.getImageData(500, 300, 1, 1).data;
106 shouldBe('d[0]', '255');
107 shouldBe('d[1]', '0');
108 shouldBe('d[2]', '0');
109 shouldBeAround('d[3]', '53');
111 // Verify blurry alpha shadow.
112 d = ctx.getImageData(398, 405, 1, 1).data;
113 shouldBe('d[0]', '255');
114 shouldBe('d[1]', '0');
115 shouldBe('d[2]', '0');
116 shouldBeAround('d[3]', '24');
118 d = ctx.getImageData(405, 501, 1, 1).data;
119 shouldBe('d[0]', '255');
120 shouldBe('d[1]', '0');
121 shouldBe('d[2]', '0');
122 shouldBeAround('d[3]', '24');
124 d = ctx.getImageData(405, 501, 1, 1).data;
125 shouldBe('d[0]', '255');
126 shouldBe('d[1]', '0');
127 shouldBe('d[2]', '0');
128 shouldBeAround('d[3]', '24');