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 }); | |
54 test('StrokeStyle', () { | 39 test('StrokeStyle', () { |
55 context.strokeStyle = "blue"; | 40 context.strokeStyle = "blue"; |
56 context.strokeRect(30, 30, 10, 20); | 41 context.strokeRect(30, 30, 10, 20); |
57 | 42 |
58 // TODO(vsm): Verify the result once we have the ability to read pixels. | 43 // TODO(vsm): Verify the result once we have the ability to read pixels. |
59 }); | 44 }); |
60 test('CreateImageData', () { | 45 test('CreateImageData', () { |
61 ImageData image = context.createImageData(canvas.width, | 46 ImageData image = context.createImageData(canvas.width, |
62 canvas.height); | 47 canvas.height); |
63 Uint8ClampedArray data = image.data; | 48 Uint8ClampedArray data = image.data; |
(...skipping 17 matching lines...) Expand all Loading... |
81 }); | 66 }); |
82 } | 67 } |
83 | 68 |
84 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) | 69 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) |
85 { | 70 { |
86 offset *= 4; | 71 offset *= 4; |
87 for (var i = 0; i < 4; ++i) { | 72 for (var i = 0; i < 4; ++i) { |
88 expect(data[offset + i], equals(rgba[i])); | 73 expect(data[offset + i], equals(rgba[i])); |
89 } | 74 } |
90 } | 75 } |
OLD | NEW |