forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpicture_test.dart
More file actions
88 lines (72 loc) · 3.01 KB
/
picture_test.dart
File metadata and controls
88 lines (72 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'common.dart';
void main() {
internalBootstrapBrowserTest(() => testMain);
}
void testMain() {
group('CkPicture', () {
setUpCanvasKitTest();
group('in browsers that do not support FinalizationRegistry', () {
test('can be disposed of manually', () {
browserSupportsFinalizationRegistry = false;
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder);
canvas.drawPaint(ui.Paint());
final CkPicture picture = recorder.endRecording() as CkPicture;
expect(picture.rawSkiaObject, isNotNull);
expect(picture.debugDisposed, isFalse);
picture.debugCheckNotDisposed('Test.'); // must not throw
picture.dispose();
expect(picture.rawSkiaObject, isNull);
expect(picture.debugDisposed, isTrue);
StateError? actualError;
try {
picture.debugCheckNotDisposed('Test.');
} on StateError catch (error) {
actualError = error;
}
expect(actualError, isNotNull);
// TODO(yjbanov): cannot test precise message due to https://github.com/flutter/flutter/issues/96298
expect('$actualError', allOf(
startsWith(
'Bad state: Test.\n'
'The picture has been disposed. '
'When the picture was disposed the stack trace was:\n'
),
contains('StackTrace_current'),
));
// Emulate SkiaObjectCache deleting the picture
picture.delete();
picture.didDelete();
expect(picture.rawSkiaObject, isNull);
// A Picture that's been disposed of can no longer be resurrected
expect(() => picture.resurrect(), throwsStateError);
expect(() => picture.toImage(10, 10), throwsStateError);
expect(() => picture.dispose(), throwsStateError);
});
test('can be deleted by SkiaObjectCache', () {
browserSupportsFinalizationRegistry = false;
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder);
canvas.drawPaint(ui.Paint());
final CkPicture picture = recorder.endRecording() as CkPicture;
expect(picture.rawSkiaObject, isNotNull);
// Emulate SkiaObjectCache deleting the picture
picture.delete();
picture.didDelete();
expect(picture.rawSkiaObject, isNull);
// Deletion is softer than disposal. An object may still be resurrected
// if it was deleted prematurely.
expect(picture.debugDisposed, isFalse);
expect(picture.resurrect(), isNotNull);
});
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/60040
}, skip: isIosSafari);
}