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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 test('toDataUrl', () { | 31 test('toDataUrl', () { |
32 var canvas = new CanvasElement(width: 100, height: 100); | 32 var canvas = new CanvasElement(width: 100, height: 100); |
33 var context = canvas.context2d; | 33 var context = canvas.context2d; |
34 context.fillStyle = 'red'; | 34 context.fillStyle = 'red'; |
35 context.fill(); | 35 context.fill(); |
36 | 36 |
37 var url = canvas.toDataUrl('image/png'); | 37 var url = canvas.toDataUrl('image/png'); |
38 | 38 |
39 var img = new ImageElement(); | 39 var img = new ImageElement(); |
40 img.on.load.add(expectAsync1((_) { | 40 img.onLoad.listen(expectAsync1((_) { |
41 expect(img.complete, true); | 41 expect(img.complete, true); |
42 })); | 42 })); |
43 img.on.error.add((_) { | 43 img.onError.listen((_) { |
44 guardAsync(() { | 44 guardAsync(() { |
45 expect(true, isFalse, reason: 'URL failed to load.'); | 45 expect(true, isFalse, reason: 'URL failed to load.'); |
46 }); | 46 }); |
47 }); | 47 }); |
48 img.src = url; | 48 img.src = url; |
49 }); | 49 }); |
50 } | 50 } |
51 | 51 |
52 void checkPixel(List<int> data, int offset, List<int> rgba) | 52 void checkPixel(List<int> data, int offset, List<int> rgba) |
53 { | 53 { |
54 offset *= 4; | 54 offset *= 4; |
55 for (var i = 0; i < 4; ++i) { | 55 for (var i = 0; i < 4; ++i) { |
56 expect(data[offset + i], equals(rgba[i])); | 56 expect(data[offset + i], equals(rgba[i])); |
57 } | 57 } |
58 } | 58 } |
OLD | NEW |