| OLD | NEW |
| 1 #library('CanvasTest'); | 1 #library('CanvasTest'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 2 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/html_config.dart'); | 3 #import('../../lib/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; |
| 11 | 11 |
| 12 canvas = new Element.tag('canvas'); | 12 canvas = new Element.tag('canvas'); |
| 13 canvas.attributes['width'] = width; | 13 canvas.attributes['width'] = width; |
| 14 canvas.attributes['height'] = height; | 14 canvas.attributes['height'] = height; |
| 15 document.body.nodes.add(canvas); | 15 document.body.nodes.add(canvas); |
| 16 | 16 |
| 17 context = canvas.getContext('2d'); | 17 context = canvas.context2d; |
| 18 | 18 |
| 19 useHtmlConfiguration(); | 19 useHtmlConfiguration(); |
| 20 test('FillStyle', () { | 20 test('FillStyle', () { |
| 21 context.fillStyle = "red"; | 21 context.fillStyle = "red"; |
| 22 context.fillRect(10, 10, 20, 20); | 22 context.fillRect(10, 10, 20, 20); |
| 23 | 23 |
| 24 Uint8ClampedArray data = context.getImageData(0, 0, width, height).data; | 24 Uint8ClampedArray data = context.getImageData(0, 0, width, height).data; |
| 25 checkPixel(data, 0, [0, 0, 0, 0]); | 25 checkPixel(data, 0, [0, 0, 0, 0]); |
| 26 checkPixel(data, 9 + width * 10, [0, 0, 0, 0]); | 26 checkPixel(data, 9 + width * 10, [0, 0, 0, 0]); |
| 27 checkPixel(data, 10 + width * 10, [255, 0, 0, 255]); | 27 checkPixel(data, 10 + width * 10, [255, 0, 0, 255]); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 }); | 81 }); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) | 84 void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba) |
| 85 { | 85 { |
| 86 offset *= 4; | 86 offset *= 4; |
| 87 for (var i = 0; i < 4; ++i) { | 87 for (var i = 0; i < 4; ++i) { |
| 88 Expect.equals(rgba[i], data[offset + i]); | 88 Expect.equals(rgba[i], data[offset + i]); |
| 89 } | 89 } |
| 90 } | 90 } |
| OLD | NEW |