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

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

Issue 11448034: Updating Canvas test to use the most common syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library CanvasTest; 1 library CanvasTest;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:html'; 4 import 'dart:html';
5 5
6 main() { 6 main() {
7 CanvasElement canvas; 7 CanvasElement canvas;
8 CanvasRenderingContext2D context; 8 CanvasRenderingContext2D context;
9 int width = 100; 9 int width = 100;
10 int height = 100; 10 int height = 100;
11 11
12 canvas = new Element.tag('canvas'); 12 canvas = new CanvasElement(width:width, height:height);
13 canvas.attributes['width'] = width;
14 canvas.attributes['height'] = height;
15 document.body.nodes.add(canvas); 13 document.body.nodes.add(canvas);
16 14
17 context = canvas.context2d; 15 context = canvas.context2d;
18 16
19 useHtmlConfiguration(); 17 useHtmlConfiguration();
20 test('CreateImageData', () { 18 test('CreateImageData', () {
21 ImageData image = context.createImageData(canvas.width, 19 ImageData image = context.createImageData(canvas.width,
22 canvas.height); 20 canvas.height);
23 Uint8ClampedArray data = image.data; 21 Uint8ClampedArray data = image.data;
24 22
25 expect(data, hasLength(40000)); 23 expect(data, hasLength(40000));
26 checkPixel(data, 0, [0, 0, 0, 0]); 24 checkPixel(data, 0, [0, 0, 0, 0]);
27 checkPixel(data, width * height - 1, [0, 0, 0, 0]); 25 checkPixel(data, width * height - 1, [0, 0, 0, 0]);
28 26
29 data[100] = 200; 27 data[100] = 200;
30 expect(data[100], equals(200)); 28 expect(data[100], equals(200));
31 }); 29 });
32 } 30 }
33 31
34 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) 32 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba)
35 { 33 {
36 offset *= 4; 34 offset *= 4;
37 for (var i = 0; i < 4; ++i) { 35 for (var i = 0; i < 4; ++i) {
38 expect(data[offset + i], equals(rgba[i])); 36 expect(data[offset + i], equals(rgba[i]));
39 } 37 }
40 } 38 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698