4cc31f8f4f
There are no behavioral changes here, I just ran `dart format` on the `tests/lib/html/` directory. Change-Id: I221b2a370adc393e49621db1d37aa6eeb09b3015 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425329 Reviewed-by: Srujan Gaddam <srujzs@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com>
85 lines
2.1 KiB
Dart
85 lines
2.1 KiB
Dart
// Copyright (c) 2012, 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 canvas_rendering_context_2d_test;
|
|
|
|
import 'dart:html';
|
|
import 'dart:math';
|
|
|
|
import 'package:expect/legacy/minitest.dart'; // ignore: deprecated_member_use_from_same_package
|
|
|
|
// Some rounding errors in the browsers.
|
|
checkPixel(List<int> pixel, List<int> expected) {
|
|
expect(pixel[0], closeTo(expected[0], 2));
|
|
expect(pixel[1], closeTo(expected[1], 2));
|
|
expect(pixel[2], closeTo(expected[2], 2));
|
|
expect(pixel[3], closeTo(expected[3], 2));
|
|
}
|
|
|
|
var canvas;
|
|
var context;
|
|
var otherCanvas;
|
|
var otherContext;
|
|
var video;
|
|
|
|
void createCanvas() {
|
|
canvas = new CanvasElement();
|
|
canvas.width = 100;
|
|
canvas.height = 100;
|
|
|
|
context = canvas.context2D;
|
|
}
|
|
|
|
void createOtherCanvas() {
|
|
otherCanvas = new CanvasElement();
|
|
otherCanvas.width = 10;
|
|
otherCanvas.height = 10;
|
|
otherContext = otherCanvas.context2D;
|
|
otherContext.fillStyle = "red";
|
|
otherContext.fillRect(0, 0, otherCanvas.width, otherCanvas.height);
|
|
}
|
|
|
|
void setupFunc() {
|
|
createCanvas();
|
|
createOtherCanvas();
|
|
video = new VideoElement();
|
|
}
|
|
|
|
void tearDownFunc() {
|
|
canvas = null;
|
|
context = null;
|
|
otherCanvas = null;
|
|
otherContext = null;
|
|
video = null;
|
|
}
|
|
|
|
List<int> readPixel(int x, int y) {
|
|
var imageData = context.getImageData(x, y, 1, 1);
|
|
return imageData.data;
|
|
}
|
|
|
|
/// Returns true if the pixel has some data in it, false otherwise.
|
|
bool isPixelFilled(int x, int y) => readPixel(x, y).any((p) => p != 0);
|
|
|
|
String pixelDataToString(List<int> data, int x, int y) {
|
|
return '[${data.join(", ")}]';
|
|
}
|
|
|
|
String _filled(bool v) => v ? "filled" : "unfilled";
|
|
|
|
void expectPixelFilled(int x, int y, [bool filled = true]) {
|
|
expect(
|
|
isPixelFilled(x, y),
|
|
filled,
|
|
reason:
|
|
'Pixel at ($x, $y) was expected to'
|
|
' be: <${_filled(filled)}> but was: <${_filled(!filled)}> with data: '
|
|
'${pixelDataToString(readPixel(x, y), x, y)}',
|
|
);
|
|
}
|
|
|
|
void expectPixelUnfilled(int x, int y) {
|
|
expectPixelFilled(x, y, false);
|
|
}
|