semantics_4_test.dart 4.29 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 8
// 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';

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

void main() {
12
  testWidgets('Semantics 4', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
14

15 16 17 18 19 20
    //    O
    //   / \       O=root
    //  L   L      L=node with label
    //     / \     C=node with checked
    //    C   C*   *=node removed next pass
    //
21
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
22
      textDirection: TextDirection.ltr,
23
      child: Stack(
24
        fit: StackFit.expand,
25
        children: <Widget>[
26
          Semantics(
27
            container: true,
28
            label: 'L1',
29
          ),
30
          Semantics(
31
            label: 'L2',
32
            container: true,
33
            child: Stack(
34
              fit: StackFit.expand,
35
              children: <Widget>[
36
                Semantics(
37
                  checked: true,
38
                ),
39
                Semantics(
40 41 42 43 44 45 46
                  checked: false,
                ),
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
47
    ));
48 49

    expect(semantics, hasSemantics(
50
      TestSemantics.root(
51
        children: <TestSemantics>[
52
          TestSemantics.rootChild(
53
            id: 1,
54
            label: 'L1',
55
            rect: TestSemantics.fullScreen,
56
          ),
57
          TestSemantics.rootChild(
58
            id: 2,
59
            label: 'L2',
60
            rect: TestSemantics.fullScreen,
61
            children: <TestSemantics>[
62
              TestSemantics(
63
                id: 3,
64
                flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
65
                rect: TestSemantics.fullScreen,
66
              ),
67
              TestSemantics(
68
                id: 4,
69
                flags: SemanticsFlag.hasCheckedState.index,
70
                rect: TestSemantics.fullScreen,
71
              ),
72
            ],
73 74
          ),
        ],
75
      ),
76
    ));
Hixie's avatar
Hixie committed
77

78 79 80 81 82
    //    O        O=root
    //   / \       L=node with label
    //  L* LC      C=node with checked
    //             *=node removed next pass
    //
83
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
84
      textDirection: TextDirection.ltr,
85
      child: Stack(
86
        fit: StackFit.expand,
87
        children: <Widget>[
88
          Semantics(
89
            label: 'L1',
90
            container: true,
91
          ),
92
          Semantics(
93
            label: 'L2',
94
            container: true,
95
            child: Stack(
96
              fit: StackFit.expand,
97
              children: <Widget>[
98
                Semantics(
99
                  checked: true,
100
                ),
101
                Semantics(),
102 103 104 105 106
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
107
    ));
108 109

    expect(semantics, hasSemantics(
110
      TestSemantics.root(
111
        children: <TestSemantics>[
112
          TestSemantics.rootChild(
113
            id: 1,
114
            label: 'L1',
115
            rect: TestSemantics.fullScreen,
116
          ),
117
          TestSemantics.rootChild(
118
            id: 2,
119
            label: 'L2',
120
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
121
            rect: TestSemantics.fullScreen,
122 123
          ),
        ],
124
      ),
125
    ));
Hixie's avatar
Hixie committed
126

127 128 129 130
    //             O=root
    //    OLC      L=node with label
    //             C=node with checked
    //
131
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
132
      textDirection: TextDirection.ltr,
133
      child: Stack(
134
        fit: StackFit.expand,
135
        children: <Widget>[
136 137
          Semantics(),
          Semantics(
138
            label: 'L2',
139
            container: true,
140
            child: Stack(
141
              fit: StackFit.expand,
142
              children: <Widget>[
143
                Semantics(
144
                  checked: true,
145
                ),
146
                Semantics(),
147 148 149 150 151
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
152
    ));
153 154

    expect(semantics, hasSemantics(
155
      TestSemantics.root(
156
        children: <TestSemantics>[
157
          TestSemantics.rootChild(
158
            id: 2,
159
            label: 'L2',
160
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
161 162 163
            rect: TestSemantics.fullScreen,
          ),
        ],
164
      ),
165 166 167
    ));

    semantics.dispose();
Hixie's avatar
Hixie committed
168 169
  });
}