Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Unified Diff: tests/html/canvas_pixel_array_type_alias_test.dart

Issue 133763009: Add tests covering cases in issue 16069 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/html/html.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/canvas_pixel_array_type_alias_test.dart
diff --git a/tests/html/canvas_pixel_array_type_alias_test.dart b/tests/html/canvas_pixel_array_type_alias_test.dart
index 250824d86429d850a26052216f72b2ef5257525f..9323ec08895353de354afca750a0c52af0571c45 100644
--- a/tests/html/canvas_pixel_array_type_alias_test.dart
+++ b/tests/html/canvas_pixel_array_type_alias_test.dart
@@ -1,50 +1,109 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file
+
library CanvasTest;
import '../../pkg/unittest/lib/unittest.dart';
import '../../pkg/unittest/lib/html_config.dart';
import 'dart:html';
+import 'dart:typed_data';
// We have aliased the legacy type CanvasPixelArray with the new type
// Uint8ClampedArray by mapping the CanvasPixelArray type tag to
// Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is
// missing the ArrayBufferView members. These should appear to be null.
-Object confuseType(x) => [1, x, [x], 's'] [1];
+var inscrutable;
main() {
- CanvasElement canvas;
- CanvasRenderingContext2D context;
+
+ inscrutable = (x) => x;
+
int width = 100;
int height = 100;
- canvas = new Element.tag('canvas');
- canvas.width = width;
- canvas.height = height;
+ CanvasElement canvas = new CanvasElement(width: width, height: height);
document.body.append(canvas);
- context = canvas.getContext('2d');
+ CanvasRenderingContext2D context = canvas.context2D;
useHtmlConfiguration();
- test('CreateImageData', () {
- ImageData image = context.createImageData(canvas.width,
- canvas.height);
- List<int> data = image.data;
- // It is legal for the dart2js compiler to believe the type of the native
- // ImageData.data and elides the check, so check the type explicitly:
- expect(confuseType(data) is List<int>, isTrue,
- reason: 'canvas array type');
-
- expect(data, hasLength(40000));
- checkPixel(data, 0, [0, 0, 0, 0]);
- checkPixel(data, width * height - 1, [0, 0, 0, 0]);
-
- data[100] = 200;
- expect(data[100], equals(200));
+ group('basic', () {
+ test('CreateImageData', () {
+ ImageData image = context.createImageData(canvas.width,
+ canvas.height);
+ List<int> data = image.data;
+ // It is legal for the dart2js compiler to believe the type of the native
+ // ImageData.data and elides the check, so check the type explicitly:
+ expect(inscrutable(data) is List<int>, isTrue,
+ reason: 'canvas array type');
+
+ expect(data, hasLength(40000));
+ checkPixel(data, 0, [0, 0, 0, 0]);
+ checkPixel(data, width * height - 1, [0, 0, 0, 0]);
+
+ data[100] = 200;
+ expect(data[100], equals(200));
+ });
+ });
+
+ group('types1', () {
+ test('isList', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data) is List, true);
+ });
+
+ test('isListT_pos', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data) is List<int>, true);
+ });
+ });
+
+ group('types2', () {
+ test('isListT_neg', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data) is List<String>, false);
+ });
+
+ test('isUint8ClampedList', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data) is Uint8ClampedList, true);
+ });
+
+ test('consistent_isUint8ClampedList', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ // Static and dynamic values consistent? Type inference should be able to
+ // constant-fold 'data is Uint8ClampedList' to 'true'.
+ expect(inscrutable(data) is Uint8ClampedList == data is Uint8ClampedList,
+ isTrue);
+ });
+
+ test('runtimeType', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data).runtimeType, Uint8ClampedList);
+ });
+
+ test('consistent_runtimeType', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data).runtimeType == data.runtimeType, isTrue);
+ });
+
+ test('runtimeTypeName', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect('${inscrutable(data).runtimeType}', 'Uint8ClampedList');
+ });
+ });
+
+ group('typed_data', () {
+ test('elementSizeInBytes', () {
+ var data = context.createImageData(canvas.width, canvas.height).data;
+ expect(inscrutable(data).elementSizeInBytes, 1);
+ });
});
}
-void checkPixel(List<int> data, int offset, List<int> rgba)
-{
+void checkPixel(List<int> data, int offset, List<int> rgba) {
offset *= 4;
for (var i = 0; i < 4; ++i) {
expect(rgba[i], equals(data[offset + i]));
« no previous file with comments | « no previous file | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698