semantics_4_test.dart 4.17 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 6
import 'dart:ui' show SemanticsFlags;

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

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

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

17 18 19 20 21 22
    //    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
23 24 25
    await tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Stack(
26
        fit: StackFit.expand,
27
        children: <Widget>[
28
          const Semantics(
29
            label: 'L1',
30 31 32 33
          ),
          new Semantics(
            label: 'L2',
            child: new Stack(
34
              fit: StackFit.expand,
35
              children: <Widget>[
36
                const Semantics(
37
                  checked: true,
38
                ),
39
                const Semantics(
40 41 42 43 44 45 46
                  checked: false,
                ),
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
47
    ));
48 49

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

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

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

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

    expect(semantics, hasSemantics(
152
      new TestSemantics.root(
153 154 155 156 157 158
        label: 'L2',
        flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
      )
    ));

    semantics.dispose();
Hixie's avatar
Hixie committed
159 160
  });
}