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

Commit e17a676

Browse files
committed
add non-recording canvas test; fix Firefox test
1 parent 896c745 commit e17a676

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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)