semantics_2_test.dart 4.68 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6 7 8 9
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 2', (WidgetTester tester) async {
14
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
15

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

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

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

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

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

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

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

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