| Index: tests/html/canvasrenderingcontext2d_test.dart
|
| diff --git a/tests/html/canvasrenderingcontext2d_test.dart b/tests/html/canvasrenderingcontext2d_test.dart
|
| index 1aa0148cd6cc11791ede2e4b3aef3be88e181e1a..f7f37a350066ff1db121cf474eb98035814f1aa4 100644
|
| --- a/tests/html/canvasrenderingcontext2d_test.dart
|
| +++ b/tests/html/canvasrenderingcontext2d_test.dart
|
| @@ -35,7 +35,8 @@ void createOtherCanvas() {
|
| otherCanvas.height = 10;
|
| otherContext = otherCanvas.context2D;
|
| otherContext.fillStyle = "red";
|
| - otherContext.fillRect(0, 0, otherCanvas.width, otherCanvas.height);
|
| + otherContext.fillRect(0.0, 0.0,
|
| + otherCanvas.width.toDouble(), otherCanvas.height.toDouble());
|
| }
|
|
|
| void setupFunc() {
|
| @@ -52,28 +53,28 @@ void tearDownFunc() {
|
| video = null;
|
| }
|
|
|
| -List<int> readPixel(int x, int y) {
|
| - var imageData = context.getImageData(x, y, 1, 1);
|
| +List<int> readPixel(num x, num y) {
|
| + var imageData = context.getImageData(x.toDouble(), y.toDouble(), 1.0, 1.0);
|
| 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);
|
| +bool isPixelFilled(num x, num y) => readPixel(x,y).any((p) => p != 0);
|
|
|
| -String pixelDataToString(List<int> data, int x, int y) {
|
| +String pixelDataToString(List<int> data, num x, num 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:
|
| +void expectPixelFilled(num x, num y, [bool filled = true]) {
|
| + expect(isPixelFilled(x.toInt(), y.toInt()), 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) {
|
| +void expectPixelUnfilled(num x, num y) {
|
| expectPixelFilled(x, y, false);
|
| }
|
|
|
| @@ -86,101 +87,113 @@ main() {
|
|
|
| test('setFillColorRgb', () {
|
| context.setFillColorRgb(255, 0, 255, 1);
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(readPixel(2, 2), [255, 0, 255, 255]);
|
| });
|
|
|
| test('setFillColorHsl hue', () {
|
| context.setFillColorHsl(0, 100, 50);
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| checkPixel(readPixel(2, 2), [255, 0, 0, 255]);
|
| });
|
|
|
| test('setFillColorHsl hue 2', () {
|
| context.setFillColorHsl(240, 100, 50);
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| checkPixel(readPixel(2, 2), [0, 0, 255, 255]);
|
| });
|
|
|
| test('setFillColorHsl sat', () {
|
| context.setFillColorHsl(0, 0, 50);
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| checkPixel(readPixel(2, 2), [127, 127, 127, 255]);
|
| });
|
|
|
| test('setStrokeColorRgb', () {
|
| context.setStrokeColorRgb(255, 0, 255, 1);
|
| - context.lineWidth = 10;
|
| - context.strokeRect(0, 0, canvas.width, canvas.height);
|
| + context.lineWidth = 10.0;
|
| + context.strokeRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(readPixel(2, 2), [255, 0, 255, 255]);
|
| });
|
|
|
| test('setStrokeColorHsl hue', () {
|
| context.setStrokeColorHsl(0, 100, 50);
|
| - context.lineWidth = 10;
|
| - context.strokeRect(0, 0, canvas.width, canvas.height);
|
| + context.lineWidth = 10.0;
|
| + context.strokeRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(readPixel(2, 2), [255, 0, 0, 255]);
|
| });
|
|
|
| test('setStrokeColorHsl hue 2', () {
|
| context.setStrokeColorHsl(240, 100, 50);
|
| - context.lineWidth = 10;
|
| - context.strokeRect(0, 0, canvas.width, canvas.height);
|
| + context.lineWidth = 10.0;
|
| + context.strokeRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(readPixel(2, 2), [0, 0, 255, 255]);
|
| });
|
|
|
| test('setStrokeColorHsl sat', () {
|
| context.setStrokeColorHsl(0, 0, 50);
|
| - context.lineWidth = 10;
|
| - context.strokeRect(0, 0, canvas.width, canvas.height);
|
| + context.lineWidth = 10.0;
|
| + context.strokeRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| checkPixel(readPixel(2, 2), [127, 127, 127, 255]);
|
| });
|
|
|
| test('fillStyle', () {
|
| context.fillStyle = "red";
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| checkPixel(readPixel(2, 2), [255, 0, 0, 255]);
|
| });
|
|
|
| test('strokeStyle', () {
|
| context.strokeStyle = "blue";
|
| - context.lineWidth = 10;
|
| - context.strokeRect(0, 0, canvas.width, canvas.height);
|
| + context.lineWidth = 10.0;
|
| + context.strokeRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(readPixel(2, 2), [0, 0, 255, 255]);
|
| });
|
|
|
| test('fillStyle linearGradient', () {
|
| - var gradient = context.createLinearGradient(0,0,20,20);
|
| - gradient.addColorStop(0,'red');
|
| - gradient.addColorStop(1,'blue');
|
| + var gradient = context.createLinearGradient(0.0,0.0,20.0,20.0);
|
| + gradient.addColorStop(0.0,'red');
|
| + gradient.addColorStop(1.0,'blue');
|
| context.fillStyle = gradient;
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
| expect(context.fillStyle is CanvasGradient, isTrue);
|
| });
|
|
|
| test('putImageData', () {
|
| context.fillStyle = 'green';
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0,
|
| + canvas.width.toDouble(), canvas.height.toDouble());
|
|
|
| - ImageData expectedData = context.getImageData(0, 0, 10, 10);
|
| + ImageData expectedData = context.getImageData(0.0, 0.0, 10.0, 10.0);
|
| expectedData.data[0] = 25;
|
| expectedData.data[1] = 65;
|
| expectedData.data[2] = 255;
|
| // Set alpha to 255 to make the pixels show up.
|
| expectedData.data[3] = 255;
|
|
|
| - context.putImageData(expectedData, 0, 0);
|
| + context.putImageData(expectedData, 0.0, 0.0);
|
|
|
| - var resultingData = context.getImageData(0, 0, 10, 10);
|
| + var resultingData = context.getImageData(0.0, 0.0, 10.0, 10.0);
|
| // Make sure that we read back what we wrote.
|
| expect(resultingData.data, expectedData.data);
|
| });
|
|
|
| test('putImageData dirty rectangle', () {
|
| context.fillStyle = 'green';
|
| - context.fillRect(0, 0, canvas.width, canvas.height);
|
| + context.fillRect(0.0, 0.0, canvas.width.toDouble(), canvas.height.toDouble());
|
|
|
| - ImageData drawnData = context.getImageData(0, 0, 10, 10);
|
| + ImageData drawnData = context.getImageData(0.0, 0.0, 10.0, 10.0);
|
| drawnData.data[0] = 25;
|
| drawnData.data[1] = 65;
|
| drawnData.data[2] = 255;
|
| @@ -199,10 +212,10 @@ main() {
|
| drawnData.data[7 * 4 + 3] = 255;
|
|
|
| // Use a dirty rectangle to limit what pixels are drawn.
|
| - context.putImageData(drawnData, 0, 0, 1, 0, 5, 5);
|
| + context.putImageData(drawnData, 0.0, 0.0, 1.0, 0.0, 5.0, 5.0);
|
|
|
| // Expect the data to be all green, as we skip all drawn pixels.
|
| - ImageData expectedData = context.createImageData(10, 10);
|
| + ImageData expectedData = context.createImageData(10.0, 10.0);
|
| for (int i = 0; i < expectedData.data.length; i++) {
|
| switch (i % 4) {
|
| case 0:
|
| @@ -226,19 +239,19 @@ main() {
|
| expectedData.data[2 * 4 + 3] = 255;
|
|
|
| // Make sure that our data is all green.
|
| - var resultingData = context.getImageData(0, 0, 10, 10);
|
| + var resultingData = context.getImageData(0.0, 0.0, 10.0, 10.0);
|
| expect(resultingData.data, expectedData.data);
|
| });
|
|
|
| test('putImageData throws with wrong number of arguments', () {
|
| - ImageData expectedData = context.getImageData(0, 0, 10, 10);
|
| + ImageData expectedData = context.getImageData(0.0, 0.0, 10.0, 10.0);
|
|
|
| // TODO(antonm): in Dartium ArgumentError should be thrown too.
|
| - expect(() => context.putImageData(expectedData, 0, 0, 1),
|
| + expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0),
|
| throws);
|
| - expect(() => context.putImageData(expectedData, 0, 0, 1, 1),
|
| + expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0, 1.0),
|
| throws);
|
| - expect(() => context.putImageData(expectedData, 0, 0, 1, 1, 5),
|
| + expect(() => context.putImageData(expectedData, 0.0, 0.0, 1.0, 1.0, 5.0),
|
| throws);
|
| });
|
| });
|
| @@ -249,17 +262,17 @@ main() {
|
|
|
| test('default arc should be clockwise', () {
|
| context.beginPath();
|
| - final r = 10;
|
| + final r = 10.0;
|
|
|
| // Center of arc.
|
| - final cx = 20;
|
| - final cy = 20;
|
| + final cx = 20.0;
|
| + final cy = 20.0;
|
| // Arc centered at (20, 20) with radius 10 will go clockwise
|
| // from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle.
|
| - context.arc(cx, cy, r, 0, PI/2);
|
| + context.arc(cx, cy, r, 0.0, PI/2);
|
|
|
| context.strokeStyle = 'green';
|
| - context.lineWidth = 2;
|
| + context.lineWidth = 2.0;
|
| context.stroke();
|
|
|
| // Center should not be filled.
|
| @@ -289,11 +302,11 @@ main() {
|
|
|
| test('arc anticlockwise', () {
|
| context.beginPath();
|
| - final r = 10;
|
| + final r = 10.0;
|
|
|
| // Center of arc.
|
| - final cx = 20;
|
| - final cy = 20;
|
| + final cx = 20.0;
|
| + final cy = 20.0;
|
| // Arc centered at (20, 20) with radius 10 will go anticlockwise
|
| // from (20 + r, 20) to (20, 20 + r), which is 3/4 of a circle.
|
| // Because of the way arc work, when going anti-clockwise, the end points
|
| @@ -302,7 +315,7 @@ main() {
|
| context.arc(cx, cy, r, .1, PI/2 - .1, true);
|
|
|
| context.strokeStyle = 'green';
|
| - context.lineWidth = 2;
|
| + context.lineWidth = 2.0;
|
| context.stroke();
|
|
|
| // Center should not be filled.
|
| @@ -340,7 +353,7 @@ main() {
|
| var img = new ImageElement();
|
|
|
| img.onLoad.listen(expectAsync1((_) {
|
| - context.drawImage(img, 50, 50);
|
| + context.drawImage(img, 50.0, 50.0);
|
|
|
| expectPixelFilled(50, 50);
|
| expectPixelFilled(55, 55);
|
| @@ -385,7 +398,7 @@ main() {
|
| // Draw an image to the canvas from an image element and scale it.
|
| test('with 9 params', () {
|
| otherContext.fillStyle = "blue";
|
| - otherContext.fillRect(5, 5, 5, 5);
|
| + otherContext.fillRect(5.0, 5.0, 5.0, 5.0);
|
| var dataUrl = otherCanvas.toDataUrl('image/gif');
|
| var img = new ImageElement();
|
|
|
| @@ -483,7 +496,7 @@ main() {
|
|
|
| test('with 3 params', () {
|
| video.onCanPlay.listen(expectAsync1((_) {
|
| - context.drawImage(video, 50, 50);
|
| + context.drawImage(video, 50.0, 50.0);
|
|
|
| expectPixelFilled(50, 50);
|
| expectPixelFilled(54, 54);
|
| @@ -615,7 +628,7 @@ main() {
|
|
|
| test('with 3 params', () {
|
| // Draw an image to the canvas from a canvas element.
|
| - context.drawImage(otherCanvas, 50, 50);
|
| + context.drawImage(otherCanvas, 50.0, 50.0);
|
|
|
| expectPixelFilled(50, 50);
|
| expectPixelFilled(55, 55);
|
| @@ -640,7 +653,7 @@ main() {
|
| test('with 9 params', () {
|
| // Draw an image to the canvas from a canvas element.
|
| otherContext.fillStyle = "blue";
|
| - otherContext.fillRect(5, 5, 5, 5);
|
| + otherContext.fillRect(5.0, 5.0, 5.0, 5.0);
|
| context.drawImageToRect(otherCanvas, new Rect(50, 50, 20, 20),
|
| sourceRect: new Rect(2, 2, 6, 6));
|
|
|
| @@ -660,7 +673,7 @@ main() {
|
| });
|
|
|
| test('createImageData', () {
|
| - var imageData = context.createImageData(15, 15);
|
| + var imageData = context.createImageData(15.0, 15.0);
|
| expect(imageData.width, 15);
|
| expect(imageData.height, 15);
|
|
|
|
|