[web] sync => isSync , scuba => golden (flutter/engine#43699)

This PR addresses some of the items in https://github.com/flutter/flutter/issues/100394
This commit is contained in:
Mouad Debbar
2023-07-18 14:28:13 -04:00
committed by GitHub
parent 2e1160d33e
commit 6d0be04af3
14 changed files with 43 additions and 52 deletions

View File

@@ -6933,10 +6933,10 @@ Future<T> _futurize<T>(_Callbacker<T> 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<T> _futurize<T>(_Callbacker<T> callbacker) {
completer.complete(t);
}
});
sync = false;
isSync = false;
if (error != null) {
throw Exception(error);
}

View File

@@ -52,10 +52,10 @@ Future<T> futurize<T>(Callbacker<T> 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<T> futurize<T>(Callbacker<T> callbacker) {
completer.complete(t);
}
});
sync = false;
isSync = false;
if (error != null) {
throw Exception(error);
}

View File

@@ -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 =

View File

@@ -382,7 +382,7 @@ Future<void> 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<void> testMain() async {
region: region);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
// screenshot.
sceneElement.remove();
}
});

View File

@@ -17,7 +17,7 @@ Future<void> 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

View File

@@ -14,9 +14,9 @@ void main() {
}
Future<void> 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<void> testPath(Path path, String scubaFileName) async {
Future<void> 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<void> 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();
}

View File

@@ -85,7 +85,7 @@ Future<void> 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();
}
}

View File

@@ -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<EngineScubaTester> initialize(
static Future<EngineGoldenTester> 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();
}
}

View File

@@ -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<void> 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<void> 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<void> 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<void> 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<void> 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<void> 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;

View File

@@ -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<void> testMain() async {
final EngineScubaTester scuba = await EngineScubaTester.initialize(
final EngineGoldenTester goldenTester = await EngineGoldenTester.initialize(
viewportSize: const Size(800, 800),
);
@@ -55,6 +55,6 @@ Future<void> 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');
});
}

View File

@@ -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<void> testMain() async {
final EngineScubaTester scuba = await EngineScubaTester.initialize(
final EngineGoldenTester goldenTester = await EngineGoldenTester.initialize(
viewportSize: const Size(600, 600),
);
@@ -42,7 +42,7 @@ Future<void> 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<void> testMain() async {
);
recordingCanvas.endRecording();
recordingCanvas.apply(canvas, screenRect);
return scuba.diffCanvasScreenshot(canvas, 'text_align_with_placeholders');
return goldenTester.diffCanvasScreenshot(canvas, 'text_align_with_placeholders');
});
}

View File

@@ -22,9 +22,9 @@ enum PaintMode {
Future<void> 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<void> testPath(Path path, String scubaFileName,
Future<void> 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<void> testMain() async {
sceneElement.append(bitmapCanvas.rootElement);
sceneElement.append(svgElement);
await matchGoldenFile('$scubaFileName.png',
await matchGoldenFile('$goldenFileName.png',
region: region);
bitmapCanvas.rootElement.remove();

View File

@@ -35,7 +35,7 @@ Future<void> 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<void> 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();
}
}

View File

@@ -48,7 +48,7 @@ Future<void> 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<void> 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();
}
}