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

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: Corrections 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(ctx, a, b, c, d, e, f)
199 {
200 matrix.a = a;
201 matrix.b = b;
202 matrix.c = c;
203 matrix.d = d;
204 matrix.e = e;
205 matrix.f = f;
206 ctx.currentTransform = matrix;
207 matrix.a = NaN;
208 matrix.b = NaN;
209 matrix.c = NaN;
210 matrix.d = NaN;
211 matrix.e = NaN;
212 matrix.f = NaN;
213 matrix = ctx.currentTransform;
214 assert_equals(matrix.a, 1);
215 assert_equals(matrix.b, 0);
216 assert_equals(matrix.c, 0);
217 assert_equals(matrix.d, 1);
218 assert_equals(matrix.e, 100);
219 assert_equals(matrix.f, 10);
220 }
221
222 ctx.translate(100, 10);
223 matrix = ctx.currentTransform;
224 assert_equals(matrix.a, 1);
225 assert_equals(matrix.b, 0);
226 assert_equals(matrix.c, 0);
227 assert_equals(matrix.d, 1);
228 assert_equals(matrix.e, 100);
229 assert_equals(matrix.f, 10);
230 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, 0, 0);
Justin Novosad 2017/02/08 18:23:33 this would be a really good place to use generate_
zakerinasab 2017/02/08 19:57:50 Done.
231 setCurrentTransformToNonfinite(ctx, -Infinity, 0, 0, 0, 0, 0);
232 setCurrentTransformToNonfinite(ctx, NaN, 0, 0, 0, 0, 0);
233 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, 0, 0);
234 setCurrentTransformToNonfinite(ctx, 0, -Infinity, 0, 0, 0, 0);
235 setCurrentTransformToNonfinite(ctx, 0, NaN, 0, 0, 0, 0);
236 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, 0, 0);
237 setCurrentTransformToNonfinite(ctx, 0, 0, -Infinity, 0, 0, 0);
238 setCurrentTransformToNonfinite(ctx, 0, 0, NaN, 0, 0, 0);
239 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, 0, 0);
240 setCurrentTransformToNonfinite(ctx, 0, 0, 0, -Infinity, 0, 0);
241 setCurrentTransformToNonfinite(ctx, 0, 0, 0, NaN, 0, 0);
242 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, Infinity, 0);
243 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, -Infinity, 0);
244 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, NaN, 0);
245 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, Infinity);
246 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, -Infinity);
247 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, NaN);
248 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, 0, 0);
249 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, 0, 0);
250 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, 0, 0);
251 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, Infinity, 0);
252 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity);
253 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, 0, Infinity);
254 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, Infinit y, 0);
255 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, Infinit y, Infinity);
256 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, 0, Infi nity);
257 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, 0, 0);
258 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, Infinit y, 0);
259 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, Infinit y, Infinity);
260 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, 0, Infi nity);
261 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, Infinity, 0);
262 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, Infinity, Infi nity);
263 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, 0, Infinity);
264 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, 0, 0);
265 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, 0, 0);
266 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, Infinit y, 0);
267 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, Infinit y, Infinity);
268 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, 0, Infi nity);
269 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, Infinity, 0);
270 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, Infinity, Infi nity);
271 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, 0, Infinity);
272 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, 0, 0);
273 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, Infinity, 0);
274 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, Infinity, Infi nity);
275 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, 0, Infinity);
276 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, Infinity, 0);
277 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, Infinity, Infinity);
278 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, 0, Infinity);
279 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, 0, 0);
280 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, 0, 0);
281 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, Infinit y, 0);
282 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, Infinit y, Infinity);
283 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, 0, Infi nity);
284 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, Infinity, 0);
285 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, Infinity, Infi nity);
286 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, 0, Infinity);
287 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, 0, 0);
288 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, Infinity, 0);
289 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, Infinity, Infi nity);
290 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, 0, Infinity);
291 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, Infinity, 0);
292 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, Infinity, Infinity);
293 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, 0, Infinity);
294 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, 0, 0);
295 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, Infinity, 0);
296 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, Infinity, Infi nity);
297 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, 0, Infinity);
298 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, Infinity, 0);
299 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, Infinity, Infinity);
300 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, 0, Infinity);
301 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, Infinity, 0);
302 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, Infinity, Infinity);
303 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, 0, Infinity);
304 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, Infinity, Infinity);
305 matrix = ctx.currentTransform;
306 assert_equals(matrix.a, 1);
307 assert_equals(matrix.b, 0);
308 assert_equals(matrix.c, 0);
309 assert_equals(matrix.d, 1);
310 assert_equals(matrix.e, 100);
311 assert_equals(matrix.f, 10);
312
313 ctx.fillStyle = 'green';
314 ctx.fillRect(-100, -10, 100, 100);
315
316 imageData = ctx.getImageData(1, 1, 98, 98);
317 imgdata = imageData.data;
318 assert_equals(imgdata[4], 0);
319 assert_equals(imgdata[5], 128);
320 assert_equals(imgdata[6], 0);
321 }, "Series of tests to ensure correct behaviour of canvas.currentTransform");
322 </script>
8 </body> 323 </body>
9 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698