semantics_1_test.dart 6.21 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 11
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

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

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

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

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

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

75
    expect(semantics, hasSemantics(TestSemantics.root(
76
      children: <TestSemantics>[
77
        TestSemantics.rootChild(
78 79 80
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
81
          flags: SemanticsFlag.isSelected.index,
82
        ),
83 84
      ],
    )));
Hixie's avatar
Hixie committed
85

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

117
    expect(semantics, hasSemantics(TestSemantics.root(
118
      children: <TestSemantics>[
119
        TestSemantics.rootChild(
120 121 122
          id: 1,
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
123
            TestSemantics(
124 125
              id: 2,
              label: 'child1',
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
            TestSemantics(
130 131
              id: 3,
              label: 'child2',
Dan Field's avatar
Dan Field committed
132
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
133
              flags: SemanticsFlag.isSelected.index,
134 135 136 137 138
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
Hixie's avatar
Hixie committed
139

140
    // toggle a branch off
141
    await tester.pumpWidget(
142
      Semantics(
143
        container: true,
144
        child: Column(
145 146
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
147
            Container(
148
              height: 10.0,
149
              child: Semantics(
150 151 152 153 154
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
155
            Container(
156
              height: 10.0,
157
              child: IgnorePointer(
158
                ignoring: true,
159
                child: Semantics(
160 161 162 163 164 165 166 167 168
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
169
    );
170

171
    expect(semantics, hasSemantics(TestSemantics.root(
172
      children: <TestSemantics>[
173
        TestSemantics.rootChild(
174 175 176
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
177
          flags: SemanticsFlag.isSelected.index,
178
        ),
179 180
      ],
    )));
Hixie's avatar
Hixie committed
181

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

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

    semantics.dispose();
Hixie's avatar
Hixie committed
237 238
  });
}