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

Side by Side Diff: LayoutTests/fast/canvas/script-tests/canvas-currentTransform.js

Issue 24233004: Support currentTransform in 2D Canvas. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Previous CL includes WIP file. Created 7 years, 3 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
(Empty)
1 description("Series of tests to ensure correct behaviour of canvas.currentTransf orm");
2 var ctx = document.createElement('canvas').getContext('2d');
3
4 var matrix = ctx.currentTransform;
5
6 debug("Check initial currentTransform values");
7 shouldBe("matrix.a", "1");
8 shouldBe("matrix.b", "0");
9 shouldBe("matrix.c", "0");
10 shouldBe("matrix.d", "1");
11 shouldBe("matrix.e", "0");
12 shouldBe("matrix.f", "0");
13
14 function setCurrentTransform(ctx, a, b, c, d, e, f)
15 {
16 matrix.a = a;
17 matrix.b = b;
18 matrix.c = c;
19 matrix.d = d;
20 matrix.e = e;
21 matrix.f = f;
22 ctx.currentTransform = matrix;
23 matrix = ctx.currentTransform;
24 shouldBe("matrix.a", "" + a);
25 shouldBe("matrix.b", "" + b);
26 shouldBe("matrix.c", "" + c);
27 shouldBe("matrix.d", "" + d);
28 shouldBe("matrix.e", "" + e);
29 shouldBe("matrix.f", "" + f);
30 }
31
32 matrix.a = 2;
33 debug("Changing matrix should not affect the CTM");
34 shouldBe("ctx.currentTransform.a", "1");
35 shouldBe("ctx.currentTransform.b", "0");
36 shouldBe("ctx.currentTransform.c", "0");
37 shouldBe("ctx.currentTransform.d", "1");
38 shouldBe("ctx.currentTransform.e", "0");
39 shouldBe("ctx.currentTransform.f", "0");
40
41 debug("Reset the CTM to the initial matrix");
42 ctx.beginPath();
43 ctx.scale(0.5, 0.5);
44 matrix = ctx.currentTransform;
45 shouldBe("matrix.a", "0.5");
46 shouldBe("matrix.b", "0");
47 shouldBe("matrix.c", "0");
48 shouldBe("matrix.d", "0.5");
49 shouldBe("matrix.e", "0");
50 shouldBe("matrix.f", "0");
51 setCurrentTransform(ctx, 1, 0, 0, 1, 0, 0);
52 ctx.fillStyle = 'green';
53 ctx.fillRect(0, 0, 100, 100);
54
55 var imageData = ctx.getImageData(1, 1, 98, 98);
56 var imgdata = imageData.data;
57 shouldBe("imgdata[4]", "0");
58 shouldBe("imgdata[5]", "128");
59 shouldBe("imgdata[6]", "0");
60
61 debug("currentTransform should not affect the current path");
62 ctx.beginPath();
63 ctx.rect(0,0,100,100);
64 ctx.save();
65 setCurrentTransform(ctx, 0.5, 0, 0, 0.5, 10, 10);
66 ctx.fillStyle = 'red';
67 ctx.fillRect(0, 0, 100, 100);
68 ctx.restore();
69 matrix = ctx.currentTransform;
70 shouldBe("matrix.a", "1");
71 shouldBe("matrix.b", "0");
72 shouldBe("matrix.c", "0");
73 shouldBe("matrix.d", "1");
74 shouldBe("matrix.e", "0");
75 shouldBe("matrix.f", "0");
76 ctx.fillStyle = 'green';
77 ctx.fillRect(0, 0, 100, 100);
78
79 imageData = ctx.getImageData(1, 1, 98, 98);
80 imgdata = imageData.data;
81 shouldBe("imgdata[4]", "0");
82 shouldBe("imgdata[5]", "128");
83 shouldBe("imgdata[6]", "0");
84
85 debug("currentTransform should not affect the CTM outside of save() and restore( )");
86 ctx.beginPath();
87 ctx.fillStyle = 'green';
88 ctx.save();
89 setCurrentTransform(ctx, 0.5, 0, 0, 0.5, 0, 0);
90 ctx.fillStyle = 'red';
91 ctx.fillRect(0, 0, 100, 100);
92 ctx.restore();
93 matrix = ctx.currentTransform;
94 shouldBe("matrix.a", "1");
95 shouldBe("matrix.b", "0");
96 shouldBe("matrix.c", "0");
97 shouldBe("matrix.d", "1");
98 shouldBe("matrix.e", "0");
99 shouldBe("matrix.f", "0");
100 ctx.fillRect(0, 0, 100, 100);
101
102 imageData = ctx.getImageData(1, 1, 98, 98);
103 imgdata = imageData.data;
104 shouldBe("imgdata[4]", "0");
105 shouldBe("imgdata[5]", "128");
106 shouldBe("imgdata[6]", "0");
107
108 debug("stop drawing on not-invertible CTM");
109 ctx.beginPath();
110 ctx.fillStyle = 'green';
111 ctx.fillRect(0, 0, 100, 100);
112 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0);
113 ctx.fillStyle = 'red';
114 ctx.fillRect(0, 0, 100, 100);
115
116 imageData = ctx.getImageData(1, 1, 98, 98);
117 imgdata = imageData.data;
118 shouldBe("imgdata[4]", "0");
119 shouldBe("imgdata[5]", "128");
120 shouldBe("imgdata[6]", "0");
121
122 debug("currentTransform with a not-invertible matrix should only stop the drawin g up to the next restore()");
123 ctx.beginPath();
124 ctx.resetTransform();
125 matrix = ctx.currentTransform;
126 shouldBe("matrix.a", "1");
127 shouldBe("matrix.b", "0");
128 shouldBe("matrix.c", "0");
129 shouldBe("matrix.d", "1");
130 shouldBe("matrix.e", "0");
131 shouldBe("matrix.f", "0");
132 ctx.save();
133 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0);
134 ctx.fillStyle = 'red';
135 ctx.fillRect(0, 0, 100, 100);
136 ctx.restore();
137 matrix = ctx.currentTransform;
138 shouldBe("matrix.a", "1");
139 shouldBe("matrix.b", "0");
140 shouldBe("matrix.c", "0");
141 shouldBe("matrix.d", "1");
142 shouldBe("matrix.e", "0");
143 shouldBe("matrix.f", "0");
144 ctx.fillStyle = 'blue';
145 ctx.fillRect(0, 0, 100, 100);
146
147 imageData = ctx.getImageData(1, 1, 98, 98);
148 imgdata = imageData.data;
149 shouldBe("imgdata[4]", "0");
150 shouldBe("imgdata[5]", "0");
151 shouldBe("imgdata[6]", "255");
152
153 debug("currentTransform should set transform although CTM is not-invertible");
154 ctx.beginPath();
155 ctx.fillStyle = 'red';
156 ctx.fillRect(0, 0, 100, 100);
157 setCurrentTransform(ctx, 0, 0, 0, 0, 0, 0);
158 ctx.fillStyle = 'green';
159 ctx.fillRect(0, 0, 100, 100);
160 setCurrentTransform(ctx, 1, 0, 0, 1, 0, 0);
161 ctx.fillStyle = 'blue';
162 ctx.fillRect(0, 0, 100, 100);
163
164 imageData = ctx.getImageData(1, 1, 98, 98);
165 imgdata = imageData.data;
166 shouldBe("imgdata[4]", "0");
167 shouldBe("imgdata[5]", "0");
168 shouldBe("imgdata[6]", "255");
169
170 debug("Check assigning an invalid object throws exception as expected");
171 shouldThrow("ctx.currentTransform = ctx", "'TypeError: Type error'");
172
173 debug("Check handling non-finite values. see 2d.transformation.setTransform.nonf inite.html");
174 ctx.fillStyle = 'red';
175 ctx.fillRect(0, 0, 100, 100);
176
177 function setCurrentTransformToNonfinite(ctx, a, b, c, d, e, f)
178 {
179 matrix.a = a;
180 matrix.b = b;
181 matrix.c = c;
182 matrix.d = d;
183 matrix.e = e;
184 matrix.f = f;
185 ctx.currentTransform = matrix;
186 matrix = ctx.currentTransform;
187 shouldBe("matrix.a", "1");
188 shouldBe("matrix.b", "0");
189 shouldBe("matrix.c", "0");
190 shouldBe("matrix.d", "1");
191 shouldBe("matrix.e", "100");
192 shouldBe("matrix.f", "10");
193 }
194
195 ctx.translate(100, 10);
196 matrix = ctx.currentTransform;
197 shouldBe("matrix.a", "1");
198 shouldBe("matrix.b", "0");
199 shouldBe("matrix.c", "0");
200 shouldBe("matrix.d", "1");
201 shouldBe("matrix.e", "100");
202 shouldBe("matrix.f", "10");
203 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, 0, 0);
204 setCurrentTransformToNonfinite(ctx, -Infinity, 0, 0, 0, 0, 0);
205 setCurrentTransformToNonfinite(ctx, NaN, 0, 0, 0, 0, 0);
206 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, 0, 0);
207 setCurrentTransformToNonfinite(ctx, 0, -Infinity, 0, 0, 0, 0);
208 setCurrentTransformToNonfinite(ctx, 0, NaN, 0, 0, 0, 0);
209 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, 0, 0);
210 setCurrentTransformToNonfinite(ctx, 0, 0, -Infinity, 0, 0, 0);
211 setCurrentTransformToNonfinite(ctx, 0, 0, NaN, 0, 0, 0);
212 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, 0, 0);
213 setCurrentTransformToNonfinite(ctx, 0, 0, 0, -Infinity, 0, 0);
214 setCurrentTransformToNonfinite(ctx, 0, 0, 0, NaN, 0, 0);
215 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, Infinity, 0);
216 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, -Infinity, 0);
217 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, NaN, 0);
218 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, Infinity);
219 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, -Infinity);
220 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, 0, NaN);
221 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, 0, 0);
222 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, 0, 0);
223 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, 0, 0 );
224 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, Infi nity, 0);
225 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, Infi nity, Infinity);
226 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, Infinity, 0, I nfinity);
227 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, Infinity, 0 );
228 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, Infinity, I nfinity);
229 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, Infinity, 0, 0, Infinity );
230 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, 0, 0);
231 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, Infinity, 0 );
232 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, Infinity, I nfinity);
233 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, Infinity, 0, Infinity );
234 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, Infinity, 0);
235 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, Infinity, Infinity );
236 setCurrentTransformToNonfinite(ctx, Infinity, Infinity, 0, 0, 0, Infinity);
237 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, 0, 0);
238 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, 0, 0);
239 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, Infinity, 0 );
240 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, Infinity, I nfinity);
241 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, Infinity, 0, Infinity );
242 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, Infinity, 0);
243 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, Infinity, Infinity );
244 setCurrentTransformToNonfinite(ctx, Infinity, 0, Infinity, 0, 0, Infinity);
245 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, 0, 0);
246 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, Infinity, 0);
247 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, Infinity, Infinity );
248 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, Infinity, 0, Infinity);
249 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, Infinity, 0);
250 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, Infinity, Infinity);
251 setCurrentTransformToNonfinite(ctx, Infinity, 0, 0, 0, 0, Infinity);
252 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, 0, 0);
253 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, 0, 0);
254 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, Infinity, 0 );
255 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, Infinity, I nfinity);
256 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, Infinity, 0, Infinity );
257 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, Infinity, 0);
258 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, Infinity, Infinity );
259 setCurrentTransformToNonfinite(ctx, 0, Infinity, Infinity, 0, 0, Infinity);
260 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, 0, 0);
261 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, Infinity, 0);
262 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, Infinity, Infinity );
263 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, Infinity, 0, Infinity);
264 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, Infinity, 0);
265 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, Infinity, Infinity);
266 setCurrentTransformToNonfinite(ctx, 0, Infinity, 0, 0, 0, Infinity);
267 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, 0, 0);
268 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, Infinity, 0);
269 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, Infinity, Infinity );
270 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, Infinity, 0, Infinity);
271 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, Infinity, 0);
272 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, Infinity, Infinity);
273 setCurrentTransformToNonfinite(ctx, 0, 0, Infinity, 0, 0, Infinity);
274 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, Infinity, 0);
275 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, Infinity, Infinity);
276 setCurrentTransformToNonfinite(ctx, 0, 0, 0, Infinity, 0, Infinity);
277 setCurrentTransformToNonfinite(ctx, 0, 0, 0, 0, Infinity, Infinity);
278 matrix = ctx.currentTransform;
279 shouldBe("matrix.a", "1");
280 shouldBe("matrix.b", "0");
281 shouldBe("matrix.c", "0");
282 shouldBe("matrix.d", "1");
283 shouldBe("matrix.e", "100");
284 shouldBe("matrix.f", "10");
285
286 ctx.fillStyle = 'green';
287 ctx.fillRect(-100, -10, 100, 100);
288
289 imageData = ctx.getImageData(1, 1, 98, 98);
290 imgdata = imageData.data;
291 shouldBe("imgdata[4]", "0");
292 shouldBe("imgdata[5]", "128");
293 shouldBe("imgdata[6]", "0");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698