OLD | NEW |
1 #library('CanvasTest'); | 1 #library('CanvasTest'); |
2 #import('../../pkg/unittest/unittest.dart'); | 2 #import('../../pkg/unittest/unittest.dart'); |
3 #import('../../pkg/unittest/html_config.dart'); | 3 #import('../../pkg/unittest/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 18 matching lines...) Expand all Loading... |
29 checkPixel(data, 30 + width * 10, [0, 0, 0, 0]); | 29 checkPixel(data, 30 + width * 10, [0, 0, 0, 0]); |
30 }); | 30 }); |
31 test('FillStyleGradient', () { | 31 test('FillStyleGradient', () { |
32 var gradient = context.createLinearGradient(0,0,20,20); | 32 var gradient = context.createLinearGradient(0,0,20,20); |
33 gradient.addColorStop(0,'red'); | 33 gradient.addColorStop(0,'red'); |
34 gradient.addColorStop(1,'blue'); | 34 gradient.addColorStop(1,'blue'); |
35 context.fillStyle = gradient; | 35 context.fillStyle = gradient; |
36 context.fillRect(0, 0, 20, 20); | 36 context.fillRect(0, 0, 20, 20); |
37 expect(context.fillStyle is CanvasGradient, isTrue); | 37 expect(context.fillStyle is CanvasGradient, isTrue); |
38 }); | 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 }); |
39 test('StrokeStyle', () { | 54 test('StrokeStyle', () { |
40 context.strokeStyle = "blue"; | 55 context.strokeStyle = "blue"; |
41 context.strokeRect(30, 30, 10, 20); | 56 context.strokeRect(30, 30, 10, 20); |
42 | 57 |
43 // TODO(vsm): Verify the result once we have the ability to read pixels. | 58 // TODO(vsm): Verify the result once we have the ability to read pixels. |
44 }); | 59 }); |
45 test('CreateImageData', () { | 60 test('CreateImageData', () { |
46 ImageData image = context.createImageData(canvas.width, | 61 ImageData image = context.createImageData(canvas.width, |
47 canvas.height); | 62 canvas.height); |
48 Uint8ClampedArray data = image.data; | 63 Uint8ClampedArray data = image.data; |
(...skipping 17 matching lines...) Expand all Loading... |
66 }); | 81 }); |
67 } | 82 } |
68 | 83 |
69 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) | 84 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) |
70 { | 85 { |
71 offset *= 4; | 86 offset *= 4; |
72 for (var i = 0; i < 4; ++i) { | 87 for (var i = 0; i < 4; ++i) { |
73 expect(data[offset + i], equals(rgba[i])); | 88 expect(data[offset + i], equals(rgba[i])); |
74 } | 89 } |
75 } | 90 } |
OLD | NEW |