semantics_7_test.dart 3.59 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// 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/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

9
import 'semantics_tester.dart';
10

11
void main() {
12
  testWidgets('Semantics 7 - Merging', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
14

15
    String label;
16

17
    label = '1';
18
    await tester.pumpWidget(
19
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
20
        textDirection: TextDirection.ltr,
21
        child: Stack(
Ian Hickson's avatar
Ian Hickson committed
22 23
          fit: StackFit.expand,
          children: <Widget>[
24 25
            MergeSemantics(
              child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
26
                checked: true,
27
                container: true,
28
                child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
29
                  container: true,
30 31
                  label: label,
                ),
Ian Hickson's avatar
Ian Hickson committed
32 33
              ),
            ),
34 35
            MergeSemantics(
              child: Stack(
Ian Hickson's avatar
Ian Hickson committed
36 37
                fit: StackFit.expand,
                children: <Widget>[
38
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
39 40
                    checked: true,
                  ),
41
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
42 43 44 45 46 47 48 49
                    label: label,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
50
    );
51 52

    expect(semantics, hasSemantics(
53
      TestSemantics.root(
54
        children: <TestSemantics>[
55
          TestSemantics.rootChild(
56
            id: 1,
57
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
58
            label: label,
59
            rect: TestSemantics.fullScreen,
60 61
          ),
          // IDs 2 and 3 are used up by the nodes that get merged in
62
          TestSemantics.rootChild(
63
            id: 4,
64
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
65
            label: label,
66
            rect: TestSemantics.fullScreen,
67 68 69
          ),
          // IDs 5 and 6 are used up by the nodes that get merged in
        ],
70
      ),
71
    ));
72

73
    label = '2';
74
    await tester.pumpWidget(
75
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
76
        textDirection: TextDirection.ltr,
77
        child: Stack(
Ian Hickson's avatar
Ian Hickson committed
78 79
          fit: StackFit.expand,
          children: <Widget>[
80 81
            MergeSemantics(
              child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
82
                checked: true,
83
                container: true,
84
                child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
85
                  container: true,
86
                  label: label,
Ian Hickson's avatar
Ian Hickson committed
87 88 89
                ),
              ),
            ),
90 91
            MergeSemantics(
              child: Stack(
Ian Hickson's avatar
Ian Hickson committed
92 93
                fit: StackFit.expand,
                children: <Widget>[
94
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
95 96
                    checked: true,
                  ),
97
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
98 99 100 101 102 103 104 105
                    label: label,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
106 107
    );

108
    expect(semantics, hasSemantics(
109
      TestSemantics.root(
110
        children: <TestSemantics>[
111
          TestSemantics.rootChild(
112
            id: 1,
113
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
114
            label: label,
115
            rect: TestSemantics.fullScreen,
116 117
          ),
          // IDs 2 and 3 are used up by the nodes that get merged in
118
          TestSemantics.rootChild(
119
            id: 4,
120
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
121
            label: label,
122
            rect: TestSemantics.fullScreen,
123 124 125
          ),
          // IDs 5 and 6 are used up by the nodes that get merged in
        ],
126
      ),
127
    ));
128

129
    semantics.dispose();
130 131
  });
}