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

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

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

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

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

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

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

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

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

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

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

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

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

    semantics.dispose();
Hixie's avatar
Hixie committed
235 236
  });
}