| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 CanvasTest; | |
| 6 import 'package:unittest/unittest.dart'; | |
| 7 import 'package:unittest/html_individual_config.dart'; | |
| 8 import 'dart:html'; | 5 import 'dart:html'; |
| 9 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
| 10 | 7 |
| 8 import 'package:minitest/minitest.dart'; |
| 9 |
| 11 // We have aliased the legacy type CanvasPixelArray with the new type | 10 // We have aliased the legacy type CanvasPixelArray with the new type |
| 12 // Uint8ClampedArray by mapping the CanvasPixelArray type tag to | 11 // Uint8ClampedArray by mapping the CanvasPixelArray type tag to |
| 13 // Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is | 12 // Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is |
| 14 // missing the ArrayBufferView members. These should appear to be null. | 13 // missing the ArrayBufferView members. These should appear to be null. |
| 15 | 14 |
| 16 var inscrutable; | 15 var inscrutable; |
| 17 | 16 |
| 18 main() { | 17 main() { |
| 19 | |
| 20 useHtmlIndividualConfiguration(); | |
| 21 | |
| 22 inscrutable = (x) => x; | 18 inscrutable = (x) => x; |
| 23 | 19 |
| 24 int width = 100; | 20 int width = 100; |
| 25 int height = 100; | 21 int height = 100; |
| 26 | 22 |
| 27 CanvasElement canvas = new CanvasElement(width: width, height: height); | 23 CanvasElement canvas = new CanvasElement(width: width, height: height); |
| 28 document.body.append(canvas); | 24 document.body.append(canvas); |
| 29 | 25 |
| 30 CanvasRenderingContext2D context = canvas.context2D; | 26 CanvasRenderingContext2D context = canvas.context2D; |
| 31 | 27 |
| 32 group('basic', () { | 28 group('basic', () { |
| 33 test('CreateImageData', () { | 29 test('CreateImageData', () { |
| 34 ImageData image = context.createImageData(canvas.width, | 30 ImageData image = context.createImageData(canvas.width, |
| 35 canvas.height); | 31 canvas.height); |
| 36 List<int> data = image.data; | 32 List<int> data = image.data; |
| 37 // It is legal for the dart2js compiler to believe the type of the native | 33 // It is legal for the dart2js compiler to believe the type of the native |
| 38 // ImageData.data and elides the check, so check the type explicitly: | 34 // ImageData.data and elides the check, so check the type explicitly: |
| 39 expect(inscrutable(data) is List<int>, isTrue, | 35 expect(inscrutable(data) is List<int>, isTrue, |
| 40 reason: 'canvas array type'); | 36 reason: 'canvas array type'); |
| 41 | 37 |
| 42 expect(data, hasLength(40000)); | 38 expect(data.length, 40000); |
| 43 checkPixel(data, 0, [0, 0, 0, 0]); | 39 checkPixel(data, 0, [0, 0, 0, 0]); |
| 44 checkPixel(data, width * height - 1, [0, 0, 0, 0]); | 40 checkPixel(data, width * height - 1, [0, 0, 0, 0]); |
| 45 | 41 |
| 46 data[100] = 200; | 42 data[100] = 200; |
| 47 expect(data[100], equals(200)); | 43 expect(data[100], equals(200)); |
| 48 }); | 44 }); |
| 49 }); | 45 }); |
| 50 | 46 |
| 51 group('types1', () { | 47 group('types1', () { |
| 52 test('isList', () { | 48 test('isList', () { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }); | 106 }); |
| 111 }); | 107 }); |
| 112 } | 108 } |
| 113 | 109 |
| 114 void checkPixel(List<int> data, int offset, List<int> rgba) { | 110 void checkPixel(List<int> data, int offset, List<int> rgba) { |
| 115 offset *= 4; | 111 offset *= 4; |
| 116 for (var i = 0; i < 4; ++i) { | 112 for (var i = 0; i < 4; ++i) { |
| 117 expect(rgba[i], equals(data[offset + i])); | 113 expect(rgba[i], equals(data[offset + i])); |
| 118 } | 114 } |
| 119 } | 115 } |
| OLD | NEW |