1 description("Test that the rendering context's strokeStyle and fillStyle are intact after calling strokeText() and fillText()");
2 var ctx = document.createElement('canvas').getContext('2d');
5 ctx.fillRect(0, 0, 1, 1);
7 debug("Checking initial state for sanity");
8 var imageData = ctx.getImageData(0, 0, 2, 1);
9 var imgdata = imageData.data;
10 shouldBe("ctx.fillStyle", "'#ff0000'");
11 shouldBe("imgdata[0]", "255");
12 shouldBe("imgdata[1]", "0");
13 shouldBe("imgdata[2]", "0");
14 shouldBe("imgdata[3]", "255");
15 shouldBe("imgdata[4]", "0");
16 shouldBe("imgdata[5]", "0");
17 shouldBe("imgdata[6]", "0");
18 shouldBe("imgdata[7]", "0");
20 debug("Calling fillText() to try and break the strokeStyle.");
21 ctx.strokeStyle = 'green';
23 ctx.fillStyle = 'red';
24 ctx.fillText("X", 0, 0);
25 shouldBe("ctx.strokeStyle", "'#008000'");
30 imageData = ctx.getImageData(2, 2, 1, 1);
31 imgdata = imageData.data;
32 shouldBe("imgdata[0]", "0");
33 shouldBe("imgdata[1]", "128");
34 shouldBe("imgdata[2]", "0");
35 shouldBe("imgdata[3]", "255");
37 debug("Calling strokeText() to try and break the fillStyle.");
38 ctx.strokeStyle = 'red';
40 ctx.fillStyle = 'green';
41 ctx.strokeText("X", 0, 0);
42 shouldBe("ctx.fillStyle", "'#008000'");
43 ctx.fillRect(0, 0, 10, 10);
44 imageData = ctx.getImageData(2, 2, 1, 1);
45 imgdata = imageData.data;
46 shouldBe("imgdata[0]", "0");
47 shouldBe("imgdata[1]", "128");
48 shouldBe("imgdata[2]", "0");
49 shouldBe("imgdata[3]", "255");