semantics_2_test.dart 4.72 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 2', (WidgetTester tester) async {
16
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
17

18 19 20
    // this test is the same as the test in Semantics 1, but
    // starting with the second branch being ignored and then
    // switching to not ignoring it.
Hixie's avatar
Hixie committed
21

22
    // forking semantics
23
    await tester.pumpWidget(
24
      Semantics(
25
        container: true,
26
        child: Column(
27 28
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
29
            Container(
30
              height: 10.0,
31
              child: Semantics(
32 33 34 35 36
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
37
            Container(
38
              height: 10.0,
39
              child: IgnorePointer(
40
                ignoring: false,
41
                child: Semantics(
42 43 44 45 46 47 48 49 50
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
51
    );
52

53
    expect(semantics, hasSemantics(TestSemantics.root(
54
      children: <TestSemantics>[
55
        TestSemantics.rootChild(
56
          id: 1,
57 58
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
59
            TestSemantics(
60
              id: 2,
61
              label: 'child1',
Dan Field's avatar
Dan Field committed
62
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
63
              flags: SemanticsFlag.isSelected.index,
64
            ),
65
            TestSemantics(
66
              id: 3,
67
              label: 'child2',
Dan Field's avatar
Dan Field committed
68
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
69
              flags: SemanticsFlag.isSelected.index,
70 71 72 73 74
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
Hixie's avatar
Hixie committed
75

76
    // toggle a branch off
77
    await tester.pumpWidget(
78
      Semantics(
79
        container: true,
80
        child: Column(
81 82
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
83
            Container(
84
              height: 10.0,
85
              child: Semantics(
86 87 88 89 90
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
91
            Container(
92
              height: 10.0,
93
              child: IgnorePointer(
94
                ignoring: true,
95
                child: Semantics(
96 97 98 99 100 101 102 103 104
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
105
    );
106

107
    expect(semantics, hasSemantics(TestSemantics.root(
108
      children: <TestSemantics>[
109
        TestSemantics.rootChild(
110
          id: 1,
111 112
          label: 'child1',
          rect: TestSemantics.fullScreen,
113
          flags: SemanticsFlag.isSelected.index,
114
        ),
115 116
      ],
    )));
Hixie's avatar
Hixie committed
117

118
    // toggle a branch back on
119
    await tester.pumpWidget(
120
      Semantics(
121
        container: true,
122
        child: Column(
123 124
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
125
            Container(
126
              height: 10.0,
127
              child: Semantics(
128 129 130 131 132
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
133
            Container(
134
              height: 10.0,
135
              child: IgnorePointer(
136
                ignoring: false,
137
                child: Semantics(
138 139 140 141 142 143 144 145 146
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
147
    );
148

149
    expect(semantics, hasSemantics(TestSemantics.root(
150
      children: <TestSemantics>[
151
        TestSemantics.rootChild(
152
          id: 1,
153 154
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
155
            TestSemantics(
156 157
              id: 4,
              label: 'child1',
Dan Field's avatar
Dan Field committed
158
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
159
              flags: SemanticsFlag.isSelected.index,
160
            ),
161
            TestSemantics(
162
              id: 3,
163
              label: 'child2',
Dan Field's avatar
Dan Field committed
164
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
165
              flags: SemanticsFlag.isSelected.index,
166 167 168 169 170
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
171 172

    semantics.dispose();
Hixie's avatar
Hixie committed
173 174
  });
}