未验证 提交 e5abd98c 编写于 作者: F Ferhat 提交者: GitHub

migrate tests to nullsafe (#25616)

上级 65e36e43
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart'; import 'package:test/bootstrap/browser.dart';
...@@ -56,9 +55,9 @@ void testMain() async { ...@@ -56,9 +55,9 @@ void testMain() async {
builder.pop(); builder.pop();
builder.pop(); builder.pop();
html.document.body.append(builder html.document.body!.append(builder
.build() .build()
.webOnlyRootElement); .webOnlyRootElement!);
await matchGoldenFile('backdrop_filter_clip.png', region: region, await matchGoldenFile('backdrop_filter_clip.png', region: region,
maxDiffRatePercent: 0.8); maxDiffRatePercent: 0.8);
...@@ -107,9 +106,9 @@ void testMain() async { ...@@ -107,9 +106,9 @@ void testMain() async {
builder2.pop(); builder2.pop();
builder2.pop(); builder2.pop();
html.document.body.append(builder2 html.document.body!.append(builder2
.build() .build()
.webOnlyRootElement); .webOnlyRootElement!);
await matchGoldenFile('backdrop_filter_clip_moved.png', region: region, await matchGoldenFile('backdrop_filter_clip_moved.png', region: region,
maxDiffRatePercent: 0.8); maxDiffRatePercent: 0.8);
...@@ -139,9 +138,9 @@ void testMain() async { ...@@ -139,9 +138,9 @@ void testMain() async {
builder.pop(); builder.pop();
builder.pop(); builder.pop();
html.document.body.append(builder html.document.body!.append(builder
.build() .build()
.webOnlyRootElement); .webOnlyRootElement!);
await matchGoldenFile('backdrop_filter_no_child_rendering.png', region: region, await matchGoldenFile('backdrop_filter_no_child_rendering.png', region: region,
maxDiffRatePercent: 0.8); maxDiffRatePercent: 0.8);
...@@ -149,39 +148,39 @@ void testMain() async { ...@@ -149,39 +148,39 @@ void testMain() async {
} }
Picture _drawTestPictureWithCircles(Rect region, double offsetX, double offsetY) { Picture _drawTestPictureWithCircles(Rect region, double offsetX, double offsetY) {
final EnginePictureRecorder recorder = PictureRecorder(); final EnginePictureRecorder recorder = PictureRecorder() as EnginePictureRecorder;
final RecordingCanvas canvas = final RecordingCanvas canvas =
recorder.beginRecording(region); recorder.beginRecording(region);
canvas.drawCircle( canvas.drawCircle(
Offset(offsetX + 10, offsetY + 10), 10, Paint()..style = PaintingStyle.fill); Offset(offsetX + 10, offsetY + 10), 10, SurfacePaint()..style = PaintingStyle.fill);
canvas.drawCircle( canvas.drawCircle(
Offset(offsetX + 60, offsetY + 10), Offset(offsetX + 60, offsetY + 10),
10, 10,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromRGBO(255, 0, 0, 1)); ..color = const Color.fromRGBO(255, 0, 0, 1));
canvas.drawCircle( canvas.drawCircle(
Offset(offsetX + 10, offsetY + 60), Offset(offsetX + 10, offsetY + 60),
10, 10,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromRGBO(0, 255, 0, 1)); ..color = const Color.fromRGBO(0, 255, 0, 1));
canvas.drawCircle( canvas.drawCircle(
Offset(offsetX + 60, offsetY + 60), Offset(offsetX + 60, offsetY + 60),
10, 10,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromRGBO(0, 0, 255, 1)); ..color = const Color.fromRGBO(0, 0, 255, 1));
return recorder.endRecording(); return recorder.endRecording();
} }
Picture _drawBackground(Rect region) { Picture _drawBackground(Rect region) {
final EnginePictureRecorder recorder = PictureRecorder(); final EnginePictureRecorder recorder = PictureRecorder() as EnginePictureRecorder;
final RecordingCanvas canvas = final RecordingCanvas canvas =
recorder.beginRecording(region); recorder.beginRecording(region);
canvas.drawRect( canvas.drawRect(
region.deflate(8.0), region.deflate(8.0),
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = Color(0xFFE0FFE0) ..color = Color(0xFFE0FFE0)
); );
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'dart:math' as math; import 'dart:math' as math;
import 'package:test/bootstrap/browser.dart'; import 'package:test/bootstrap/browser.dart';
...@@ -19,7 +18,7 @@ void main() { ...@@ -19,7 +18,7 @@ void main() {
void testMain() async { void testMain() async {
final Rect region = Rect.fromLTWH(0, 0, 400, 600); final Rect region = Rect.fromLTWH(0, 0, 400, 600);
BitmapCanvas canvas; late BitmapCanvas canvas;
setUp(() { setUp(() {
canvas = BitmapCanvas(region, RenderStrategy()); canvas = BitmapCanvas(region, RenderStrategy());
...@@ -48,7 +47,7 @@ void testMain() async { ...@@ -48,7 +47,7 @@ void testMain() async {
largeArc: true, clockwise: true, distance: -20); largeArc: true, clockwise: true, distance: -20);
html.document.body.append(canvas.rootElement); html.document.body!.append(canvas.rootElement);
await matchGoldenFile('canvas_arc_to_point.png', region: region); await matchGoldenFile('canvas_arc_to_point.png', region: region);
}); });
...@@ -63,7 +62,7 @@ void testMain() async { ...@@ -63,7 +62,7 @@ void testMain() async {
..color = Color(0xFFFF9800) // orange ..color = Color(0xFFFF9800) // orange
..style = PaintingStyle.fill); ..style = PaintingStyle.fill);
html.document.body.append(canvas.rootElement); html.document.body!.append(canvas.rootElement);
await matchGoldenFile('canvas_addarc.png', region: region); await matchGoldenFile('canvas_addarc.png', region: region);
}); });
...@@ -81,7 +80,7 @@ void testMain() async { ...@@ -81,7 +80,7 @@ void testMain() async {
..color = Color(0xFFFF9800) // orange ..color = Color(0xFFFF9800) // orange
..style = PaintingStyle.fill); ..style = PaintingStyle.fill);
html.document.body.append(canvas.rootElement); html.document.body!.append(canvas.rootElement);
await matchGoldenFile('canvas_addarc_ccw.png', region: region); await matchGoldenFile('canvas_addarc_ccw.png', region: region);
}); });
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'dart:js_util' as js_util; import 'dart:js_util' as js_util;
...@@ -35,7 +34,7 @@ void testMain() async { ...@@ -35,7 +34,7 @@ void testMain() async {
final html.Element sceneElement = html.Element.tag('flt-scene'); final html.Element sceneElement = html.Element.tag('flt-scene');
try { try {
sceneElement.append(engineCanvas.rootElement); sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement); html.document.body!.append(sceneElement);
await matchGoldenFile('$fileName.png', region: region, await matchGoldenFile('$fileName.png', region: region,
maxDiffRatePercent: maxDiffRatePercent, write: write); maxDiffRatePercent: maxDiffRatePercent, write: write);
} finally { } finally {
...@@ -58,13 +57,13 @@ void testMain() async { ...@@ -58,13 +57,13 @@ void testMain() async {
rc.save(); rc.save();
rc.drawRect( rc.drawRect(
Rect.fromLTRB(0, 0, 400, 400), Rect.fromLTRB(0, 0, 400, 400),
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(255, 255, 255, 255)); ..color = const Color.fromARGB(255, 255, 255, 255));
rc.drawCircle( rc.drawCircle(
Offset(100, 100), Offset(100, 100),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(128, 255, 0, 0) ..color = const Color.fromARGB(128, 255, 0, 0)
..blendMode = BlendMode.difference); ..blendMode = BlendMode.difference);
...@@ -72,7 +71,7 @@ void testMain() async { ...@@ -72,7 +71,7 @@ void testMain() async {
rc.drawCircle( rc.drawCircle(
Offset(170, 100), Offset(170, 100),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..blendMode = BlendMode.color ..blendMode = BlendMode.color
..color = const Color.fromARGB(128, 0, 255, 0)); ..color = const Color.fromARGB(128, 0, 255, 0));
...@@ -80,7 +79,7 @@ void testMain() async { ...@@ -80,7 +79,7 @@ void testMain() async {
rc.drawCircle( rc.drawCircle(
Offset(135, 170), Offset(135, 170),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(128, 255, 0, 0)); ..color = const Color.fromARGB(128, 255, 0, 0));
rc.restore(); rc.restore();
...@@ -95,20 +94,20 @@ void testMain() async { ...@@ -95,20 +94,20 @@ void testMain() async {
rc.save(); rc.save();
rc.drawRect( rc.drawRect(
Rect.fromLTRB(0, 0, 400, 400), Rect.fromLTRB(0, 0, 400, 400),
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(255, 255, 255, 255)); ..color = const Color.fromARGB(255, 255, 255, 255));
rc.drawCircle( rc.drawCircle(
Offset(100, 100), Offset(100, 100),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(128, 255, 0, 0) ..color = const Color.fromARGB(128, 255, 0, 0)
..blendMode = BlendMode.difference); ..blendMode = BlendMode.difference);
rc.drawCircle( rc.drawCircle(
Offset(170, 100), Offset(170, 100),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..blendMode = BlendMode.color ..blendMode = BlendMode.color
..color = const Color.fromARGB(128, 0, 255, 0)); ..color = const Color.fromARGB(128, 0, 255, 0));
...@@ -116,11 +115,11 @@ void testMain() async { ...@@ -116,11 +115,11 @@ void testMain() async {
rc.drawCircle( rc.drawCircle(
Offset(135, 170), Offset(135, 170),
80.0, 80.0,
Paint() SurfacePaint()
..style = PaintingStyle.fill ..style = PaintingStyle.fill
..color = const Color.fromARGB(128, 255, 0, 0)); ..color = const Color.fromARGB(128, 255, 0, 0));
rc.drawImage(createTestImage(), Offset(135.0, 130.0), rc.drawImage(createTestImage(), Offset(135.0, 130.0),
Paint()..blendMode = BlendMode.multiply); SurfacePaint()..blendMode = BlendMode.multiply);
rc.restore(); rc.restore();
await _checkScreenshot(rc, 'canvas_blend_image_multiply', await _checkScreenshot(rc, 'canvas_blend_image_multiply',
maxDiffRatePercent: operatingSystem == OperatingSystem.macOs ? 2.95 : maxDiffRatePercent: operatingSystem == OperatingSystem.macOs ? 2.95 :
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'dart:js_util' as js_util; import 'dart:js_util' as js_util;
...@@ -42,7 +41,7 @@ void testMain() async { ...@@ -42,7 +41,7 @@ void testMain() async {
path.addOval(Rect.fromLTWH(100, 30, testWidth, testHeight)); path.addOval(Rect.fromLTWH(100, 30, testWidth, testHeight));
rc.clipPath(path); rc.clipPath(path);
rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight), rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight),
Rect.fromLTWH(100, 30, testWidth, testHeight), Paint()); Rect.fromLTWH(100, 30, testWidth, testHeight), engine.SurfacePaint());
rc.restore(); rc.restore();
await canvasScreenshot(rc, 'image_clipped_by_oval', await canvasScreenshot(rc, 'image_clipped_by_oval',
region: screenRect); region: screenRect);
...@@ -65,7 +64,7 @@ void testMain() async { ...@@ -65,7 +64,7 @@ void testMain() async {
paintPath.close(); paintPath.close();
rc.drawPath( rc.drawPath(
paintPath, paintPath,
Paint() engine.SurfacePaint()
..color = Color(0xFF00FF00) ..color = Color(0xFF00FF00)
..style = PaintingStyle.fill); ..style = PaintingStyle.fill);
rc.restore(); rc.restore();
...@@ -85,7 +84,7 @@ void testMain() async { ...@@ -85,7 +84,7 @@ void testMain() async {
paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight)); paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight));
paintPath.close(); paintPath.close();
rc.drawPath(paintPath, rc.drawPath(paintPath,
Paint() engine.SurfacePaint()
..color = Color(0xFF000000) ..color = Color(0xFF000000)
..style = PaintingStyle.stroke); ..style = PaintingStyle.stroke);
...@@ -96,7 +95,7 @@ void testMain() async { ...@@ -96,7 +95,7 @@ void testMain() async {
path.close(); path.close();
rc.clipPath(path); rc.clipPath(path);
rc.drawImageRect(createTestImage(), Rect.fromLTRB(0, 0, testWidth, testHeight), rc.drawImageRect(createTestImage(), Rect.fromLTRB(0, 0, testWidth, testHeight),
Rect.fromLTWH(-50, 0, testWidth, testHeight), Paint()); Rect.fromLTWH(-50, 0, testWidth, testHeight), engine.SurfacePaint());
rc.restore(); rc.restore();
await canvasScreenshot(rc, 'image_clipped_by_triangle_off_screen'); await canvasScreenshot(rc, 'image_clipped_by_triangle_off_screen');
}); });
...@@ -113,7 +112,7 @@ void testMain() async { ...@@ -113,7 +112,7 @@ void testMain() async {
paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight)); paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight));
paintPath.close(); paintPath.close();
rc.drawPath(paintPath, rc.drawPath(paintPath,
Paint() engine.SurfacePaint()
..color = Color(0xFF000000) ..color = Color(0xFF000000)
..style = PaintingStyle.stroke); ..style = PaintingStyle.stroke);
...@@ -121,7 +120,7 @@ void testMain() async { ...@@ -121,7 +120,7 @@ void testMain() async {
path.addOval(Rect.fromLTRB(-200, 0, 100, 150)); path.addOval(Rect.fromLTRB(-200, 0, 100, 150));
rc.clipPath(path); rc.clipPath(path);
rc.drawImageRect(createTestImage(), Rect.fromLTRB(0, 0, testWidth, testHeight), rc.drawImageRect(createTestImage(), Rect.fromLTRB(0, 0, testWidth, testHeight),
Rect.fromLTWH(-50, 0, testWidth, testHeight), Paint()); Rect.fromLTWH(-50, 0, testWidth, testHeight), engine.SurfacePaint());
rc.restore(); rc.restore();
await canvasScreenshot(rc, 'image_clipped_by_oval_path'); await canvasScreenshot(rc, 'image_clipped_by_oval_path');
}); });
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart'; import 'package:test/bootstrap/browser.dart';
...@@ -35,7 +34,7 @@ void testMain() async { ...@@ -35,7 +34,7 @@ void testMain() async {
final html.Element sceneElement = html.Element.tag('flt-scene'); final html.Element sceneElement = html.Element.tag('flt-scene');
try { try {
sceneElement.append(engineCanvas.rootElement); sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement); html.document.body!.append(sceneElement);
// TODO(yjbanov): 10% diff rate is excessive. Update goldens. // TODO(yjbanov): 10% diff rate is excessive. Update goldens.
await matchGoldenFile('$fileName.png', region: region, maxDiffRatePercent: 10); await matchGoldenFile('$fileName.png', region: region, maxDiffRatePercent: 10);
} finally { } finally {
...@@ -57,7 +56,7 @@ void testMain() async { ...@@ -57,7 +56,7 @@ void testMain() async {
test('Clips image with oval clip path', () async { test('Clips image with oval clip path', () async {
final engine.RecordingCanvas rc = final engine.RecordingCanvas rc =
engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300));
final Paint paint = Paint() final engine.SurfacePaint paint = Paint() as engine.SurfacePaint
..color = Color(0xFF00FF00) ..color = Color(0xFF00FF00)
..style = PaintingStyle.fill; ..style = PaintingStyle.fill;
rc.save(); rc.save();
...@@ -98,11 +97,11 @@ void testMain() async { ...@@ -98,11 +97,11 @@ void testMain() async {
rc.save(); rc.save();
rc.restore(); rc.restore();
// The rectangle should be clipped against oval. // The rectangle should be clipped against oval.
rc.drawRect(Rect.fromLTWH(0, 0, 300, 300), badPaint); rc.drawRect(Rect.fromLTWH(0, 0, 300, 300), badPaint as engine.SurfacePaint);
rc.restore(); rc.restore();
// The rectangle should paint without clipping since we restored // The rectangle should paint without clipping since we restored
// context. // context.
rc.drawRect(Rect.fromLTWH(0, 0, 200, 200), goodPaint); rc.drawRect(Rect.fromLTWH(0, 0, 200, 200), goodPaint as engine.SurfacePaint);
await _checkScreenshot(rc, 'context_save_restore_clip'); await _checkScreenshot(rc, 'context_save_restore_clip');
}); });
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'package:ui/ui.dart' as ui; import 'package:ui/ui.dart' as ui;
import 'package:ui/src/engine.dart'; import 'package:ui/src/engine.dart';
...@@ -23,7 +22,7 @@ Future<void> canvasScreenshot(RecordingCanvas rc, String fileName, ...@@ -23,7 +22,7 @@ Future<void> canvasScreenshot(RecordingCanvas rc, String fileName,
final html.Element sceneElement = html.Element.tag('flt-scene'); final html.Element sceneElement = html.Element.tag('flt-scene');
try { try {
sceneElement.append(engineCanvas.rootElement); sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement); html.document.body!.append(sceneElement);
await matchGoldenFile('$fileName.png', await matchGoldenFile('$fileName.png',
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write); region: region, maxDiffRatePercent: maxDiffRatePercent, write: write);
} finally { } finally {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart'; import 'package:test/bootstrap/browser.dart';
...@@ -16,7 +15,7 @@ void main() { ...@@ -16,7 +15,7 @@ void main() {
void testMain() { void testMain() {
test('screenshot test reports failure', () async { test('screenshot test reports failure', () async {
html.document.body.innerHtml = 'Text that does not appear on the screenshot!'; html.document.body!.innerHtml = 'Text that does not appear on the screenshot!';
await matchGoldenFile('__local__/smoke_test.png', region: Rect.fromLTWH(0, 0, 320, 200)); await matchGoldenFile('__local__/smoke_test.png', region: Rect.fromLTWH(0, 0, 320, 200));
}); });
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.6
import 'dart:html' as html; import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart'; import 'package:test/bootstrap/browser.dart';
...@@ -20,8 +19,8 @@ void testMain() async { ...@@ -20,8 +19,8 @@ void testMain() async {
await webOnlyInitializePlatform(assetManager: WebOnlyMockAssetManager()); await webOnlyInitializePlatform(assetManager: WebOnlyMockAssetManager());
test('screenshot test reports success', () async { test('screenshot test reports success', () async {
html.document.body.style.fontFamily = 'Roboto'; html.document.body!.style.fontFamily = 'Roboto';
html.document.body.innerHtml = 'Hello world!'; html.document.body!.innerHtml = 'Hello world!';
// TODO: https://github.com/flutter/flutter/issues/74702 , reduce webkit percentage. // TODO: https://github.com/flutter/flutter/issues/74702 , reduce webkit percentage.
await matchGoldenFile('__local__/smoke_test.png', region: Rect.fromLTWH(0, 0, 320, 200), await matchGoldenFile('__local__/smoke_test.png', region: Rect.fromLTWH(0, 0, 320, 200),
maxDiffRatePercent: browserEngine == BrowserEngine.webkit ? 3.0 : 0.28); maxDiffRatePercent: browserEngine == BrowserEngine.webkit ? 3.0 : 0.28);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册