mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 13:22:01 +00:00
2dcd56ef43
There are far too many files here to review everyone carefully. Spot checking most of the diffs look good as test code is generally written with less care than application code so lots of ugly formatting get through. If people notice files where the automated formatting bothers them feel free to comment indicating file names and I'll move spaces within comments to make the formatting cleaner and use comments to force block formatting as I have done for other case where formatting looked bad. BUG= R=efortuna@google.com Review-Url: https://codereview.chromium.org/2771453003 .
56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
library CanvasTest;
|
|
|
|
import 'package:unittest/unittest.dart';
|
|
import 'package:unittest/html_config.dart';
|
|
import 'dart:html';
|
|
|
|
main() {
|
|
CanvasElement canvas;
|
|
CanvasRenderingContext2D context;
|
|
int width = 100;
|
|
int height = 100;
|
|
|
|
canvas = new CanvasElement(width: width, height: height);
|
|
document.body.append(canvas);
|
|
|
|
context = canvas.context2D;
|
|
|
|
useHtmlConfiguration();
|
|
test('CreateImageData', () {
|
|
ImageData image = context.createImageData(canvas.width, canvas.height);
|
|
List<int> data = image.data;
|
|
|
|
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));
|
|
});
|
|
|
|
test('toDataUrl', () {
|
|
var canvas = new CanvasElement(width: 100, height: 100);
|
|
var context = canvas.context2D;
|
|
context.fillStyle = 'red';
|
|
context.fill();
|
|
|
|
var url = canvas.toDataUrl();
|
|
|
|
var img = new ImageElement();
|
|
img.onLoad.listen(expectAsync((_) {
|
|
expect(img.complete, true);
|
|
}));
|
|
img.onError.listen((_) {
|
|
fail('URL failed to load.');
|
|
});
|
|
img.src = url;
|
|
});
|
|
}
|
|
|
|
void checkPixel(List<int> data, int offset, List<int> rgba) {
|
|
offset *= 4;
|
|
for (var i = 0; i < 4; ++i) {
|
|
expect(data[offset + i], equals(rgba[i]));
|
|
}
|
|
}
|