semantics_3_test.dart 3.44 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
        child: Container(
          child: Semantics(
21 22
            label: 'test',
            textDirection: TextDirection.ltr,
23 24
            child: Container(
              child: Semantics(
25 26 27 28 29 30
                checked: true
              ),
            ),
          ),
        ),
      ),
31
    );
32 33

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

46
    // remove one
47
    await tester.pumpWidget(
48
      Semantics(
49
        container: true,
50 51
        child: Container(
          child: Semantics(
52 53 54 55
             checked: true,
          ),
        ),
      ),
56
    );
57 58

    expect(semantics, hasSemantics(
59
      TestSemantics.root(
60
        children: <TestSemantics>[
61
          TestSemantics.rootChild(
62
            id: 1,
63
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
64 65
            rect: TestSemantics.fullScreen,
          ),
66 67
        ],
      ),
68
    ));
Hixie's avatar
Hixie committed
69

70
    // change what it says
71
    await tester.pumpWidget(
72
      Semantics(
73
        container: true,
74 75
        child: Container(
          child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
76 77
            label: 'test',
            textDirection: TextDirection.ltr,
78 79 80
          ),
        ),
      ),
81
    );
82 83

    expect(semantics, hasSemantics(
84
      TestSemantics.root(
85
        children: <TestSemantics>[
86
          TestSemantics.rootChild(
87 88 89 90 91
            id: 1,
            label: 'test',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
          ),
92 93
        ],
      ),
94
    ));
95 96

    // add a node
97
    await tester.pumpWidget(
98
      Semantics(
99
        container: true,
100 101
        child: Container(
          child: Semantics(
102
            checked: true,
103
            child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
104 105
              label: 'test',
              textDirection: TextDirection.ltr,
106 107 108 109
            ),
          ),
        ),
      ),
110
    );
111 112

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

    int changeCount = 0;
    tester.binding.pipelineOwner.semanticsOwner.addListener(() {
      changeCount += 1;
    });
Hixie's avatar
Hixie committed
129

130
    // make no changes
131
    await tester.pumpWidget(
132
      Semantics(
133
        container: true,
134 135
        child: Container(
          child: Semantics(
136
            checked: true,
137
            child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
138 139
              label: 'test',
              textDirection: TextDirection.ltr,
140 141 142 143
            ),
          ),
        ),
      ),
144
    );
145 146 147 148

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
149 150
  });
}