1 description("Ensure correct behavior of canvas with path fill 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 function shouldNotBe(a, b)
23 print("PASS " + a + " should not be " + b + " and it's not.", "green")
25 print("FAIL " + a + " should not be " + b + " but it is.", "red");
28 var canvas = document.createElement('canvas');
29 document.body.appendChild(canvas);
30 canvas.setAttribute('width', '700');
31 canvas.setAttribute('height', '700');
32 var ctx = canvas.getContext('2d');
37 ctx.bezierCurveTo(200, 40, 75, 150, 30, 30);
38 ctx.quadraticCurveTo(250, 75, 50, 300);
39 ctx.shadowOffsetX = 350;
40 ctx.shadowColor = 'rgba(255, 20, 0, 0.5)';
42 ctx.fillStyle = 'rgba(0, 0, 255, 1)';
49 ctx.bezierCurveTo(200, 390, 75, 500, 30, 380);
50 ctx.quadraticCurveTo(250, 425, 50, 650);
51 ctx.shadowOffsetX = 350;
52 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
54 ctx.fillStyle = 'rgba(0, 0, 255, 1)';
60 // Verify solid shadow.
61 imageData = ctx.getImageData(640, 290, 1, 1);
62 data = imageData.data;
63 shouldBe('data[0]', '255');
64 shouldBe('data[1]', '20');
65 shouldBe('data[2]', '0');
67 imageData = ctx.getImageData(570, 85, 1, 1);
68 data = imageData.data;
69 shouldBe('data[0]', '255');
70 shouldBe('data[1]', '20');
71 shouldBe('data[2]', '0');
73 imageData = ctx.getImageData(380, 30, 1, 1);
74 data = imageData.data;
75 shouldBe('data[0]', '255');
76 shouldBeCloseTo('data[1]', 20, 3);
77 shouldBe('data[2]', '0');
79 imageData = ctx.getImageData(400, 40, 1, 1);
80 data = imageData.data;
81 shouldBe('data[0]', '255');
82 shouldBe('data[1]', '20');
83 shouldBe('data[2]', '0');
85 // Verify blurry shadow.
86 imageData = ctx.getImageData(640, 640, 1, 1);
87 data = imageData.data;
88 shouldBe('data[0]', '255');
89 shouldBe('data[1]', '0');
90 shouldBe('data[2]', '0');
91 shouldNotBe('data[3]', '255');
93 imageData = ctx.getImageData(650, 400, 1, 1);
94 data = imageData.data;
95 shouldBe('data[0]', '255');
96 shouldBe('data[1]', '0');
97 shouldBe('data[2]', '0');
98 shouldNotBe('data[3]', '255');
100 imageData = ctx.getImageData(380, 380, 1, 1);
101 data = imageData.data;
102 shouldBe('data[0]', '255');
103 shouldBe('data[1]', '0');
104 shouldBe('data[2]', '0');
105 shouldNotBe('data[3]', '255');
107 imageData = ctx.getImageData(375, 390, 1, 1);
108 data = imageData.data;
109 shouldBe('data[0]', '255');
110 shouldBe('data[1]', '0');
111 shouldBe('data[2]', '0');
112 shouldNotBe('data[3]', '255');