From 6d0be04af374646544af096c4bd7f061418c429e Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Tue, 18 Jul 2023 14:28:13 -0400 Subject: [PATCH] [web] sync => isSync , scuba => golden (flutter/engine#43699) This PR addresses some of the items in https://github.com/flutter/flutter/issues/100394 --- engine/src/flutter/lib/ui/painting.dart | 6 +++--- .../lib/web_ui/lib/src/engine/util.dart | 6 +++--- .../test/engine/recording_canvas_test.dart | 2 +- .../canvas_draw_image_golden_test.dart | 4 ++-- .../drawing/canvas_rrect_golden_test.dart | 2 +- .../test/html/drawing/conic_golden_test.dart | 6 +++--- .../web_ui/test/html/paragraph/helper.dart | 2 +- .../{text_scuba.dart => text_goldens.dart} | 21 +++++++------------ .../text_multiline_clipping_golden_test.dart | 18 +++++++--------- .../paragraph/text_overflow_golden_test.dart | 6 +++--- .../text_placeholders_golden_test.dart | 8 +++---- .../test/html/path_to_svg_golden_test.dart | 6 +++--- .../html/recording_canvas_golden_test.dart | 4 ++-- .../lib/web_ui/test/html/screenshot.dart | 4 ++-- 14 files changed, 43 insertions(+), 52 deletions(-) rename engine/src/flutter/lib/web_ui/test/html/paragraph/{text_scuba.dart => text_goldens.dart} (85%) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 238dcd5047..0a6ccf3331 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -6933,10 +6933,10 @@ Future _futurize(_Callbacker callbacker) { // If the callback synchronously throws an error, then synchronously // rethrow that error instead of adding it to the completer. This // prevents the Zone from receiving an uncaught exception. - bool sync = true; + bool isSync = true; final String? error = callbacker((T? t) { if (t == null) { - if (sync) { + if (isSync) { throw Exception('operation failed'); } else { completer.completeError(Exception('operation failed')); @@ -6945,7 +6945,7 @@ Future _futurize(_Callbacker callbacker) { completer.complete(t); } }); - sync = false; + isSync = false; if (error != null) { throw Exception(error); } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart index 13f2377d71..bd4ad5b0ef 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart @@ -52,10 +52,10 @@ Future futurize(Callbacker callbacker) { // If the callback synchronously throws an error, then synchronously // rethrow that error instead of adding it to the completer. This // prevents the Zone from receiving an uncaught exception. - bool sync = true; + bool isSync = true; final String? error = callbacker((T? t) { if (t == null) { - if (sync) { + if (isSync) { throw Exception('operation failed'); } else { completer.completeError(Exception('operation failed')); @@ -64,7 +64,7 @@ Future futurize(Callbacker callbacker) { completer.complete(t); } }); - sync = false; + isSync = false; if (error != null) { throw Exception(error); } diff --git a/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart b/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart index 6ff41a2bff..14ebcb824a 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart @@ -187,7 +187,7 @@ void testMain() { }); }); - test('preserve old scuba test behavior', () { + test('preserve old golden test behavior', () { final RRect outer = RRect.fromRectAndCorners(const Rect.fromLTRB(10, 20, 30, 40)); final RRect inner = diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart index 6c6de54d98..66e7d425b5 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart @@ -382,7 +382,7 @@ Future testMain() async { region: region); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement.remove(); } }); @@ -421,7 +421,7 @@ Future testMain() async { region: region); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement.remove(); } }); diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_rrect_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_rrect_golden_test.dart index 31f5d45e7b..3a7e1359a9 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_rrect_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_rrect_golden_test.dart @@ -17,7 +17,7 @@ Future testMain() async { late RecordingCanvas rc; const Rect canvasRect = Rect.fromLTWH(0, 0, 500, 100); - const Rect region = Rect.fromLTWH(8, 8, 500, 100); // Compensate for old scuba tester padding + const Rect region = Rect.fromLTWH(8, 8, 500, 100); // Compensate for old golden tester padding final SurfacePaint niceRRectPaint = SurfacePaint() ..color = const Color.fromRGBO(250, 186, 218, 1.0) // #fabada diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/conic_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/conic_golden_test.dart index 535f7d1529..851b97801d 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/conic_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/conic_golden_test.dart @@ -14,9 +14,9 @@ void main() { } Future testMain() async { - const Rect region = Rect.fromLTWH(8, 8, 600, 800); // Compensate for old scuba tester padding + const Rect region = Rect.fromLTWH(8, 8, 600, 800); // Compensate for old golden tester padding - Future testPath(Path path, String scubaFileName) async { + Future testPath(Path path, String goldenFileName) async { const Rect canvasBounds = Rect.fromLTWH(0, 0, 600, 800); final BitmapCanvas bitmapCanvas = BitmapCanvas(canvasBounds, RenderStrategy()); @@ -38,7 +38,7 @@ Future testMain() async { domDocument.body!.append(bitmapCanvas.rootElement); canvas.apply(bitmapCanvas, canvasBounds); - await matchGoldenFile('$scubaFileName.png', region: region); + await matchGoldenFile('$goldenFileName.png', region: region); bitmapCanvas.rootElement.remove(); } diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart index 23d56fa27c..855da331fb 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart @@ -85,7 +85,7 @@ Future takeScreenshot( await matchGoldenFile('$fileName.png', region: region); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement.remove(); } } diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_goldens.dart similarity index 85% rename from engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart rename to engine/src/flutter/lib/web_ui/test/html/paragraph/text_goldens.dart index 1f2c5cbb35..f6542a54e8 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_goldens.dart @@ -13,29 +13,24 @@ import 'package:web_engine_tester/golden_tester.dart'; import 'helper.dart'; /// Class that controls some details of how screenshotting is made. -/// -/// (For Googlers: Not really related with internal Scuba anymore) -class EngineScubaTester { - EngineScubaTester(this.viewportSize); +class EngineGoldenTester { + EngineGoldenTester(this.viewportSize); - /// The size of the browser window used in this scuba test. + /// The size of the browser window used in this golden test. final ui.Size viewportSize; - static Future initialize( + static Future initialize( {ui.Size viewportSize = const ui.Size(2400, 1800)}) async { assert(() { if (viewportSize.width.ceil() != viewportSize.width || viewportSize.height.ceil() != viewportSize.height) { throw Exception( - 'Scuba only supports integer screen sizes, but found: $viewportSize'); - } - if (viewportSize.width < 472) { - throw Exception('Scuba does not support screen width smaller than 472'); + 'Gold only supports integer screen sizes, but found: $viewportSize'); } return true; }()); - return EngineScubaTester(viewportSize); + return EngineGoldenTester(viewportSize); } ui.Rect get viewportRegion => @@ -51,7 +46,7 @@ class EngineScubaTester { ); } - /// Prepares the DOM and inserts all the necessary nodes, then invokes scuba's + /// Prepares the DOM and inserts all the necessary nodes, then invokes Gold's /// screenshot diffing. /// /// It also cleans up the DOM after itself. @@ -81,7 +76,7 @@ class EngineScubaTester { ); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement.remove(); } } diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_multiline_clipping_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_multiline_clipping_golden_test.dart index 3350c212c9..375cc68eeb 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_multiline_clipping_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_multiline_clipping_golden_test.dart @@ -9,7 +9,7 @@ import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart'; import '../../common/test_initialization.dart'; -import 'text_scuba.dart'; +import 'text_goldens.dart'; typedef PaintTest = void Function(RecordingCanvas recordingCanvas); @@ -18,8 +18,7 @@ void main() { } Future testMain() async { - // Scuba doesn't give us viewport smaller than 472px wide. - final EngineScubaTester scuba = await EngineScubaTester.initialize( + final EngineGoldenTester goldenTester = await EngineGoldenTester.initialize( viewportSize: const Size(600, 600), ); @@ -42,7 +41,7 @@ Future testMain() async { // [DomCanvas] doesn't support clip commands. if (canvas is! DomCanvas) { paintTest(canvas, paintTextWithClipRect); - return scuba.diffCanvasScreenshot( + return goldenTester.diffCanvasScreenshot( canvas, 'multiline_text_clipping_rect'); } return null; @@ -55,7 +54,7 @@ Future testMain() async { // [DomCanvas] doesn't support clip commands. if (canvas is! DomCanvas) { paintTest(canvas, paintTextWithClipRectTranslated); - return scuba.diffCanvasScreenshot( + return goldenTester.diffCanvasScreenshot( canvas, 'multiline_text_clipping_rect_translate'); } return null; @@ -68,7 +67,7 @@ Future testMain() async { // [DomCanvas] doesn't support clip commands. if (canvas is! DomCanvas) { paintTest(canvas, paintTextWithClipRoundRect); - return scuba.diffCanvasScreenshot( + return goldenTester.diffCanvasScreenshot( canvas, 'multiline_text_clipping_roundrect'); } return null; @@ -81,7 +80,7 @@ Future testMain() async { // [DomCanvas] doesn't support clip commands. if (canvas is! DomCanvas) { paintTest(canvas, paintTextWithClipPath); - return scuba.diffCanvasScreenshot( + return goldenTester.diffCanvasScreenshot( canvas, 'multiline_text_clipping_path'); } return null; @@ -93,11 +92,8 @@ Future testMain() async { (EngineCanvas canvas) { // [DomCanvas] doesn't support clip commands. if (canvas is! DomCanvas) { - // TODO(mdebbar): https://github.com/flutter/flutter/issues/35086 - // This produces the wrong result when using [BitmapCanvas] but without - // the new experimental canvas mode. paintTest(canvas, paintTextWithClipStack); - return scuba.diffCanvasScreenshot( + return goldenTester.diffCanvasScreenshot( canvas, 'multiline_text_clipping_stack1'); } return null; diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_overflow_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_overflow_golden_test.dart index 6d922396d9..26744ec87d 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_overflow_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_overflow_golden_test.dart @@ -9,7 +9,7 @@ import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart' hide window; import '../../common/test_initialization.dart'; -import 'text_scuba.dart'; +import 'text_goldens.dart'; const String threeLines = 'First\nSecond\nThird'; const String veryLong = @@ -21,7 +21,7 @@ void main() { } Future testMain() async { - final EngineScubaTester scuba = await EngineScubaTester.initialize( + final EngineGoldenTester goldenTester = await EngineGoldenTester.initialize( viewportSize: const Size(800, 800), ); @@ -55,6 +55,6 @@ Future testMain() async { canvas.drawParagraph(p, offset); offset = offset.translate(0, p.height + 10); - return scuba.diffCanvasScreenshot(canvas, 'text_max_lines'); + return goldenTester.diffCanvasScreenshot(canvas, 'text_max_lines'); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_placeholders_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_placeholders_golden_test.dart index 15a961ced6..916d28a283 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_placeholders_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_placeholders_golden_test.dart @@ -8,14 +8,14 @@ import 'package:ui/ui.dart'; import '../../common/test_initialization.dart'; import 'helper.dart'; -import 'text_scuba.dart'; +import 'text_goldens.dart'; void main() { internalBootstrapBrowserTest(() => testMain); } Future testMain() async { - final EngineScubaTester scuba = await EngineScubaTester.initialize( + final EngineGoldenTester goldenTester = await EngineGoldenTester.initialize( viewportSize: const Size(600, 600), ); @@ -42,7 +42,7 @@ Future testMain() async { } recordingCanvas.endRecording(); recordingCanvas.apply(canvas, screenRect); - return scuba.diffCanvasScreenshot(canvas, 'text_with_placeholders'); + return goldenTester.diffCanvasScreenshot(canvas, 'text_with_placeholders'); }); testEachCanvas('text alignment and placeholders', (EngineCanvas canvas) { @@ -75,7 +75,7 @@ Future testMain() async { ); recordingCanvas.endRecording(); recordingCanvas.apply(canvas, screenRect); - return scuba.diffCanvasScreenshot(canvas, 'text_align_with_placeholders'); + return goldenTester.diffCanvasScreenshot(canvas, 'text_align_with_placeholders'); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart index c40471289c..048803defc 100644 --- a/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart @@ -22,9 +22,9 @@ enum PaintMode { Future testMain() async { const Rect region = - Rect.fromLTWH(8, 8, 600, 400); // Compensate for old scuba tester padding + Rect.fromLTWH(8, 8, 600, 400); // Compensate for old golden tester padding - Future testPath(Path path, String scubaFileName, + Future testPath(Path path, String goldenFileName, {SurfacePaint? paint, PaintMode mode = PaintMode.kStrokeAndFill}) async { const Rect canvasBounds = Rect.fromLTWH(0, 0, 600, 400); @@ -72,7 +72,7 @@ Future testMain() async { sceneElement.append(bitmapCanvas.rootElement); sceneElement.append(svgElement); - await matchGoldenFile('$scubaFileName.png', + await matchGoldenFile('$goldenFileName.png', region: region); bitmapCanvas.rootElement.remove(); diff --git a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart index 8326648b4b..071754c1fe 100644 --- a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart @@ -35,7 +35,7 @@ Future testMain() async { final EngineCanvas engineCanvas = BitmapCanvas(screenRect, RenderStrategy()); - // Draws the estimated bounds so we can spot the bug in Scuba. + // Draws the estimated bounds so we can spot the bug in Gold. engineCanvas ..save() ..drawRect( @@ -63,7 +63,7 @@ Future testMain() async { 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. + // screenshot. sceneElement.remove(); } } diff --git a/engine/src/flutter/lib/web_ui/test/html/screenshot.dart b/engine/src/flutter/lib/web_ui/test/html/screenshot.dart index 445744c51c..f27177caab 100644 --- a/engine/src/flutter/lib/web_ui/test/html/screenshot.dart +++ b/engine/src/flutter/lib/web_ui/test/html/screenshot.dart @@ -48,7 +48,7 @@ Future canvasScreenshot( region: region); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement.remove(); } } @@ -65,7 +65,7 @@ Future sceneScreenshot(SurfaceSceneBuilder sceneBuilder, String fileName, region: region); } finally { // The page is reused across tests, so remove the element after taking the - // Scuba screenshot. + // screenshot. sceneElement?.remove(); } }