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

15 16 17
    // 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
18

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

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

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

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

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

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

    semantics.dispose();
Hixie's avatar
Hixie committed
170 171
  });
}