1 description("Test of save and restore on canvas graphics context.");
3 var canvas = document.createElement("canvas");
4 var context = canvas.getContext('2d');
8 var hexDigits = "0123456789abcdef";
9 return hexDigits[number >> 4] + hexDigits[number & 0xF];
14 var imageData = context.getImageData(0, 0, 1, 1);
15 return "#" + hex(imageData.data[0]) + hex(imageData.data[1]) + hex(imageData.data[2]);
20 var green = "#008000";
23 context.fillStyle = "black";
24 context.fillRect(0, 0, 1, 1);
25 shouldBe("pixel()", "black");
28 context.fillStyle = "red";
29 context.fillRect(0, 0, 1, 1);
30 shouldBe("pixel()", "red");
33 context.fillRect(0, 0, 1, 1);
34 shouldBe("pixel()", "black");
37 // (save (save set restore) restore)
38 context.fillStyle = "black";
39 context.fillRect(0, 0, 1, 1);
40 shouldBe("pixel()", "black");
45 context.fillStyle = "red";
46 context.fillRect(0, 0, 1, 1);
47 shouldBe("pixel()", "red");
50 context.fillRect(0, 0, 1, 1);
51 shouldBe("pixel()", "black");
54 context.fillRect(0, 0, 1, 1);
55 shouldBe("pixel()", "black");
58 // (save (save restore) set restore)
59 context.fillStyle = "black";
60 context.fillRect(0, 0, 1, 1);
61 shouldBe("pixel()", "black");
67 context.fillStyle = "red";
68 context.fillRect(0, 0, 1, 1);
69 shouldBe("pixel()", "red");
72 context.fillRect(0, 0, 1, 1);
73 shouldBe("pixel()", "black");
76 // (save (save (save set restore) set (save set restore) restore) restore)
77 context.fillStyle = "black";
78 context.fillRect(0, 0, 1, 1);
79 shouldBe("pixel()", "black");
82 context.fillRect(0, 0, 1, 1);
83 shouldBe("pixel()", "black");
86 context.fillStyle = "red";
87 context.fillRect(0, 0, 1, 1);
88 shouldBe("pixel()", "red");
91 context.fillRect(0, 0, 1, 1);
92 shouldBe("pixel()", "black");
94 context.fillStyle = "green";
95 context.fillRect(0, 0, 1, 1);
96 shouldBe("pixel()", "green");
99 context.fillRect(0, 0, 1, 1);
100 shouldBe("pixel()", "green");
102 context.fillStyle = "red";
103 context.fillRect(0, 0, 1, 1);
104 shouldBe("pixel()", "red");
107 context.fillRect(0, 0, 1, 1);
108 shouldBe("pixel()", "green");
111 context.fillRect(0, 0, 1, 1);
112 shouldBe("pixel()", "black");
115 context.fillRect(0, 0, 1, 1);
116 shouldBe("pixel()", "black");
119 // (save (save set (save (save set restore) restore) set restore) restore)
120 context.fillStyle = "black";
121 context.fillRect(0, 0, 1, 1);
122 shouldBe("pixel()", "black");
125 context.fillRect(0, 0, 1, 1);
126 shouldBe("pixel()", "black");
129 context.fillStyle = "red";
130 context.fillRect(0, 0, 1, 1);
131 shouldBe("pixel()", "red");
134 context.fillRect(0, 0, 1, 1);
135 shouldBe("pixel()", "red");
138 context.fillStyle = "green";
139 context.fillRect(0, 0, 1, 1);
140 shouldBe("pixel()", "green");
143 context.fillRect(0, 0, 1, 1);
144 shouldBe("pixel()", "red");
147 context.fillRect(0, 0, 1, 1);
148 shouldBe("pixel()", "red");
150 context.fillStyle = "green";
151 context.fillRect(0, 0, 1, 1);
152 shouldBe("pixel()", "green");
155 context.fillRect(0, 0, 1, 1);
156 shouldBe("pixel()", "black");
159 context.fillRect(0, 0, 1, 1);
160 shouldBe("pixel()", "black");