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

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

Issue 10178014: Copy lib/dom tests that use dart:html to lib/html. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 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
(Empty)
1 #library('CanvasTest');
2 #import('../../lib/unittest/unittest.dart');
3 #import('../../lib/unittest/html_config.dart');
4 #import('dart:html');
5
6 main() {
7 CanvasElement canvas;
8 CanvasRenderingContext2D context;
9 int width = 100;
10 int height = 100;
11
12 canvas = new Element.tag('canvas');
13 canvas.attributes['width'] = width;
14 canvas.attributes['height'] = height;
15 document.body.nodes.add(canvas);
16
17 context = canvas.getContext('2d');
18
19 useHtmlConfiguration();
20 test('FillStyle', () {
21 context.fillStyle = "red";
22 context.fillRect(10, 10, 20, 20);
23
24 Uint8ClampedArray data = context.getImageData(0, 0, width, height).data;
25 checkPixel(data, 0, [0, 0, 0, 0]);
26 checkPixel(data, 9 + width * 10, [0, 0, 0, 0]);
27 checkPixel(data, 10 + width * 10, [255, 0, 0, 255]);
28 checkPixel(data, 29 + width * 10, [255, 0, 0, 255]);
29 checkPixel(data, 30 + width * 10, [0, 0, 0, 0]);
30 });
31 test('FillStyleGradient', () {
32 var gradient = context.createLinearGradient(0,0,20,20);
33 gradient.addColorStop(0,'red');
34 gradient.addColorStop(1,'blue');
35 context.fillStyle = gradient;
36 context.fillRect(0, 0, 20, 20);
37 expect(context.fillStyle is CanvasGradient).isTrue();
38 });
39 test('SetFillColor', () {
40 // With floats.
41 context.setFillColor(10, 10, 10, 10);
42 context.fillRect(10, 10, 20, 20);
43
44 // With rationals.
45 context.setFillColor(10.0, 10.0, 10.0, 10.0);
46 context.fillRect(20, 20, 30, 30);
47
48 // With ints.
49 context.setFillColor(10, 10, 10, 10);
50 context.fillRect(30, 30, 40, 40);
51
52 // TODO(vsm): Verify the result once we have the ability to read pixels.
53 });
54 test('StrokeStyle', () {
55 context.strokeStyle = "blue";
56 context.strokeRect(30, 30, 10, 20);
57
58 // TODO(vsm): Verify the result once we have the ability to read pixels.
59 });
60 test('CreateImageData', () {
61 ImageData image = context.createImageData(canvas.width,
62 canvas.height);
63 Uint8ClampedArray data = image.data;
64
65 Expect.equals(40000, data.length);
66 checkPixel(data, 0, [0, 0, 0, 0]);
67 checkPixel(data, width * height - 1, [0, 0, 0, 0]);
68
69 data[100] = 200;
70 Expect.equals(200, data[100]);
71 });
72 test('PutImageData', () {
73 ImageData data = context.getImageData(0, 0, width, height);
74 data.data[0] = 25;
75 data.data[3] = 255;
76 context.putImageData(data, 0, 0);
77
78 data = context.getImageData(0, 0, width, height);
79 Expect.equals(25, data.data[0]);
80 Expect.equals(255, data.data[3]);
81 });
82 }
83
84 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba)
85 {
86 offset *= 4;
87 for (var i = 0; i < 4; ++i) {
88 Expect.equals(rgba[i], data[offset + i]);
89 }
90 }
OLDNEW
« no previous file with comments | « tests/dom/canvas_pixel_array_type_alias_test.dart ('k') | tests/dom/canvas_using_html_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698