semantics_2_test.dart 4.82 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 = new 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 23 24 25 26 27 28
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
29
              child: new Semantics(
30 31 32 33 34 35 36
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
37
              child: new IgnorePointer(
38
                ignoring: false,
39
                child: new Semantics(
40 41 42 43 44 45 46 47 48
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
49
    );
50

51 52 53
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
54
          id: 1,
55 56 57
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
            new TestSemantics(
58
              id: 2,
59 60
              label: 'child1',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
61
              flags: SemanticsFlag.isSelected.index,
62 63
            ),
            new TestSemantics(
64
              id: 3,
65 66
              label: 'child2',
              rect: new 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 77 78 79 80 81 82
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
83
              child: new Semantics(
84 85 86 87 88 89 90
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
91
              child: new IgnorePointer(
92
                ignoring: true,
93
                child: new Semantics(
94 95 96 97 98 99 100 101 102
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
103
    );
104

105 106 107
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new 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 119 120 121 122 123 124
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
125
              child: new Semantics(
126 127 128 129 130 131 132
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
133
              child: new IgnorePointer(
134
                ignoring: false,
135
                child: new Semantics(
136 137 138 139 140 141 142 143 144
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
145
    );
146

147 148 149
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
150
          id: 1,
151 152 153 154 155 156
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
            new TestSemantics(
              id: 4,
              label: 'child1',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
157
              flags: SemanticsFlag.isSelected.index,
158 159
            ),
            new TestSemantics(
160
              id: 3,
161 162
              label: 'child2',
              rect: new 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
  });
}