Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1a35ebd

Browse files
committed
add non-recording canvas test; fix Firefox test
1 parent 447f9df commit 1a35ebd

File tree

4 files changed

+52
-53
lines changed

4 files changed

+52
-53
lines changed

lib/web_ui/dev/test_runner.dart

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -436,39 +436,39 @@ class TestCommand extends Command<bool> with ArgUtils {
436436
'test',
437437
));
438438

439-
if (isUnitTestsScreenshotsAvailable) {
440-
// Separate screenshot tests from unit-tests. Screenshot tests must run
441-
// one at a time. Otherwise, they will end up screenshotting each other.
442-
// This is not an issue for unit-tests.
443-
final FilePath failureSmokeTestPath = FilePath.fromWebUi(
444-
'test/golden_tests/golden_failure_smoke_test.dart',
445-
);
446-
final List<FilePath> screenshotTestFiles = <FilePath>[];
447-
final List<FilePath> unitTestFiles = <FilePath>[];
448-
449-
for (io.File testFile
450-
in testDir.listSync(recursive: true).whereType<io.File>()) {
451-
final FilePath testFilePath = FilePath.fromCwd(testFile.path);
452-
if (!testFilePath.absolute.endsWith('_test.dart')) {
453-
// Not a test file at all. Skip.
454-
continue;
455-
}
456-
if (testFilePath == failureSmokeTestPath) {
457-
// A smoke test that fails on purpose. Skip.
458-
continue;
459-
}
439+
// Separate screenshot tests from unit-tests. Screenshot tests must run
440+
// one at a time. Otherwise, they will end up screenshotting each other.
441+
// This is not an issue for unit-tests.
442+
final FilePath failureSmokeTestPath = FilePath.fromWebUi(
443+
'test/golden_tests/golden_failure_smoke_test.dart',
444+
);
445+
final List<FilePath> screenshotTestFiles = <FilePath>[];
446+
final List<FilePath> unitTestFiles = <FilePath>[];
447+
448+
for (io.File testFile
449+
in testDir.listSync(recursive: true).whereType<io.File>()) {
450+
final FilePath testFilePath = FilePath.fromCwd(testFile.path);
451+
if (!testFilePath.absolute.endsWith('_test.dart')) {
452+
// Not a test file at all. Skip.
453+
continue;
454+
}
455+
if (testFilePath == failureSmokeTestPath) {
456+
// A smoke test that fails on purpose. Skip.
457+
continue;
458+
}
460459

461-
// All files under test/golden_tests are considered golden tests.
462-
final bool isUnderGoldenTestsDirectory = path.split(testFilePath.relativeToWebUi).contains('golden_tests');
463-
// Any file whose name ends with "_golden_test.dart" is run as a golden test.
464-
final bool isGoldenTestFile = path.basename(testFilePath.relativeToWebUi).endsWith('_golden_test.dart');
465-
if (isUnderGoldenTestsDirectory || isGoldenTestFile) {
466-
screenshotTestFiles.add(testFilePath);
467-
} else {
468-
unitTestFiles.add(testFilePath);
469-
}
460+
// All files under test/golden_tests are considered golden tests.
461+
final bool isUnderGoldenTestsDirectory = path.split(testFilePath.relativeToWebUi).contains('golden_tests');
462+
// Any file whose name ends with "_golden_test.dart" is run as a golden test.
463+
final bool isGoldenTestFile = path.basename(testFilePath.relativeToWebUi).endsWith('_golden_test.dart');
464+
if (isUnderGoldenTestsDirectory || isGoldenTestFile) {
465+
screenshotTestFiles.add(testFilePath);
466+
} else {
467+
unitTestFiles.add(testFilePath);
470468
}
469+
}
471470

471+
if (isUnitTestsScreenshotsAvailable) {
472472
// This test returns a non-zero exit code on purpose. Run it separately.
473473
if (io.Platform.environment['CIRRUS_CI'] != 'true') {
474474
await _runTestBatch(
@@ -478,11 +478,13 @@ class TestCommand extends Command<bool> with ArgUtils {
478478
);
479479
_checkExitCode();
480480
}
481+
}
481482

482-
// Run all unit-tests as a single batch.
483-
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
484-
_checkExitCode();
483+
// Run all unit-tests as a single batch.
484+
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
485+
_checkExitCode();
485486

487+
if (isUnitTestsScreenshotsAvailable) {
486488
// Run screenshot tests one at a time.
487489
for (FilePath testFilePath in screenshotTestFiles) {
488490
await _runTestBatch(
@@ -492,24 +494,6 @@ class TestCommand extends Command<bool> with ArgUtils {
492494
);
493495
_checkExitCode();
494496
}
495-
} else {
496-
final List<FilePath> unitTestFiles = <FilePath>[];
497-
for (io.File testFile
498-
in testDir.listSync(recursive: true).whereType<io.File>()) {
499-
final FilePath testFilePath = FilePath.fromCwd(testFile.path);
500-
if (!testFilePath.absolute.endsWith('_test.dart')) {
501-
// Not a test file at all. Skip.
502-
continue;
503-
}
504-
if (!path
505-
.split(testFilePath.relativeToWebUi)
506-
.contains('golden_tests')) {
507-
unitTestFiles.add(testFilePath);
508-
}
509-
}
510-
// Run all unit-tests as a single batch.
511-
await _runTestBatch(unitTestFiles, concurrency: 10, expectFailure: false);
512-
_checkExitCode();
513497
}
514498
}
515499

lib/web_ui/lib/src/engine/canvaskit/text.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ class CkParagraphBuilder implements ui.ParagraphBuilder {
703703
_styleStack.add(skStyle);
704704
_commands.add(_ParagraphCommand.pushStyle(ckStyle));
705705
if (skStyle.foreground != null || skStyle.background != null) {
706-
// TODO(yjbanov): https://github.com/flutter/flutter/issues/71512
707706
final SkPaint foreground = skStyle.foreground?.skiaObject ?? SkPaint();
708707
final SkPaint background = skStyle.background?.skiaObject ?? SkPaint();
709708
_paragraphBuilder.pushPaintStyle(

lib/web_ui/test/canvaskit/canvas_golden_test.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ void testMain() {
3535
group('CkCanvas', () {
3636
setUpCanvasKitTest();
3737

38-
test('can restore a picture from a snapshot', () async {
38+
test('renders using non-recording canvas if weak refs are supported', () async {
39+
expect(browserSupportsFinalizationRegistry, isTrue,
40+
reason: 'This test specifically tests non-recording canvas, which '
41+
'only works if FinalizationRegistry is available.');
42+
final CkPictureRecorder recorder = CkPictureRecorder();
43+
final CkCanvas canvas = recorder.beginRecording(region);
44+
expect(canvas.runtimeType, CkCanvas);
45+
drawTestPicture(canvas);
46+
await matchPictureGolden('canvaskit_picture_original.png', recorder.endRecording());
47+
});
48+
49+
test('renders using a recording canvas if weak refs are not supported', () async {
3950
browserSupportsFinalizationRegistry = false;
4051
final CkPictureRecorder recorder = CkPictureRecorder();
4152
final CkCanvas canvas = recorder.beginRecording(region);
@@ -47,6 +58,7 @@ void testMain() {
4758

4859
final ByteData originalPixels = await (await originalPicture.toImage(50, 50)).toByteData() as ByteData;
4960

61+
// Test that a picture restored from a snapshot looks the same.
5062
final CkPictureSnapshot? snapshot = canvas.pictureSnapshot;
5163
expect(snapshot, isNotNull);
5264
final SkPicture restoredSkPicture = snapshot!.toPicture();

lib/web_ui/test/canvaskit/canvaskit_api_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,10 @@ void _canvasTests() {
11691169
});
11701170

11711171
test('toImage.toByteData', () async {
1172+
// Pretend that FinalizationRegistry is supported, so we can run this
1173+
// test in older browsers (the test will use a TestCollector instead of
1174+
// ProductionCollector)
1175+
browserSupportsFinalizationRegistry = true;
11721176
final SkPictureRecorder otherRecorder = SkPictureRecorder();
11731177
final SkCanvas otherCanvas =
11741178
otherRecorder.beginRecording(Float32List.fromList([0, 0, 1, 1]));

0 commit comments

Comments
 (0)