OLD | NEW |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | 3 <body> |
7 <script src="script-tests/canvas-currentTransform.js"></script> | 4 <script> |
5 test(function(t) { | |
6 var ctx = document.createElement('canvas').getContext('2d'); | |
7 | |
8 var matrix = ctx.currentTransform; | |
9 assert_equals(matrix.a, 1); | |
10 assert_equals(matrix.b, 0); | |
11 assert_equals(matrix.c, 0); | |
12 assert_equals(matrix.d, 1); | |
13 assert_equals(matrix.e, 0); | |
14 assert_equals(matrix.f, 0); | |
15 | |
16 function setCurrentTransform(ctx, a, b, c, d, e, f) | |
17 { | |
18 matrix.a = a; | |
19 matrix.b = b; | |
20 matrix.c = c; | |
21 matrix.d = d; | |
22 matrix.e = e; | |
23 matrix.f = f; | |
24 ctx.currentTransform = matrix; | |
25 matrix.a = NaN; | |
26 matrix.b = NaN; | |
27 matrix.c = NaN; | |
28 matrix.d = NaN; | |
29 matrix.e = NaN; | |
30 matrix.f = NaN; | |
31 matrix = ctx.currentTransform; | |
32 assert_equals(matrix.a, a); | |
33 assert_equals(matrix.b, b); | |
34 assert_equals(matrix.c, c); | |
35 assert_equals(matrix.d, d); | |
36 assert_equals(matrix.e, e); | |
37 assert_equals(matrix.f, f); | |
38 } | |
39 | |
40 matrix.a = 2; | |
41 | |
42 assert_equals(ctx.currentTransform.a, 1); | |
43 assert_equals(ctx.currentTransform.b, 0); | |
44 assert_equals(ctx.currentTransform.c, 0); | |
45 assert_equals(ctx.currentTransform.d, 1); | |
46 assert_equals(ctx.currentTransform.e, 0); | |
47 assert_equals(ctx.currentTransform.f, 0); | |
48 | |
49 | |
50 ctx.beginPath(); | |
51 ctx.scale(0.5, 0.5); | |
52 matrix = ctx.currentTransform; | |
53 assert_equals(matrix.a, 0.5); | |
54 assert_equals(matrix.b, 0); | |
55 assert_equals(matrix.c, 0); | |
56 assert_equals(matrix.d, 0.5); | |
57 assert_equals(matrix.e, 0); | |
58 assert_equals(matrix.f, 0); | |
59 setCurrentTransform(ctx, 1, 0, 0, 1, 0, 0); | |
60 ctx.fillStyle = 'green'; | |
61 ctx.fillRect(0, 0, 100, 100); | |
62 | |
63 var imageData = ctx.getImageData(1, 1, 98, 98); | |
64 var imgdata = imageData.data; | |
65 assert_equals(imgdata[4], 0); | |
66 assert_equals(imgdata[5], 128); | |
67 assert_equals(imgdata[6], 0); | |
68 | |
69 | |
70 ctx.beginPath(); | |
71 ctx.rect(0,0,100,100); | |
72 ctx.save(); | |
73 setCurrentTransform(ctx, 0.5, 0, 0, 0.5, 10, 10); | |
74 ctx.fillStyle = 'red'; | |
75 ctx.fillRect(0, 0, 100, 100); | |
76 ctx.restore(); | |
77 matrix = ctx.currentTransform; | |
78 assert_equals(matrix.a, 1); | |
79 assert_equals(matrix.b, 0); | |
80 assert_equals(matrix.c, 0); | |
81 assert_equals(matrix.d, 1); | |
82 assert_equals(matrix.e, 0); | |
83 assert_equals(matrix.f, 0); | |
84 ctx.fillStyle = 'green'; | |
85 ctx.fillRect(0, 0, 100, 100); | |
86 | |
87 imageData = ctx.getImageData(1, 1, 98, 98); | |
88 imgdata = imageData.data; | |
89 assert_equals(imgdata[4], 0); | |
90 assert_equals(imgdata[5], 128); | |
91 assert_equals(imgdata[6], 0); | |
92 | |
93 | |
94 ctx.beginPath(); | |
95 ctx.fillStyle = 'green'; | |
96 ctx.save(); | |
97 setCurrentTransform(ctx, 0.5, 0, 0, 0.5, 0, 0); | |
98 ctx.fillStyle = 'red'; | |
99 ctx.fillRect(0, 0, 100, 100); | |
100 ctx.restore(); | |
101 matrix = ctx.currentTransform; | |
102 assert_equals(matrix.a, 1); | |
103 assert_equals(matrix.b, 0); | |
104 assert_equals(matrix.c, 0); | |
105 assert_equals(matrix.d, 1); | |
106 assert_equals(matrix.e, 0); | |
107 assert_equals(matrix.f, 0); | |
108 ctx.fillRect(0, 0, 100, 100); | |
109 | |
110 imageData = ctx.getImageData(1, 1, 98, 98); | |
111 imgdata = imageData.data; | |
112 assert_equals(imgdata[4], 0); | |
113 assert_equals(imgdata[5], 128); | |
114 assert_equals(imgdata[6], 0); | |
115 | |
116 | |
117 ctx.beginPath(); | |
118 ctx.fillStyle = 'green'; | |
119 ctx.fillRect(0, 0, 100, 100); | |
120 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0); | |
121 ctx.fillStyle = 'red'; | |
122 ctx.fillRect(0, 0, 100, 100); | |
123 | |
124 imageData = ctx.getImageData(1, 1, 98, 98); | |
125 imgdata = imageData.data; | |
126 assert_equals(imgdata[4], 0); | |
127 assert_equals(imgdata[5], 128); | |
128 assert_equals(imgdata[6], 0); | |
129 | |
130 | |
131 ctx.beginPath(); | |
132 ctx.resetTransform(); | |
133 matrix = ctx.currentTransform; | |
134 assert_equals(matrix.a, 1); | |
135 assert_equals(matrix.b, 0); | |
136 assert_equals(matrix.c, 0); | |
137 assert_equals(matrix.d, 1); | |
138 assert_equals(matrix.e, 0); | |
139 assert_equals(matrix.f, 0); | |
140 ctx.save(); | |
141 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0); | |
142 ctx.fillStyle = 'red'; | |
143 ctx.fillRect(0, 0, 100, 100); | |
144 ctx.restore(); | |
145 matrix = ctx.currentTransform; | |
146 assert_equals(matrix.a, 1); | |
147 assert_equals(matrix.b, 0); | |
148 assert_equals(matrix.c, 0); | |
149 assert_equals(matrix.d, 1); | |
150 assert_equals(matrix.e, 0); | |
151 assert_equals(matrix.f, 0); | |
152 ctx.fillStyle = 'blue'; | |
153 ctx.fillRect(0, 0, 100, 100); | |
154 | |
155 imageData = ctx.getImageData(1, 1, 98, 98); | |
156 imgdata = imageData.data; | |
157 assert_equals(imgdata[4], 0); | |
158 assert_equals(imgdata[5], 0); | |
159 assert_equals(imgdata[6], 255); | |
160 | |
161 ctx.beginPath(); | |
162 ctx.fillStyle = 'red'; | |
163 ctx.fillRect(0, 0, 100, 100); | |
164 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0); | |
165 ctx.fillStyle = 'green'; | |
166 ctx.fillRect(0, 0, 100, 100); | |
167 setCurrentTransform(ctx, 1, 0, 0, 1, 0, 0); | |
168 ctx.fillStyle = 'blue'; | |
169 ctx.fillRect(0, 0, 100, 100); | |
170 | |
171 imageData = ctx.getImageData(1, 1, 98, 98); | |
172 imgdata = imageData.data; | |
173 assert_equals(imgdata[4], 0); | |
174 assert_equals(imgdata[5], 0); | |
175 assert_equals(imgdata[6], 255); | |
176 | |
177 setCurrentTransform(ctx, 1, 0, 0, 1, 1, 2); | |
178 ctx.scale(0, 0); | |
179 matrix = ctx.currentTransform; | |
180 assert_equals(matrix.a, 0); | |
181 assert_equals(matrix.b, 0); | |
182 assert_equals(matrix.c, 0); | |
183 assert_equals(matrix.d, 0); | |
184 assert_equals(matrix.e, 1); | |
185 assert_equals(matrix.f, 2); | |
186 setCurrentTransform(ctx, 1, 0, 0, 1, 0, 0); | |
187 | |
188 // throws: TypeError: Failed to set the \'currentTransform\' property on \'C anvasRenderingContext2D\': The provided value is not of type \'SVGMatrix\'. | |
189 assert_throws(null, function() {ctx.currentTransform = ctx;}); | |
190 // throws: TypeError: Failed to set the \'currentTransform\' property on \'C anvasRenderingContext2D\': The provided value is not of type \'SVGMatrix\'. | |
191 assert_throws(null, function() {ctx.currentTransform = undefined;}); | |
192 // throws: TypeError: Failed to set the \'currentTransform\' property on \'C anvasRenderingContext2D\': The provided value is not of type \'SVGMatrix\'. | |
193 assert_throws(null, function() {ctx.currentTransform = null;}); | |
194 | |
195 ctx.fillStyle = 'red'; | |
196 ctx.fillRect(0, 0, 100, 100); | |
197 | |
198 function setCurrentTransformToNonfinite(parameters) | |
199 { | |
200 ctx = parameters[0]; | |
201 matrix.a = parameters[1]; | |
202 matrix.b = parameters[2]; | |
203 matrix.c = parameters[3]; | |
204 matrix.d = parameters[4]; | |
205 matrix.e = parameters[5]; | |
206 matrix.f = parameters[6]; | |
207 ctx.currentTransform = matrix; | |
208 matrix.a = NaN; | |
209 matrix.b = NaN; | |
210 matrix.c = NaN; | |
211 matrix.d = NaN; | |
212 matrix.e = NaN; | |
213 matrix.f = NaN; | |
214 matrix = ctx.currentTransform; | |
215 assert_equals(matrix.a, 1); | |
216 assert_equals(matrix.b, 0); | |
217 assert_equals(matrix.c, 0); | |
218 assert_equals(matrix.d, 1); | |
219 assert_equals(matrix.e, 100); | |
220 assert_equals(matrix.f, 10); | |
221 } | |
222 | |
223 ctx.translate(100, 10); | |
224 matrix = ctx.currentTransform; | |
225 assert_equals(matrix.a, 1); | |
226 assert_equals(matrix.b, 0); | |
227 assert_equals(matrix.c, 0); | |
228 assert_equals(matrix.d, 1); | |
229 assert_equals(matrix.e, 100); | |
230 assert_equals(matrix.f, 10); | |
231 | |
232 testScenarios = [ | |
233 ['', [ctx, Infinity, 0, 0, 0, 0, 0]], | |
Justin Novosad
2017/02/08 20:19:29
The scenarios should have names so that a reported
zakerinasab
2017/02/09 15:39:50
Done.
| |
234 ['', [ctx, -Infinity, 0, 0, 0, 0, 0]], | |
235 ['', [ctx, NaN, 0, 0, 0, 0, 0]], | |
236 ['', [ctx, 0, Infinity, 0, 0, 0, 0]], | |
237 ['', [ctx, 0, -Infinity, 0, 0, 0, 0]], | |
238 ['', [ctx, 0, NaN, 0, 0, 0, 0]], | |
239 ['', [ctx, 0, 0, Infinity, 0, 0, 0]], | |
240 ['', [ctx, 0, 0, -Infinity, 0, 0, 0]], | |
241 ['', [ctx, 0, 0, NaN, 0, 0, 0]], | |
242 ['', [ctx, 0, 0, 0, Infinity, 0, 0]], | |
243 ['', [ctx, 0, 0, 0, -Infinity, 0, 0]], | |
244 ['', [ctx, 0, 0, 0, NaN, 0, 0]], | |
245 ['', [ctx, 0, 0, 0, 0, Infinity, 0]], | |
246 ['', [ctx, 0, 0, 0, 0, -Infinity, 0]], | |
247 ['', [ctx, 0, 0, 0, 0, NaN, 0]], | |
248 ['', [ctx, 0, 0, 0, 0, 0, Infinity]], | |
249 ['', [ctx, 0, 0, 0, 0, 0, -Infinity]], | |
250 ['', [ctx, 0, 0, 0, 0, 0, NaN]], | |
251 ['', [ctx, Infinity, Infinity, 0, 0, 0, 0]], | |
252 ['', [ctx, Infinity, Infinity, Infinity, 0, 0, 0]], | |
253 ['', [ctx, Infinity, Infinity, Infinity, Infinity, 0, 0]], | |
254 ['', [ctx, Infinity, Infinity, Infinity, Infinity, Infinity, 0]], | |
255 ['', [ctx, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]], | |
256 ['', [ctx, Infinity, Infinity, Infinity, Infinity, 0, Infinity]], | |
257 ['', [ctx, Infinity, Infinity, Infinity, 0, Infinity, 0]], | |
258 ['', [ctx, Infinity, Infinity, Infinity, 0, Infinity, Infinity]], | |
259 ['', [ctx, Infinity, Infinity, Infinity, 0, 0, Infinity]], | |
260 ['', [ctx, Infinity, Infinity, 0, Infinity, 0, 0]], | |
261 ['', [ctx, Infinity, Infinity, 0, Infinity, Infinity, 0]], | |
262 ['', [ctx, Infinity, Infinity, 0, Infinity, Infinity, Infinity]], | |
263 ['', [ctx, Infinity, Infinity, 0, Infinity, 0, Infinity]], | |
264 ['', [ctx, Infinity, Infinity, 0, 0, Infinity, 0]], | |
265 ['', [ctx, Infinity, Infinity, 0, 0, Infinity, Infinity]], | |
266 ['', [ctx, Infinity, Infinity, 0, 0, 0, Infinity]], | |
267 ['', [ctx, Infinity, 0, Infinity, 0, 0, 0]], | |
268 ['', [ctx, Infinity, 0, Infinity, Infinity, 0, 0]], | |
269 ['', [ctx, Infinity, 0, Infinity, Infinity, Infinity, 0]], | |
270 ['', [ctx, Infinity, 0, Infinity, Infinity, Infinity, Infinity]], | |
271 ['', [ctx, Infinity, 0, Infinity, Infinity, 0, Infinity]], | |
272 ['', [ctx, Infinity, 0, Infinity, 0, Infinity, 0]], | |
273 ['', [ctx, Infinity, 0, Infinity, 0, Infinity, Infinity]], | |
274 ['', [ctx, Infinity, 0, Infinity, 0, 0, Infinity]], | |
275 ['', [ctx, Infinity, 0, 0, Infinity, 0, 0]], | |
276 ['', [ctx, Infinity, 0, 0, Infinity, Infinity, 0]], | |
277 ['', [ctx, Infinity, 0, 0, Infinity, Infinity, Infinity]], | |
278 ['', [ctx, Infinity, 0, 0, Infinity, 0, Infinity]], | |
279 ['', [ctx, Infinity, 0, 0, 0, Infinity, 0]], | |
280 ['', [ctx, Infinity, 0, 0, 0, Infinity, Infinity]], | |
281 ['', [ctx, Infinity, 0, 0, 0, 0, Infinity]], | |
282 ['', [ctx, 0, Infinity, Infinity, 0, 0, 0]], | |
283 ['', [ctx, 0, Infinity, Infinity, Infinity, 0, 0]], | |
284 ['', [ctx, 0, Infinity, Infinity, Infinity, Infinity, 0]], | |
285 ['', [ctx, 0, Infinity, Infinity, Infinity, Infinity, Infinity]], | |
286 ['', [ctx, 0, Infinity, Infinity, Infinity, 0, Infinity]], | |
287 ['', [ctx, 0, Infinity, Infinity, 0, Infinity, 0]], | |
288 ['', [ctx, 0, Infinity, Infinity, 0, Infinity, Infinity]], | |
289 ['', [ctx, 0, Infinity, Infinity, 0, 0, Infinity]], | |
290 ['', [ctx, 0, Infinity, 0, Infinity, 0, 0]], | |
291 ['', [ctx, 0, Infinity, 0, Infinity, Infinity, 0]], | |
292 ['', [ctx, 0, Infinity, 0, Infinity, Infinity, Infinity]], | |
293 ['', [ctx, 0, Infinity, 0, Infinity, 0, Infinity]], | |
294 ['', [ctx, 0, Infinity, 0, 0, Infinity, 0]], | |
295 ['', [ctx, 0, Infinity, 0, 0, Infinity, Infinity]], | |
296 ['', [ctx, 0, Infinity, 0, 0, 0, Infinity]], | |
297 ['', [ctx, 0, 0, Infinity, Infinity, 0, 0]], | |
298 ['', [ctx, 0, 0, Infinity, Infinity, Infinity, 0]], | |
299 ['', [ctx, 0, 0, Infinity, Infinity, Infinity, Infinity]], | |
300 ['', [ctx, 0, 0, Infinity, Infinity, 0, Infinity]], | |
301 ['', [ctx, 0, 0, Infinity, 0, Infinity, 0]], | |
302 ['', [ctx, 0, 0, Infinity, 0, Infinity, Infinity]], | |
303 ['', [ctx, 0, 0, Infinity, 0, 0, Infinity]], | |
304 ['', [ctx, 0, 0, 0, Infinity, Infinity, 0]], | |
305 ['', [ctx, 0, 0, 0, Infinity, Infinity, Infinity]], | |
306 ['', [ctx, 0, 0, 0, Infinity, 0, Infinity]], | |
307 ['', [ctx, 0, 0, 0, 0, Infinity, Infinity]] | |
308 ] | |
309 generate_tests(setCurrentTransformToNonfinite, testScenarios); | |
310 | |
311 matrix = ctx.currentTransform; | |
312 assert_equals(matrix.a, 1); | |
313 assert_equals(matrix.b, 0); | |
314 assert_equals(matrix.c, 0); | |
315 assert_equals(matrix.d, 1); | |
316 assert_equals(matrix.e, 100); | |
317 assert_equals(matrix.f, 10); | |
318 | |
319 ctx.fillStyle = 'green'; | |
320 ctx.fillRect(-100, -10, 100, 100); | |
321 | |
322 imageData = ctx.getImageData(1, 1, 98, 98); | |
323 imgdata = imageData.data; | |
324 assert_equals(imgdata[4], 0); | |
325 assert_equals(imgdata[5], 128); | |
326 assert_equals(imgdata[6], 0); | |
327 }, "Series of tests to ensure correct behaviour of canvas.currentTransform"); | |
328 </script> | |
8 </body> | 329 </body> |
9 </html> | |
OLD | NEW |