semantics_3_test.dart 3.46 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

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

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

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

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

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

48
    // remove one
49
    await tester.pumpWidget(
50
      Semantics(
51
        container: true,
52 53
        child: Container(
          child: Semantics(
54 55 56 57
             checked: true,
          ),
        ),
      ),
58
    );
59 60

    expect(semantics, hasSemantics(
61
      TestSemantics.root(
62
        children: <TestSemantics>[
63
          TestSemantics.rootChild(
64
            id: 1,
65
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
66 67
            rect: TestSemantics.fullScreen,
          ),
68 69
        ],
      ),
70
    ));
Hixie's avatar
Hixie committed
71

72
    // change what it says
73
    await tester.pumpWidget(
74
      Semantics(
75
        container: true,
76 77
        child: Container(
          child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
78 79
            label: 'test',
            textDirection: TextDirection.ltr,
80 81 82
          ),
        ),
      ),
83
    );
84 85

    expect(semantics, hasSemantics(
86
      TestSemantics.root(
87
        children: <TestSemantics>[
88
          TestSemantics.rootChild(
89 90 91 92 93
            id: 1,
            label: 'test',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
          ),
94 95
        ],
      ),
96
    ));
97 98

    // add a node
99
    await tester.pumpWidget(
100
      Semantics(
101
        container: true,
102 103
        child: Container(
          child: Semantics(
104
            checked: true,
105
            child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
106 107
              label: 'test',
              textDirection: TextDirection.ltr,
108 109 110 111
            ),
          ),
        ),
      ),
112
    );
113 114

    expect(semantics, hasSemantics(
115
      TestSemantics.root(
116
        children: <TestSemantics>[
117
          TestSemantics.rootChild(
118
            id: 1,
119
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
120 121
            label: 'test',
            rect: TestSemantics.fullScreen,
122
          ),
123 124
        ],
      ),
125 126 127 128 129 130
    ));

    int changeCount = 0;
    tester.binding.pipelineOwner.semanticsOwner.addListener(() {
      changeCount += 1;
    });
Hixie's avatar
Hixie committed
131

132
    // make no changes
133
    await tester.pumpWidget(
134
      Semantics(
135
        container: true,
136 137
        child: Container(
          child: Semantics(
138
            checked: true,
139
            child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
140 141
              label: 'test',
              textDirection: TextDirection.ltr,
142 143 144 145
            ),
          ),
        ),
      ),
146
    );
147 148 149 150

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
151 152
  });
}