semantics_3_test.dart 3.26 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie committed
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
8
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
Hixie's avatar
Hixie committed
9

10
import 'semantics_tester.dart';
Hixie's avatar
Hixie committed
11 12

void main() {
13
  testWidgetsWithLeakTracking('Semantics 3', (WidgetTester tester) async {
14
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
15

16
    // implicit annotators
17
    await tester.pumpWidget(
18
      Semantics(
19
        container: true,
20 21 22
        child: Semantics(
          label: 'test',
          textDirection: TextDirection.ltr,
23
          child: Semantics(
24
            checked: true,
25 26 27
          ),
        ),
      ),
28
    );
29 30

    expect(semantics, hasSemantics(
31
      TestSemantics.root(
32
        children: <TestSemantics>[
33
          TestSemantics.rootChild(
34
            id: 1,
35
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
36 37
            label: 'test',
            rect: TestSemantics.fullScreen,
38
          ),
39 40
        ],
      ),
41
    ));
Hixie's avatar
Hixie committed
42

43
    // remove one
44
    await tester.pumpWidget(
45
      Semantics(
46
        container: true,
47 48
        child: Semantics(
           checked: true,
49 50
        ),
      ),
51
    );
52 53

    expect(semantics, hasSemantics(
54
      TestSemantics.root(
55
        children: <TestSemantics>[
56
          TestSemantics.rootChild(
57
            id: 1,
58
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
59 60
            rect: TestSemantics.fullScreen,
          ),
61 62
        ],
      ),
63
    ));
Hixie's avatar
Hixie committed
64

65
    // change what it says
66
    await tester.pumpWidget(
67
      Semantics(
68
        container: true,
69 70 71
        child: Semantics(
          label: 'test',
          textDirection: TextDirection.ltr,
72 73
        ),
      ),
74
    );
75 76

    expect(semantics, hasSemantics(
77
      TestSemantics.root(
78
        children: <TestSemantics>[
79
          TestSemantics.rootChild(
80 81 82 83 84
            id: 1,
            label: 'test',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
          ),
85 86
        ],
      ),
87
    ));
88 89

    // add a node
90
    await tester.pumpWidget(
91
      Semantics(
92
        container: true,
93 94
        child: Semantics(
          checked: true,
95
          child: Semantics(
96 97
            label: 'test',
            textDirection: TextDirection.ltr,
98 99 100
          ),
        ),
      ),
101
    );
102 103

    expect(semantics, hasSemantics(
104
      TestSemantics.root(
105
        children: <TestSemantics>[
106
          TestSemantics.rootChild(
107
            id: 1,
108
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
109 110
            label: 'test',
            rect: TestSemantics.fullScreen,
111
          ),
112 113
        ],
      ),
114 115 116
    ));

    int changeCount = 0;
117
    tester.binding.pipelineOwner.semanticsOwner!.addListener(() {
118 119
      changeCount += 1;
    });
Hixie's avatar
Hixie committed
120

121
    // make no changes
122
    await tester.pumpWidget(
123
      Semantics(
124
        container: true,
125 126
        child: Semantics(
          checked: true,
127
          child: Semantics(
128 129
            label: 'test',
            textDirection: TextDirection.ltr,
130 131 132
          ),
        ),
      ),
133
    );
134 135 136 137

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
138 139
  });
}