semantics_1_test.dart 6.04 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 1', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
14

15
    // smoketest
16
    await tester.pumpWidget(
17
      Semantics(
18
        container: true,
19 20 21 22
        child: Semantics(
          label: 'test1',
          textDirection: TextDirection.ltr,
          selected: true,
23
          child: Container(),
24 25
        ),
      ),
26
    );
27

28
    expect(semantics, hasSemantics(TestSemantics.root(
29
      children: <TestSemantics>[
30
        TestSemantics.rootChild(
31 32 33
          id: 1,
          label: 'test1',
          rect: TestSemantics.fullScreen,
34
          flags: SemanticsFlag.isSelected.index,
35
        ),
36
      ],
37
    )));
Hixie's avatar
Hixie committed
38

39
    // control for forking
40
    await tester.pumpWidget(
41
      Semantics(
42
        container: true,
43
        child: Column(
44 45
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
46
            SizedBox(
47
              height: 10.0,
48
              child: Semantics(
49 50 51 52 53
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
54
            SizedBox(
55
              height: 10.0,
56 57
              child: IgnorePointer(
                child: Semantics(
58 59 60 61 62 63 64 65 66
                  label: 'child1',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
67
    );
68

69
    expect(semantics, hasSemantics(TestSemantics.root(
70
      children: <TestSemantics>[
71
        TestSemantics.rootChild(
72 73 74
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
75
          flags: SemanticsFlag.isSelected.index,
76
        ),
77 78
      ],
    )));
Hixie's avatar
Hixie committed
79

80
    // forking semantics
81
    await tester.pumpWidget(
82
      Semantics(
83
        container: true,
84
        child: Column(
85 86
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
87
            SizedBox(
88
              height: 10.0,
89
              child: Semantics(
90 91 92 93 94
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
95
            SizedBox(
96
              height: 10.0,
97
              child: IgnorePointer(
98
                ignoring: false,
99
                child: Semantics(
100 101 102 103 104 105 106 107 108
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
109
    );
110

111
    expect(semantics, hasSemantics(TestSemantics.root(
112
      children: <TestSemantics>[
113
        TestSemantics.rootChild(
114 115 116
          id: 1,
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
117
            TestSemantics(
118 119
              id: 2,
              label: 'child1',
Dan Field's avatar
Dan Field committed
120
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
121
              flags: SemanticsFlag.isSelected.index,
122
            ),
123
            TestSemantics(
124 125
              id: 3,
              label: 'child2',
Dan Field's avatar
Dan Field committed
126
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
127
              flags: SemanticsFlag.isSelected.index,
128 129 130 131 132
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
Hixie's avatar
Hixie committed
133

134
    // toggle a branch off
135
    await tester.pumpWidget(
136
      Semantics(
137
        container: true,
138
        child: Column(
139 140
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
141
            SizedBox(
142
              height: 10.0,
143
              child: Semantics(
144 145 146 147 148
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
149
            SizedBox(
150
              height: 10.0,
151 152
              child: IgnorePointer(
                child: Semantics(
153 154 155 156 157 158 159 160 161
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
162
    );
163

164
    expect(semantics, hasSemantics(TestSemantics.root(
165
      children: <TestSemantics>[
166
        TestSemantics.rootChild(
167 168 169
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
170
          flags: SemanticsFlag.isSelected.index,
171
        ),
172 173
      ],
    )));
Hixie's avatar
Hixie committed
174

175
    // toggle a branch back on
176
    await tester.pumpWidget(
177
      Semantics(
178
        container: true,
179
        child: Column(
180 181
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
182
            SizedBox(
183
              height: 10.0,
184
              child: Semantics(
185 186 187 188 189
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
190
            SizedBox(
191
              height: 10.0,
192
              child: IgnorePointer(
193
                ignoring: false,
194
                child: Semantics(
195 196 197 198 199 200 201 202 203
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
204
    );
205

206
    expect(semantics, hasSemantics(TestSemantics.root(
207
      children: <TestSemantics>[
208
        TestSemantics.rootChild(
209 210 211
          id: 1,
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
212
            TestSemantics(
213 214
              id: 4,
              label: 'child1',
Dan Field's avatar
Dan Field committed
215
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
216
              flags: SemanticsFlag.isSelected.index,
217
            ),
218
            TestSemantics(
219 220
              id: 3,
              label: 'child2',
Dan Field's avatar
Dan Field committed
221
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
222
              flags: SemanticsFlag.isSelected.index,
223 224 225 226 227
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
228 229

    semantics.dispose();
Hixie's avatar
Hixie committed
230 231
  });
}