semantics_4_test.dart 3.97 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
    //
23
    await tester.pumpWidget(
24
      new Stack(
25
        fit: StackFit.expand,
26
        children: <Widget>[
27
          const Semantics(
28
            label: 'L1',
29 30 31 32
          ),
          new Semantics(
            label: 'L2',
            child: new Stack(
33
              fit: StackFit.expand,
34
              children: <Widget>[
35
                const Semantics(
36
                  checked: true,
37
                ),
38
                const Semantics(
39 40 41 42 43 44 45
                  checked: false,
                ),
              ],
            ),
          ),
        ],
      ),
46
    );
47 48

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

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

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

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

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

    semantics.dispose();
Hixie's avatar
Hixie committed
156 157
  });
}