OLD | NEW |
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; |
(...skipping 10 matching lines...) Expand all Loading... |
21 List<int> data = image.data; | 21 List<int> data = image.data; |
22 | 22 |
23 expect(data, hasLength(40000)); | 23 expect(data, hasLength(40000)); |
24 checkPixel(data, 0, [0, 0, 0, 0]); | 24 checkPixel(data, 0, [0, 0, 0, 0]); |
25 checkPixel(data, width * height - 1, [0, 0, 0, 0]); | 25 checkPixel(data, width * height - 1, [0, 0, 0, 0]); |
26 | 26 |
27 data[100] = 200; | 27 data[100] = 200; |
28 expect(data[100], equals(200)); | 28 expect(data[100], equals(200)); |
29 }); | 29 }); |
30 | 30 |
31 // TODO(antonm): enable again. | |
32 if (false) | |
33 test('toDataUrl', () { | 31 test('toDataUrl', () { |
34 var canvas = new CanvasElement(width: 100, height: 100); | 32 var canvas = new CanvasElement(width: 100, height: 100); |
35 var context = canvas.context2d; | 33 var context = canvas.context2d; |
36 context.fillStyle = 'red'; | 34 context.fillStyle = 'red'; |
37 context.fill(); | 35 context.fill(); |
38 | 36 |
39 var url = canvas.toDataUrl('image/png'); | 37 var url = canvas.toDataUrl('image/png'); |
40 | 38 |
41 var img = new ImageElement(); | 39 var img = new ImageElement(); |
42 img.onLoad.listen(expectAsync1((_) { | 40 img.onLoad.listen(expectAsync1((_) { |
43 expect(img.complete, true); | 41 expect(img.complete, true); |
44 })); | 42 })); |
45 img.onError.listen((_) { | 43 img.onError.listen((_) { |
46 guardAsync(() { | 44 guardAsync(() { |
47 expect(true, isFalse, reason: 'URL failed to load.'); | 45 expect(true, isFalse, reason: 'URL failed to load.'); |
48 }); | 46 }); |
49 }); | 47 }); |
50 img.src = url; | 48 img.src = url; |
51 }); | 49 }); |
52 } | 50 } |
53 | 51 |
54 void checkPixel(List<int> data, int offset, List<int> rgba) | 52 void checkPixel(List<int> data, int offset, List<int> rgba) |
55 { | 53 { |
56 offset *= 4; | 54 offset *= 4; |
57 for (var i = 0; i < 4; ++i) { | 55 for (var i = 0; i < 4; ++i) { |
58 expect(data[offset + i], equals(rgba[i])); | 56 expect(data[offset + i], equals(rgba[i])); |
59 } | 57 } |
60 } | 58 } |
OLD | NEW |