semantics_4_test.dart 4.33 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6
// Copyright 2015 The Chromium 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:flutter/material.dart';
import 'package:flutter/widgets.dart';
7
import 'package:flutter/rendering.dart';
Hixie's avatar
Hixie committed
8 9
import 'package:flutter_test/flutter_test.dart';

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

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

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

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

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

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

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

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

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