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';
8 ctx.strokeRect(50, 0, 100, 100, 100);
10 var imageData = ctx.getImageData(1, 1, 98, 98);
11 var imgdata = imageData.data;
12 shouldBe("imgdata[4]", "0");
13 shouldBe("imgdata[5]", "128");
14 shouldBe("imgdata[6]", "0");
16 ctx.clearRect(0, 0, 100, 100);
18 // stroke rect with a pattern
19 debug("Test canvas.strokeRect() with a pattern.");
20 var canvas2 = document.createElement('canvas');
23 var ctx2 = canvas2.getContext('2d');
24 ctx2.fillStyle = 'green';
25 ctx2.fillRect(0, 0, 100, 100);
26 var pattern = ctx.createPattern(canvas2, 'repeat');
27 ctx.strokeStyle = 'pattern';
28 ctx.strokeRect(50, 0, 100, 100, 100);
30 imageData = ctx.getImageData(1, 1, 98, 98);
31 imgdata = imageData.data;
32 shouldBe("imgdata[4]", "0");
33 shouldBe("imgdata[5]", "128");
34 shouldBe("imgdata[6]", "0");
36 ctx.clearRect(0, 0, 100, 100);
38 // stroke rect with gradient
39 debug("Test canvas.strokeRect() with a gradient.");
40 var gradient = ctx.createLinearGradient(0, 0, 0, 100);
41 gradient.addColorStop(0, "green");
42 gradient.addColorStop(1, "green");
43 ctx.strokeStyle = 'gradient';
44 ctx.strokeRect(50, 0, 100, 100, 100);
46 imageData = ctx.getImageData(1, 1, 98, 98);
47 imgdata = imageData.data;
48 shouldBe("imgdata[4]", "0");
49 shouldBe("imgdata[5]", "128");
50 shouldBe("imgdata[6]", "0");
52 ctx.clearRect(0, 0, 100, 100);
54 // stroke rect with height = width = 0 and lineWidth = 2.
55 debug("Test canvas.strokeRect() with height = width = 0 and lineWidth = 2.");
56 ctx.strokeStyle = 'red';
58 ctx.strokeRect(0, 0, 0, 0);
59 imageData = ctx.getImageData(0, 0, 1, 1);
60 imgdata = imageData.data;
61 shouldBe("imgdata[0]", "0");
62 shouldBe("imgdata[1]", "0");
63 shouldBe("imgdata[2]", "0");
65 // stroke rect with height = width = 0, lineWidth = 2, and shadow.
66 debug("Test canvas.strokeRect() with height = width = 0, lineWidth = 2, and shadow.");
67 ctx.shadowOffsetX = 5;
68 ctx.shadowOffsetY = 5;
69 ctx.shadowColor = 'blue';
70 ctx.strokeStyle = 'red';
72 ctx.strokeRect(0, 0, 0, 0);
73 imageData = ctx.getImageData(0, 0, 1, 1);
74 imgdata = imageData.data;
75 shouldBe("imgdata[0]", "0");
76 shouldBe("imgdata[1]", "0");
77 shouldBe("imgdata[2]", "0");