semantics_1_test.dart 6.1 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 23
        child: Semantics(
          label: 'test1',
          textDirection: TextDirection.ltr,
          child: Container(),
          selected: true,
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
              child: IgnorePointer(
57
                ignoring: true,
58
                child: Semantics(
59 60 61 62 63 64 65 66 67
                  label: 'child1',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
68
    );
69

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

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

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

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

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

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

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

    semantics.dispose();
Hixie's avatar
Hixie committed
232 233
  });
}