1 description("Series of tests to ensure correct behaviour of canvas.strokeRect()");
2 var ctx = document.createElement('canvas').getContext('2d');
4 // stroke rect with solid green
5 debug("Test canvas.strokeRect() with solid green.");
7 ctx.strokeStyle = 'green';
9 ctx.strokeRect(50, 0, 100, 100);
11 var imageData = ctx.getImageData(1, 1, 98, 98);
12 var imgdata = imageData.data;
13 shouldBe("imgdata[4]", "0");
14 shouldBe("imgdata[5]", "128");
15 shouldBe("imgdata[6]", "0");
17 ctx.clearRect(0, 0, 100, 100);
19 // stroke rect with a pattern
20 debug("Test canvas.strokeRect() with a pattern.");
21 var canvas2 = document.createElement('canvas');
24 var ctx2 = canvas2.getContext('2d');
25 ctx2.fillStyle = 'green';
26 ctx2.fillRect(0, 0, 100, 100);
27 var pattern = ctx.createPattern(canvas2, 'repeat');
28 ctx.strokeStyle = 'pattern';
30 ctx.strokeRect(50, 0, 100, 100);
32 imageData = ctx.getImageData(1, 1, 98, 98);
33 imgdata = imageData.data;
34 shouldBe("imgdata[4]", "0");
35 shouldBe("imgdata[5]", "128");
36 shouldBe("imgdata[6]", "0");
38 ctx.clearRect(0, 0, 100, 100);
40 // stroke rect with gradient
41 debug("Test canvas.strokeRect() with a gradient.");
42 var gradient = ctx.createLinearGradient(0, 0, 0, 100);
43 gradient.addColorStop(0, "green");
44 gradient.addColorStop(1, "green");
45 ctx.strokeStyle = 'gradient';
47 ctx.strokeRect(50, 0, 100, 100);
49 imageData = ctx.getImageData(1, 1, 98, 98);
50 imgdata = imageData.data;
51 shouldBe("imgdata[4]", "0");
52 shouldBe("imgdata[5]", "128");
53 shouldBe("imgdata[6]", "0");
55 ctx.clearRect(0, 0, 100, 100);
57 // stroke rect with height = width = 0 and lineWidth = 2.
58 debug("Test canvas.strokeRect() with height = width = 0 and lineWidth = 2.");
59 ctx.strokeStyle = 'red';
61 ctx.strokeRect(0, 0, 0, 0);
62 imageData = ctx.getImageData(0, 0, 1, 1);
63 imgdata = imageData.data;
64 shouldBe("imgdata[0]", "0");
65 shouldBe("imgdata[1]", "0");
66 shouldBe("imgdata[2]", "0");
68 // stroke rect with height = width = 0, lineWidth = 2, and shadow.
69 debug("Test canvas.strokeRect() with height = width = 0, lineWidth = 2, and shadow.");
70 ctx.shadowOffsetX = 5;
71 ctx.shadowOffsetY = 5;
72 ctx.shadowColor = 'blue';
73 ctx.strokeStyle = 'red';
75 ctx.strokeRect(0, 0, 0, 0);
76 imageData = ctx.getImageData(0, 0, 1, 1);
77 imgdata = imageData.data;
78 shouldBe("imgdata[0]", "0");
79 shouldBe("imgdata[1]", "0");
80 shouldBe("imgdata[2]", "0");