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

Side by Side Diff: tests/html/canvasrenderingcontext2d_test.dart

Issue 15138002: Added tests to previously broken functionality and added null checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes t.dart'; 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes t.dart';
6 import '../../pkg/unittest/lib/html_individual_config.dart'; 6 import '../../pkg/unittest/lib/html_individual_config.dart';
7 import 'dart:html'; 7 import 'dart:html';
8 import 'dart:math'; 8 import 'dart:math';
9 9
10 // Some rounding errors in the browsers. 10 // Some rounding errors in the browsers.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 test('fillStyle linearGradient', () { 152 test('fillStyle linearGradient', () {
153 var gradient = context.createLinearGradient(0,0,20,20); 153 var gradient = context.createLinearGradient(0,0,20,20);
154 gradient.addColorStop(0,'red'); 154 gradient.addColorStop(0,'red');
155 gradient.addColorStop(1,'blue'); 155 gradient.addColorStop(1,'blue');
156 context.fillStyle = gradient; 156 context.fillStyle = gradient;
157 context.fillRect(0, 0, canvas.width, canvas.height); 157 context.fillRect(0, 0, canvas.width, canvas.height);
158 expect(context.fillStyle is CanvasGradient, isTrue); 158 expect(context.fillStyle is CanvasGradient, isTrue);
159 }); 159 });
160 160
161 test('putImageData', () { 161 test('putImageData', () {
162 context.fillStyle = 'green';
163 context.fillRect(0, 0, canvas.width, canvas.height);
164
162 ImageData expectedData = context.getImageData(0, 0, 10, 10); 165 ImageData expectedData = context.getImageData(0, 0, 10, 10);
163 expectedData.data[0] = 25; 166 expectedData.data[0] = 25;
164 expectedData.data[1] = 65; 167 expectedData.data[1] = 65;
165 expectedData.data[2] = 255; 168 expectedData.data[2] = 255;
166 // Set alpha to 255 to make the pixels show up. 169 // Set alpha to 255 to make the pixels show up.
167 expectedData.data[3] = 255; 170 expectedData.data[3] = 255;
168 context.fillStyle = 'green';
169 context.fillRect(0, 0, canvas.width, canvas.height);
170 171
171 context.putImageData(expectedData, 0, 0); 172 context.putImageData(expectedData, 0, 0);
172 173
173 var resultingData = context.getImageData(0, 0, 10, 10); 174 var resultingData = context.getImageData(0, 0, 10, 10);
174 // Make sure that we read back what we wrote. 175 // Make sure that we read back what we wrote.
175 expect(resultingData.data, expectedData.data); 176 expect(resultingData.data, expectedData.data);
176 }); 177 });
178
179 test('putImageData dirty rectangle', () {
180 context.fillStyle = 'green';
181 context.fillRect(0, 0, canvas.width, canvas.height);
182
183 ImageData drawnData = context.getImageData(0, 0, 10, 10);
184 drawnData.data[0] = 25;
185 drawnData.data[1] = 65;
186 drawnData.data[2] = 255;
187 drawnData.data[3] = 255;
188
189 // Draw these pixels to the 2nd pixel.
190 drawnData.data[2 * 4 + 0] = 25;
191 drawnData.data[2 * 4 + 1] = 65;
192 drawnData.data[2 * 4 + 2] = 255;
193 drawnData.data[2 * 4 + 3] = 255;
194
195 // Draw these pixels to the 8th pixel.
196 drawnData.data[7 * 4 + 0] = 25;
197 drawnData.data[7 * 4 + 1] = 65;
198 drawnData.data[7 * 4 + 2] = 255;
199 drawnData.data[7 * 4 + 3] = 255;
200
201 // Use a dirty rectangle to limit what pixels are drawn.
202 context.putImageData(drawnData, 0, 0, 1, 0, 5, 5);
203
204 // Expect the data to be all green, as we skip all drawn pixels.
205 ImageData expectedData = context.createImageData(10, 10);
206 for (int i = 0; i < expectedData.data.length; i++) {
207 switch (i % 4) {
208 case 0:
209 expectedData.data[i] = 0;
210 break;
211 case 1:
212 expectedData.data[i] = 128;
213 break;
214 case 2:
215 expectedData.data[i] = 0;
216 break;
217 case 3:
218 expectedData.data[i] = 255;
219 break;
220 }
221 }
222 // Third pixel was copied.
223 expectedData.data[2 * 4 + 0] = 25;
224 expectedData.data[2 * 4 + 1] = 65;
225 expectedData.data[2 * 4 + 2] = 255;
226 expectedData.data[2 * 4 + 3] = 255;
227
228 // Make sure that our data is all green.
229 var resultingData = context.getImageData(0, 0, 10, 10);
230 expect(resultingData.data, expectedData.data);
231 });
232
233 test('putImageData throws with wrong number of arguments', () {
234 ImageData expectedData = context.getImageData(0, 0, 10, 10);
235
236 expect(() => context.putImageData(expectedData, 0, 0, 1),
237 throwsArgumentError);
238 expect(() => context.putImageData(expectedData, 0, 0, 1, 1),
239 throwsArgumentError);
240 expect(() => context.putImageData(expectedData, 0, 0, 1, 1, 5),
241 throwsArgumentError);
242 });
177 }); 243 });
178 244
179 group('arc', () { 245 group('arc', () {
180 setUp(setupFunc); 246 setUp(setupFunc);
181 tearDown(tearDownFunc); 247 tearDown(tearDownFunc);
182 248
183 test('default arc should be clockwise', () { 249 test('default arc should be clockwise', () {
184 context.beginPath(); 250 context.beginPath();
185 final r = 10; 251 final r = 10;
186 252
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 var imageData = context.createImageData(15, 15); 662 var imageData = context.createImageData(15, 15);
597 expect(imageData.width, 15); 663 expect(imageData.width, 15);
598 expect(imageData.height, 15); 664 expect(imageData.height, 15);
599 665
600 var other = context.createImageDataFromImageData(imageData); 666 var other = context.createImageDataFromImageData(imageData);
601 expect(other.width, 15); 667 expect(other.width, 15);
602 expect(other.height, 15); 668 expect(other.height, 15);
603 }); 669 });
604 }); 670 });
605 } 671 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698