semantics_3_test.dart 3.58 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
import 'dart:ui' show SemanticsFlag;
6

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 3', (WidgetTester tester) async {
15
    final SemanticsTester semantics = new SemanticsTester(tester);
Hixie's avatar
Hixie committed
16

17
    // implicit annotators
18
    await tester.pumpWidget(
19 20 21 22 23 24 25
      new Semantics(
        container: true,
        child: new Container(
          child: new Semantics(
            label: 'test',
            textDirection: TextDirection.ltr,
            child: new Container(
26
              child: new Semantics(
27 28 29 30 31 32
                checked: true
              ),
            ),
          ),
        ),
      ),
33
    );
34 35

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

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

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

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

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

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

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

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

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

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
151 152
  });
}