OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library url_test; | 5 library url_test; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
11 checkPixel(Uint8ClampedArray pixel, List<int> expected) { | 11 checkPixel(List<int> pixel, List<int> expected) { |
12 expect(pixel[0], closeTo(expected[0], 1)); | 12 expect(pixel[0], closeTo(expected[0], 1)); |
13 expect(pixel[1], closeTo(expected[1], 1)); | 13 expect(pixel[1], closeTo(expected[1], 1)); |
14 expect(pixel[2], closeTo(expected[2], 1)); | 14 expect(pixel[2], closeTo(expected[2], 1)); |
15 expect(pixel[3], closeTo(expected[3], 1)); | 15 expect(pixel[3], closeTo(expected[3], 1)); |
16 } | 16 } |
17 | 17 |
18 main() { | 18 main() { |
19 useHtmlConfiguration(); | 19 useHtmlConfiguration(); |
20 var canvas = new CanvasElement(); | 20 var canvas = new CanvasElement(); |
21 canvas.width = 100; | 21 canvas.width = 100; |
22 canvas.height = 100; | 22 canvas.height = 100; |
23 | 23 |
24 var context = canvas.context2d; | 24 var context = canvas.context2d; |
25 | 25 |
26 Uint8ClampedArray readPixel() { | 26 List<int> readPixel() { |
27 var imageData = context.getImageData(2, 2, 1, 1); | 27 var imageData = context.getImageData(2, 2, 1, 1); |
28 return imageData.data; | 28 return imageData.data; |
29 } | 29 } |
30 | 30 |
31 test('setFillColorRgb', () { | 31 test('setFillColorRgb', () { |
32 context.setFillColorRgb(255, 0, 255, 1); | 32 context.setFillColorRgb(255, 0, 255, 1); |
33 context.fillRect(0, 0, canvas.width, canvas.height); | 33 context.fillRect(0, 0, canvas.width, canvas.height); |
34 expect(readPixel(), [255, 0, 255, 255]); | 34 expect(readPixel(), [255, 0, 255, 255]); |
35 }); | 35 }); |
36 | 36 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 context.fillStyle = 'green'; | 109 context.fillStyle = 'green'; |
110 context.fillRect(0, 0, canvas.width, canvas.height); | 110 context.fillRect(0, 0, canvas.width, canvas.height); |
111 | 111 |
112 context.putImageData(expectedData, 0, 0); | 112 context.putImageData(expectedData, 0, 0); |
113 | 113 |
114 var resultingData = context.getImageData(0, 0, 10, 10); | 114 var resultingData = context.getImageData(0, 0, 10, 10); |
115 // Make sure that we read back what we wrote. | 115 // Make sure that we read back what we wrote. |
116 expect(resultingData.data, expectedData.data); | 116 expect(resultingData.data, expectedData.data); |
117 }); | 117 }); |
118 } | 118 } |
OLD | NEW |