3 import "testhelper.js" as Helper
5 id:canvas; width:100;height:50; renderTarget: Canvas.Image
8 name: "state"; when: windowShown
9 function test_bitmap() {
10 var ctx = canvas.getContext('2d');
12 ctx.fillStyle = '#f00';
13 ctx.fillRect(0, 0, 100, 50);
15 ctx.fillStyle = '#0f0';
16 ctx.fillRect(0, 0, 100, 50);
18 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
20 function test_clip() {
21 var ctx = canvas.getContext('2d');
24 ctx.fillStyle = '#f00';
25 ctx.fillRect(0, 0, 100, 50);
30 ctx.fillStyle = '#0f0';
31 ctx.fillRect(0, 0, 100, 50);
32 //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
35 function test_fillStyle() {
36 var ctx = canvas.getContext('2d');
38 // Test that restore() undoes any modifications
39 var old = ctx.fillStyle;
41 ctx.fillStyle = "#ff0000";
43 compare(ctx.fillStyle, old);
45 // Also test that save() doesn't modify the values
46 ctx.fillStyle = "#ff0000";
48 // we're not interested in failures caused by get(set(x)) != x (e.g.
49 // from rounding), so compare against 'old' instead of against "#ff0000"
51 compare(ctx.fillStyle, old);
54 function test_font() {
55 var ctx = canvas.getContext('2d');
58 // Test that restore() undoes any modifications
61 ctx.font = "25px serif";
63 compare(ctx.font, old);
65 // Also test that save() doesn't modify the values
66 ctx.font = "25px serif";
68 // we're not interested in failures caused by get(set(x)) != x (e.g.
69 // from rounding), so compare against 'old' instead of against "25px serif"
71 compare(ctx.font, old);
74 function test_globalAlpha() {
75 var ctx = canvas.getContext('2d');
78 // Test that restore() undoes any modifications
79 var old = ctx.globalAlpha;
81 ctx.globalAlpha = 0.5;
83 compare(ctx.globalAlpha, old);
85 // Also test that save() doesn't modify the values
86 ctx.globalAlpha = 0.5;
87 old = ctx.globalAlpha;
88 // we're not interested in failures caused by get(set(x)) != x (e.g.
89 // from rounding), so compare against 'old' instead of against 0.5
91 compare(ctx.globalAlpha, old);
94 function test_globalCompositeOperation() {
95 var ctx = canvas.getContext('2d');
98 // Test that restore() undoes any modifications
99 var old = ctx.globalCompositeOperation;
101 ctx.globalCompositeOperation = "copy";
103 compare(ctx.globalCompositeOperation, old);
105 // Also test that save() doesn't modify the values
106 ctx.globalCompositeOperation = "copy";
107 old = ctx.globalCompositeOperation;
108 // we're not interested in failures caused by get(set(x)) != x (e.g.
109 // from rounding), so compare against 'old' instead of against "copy"
111 compare(ctx.globalCompositeOperation, old);
114 function test_lineCap() {
115 var ctx = canvas.getContext('2d');
118 // Test that restore() undoes any modifications
119 var old = ctx.lineCap;
121 ctx.lineCap = "round";
123 compare(ctx.lineCap, old);
125 // Also test that save() doesn't modify the values
126 ctx.lineCap = "round";
128 // we're not interested in failures caused by get(set(x)) != x (e.g.
129 // from rounding), so compare against 'old' instead of against "round"
131 compare(ctx.lineCap, old);
134 function test_lineJoin() {
135 var ctx = canvas.getContext('2d');
138 // Test that restore() undoes any modifications
139 var old = ctx.lineJoin;
141 ctx.lineJoin = "round";
143 compare(ctx.lineJoin, old);
145 // Also test that save() doesn't modify the values
146 ctx.lineJoin = "round";
148 // we're not interested in failures caused by get(set(x)) != x (e.g.
149 // from rounding), so compare against 'old' instead of against "round"
151 compare(ctx.lineJoin, old);
154 function test_lineWidth() {
155 var ctx = canvas.getContext('2d');
158 // Test that restore() undoes any modifications
159 var old = ctx.lineJoin;
161 ctx.lineJoin = "round";
163 compare(ctx.lineJoin, old, "ctx.lineJoin", "old");
165 // Also test that save() doesn't modify the values
166 ctx.lineJoin = "round";
168 // we're not interested in failures caused by get(set(x)) != x (e.g.
169 // from rounding), so compare against 'old' instead of against "round"
171 compare(ctx.lineJoin, old);
174 function test_miterLimit() {
175 var ctx = canvas.getContext('2d');
178 // Test that restore() undoes any modifications
179 var old = ctx.miterLimit;
181 ctx.miterLimit = 0.5;
183 compare(ctx.miterLimit, old);
185 // Also test that save() doesn't modify the values
186 ctx.miterLimit = 0.5;
187 old = ctx.miterLimit;
188 // we're not interested in failures caused by get(set(x)) != x (e.g.
189 // from rounding), so compare against 'old' instead of against 0.5
191 compare(ctx.miterLimit, old);
194 function test_path() {
195 var ctx = canvas.getContext('2d');
198 ctx.fillStyle = '#f00';
199 ctx.fillRect(0, 0, 100, 50);
201 ctx.rect(0, 0, 100, 50);
203 ctx.fillStyle = '#0f0';
205 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
207 function test_shadow() {
208 var ctx = canvas.getContext('2d');
211 // Test that restore() undoes any modifications
212 var old = ctx.shadowBlur;
216 compare(ctx.shadowBlur, old);
218 // Also test that save() doesn't modify the values
220 old = ctx.shadowBlur;
221 // we're not interested in failures caused by get(set(x)) != x (e.g.
222 // from rounding), so compare against 'old' instead of against 5
224 compare(ctx.shadowBlur, old);
227 // Test that restore() undoes any modifications
228 var old = ctx.shadowColor;
230 ctx.shadowColor = "#ff0000";
232 compare(ctx.shadowColor, old);
234 // Also test that save() doesn't modify the values
235 ctx.shadowColor = "#ff0000";
236 old = ctx.shadowColor;
237 // we're not interested in failures caused by get(set(x)) != x (e.g.
238 // from rounding), so compare against 'old' instead of against "#ff0000"
240 compare(ctx.shadowColor, old);
243 // Test that restore() undoes any modifications
244 var old = ctx.shadowOffsetX;
246 ctx.shadowOffsetX = 5;
248 compare(ctx.shadowOffsetX, old);
250 // Also test that save() doesn't modify the values
251 ctx.shadowOffsetX = 5;
252 old = ctx.shadowOffsetX;
253 // we're not interested in failures caused by get(set(x)) != x (e.g.
254 // from rounding), so compare against 'old' instead of against 5
256 compare(ctx.shadowOffsetX, old);
259 // Test that restore() undoes any modifications
260 var old = ctx.shadowOffsetY;
262 ctx.shadowOffsetY = 5;
264 compare(ctx.shadowOffsetY, old);
266 // Also test that save() doesn't modify the values
267 ctx.shadowOffsetY = 5;
268 old = ctx.shadowOffsetY;
269 // we're not interested in failures caused by get(set(x)) != x (e.g.
270 // from rounding), so compare against 'old' instead of against 5
272 compare(ctx.shadowOffsetY, old);
276 function test_stack() {
277 var ctx = canvas.getContext('2d');
285 compare(ctx.lineWidth, 3);
287 compare(ctx.lineWidth, 2);
289 compare(ctx.lineWidth, 1);
292 for (var i = 1; i < limit; ++i)
297 for (var i = limit-1; i > 0; --i)
299 testCase.compare(ctx.lineWidth, i); //strange javascript error here
303 for (var i = 0; i < 16; ++i)
307 compare(ctx.lineWidth, 0.5);
310 function test_strokeStyle() {
311 var ctx = canvas.getContext('2d');
314 // Test that restore() undoes any modifications
315 var old = ctx.strokeStyle;
317 ctx.strokeStyle = "#ff0000";
319 compare(ctx.strokeStyle, old);
321 // Also test that save() doesn't modify the values
322 ctx.strokeStyle = "#ff0000";
323 old = ctx.strokeStyle;
324 // we're not interested in failures caused by get(set(x)) != x (e.g.
325 // from rounding), so compare against 'old' instead of against "#ff0000"
327 compare(ctx.strokeStyle, old);
333 function test_text() {
334 var ctx = canvas.getContext('2d');
337 // Test that restore() undoes any modifications
338 var old = ctx.textAlign;
340 ctx.textAlign = "center";
342 compare(ctx.textAlign, old);
344 // Also test that save() doesn't modify the values
345 ctx.textAlign = "center";
347 // we're not interested in failures caused by get(set(x)) != x (e.g.
348 // from rounding), so compare against 'old' instead of against "center"
350 compare(ctx.textAlign, old);
353 // Test that restore() undoes any modifications
354 var old = ctx.textBaseline;
356 ctx.textBaseline = "bottom";
358 compare(ctx.textBaseline, old);
360 // Also test that save() doesn't modify the values
361 ctx.textBaseline = "bottom";
362 old = ctx.textBaseline;
363 // we're not interested in failures caused by get(set(x)) != x (e.g.
364 // from rounding), so compare against 'old' instead of against "bottom"
366 compare(ctx.textBaseline, old);
372 function test_transform() {
373 var ctx = canvas.getContext('2d');
376 ctx.fillStyle = '#0f0';
377 ctx.fillRect(0, 0, 100, 50);
379 ctx.translate(200, 0);
381 ctx.fillStyle = '#f00';
382 ctx.fillRect(-200, 0, 100, 50);
383 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));