@@ -18,9 +18,12 @@ void main() {
18
18
// Initialize all bindings because owner.flushSemantics() requires a window
19
19
final TestRenderObject renderObject = TestRenderObject ();
20
20
int onNeedVisualUpdateCallCount = 0 ;
21
- final PipelineOwner owner = PipelineOwner (onNeedVisualUpdate: () {
22
- onNeedVisualUpdateCallCount += 1 ;
23
- });
21
+ final PipelineOwner owner = PipelineOwner (
22
+ onNeedVisualUpdate: () {
23
+ onNeedVisualUpdateCallCount += 1 ;
24
+ },
25
+ onSemanticsUpdate: (ui.SemanticsUpdate update) {}
26
+ );
24
27
owner.ensureSemantics ();
25
28
renderObject.attach (owner);
26
29
renderObject.layout (const BoxConstraints .tightForFinite ()); // semantics are only calculated if layout information is up to date.
@@ -31,6 +34,49 @@ void main() {
31
34
expect (onNeedVisualUpdateCallCount, 2 );
32
35
});
33
36
37
+ test ('onSemanticsUpdate is called during flushSemantics.' , () {
38
+ int onSemanticsUpdateCallCount = 0 ;
39
+ final PipelineOwner owner = PipelineOwner (
40
+ onSemanticsUpdate: (ui.SemanticsUpdate update) {
41
+ onSemanticsUpdateCallCount += 1 ;
42
+ },
43
+ );
44
+ owner.ensureSemantics ();
45
+
46
+ expect (onSemanticsUpdateCallCount, 0 );
47
+
48
+ final TestRenderObject renderObject = TestRenderObject ();
49
+ renderObject.attach (owner);
50
+ renderObject.layout (const BoxConstraints .tightForFinite ());
51
+ owner.flushSemantics ();
52
+
53
+ expect (onSemanticsUpdateCallCount, 1 );
54
+ });
55
+
56
+ test ('Enabling semantics without configuring onSemanticsUpdate is invalid.' , () {
57
+ final PipelineOwner pipelineOwner = PipelineOwner ();
58
+ expect (() => pipelineOwner.ensureSemantics (), throwsAssertionError);
59
+ });
60
+
61
+
62
+ test ('onSemanticsUpdate during sendSemanticsUpdate.' , () {
63
+ int onSemanticsUpdateCallCount = 0 ;
64
+ final SemanticsOwner owner = SemanticsOwner (
65
+ onSemanticsUpdate: (ui.SemanticsUpdate update) {
66
+ onSemanticsUpdateCallCount += 1 ;
67
+ },
68
+ );
69
+
70
+ final SemanticsNode node = SemanticsNode .root (owner: owner);
71
+ node.rect = Rect .largest;
72
+
73
+ expect (onSemanticsUpdateCallCount, 0 );
74
+
75
+ owner.sendSemanticsUpdate ();
76
+
77
+ expect (onSemanticsUpdateCallCount, 1 );
78
+ });
79
+
34
80
test ('detached RenderObject does not do semantics' , () {
35
81
final TestRenderObject renderObject = TestRenderObject ();
36
82
expect (renderObject.attached, isFalse);
0 commit comments