Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/web_ui/dev/test_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class BrowserPlatform extends PlatformPlugin {
return shelf.Response.ok(json.encode('OK'));
}

final bool write = requestData['write'] as bool;
final double maxDiffRate = requestData.containsKey('maxdiffrate')
? (requestData['maxdiffrate'] as num)
.toDouble() // can be parsed as either int or double
Expand All @@ -341,22 +340,17 @@ class BrowserPlatform extends PlatformPlugin {
value.toString() == requestData['pixelComparison']);
final bool isCanvaskitTest = requestData['isCanvaskitTest'] as bool;
final String result = await _diffScreenshot(
filename, write, maxDiffRate, region, pixelComparison, isCanvaskitTest);
filename, maxDiffRate, region, pixelComparison, isCanvaskitTest);
return shelf.Response.ok(json.encode(result));
}

Future<String> _diffScreenshot(
String filename,
bool write,
double maxDiffRateFailure,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use the "max diff rate" arguments for anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several things I want to clean up in our golden tests. I'll add max diff rate to the list.

Map<String, dynamic> region,
PixelComparison pixelComparison,
bool isCanvaskitTest,
) async {
if (doUpdateScreenshotGoldens) {
write = true;
}

final Rectangle<num> regionAsRectange = Rectangle<num>(
region['x'] as num,
region['y'] as num,
Expand Down
8 changes: 1 addition & 7 deletions lib/web_ui/test/canvaskit/canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ void testMain() {
}

Future<void> testSampleText(String language, String text,
{ui.TextDirection textDirection = ui.TextDirection.ltr,
bool write = false}) async {
{ui.TextDirection textDirection = ui.TextDirection.ltr}) async {
const double testWidth = 300;
double paragraphHeight = 0;
final CkPicture picture = await generatePictureWhenFontsStable(() {
Expand All @@ -840,7 +839,6 @@ Future<void> testSampleText(String language, String text,
'canvaskit_sample_text_$language.png',
picture,
region: ui.Rect.fromLTRB(0, 0, testWidth, paragraphHeight + 20),
write: write,
);
}
}
Expand Down Expand Up @@ -1176,13 +1174,10 @@ CkImage generateTestImage() {
/// well as in the golden file name. Avoid special characters. Spaces are OK;
/// they are replaced by "_" in the file name.
///
/// Set [write] to true to overwrite the golden file.
///
/// Use [layoutWidth] to customize the width of the paragraph constraints.
Future<void> testTextStyle(
// Test properties
String name, {
bool write = false,
double? layoutWidth,
// Top-level text where only paragraph style applies
String outerText = 'Hello ',
Expand Down Expand Up @@ -1324,7 +1319,6 @@ Future<void> testTextStyle(
'canvaskit_text_styles_${name.replaceAll(' ', '_')}.png',
picture,
region: region,
write: write,
);
expect(notoDownloadQueue.debugIsLoadingFonts, isFalse);
expect(notoDownloadQueue.pendingFonts, isEmpty);
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,6 @@ void _paragraphTests() {
'paragraph_kitchen_sink.png',
region: const ui.Rect.fromLTRB(0, 0, 400, 160),
maxDiffRatePercent: 0.0,
write: true,
);
}

Expand Down
7 changes: 3 additions & 4 deletions lib/web_ui/test/canvaskit/color_filter_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ void main() {

const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

Future<void> matchSceneGolden(String goldenFile, LayerScene scene,
{bool write = false}) async {
Future<void> matchSceneGolden(String goldenFile, LayerScene scene) async {
CanvasKitRenderer.instance.rasterizer.draw(scene.layerTree);
await matchGoldenFile(goldenFile, region: region, write: write);
await matchGoldenFile(goldenFile, region: region);
}

void testMain() {
Expand Down Expand Up @@ -132,7 +131,7 @@ void testMain() {

builder.addPicture(ui.Offset.zero, invertedSquares);

await matchSceneGolden('canvaskit_inverse_colormatrix.png', builder.build(), write: true);
await matchSceneGolden('canvaskit_inverse_colormatrix.png', builder.build());
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
}, skip: isSafari || isFirefox);
Expand Down
5 changes: 2 additions & 3 deletions lib/web_ui/test/canvaskit/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ class TestCollector implements Collector {
/// The picture is drawn onto the UI at [ui.Offset.zero] with no additional
/// layers.
Future<void> matchPictureGolden(String goldenFile, CkPicture picture,
{required ui.Rect region, bool write = false}) async {
{required ui.Rect region}) async {
final LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.addPicture(ui.Offset.zero, picture);
CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree);
await matchGoldenFile(goldenFile,
region: region, maxDiffRatePercent: 0.0, write: write);
await matchGoldenFile(goldenFile, region: region, maxDiffRatePercent: 0.0);
}

/// Sends a platform message to create a Platform View with the given id and viewType.
Expand Down
5 changes: 2 additions & 3 deletions lib/web_ui/test/canvaskit/linear_gradient_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ void main() {

const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

Future<void> matchPictureGolden(String goldenFile, CkPicture picture,
{bool write = false}) async {
Future<void> matchPictureGolden(String goldenFile, CkPicture picture) async {
final LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.addPicture(ui.Offset.zero, picture);
CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree);
await matchGoldenFile(goldenFile, region: region, write: write);
await matchGoldenFile(goldenFile, region: region);
}

void testMain() {
Expand Down
5 changes: 2 additions & 3 deletions lib/web_ui/test/canvaskit/shader_mask_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ void main() {

const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

Future<void> matchSceneGolden(String goldenFile, LayerScene scene,
{bool write = false}) async {
Future<void> matchSceneGolden(String goldenFile, LayerScene scene) async {
CanvasKitRenderer.instance.rasterizer.draw(scene.layerTree);
await matchGoldenFile(goldenFile, region: region, write: write);
await matchGoldenFile(goldenFile, region: region);
}

void testMain() {
Expand Down
5 changes: 2 additions & 3 deletions lib/web_ui/test/canvaskit/sweep_gradient_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ void main() {

const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250);

Future<void> matchPictureGolden(String goldenFile, CkPicture picture,
{bool write = false}) async {
Future<void> matchPictureGolden(String goldenFile, CkPicture picture) async {
final LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.addPicture(ui.Offset.zero, picture);
CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree);
await matchGoldenFile(goldenFile, region: region, write: write);
await matchGoldenFile(goldenFile, region: region);
}

void testMain() {
Expand Down
9 changes: 3 additions & 6 deletions lib/web_ui/test/html/drawing/draw_vertices_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Future<void> testMain() async {
// Commit a recording canvas to a bitmap, and compare with the expected
Future<void> checkScreenshot(RecordingCanvas rc, String fileName,
{Rect region = const Rect.fromLTWH(0, 0, 500, 500),
double maxDiffRatePercent = 0.0,
bool write = false}) async {
double maxDiffRatePercent = 0.0}) async {
final EngineCanvas engineCanvas =
BitmapCanvas(screenRect, RenderStrategy());
rc.endRecording();
Expand All @@ -47,7 +46,6 @@ Future<void> testMain() async {
await matchGoldenFile(
'$fileName.png',
region: region,
write: write,
maxDiffRatePercent: maxDiffRatePercent,
);
} finally {
Expand All @@ -70,13 +68,12 @@ Future<void> testMain() async {
});

Future<void> testVertices(
String fileName, Vertices vertices, BlendMode blendMode, Paint paint,
{bool write = false}) async {
String fileName, Vertices vertices, BlendMode blendMode, Paint paint) async {
final RecordingCanvas rc =
RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500));
rc.drawVertices(
vertices as SurfaceVertices, blendMode, paint as SurfacePaint);
await checkScreenshot(rc, fileName, write: write);
await checkScreenshot(rc, fileName);
}

test('Should draw green hairline triangles when colors array is null.',
Expand Down
2 changes: 0 additions & 2 deletions lib/web_ui/test/html/paragraph/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Future<void> takeScreenshot(
EngineCanvas canvas,
Rect region,
String fileName, {
bool write = false,
double? maxDiffRatePercent,
}) async {
final DomElement sceneElement = createDomElement('flt-scene');
Expand All @@ -63,7 +62,6 @@ Future<void> takeScreenshot(
'$fileName.png',
region: region,
maxDiffRatePercent: maxDiffRatePercent,
write: write,
);
} finally {
// The page is reused across tests, so remove the element after taking the
Expand Down
4 changes: 0 additions & 4 deletions lib/web_ui/test/html/paragraph/text_scuba.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ class EngineScubaTester {
String fileName, {
ui.Rect? region,
double? maxDiffRatePercent,
bool write = false,
}) async {
await matchGoldenFile(
'$fileName.png',
region: region ?? viewportRegion,
maxDiffRatePercent: maxDiffRatePercent,
write: write,
);
}

Expand All @@ -62,7 +60,6 @@ class EngineScubaTester {
String fileName, {
ui.Rect? region,
double? maxDiffRatePercent,
bool write = false,
}) async {
// Wrap in <flt-scene> so that our CSS selectors kick in.
final DomElement sceneElement = createDomElement('flt-scene');
Expand All @@ -83,7 +80,6 @@ class EngineScubaTester {
screenshotName,
region: region,
maxDiffRatePercent: maxDiffRatePercent,
write: write,
);
} finally {
// The page is reused across tests, so remove the element after taking the
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/test/html/path_to_svg_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Future<void> testMain() async {
Future<void> testPath(Path path, String scubaFileName,
{SurfacePaint? paint,
double? maxDiffRatePercent,
bool write = false,
PaintMode mode = PaintMode.kStrokeAndFill}) async {
const Rect canvasBounds = Rect.fromLTWH(0, 0, 600, 400);
final BitmapCanvas bitmapCanvas =
Expand Down Expand Up @@ -75,7 +74,7 @@ Future<void> testMain() async {
sceneElement.append(svgElement);

await matchGoldenFile('$scubaFileName.png',
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write);
region: region, maxDiffRatePercent: maxDiffRatePercent);

bitmapCanvas.rootElement.remove();
svgElement.remove();
Expand Down
6 changes: 2 additions & 4 deletions lib/web_ui/test/html/recording_canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Future<void> testMain() async {

// Commit a recording canvas to a bitmap, and compare with the expected
Future<void> checkScreenshot(RecordingCanvas rc, String fileName,
{ Rect region = const Rect.fromLTWH(0, 0, 500, 500),
bool write = false }) async {
{ Rect region = const Rect.fromLTWH(0, 0, 500, 500) }) async {

final EngineCanvas engineCanvas = BitmapCanvas(screenRect,
RenderStrategy());
Expand Down Expand Up @@ -63,8 +62,7 @@ Future<void> testMain() async {
try {
sceneElement.append(engineCanvas.rootElement);
domDocument.body!.append(sceneElement);
await matchGoldenFile('paint_bounds_for_$fileName.png', region: region,
write: write);
await matchGoldenFile('paint_bounds_for_$fileName.png', region: region);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
9 changes: 4 additions & 5 deletions lib/web_ui/test/html/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import 'package:web_engine_tester/golden_tester.dart';
/// Commit a recording canvas to a bitmap, and compare with the expected.
Future<void> canvasScreenshot(RecordingCanvas rc, String fileName,
{ui.Rect region = const ui.Rect.fromLTWH(0, 0, 600, 800),
double maxDiffRatePercent = 0.0, bool setupPerspective = false,
bool write = false}) async {
double maxDiffRatePercent = 0.0, bool setupPerspective = false}) async {
final EngineCanvas engineCanvas = BitmapCanvas(region,
RenderStrategy());

Expand All @@ -38,7 +37,7 @@ Future<void> canvasScreenshot(RecordingCanvas rc, String fileName,
sceneElement.append(engineCanvas.rootElement);
domDocument.body!.append(sceneElement);
await matchGoldenFile('$fileName.png',
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write);
region: region, maxDiffRatePercent: maxDiffRatePercent);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand All @@ -48,15 +47,15 @@ Future<void> canvasScreenshot(RecordingCanvas rc, String fileName,

Future<void> sceneScreenshot(SurfaceSceneBuilder sceneBuilder, String fileName,
{ui.Rect region = const ui.Rect.fromLTWH(0, 0, 600, 800),
double maxDiffRatePercent = 0.0, bool write = false}) async {
double maxDiffRatePercent = 0.0}) async {
DomElement? sceneElement;
try {
sceneElement = sceneBuilder
.build()
.webOnlyRootElement;
domDocument.body!.append(sceneElement!);
await matchGoldenFile('$fileName.png',
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write);
region: region, maxDiffRatePercent: maxDiffRatePercent);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/test/html/shaders/gradient_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Future<void> testMain() async {
// Commit a recording canvas to a bitmap, and compare with the expected
Future<void> checkScreenshot(RecordingCanvas rc, String fileName,
{Rect region = const Rect.fromLTWH(0, 0, 500, 240),
double maxDiffRatePercent = 0.0, bool write = false}) async {
double maxDiffRatePercent = 0.0}) async {
final EngineCanvas engineCanvas = BitmapCanvas(screenRect,
RenderStrategy());

Expand All @@ -49,7 +49,7 @@ Future<void> testMain() async {
sceneElement.append(engineCanvas.rootElement);
domDocument.body!.append(sceneElement);
await matchGoldenFile('$fileName.png',
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write);
region: region, maxDiffRatePercent: maxDiffRatePercent);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ Future<void> testMain() async {
Future<void> testGradient(String fileName, Shader shader,
{Rect paintRect = const Rect.fromLTRB(50, 50, 300, 300),
Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300),
bool write = false,
double maxDiffRatePercent = 0,
Rect region = const Rect.fromLTWH(0, 0, 500, 500)}) async {
final RecordingCanvas rc = RecordingCanvas(region);
final SurfacePaint paint = SurfacePaint()..shader = shader;
final Path path = Path();
path.addRect(paintRect);
rc.drawPath(path, paint);
await canvasScreenshot(rc, fileName, write: write, region: region,
await canvasScreenshot(rc, fileName, region: region,
maxDiffRatePercent: maxDiffRatePercent);
}

Expand Down
6 changes: 1 addition & 5 deletions web_sdk/web_engine_tester/lib/golden_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ enum PixelComparison {

/// Attempts to match the current browser state with the screenshot [filename].
///
/// If [write] is true, will overwrite the golden file and fail the test. Use
/// it to update golden files.
///
/// If [region] is not null, the golden will only include the part contained by
/// the rectangle.
///
Expand All @@ -51,10 +48,9 @@ enum PixelComparison {
/// [pixelComparison] determines the algorithm used to compare pixels. Uses
/// fuzzy comparison by default.
Future<void> matchGoldenFile(String filename,
{bool write = false, Rect? region, double? maxDiffRatePercent, PixelComparison pixelComparison = PixelComparison.fuzzy}) async {
{Rect? region, double? maxDiffRatePercent, PixelComparison pixelComparison = PixelComparison.fuzzy}) async {
final Map<String, dynamic> serverParams = <String, dynamic>{
'filename': filename,
'write': write,
'region': region == null
? null
: <String, dynamic>{
Expand Down