Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-currentTransform.html

Issue 2675763005: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Addressing comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ['Case 1' , [ctx, Infinity, 0, 0, 0, 0, 0]],
234 ['Case 2' , [ctx, -Infinity, 0, 0, 0, 0, 0]],
235 ['Case 3' , [ctx, NaN, 0, 0, 0, 0, 0]],
236 ['Case 4' , [ctx, 0, Infinity, 0, 0, 0, 0]],
237 ['Case 5' , [ctx, 0, -Infinity, 0, 0, 0, 0]],
238 ['Case 6' , [ctx, 0, NaN, 0, 0, 0, 0]],
239 ['Case 7' , [ctx, 0, 0, Infinity, 0, 0, 0]],
240 ['Case 8' , [ctx, 0, 0, -Infinity, 0, 0, 0]],
241 ['Case 9' , [ctx, 0, 0, NaN, 0, 0, 0]],
242 ['Case 10' , [ctx, 0, 0, 0, Infinity, 0, 0]],
243 ['Case 11' , [ctx, 0, 0, 0, -Infinity, 0, 0]],
244 ['Case 12' , [ctx, 0, 0, 0, NaN, 0, 0]],
245 ['Case 13' , [ctx, 0, 0, 0, 0, Infinity, 0]],
246 ['Case 14' , [ctx, 0, 0, 0, 0, -Infinity, 0]],
247 ['Case 15' , [ctx, 0, 0, 0, 0, NaN, 0]],
248 ['Case 16' , [ctx, 0, 0, 0, 0, 0, Infinity]],
249 ['Case 17' , [ctx, 0, 0, 0, 0, 0, -Infinity]],
250 ['Case 18' , [ctx, 0, 0, 0, 0, 0, NaN]],
251 ['Case 19' , [ctx, Infinity, Infinity, 0, 0, 0, 0]],
252 ['Case 20' , [ctx, Infinity, Infinity, Infinity, 0, 0, 0]],
253 ['Case 21' , [ctx, Infinity, Infinity, Infinity, Infinity, 0, 0]],
254 ['Case 22' , [ctx, Infinity, Infinity, Infinity, Infinity, Infinity, 0]] ,
255 ['Case 23' , [ctx, Infinity, Infinity, Infinity, Infinity, Infinity, Inf inity]],
256 ['Case 24' , [ctx, Infinity, Infinity, Infinity, Infinity, 0, Infinity]] ,
257 ['Case 25' , [ctx, Infinity, Infinity, Infinity, 0, Infinity, 0]],
258 ['Case 26' , [ctx, Infinity, Infinity, Infinity, 0, Infinity, Infinity]] ,
259 ['Case 27' , [ctx, Infinity, Infinity, Infinity, 0, 0, Infinity]],
260 ['Case 28' , [ctx, Infinity, Infinity, 0, Infinity, 0, 0]],
261 ['Case 29' , [ctx, Infinity, Infinity, 0, Infinity, Infinity, 0]],
262 ['Case 30' , [ctx, Infinity, Infinity, 0, Infinity, Infinity, Infinity]] ,
263 ['Case 31' , [ctx, Infinity, Infinity, 0, Infinity, 0, Infinity]],
264 ['Case 32' , [ctx, Infinity, Infinity, 0, 0, Infinity, 0]],
265 ['Case 33' , [ctx, Infinity, Infinity, 0, 0, Infinity, Infinity]],
266 ['Case 34' , [ctx, Infinity, Infinity, 0, 0, 0, Infinity]],
267 ['Case 35' , [ctx, Infinity, 0, Infinity, 0, 0, 0]],
268 ['Case 36' , [ctx, Infinity, 0, Infinity, Infinity, 0, 0]],
269 ['Case 37' , [ctx, Infinity, 0, Infinity, Infinity, Infinity, 0]],
270 ['Case 38' , [ctx, Infinity, 0, Infinity, Infinity, Infinity, Infinity]] ,
271 ['Case 39' , [ctx, Infinity, 0, Infinity, Infinity, 0, Infinity]],
272 ['Case 40' , [ctx, Infinity, 0, Infinity, 0, Infinity, 0]],
273 ['Case 41' , [ctx, Infinity, 0, Infinity, 0, Infinity, Infinity]],
274 ['Case 42' , [ctx, Infinity, 0, Infinity, 0, 0, Infinity]],
275 ['Case 43' , [ctx, Infinity, 0, 0, Infinity, 0, 0]],
276 ['Case 44' , [ctx, Infinity, 0, 0, Infinity, Infinity, 0]],
277 ['Case 45' , [ctx, Infinity, 0, 0, Infinity, Infinity, Infinity]],
278 ['Case 46' , [ctx, Infinity, 0, 0, Infinity, 0, Infinity]],
279 ['Case 47' , [ctx, Infinity, 0, 0, 0, Infinity, 0]],
280 ['Case 48' , [ctx, Infinity, 0, 0, 0, Infinity, Infinity]],
281 ['Case 49' , [ctx, Infinity, 0, 0, 0, 0, Infinity]],
282 ['Case 50' , [ctx, 0, Infinity, Infinity, 0, 0, 0]],
283 ['Case 51' , [ctx, 0, Infinity, Infinity, Infinity, 0, 0]],
284 ['Case 52' , [ctx, 0, Infinity, Infinity, Infinity, Infinity, 0]],
285 ['Case 53' , [ctx, 0, Infinity, Infinity, Infinity, Infinity, Infinity]] ,
286 ['Case 54' , [ctx, 0, Infinity, Infinity, Infinity, 0, Infinity]],
287 ['Case 55' , [ctx, 0, Infinity, Infinity, 0, Infinity, 0]],
288 ['Case 56' , [ctx, 0, Infinity, Infinity, 0, Infinity, Infinity]],
289 ['Case 57' , [ctx, 0, Infinity, Infinity, 0, 0, Infinity]],
290 ['Case 58' , [ctx, 0, Infinity, 0, Infinity, 0, 0]],
291 ['Case 59' , [ctx, 0, Infinity, 0, Infinity, Infinity, 0]],
292 ['Case 60' , [ctx, 0, Infinity, 0, Infinity, Infinity, Infinity]],
293 ['Case 61' , [ctx, 0, Infinity, 0, Infinity, 0, Infinity]],
294 ['Case 62' , [ctx, 0, Infinity, 0, 0, Infinity, 0]],
295 ['Case 63' , [ctx, 0, Infinity, 0, 0, Infinity, Infinity]],
296 ['Case 64' , [ctx, 0, Infinity, 0, 0, 0, Infinity]],
297 ['Case 65' , [ctx, 0, 0, Infinity, Infinity, 0, 0]],
298 ['Case 66' , [ctx, 0, 0, Infinity, Infinity, Infinity, 0]],
299 ['Case 67' , [ctx, 0, 0, Infinity, Infinity, Infinity, Infinity]],
300 ['Case 68' , [ctx, 0, 0, Infinity, Infinity, 0, Infinity]],
301 ['Case 69' , [ctx, 0, 0, Infinity, 0, Infinity, 0]],
302 ['Case 70' , [ctx, 0, 0, Infinity, 0, Infinity, Infinity]],
303 ['Case 71' , [ctx, 0, 0, Infinity, 0, 0, Infinity]],
304 ['Case 72' , [ctx, 0, 0, 0, Infinity, Infinity, 0]],
305 ['Case 73' , [ctx, 0, 0, 0, Infinity, Infinity, Infinity]],
306 ['Case 74' , [ctx, 0, 0, 0, Infinity, 0, Infinity]],
307 ['Case 75' , [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>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698