semantics_3_test.dart 3.16 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie committed
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';
Hixie's avatar
Hixie committed
10 11

void main() {
12
  testWidgets('Semantics 3', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
14

15
    // implicit annotators
16
    await tester.pumpWidget(
17
      Semantics(
18
        container: true,
19 20 21
        child: Semantics(
          label: 'test',
          textDirection: TextDirection.ltr,
22
          child: Semantics(
23
            checked: true,
24 25 26
          ),
        ),
      ),
27
    );
28 29

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

42
    // remove one
43
    await tester.pumpWidget(
44
      Semantics(
45
        container: true,
46 47
        child: Semantics(
           checked: true,
48 49
        ),
      ),
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 59
            rect: TestSemantics.fullScreen,
          ),
60 61
        ],
      ),
62
    ));
Hixie's avatar
Hixie committed
63

64
    // change what it says
65
    await tester.pumpWidget(
66
      Semantics(
67
        container: true,
68 69 70
        child: Semantics(
          label: 'test',
          textDirection: TextDirection.ltr,
71 72
        ),
      ),
73
    );
74 75

    expect(semantics, hasSemantics(
76
      TestSemantics.root(
77
        children: <TestSemantics>[
78
          TestSemantics.rootChild(
79 80 81 82 83
            id: 1,
            label: 'test',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
          ),
84 85
        ],
      ),
86
    ));
87 88

    // add a node
89
    await tester.pumpWidget(
90
      Semantics(
91
        container: true,
92 93
        child: Semantics(
          checked: true,
94
          child: Semantics(
95 96
            label: 'test',
            textDirection: TextDirection.ltr,
97 98 99
          ),
        ),
      ),
100
    );
101 102

    expect(semantics, hasSemantics(
103
      TestSemantics.root(
104
        children: <TestSemantics>[
105
          TestSemantics.rootChild(
106
            id: 1,
107
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
108 109
            label: 'test',
            rect: TestSemantics.fullScreen,
110
          ),
111 112
        ],
      ),
113 114 115
    ));

    int changeCount = 0;
116
    tester.binding.pipelineOwner.semanticsOwner!.addListener(() {
117 118
      changeCount += 1;
    });
Hixie's avatar
Hixie committed
119

120
    // make no changes
121
    await tester.pumpWidget(
122
      Semantics(
123
        container: true,
124 125
        child: Semantics(
          checked: true,
126
          child: Semantics(
127 128
            label: 'test',
            textDirection: TextDirection.ltr,
129 130 131
          ),
        ),
      ),
132
    );
133 134 135 136

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
137 138
  });
}