semantics_4_test.dart 4.49 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// 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.

5
import 'dart:ui' show SemanticsFlag;
6

Hixie's avatar
Hixie committed
7 8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
9
import 'package:flutter/rendering.dart';
Hixie's avatar
Hixie committed
10 11
import 'package:flutter_test/flutter_test.dart';

12
import 'semantics_tester.dart';
Hixie's avatar
Hixie committed
13 14

void main() {
15
  testWidgets('Semantics 4', (WidgetTester tester) async {
16
    final SemanticsTester semantics = new SemanticsTester(tester);
Hixie's avatar
Hixie committed
17

18 19 20 21 22 23
    //    O
    //   / \       O=root
    //  L   L      L=node with label
    //     / \     C=node with checked
    //    C   C*   *=node removed next pass
    //
Ian Hickson's avatar
Ian Hickson committed
24 25 26
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Stack(
27
        fit: StackFit.expand,
28
        children: <Widget>[
29
          new Semantics(
30
            container: true,
31
            label: 'L1',
32 33 34
          ),
          new Semantics(
            label: 'L2',
35
            container: true,
36
            child: new Stack(
37
              fit: StackFit.expand,
38
              children: <Widget>[
39
                new Semantics(
40
                  checked: true,
41
                ),
42
                new Semantics(
43 44 45 46 47 48 49
                  checked: false,
                ),
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
50
    ));
51 52

    expect(semantics, hasSemantics(
53
      new TestSemantics.root(
54
        children: <TestSemantics>[
55
          new TestSemantics.rootChild(
56
            id: 1,
57
            label: 'L1',
58
            rect: TestSemantics.fullScreen,
59
          ),
60
          new TestSemantics.rootChild(
61
            id: 2,
62
            label: 'L2',
63
            rect: TestSemantics.fullScreen,
64 65
            children: <TestSemantics>[
              new TestSemantics(
66
                id: 3,
67
                flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
68
                rect: TestSemantics.fullScreen,
69 70
              ),
              new TestSemantics(
71
                id: 4,
72
                flags: SemanticsFlag.hasCheckedState.index,
73
                rect: TestSemantics.fullScreen,
74 75 76 77 78 79
              ),
            ]
          ),
        ],
      )
    ));
Hixie's avatar
Hixie committed
80

81 82 83 84 85
    //    O        O=root
    //   / \       L=node with label
    //  L* LC      C=node with checked
    //             *=node removed next pass
    //
Ian Hickson's avatar
Ian Hickson committed
86 87 88
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Stack(
89
        fit: StackFit.expand,
90
        children: <Widget>[
91
          new Semantics(
92
            label: 'L1',
93
            container: true,
94 95 96
          ),
          new Semantics(
            label: 'L2',
97
            container: true,
98
            child: new Stack(
99
              fit: StackFit.expand,
100
              children: <Widget>[
101
                new Semantics(
102
                  checked: true,
103
                ),
104
                new Semantics(),
105 106 107 108 109
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
110
    ));
111 112

    expect(semantics, hasSemantics(
113
      new TestSemantics.root(
114
        children: <TestSemantics>[
115
          new TestSemantics.rootChild(
116
            id: 1,
117
            label: 'L1',
118
            rect: TestSemantics.fullScreen,
119
          ),
120
          new TestSemantics.rootChild(
121
            id: 2,
122
            label: 'L2',
123
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
124
            rect: TestSemantics.fullScreen,
125 126 127 128
          ),
        ],
      )
    ));
Hixie's avatar
Hixie committed
129

130 131 132 133
    //             O=root
    //    OLC      L=node with label
    //             C=node with checked
    //
Ian Hickson's avatar
Ian Hickson committed
134 135 136
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Stack(
137
        fit: StackFit.expand,
138
        children: <Widget>[
139
          new Semantics(),
140 141
          new Semantics(
            label: 'L2',
142
            container: true,
143
            child: new Stack(
144
              fit: StackFit.expand,
145
              children: <Widget>[
146
                new Semantics(
147
                  checked: true,
148
                ),
149
                new Semantics(),
150 151 152 153 154
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
155
    ));
156 157

    expect(semantics, hasSemantics(
158
      new TestSemantics.root(
159 160
        children: <TestSemantics>[
          new TestSemantics.rootChild(
161
            id: 2,
162
            label: 'L2',
163
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
164 165 166
            rect: TestSemantics.fullScreen,
          ),
        ],
167 168 169 170
      )
    ));

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