semantics_1_test.dart 6.37 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 1', (WidgetTester tester) async {
14
    final SemanticsTester semantics = new SemanticsTester(tester);
Hixie's avatar
Hixie committed
15

16
    // smoketest
17
    await tester.pumpWidget(
18 19 20 21 22 23 24 25 26 27 28
      new Semantics(
        container: true,
        child: new Container(
          child: new Semantics(
            label: 'test1',
            textDirection: TextDirection.ltr,
            child: new Container(),
            selected: true,
          ),
        ),
      ),
29
    );
30

31 32 33 34 35 36
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
          id: 1,
          label: 'test1',
          rect: TestSemantics.fullScreen,
37
          flags: SemanticsFlag.isSelected.index,
38 39 40
        )
      ]
    )));
Hixie's avatar
Hixie committed
41

42
    // control for forking
43
    await tester.pumpWidget(
44 45 46 47 48 49 50
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
51
              child: new Semantics(
52 53 54 55 56 57 58
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
59
              child: new IgnorePointer(
60
                ignoring: true,
61
                child: new Semantics(
62 63 64 65 66 67 68 69 70
                  label: 'child1',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
71
    );
72

73 74 75 76 77 78
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
79
          flags: SemanticsFlag.isSelected.index,
80 81 82
        )
      ],
    )));
Hixie's avatar
Hixie committed
83

84
    // forking semantics
85
    await tester.pumpWidget(
86 87 88 89 90 91 92
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
93
              child: new Semantics(
94 95 96 97 98 99 100
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
101
              child: new IgnorePointer(
102
                ignoring: false,
103
                child: new Semantics(
104 105 106 107 108 109 110 111 112
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
113
    );
114

115 116 117 118 119 120 121 122 123 124
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
          id: 1,
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
            new TestSemantics(
              id: 2,
              label: 'child1',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
125
              flags: SemanticsFlag.isSelected.index,
126 127 128 129 130
            ),
            new TestSemantics(
              id: 3,
              label: 'child2',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
131
              flags: SemanticsFlag.isSelected.index,
132 133 134 135 136
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
Hixie's avatar
Hixie committed
137

138
    // toggle a branch off
139
    await tester.pumpWidget(
140 141 142 143 144 145 146
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
147
              child: new Semantics(
148 149 150 151 152 153 154
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
155
              child: new IgnorePointer(
156
                ignoring: true,
157
                child: new Semantics(
158 159 160 161 162 163 164 165 166
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
167
    );
168

169 170 171 172 173 174
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
          id: 1,
          label: 'child1',
          rect: TestSemantics.fullScreen,
175
          flags: SemanticsFlag.isSelected.index,
176 177 178
        )
      ],
    )));
Hixie's avatar
Hixie committed
179

180
    // toggle a branch back on
181
    await tester.pumpWidget(
182 183 184 185 186 187 188
      new Semantics(
        container: true,
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              height: 10.0,
189
              child: new Semantics(
190 191 192 193 194 195 196
                label: 'child1',
                textDirection: TextDirection.ltr,
                selected: true,
              ),
            ),
            new Container(
              height: 10.0,
197
              child: new IgnorePointer(
198
                ignoring: false,
199
                child: new Semantics(
200 201 202 203 204 205 206 207 208
                  label: 'child2',
                  textDirection: TextDirection.ltr,
                  selected: true,
                ),
              ),
            ),
          ],
        ),
      ),
209
    );
210

211 212 213 214 215 216 217 218 219 220
    expect(semantics, hasSemantics(new TestSemantics.root(
      children: <TestSemantics>[
        new TestSemantics.rootChild(
          id: 1,
          rect: TestSemantics.fullScreen,
          children: <TestSemantics>[
            new TestSemantics(
              id: 4,
              label: 'child1',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
221
              flags: SemanticsFlag.isSelected.index,
222 223 224 225 226
            ),
            new TestSemantics(
              id: 3,
              label: 'child2',
              rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
227
              flags: SemanticsFlag.isSelected.index,
228 229 230 231 232
            ),
          ],
        ),
      ],
    ), ignoreTransform: true));
233 234

    semantics.dispose();
Hixie's avatar
Hixie committed
235 236
  });
}