semantics_2_test.dart 4.73 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
// 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';
8
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
Hixie's avatar
Hixie committed
9

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

void main() {
13
  testWidgetsWithLeakTracking('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
            SizedBox(
28
              height: 10.0,
29
              child: Semantics(
30 31 32 33 34
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
35
            SizedBox(
36
              height: 10.0,
37 38
              child: ExcludeSemantics(
                excluding: 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',
Dan Field's avatar
Dan Field committed
60
              rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
61
              flags: SemanticsFlag.isSelected.index,
62
            ),
63
            TestSemantics(
64
              id: 3,
65
              label: 'child2',
Dan Field's avatar
Dan Field committed
66
              rect: const 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
            SizedBox(
82
              height: 10.0,
83
              child: Semantics(
84 85 86 87 88
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
89
            SizedBox(
90
              height: 10.0,
91
              child: ExcludeSemantics(
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 133
              child: ExcludeSemantics(
                excluding: 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
  });
}