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

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

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
        label: 'test',
      )
    ));
Hixie's avatar
Hixie committed
38

39
    // remove one
40
    await tester.pumpWidget(
41 42 43 44
      new Container(
        child: new Container(
          child: new Semantics(
            checked: true
Hixie's avatar
Hixie committed
45 46
          )
        )
47 48
      )
    );
49 50 51 52 53 54 55

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
      )
    ));
Hixie's avatar
Hixie committed
56

57
    // change what it says
58
    await tester.pumpWidget(
59 60
      new Container(
        child: new Container(
Hixie's avatar
Hixie committed
61
          child: new Semantics(
62 63 64 65 66
            label: 'test'
          )
        )
      )
    );
67 68 69 70 71 72 73

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        label: 'test',
      )
    ));
74 75

    // add a node
76
    await tester.pumpWidget(
77 78 79 80 81 82
      new Container(
        child: new Semantics(
          checked: true,
          child: new Container(
            child: new Semantics(
              label: 'test'
Hixie's avatar
Hixie committed
83 84 85
            )
          )
        )
86 87
      )
    );
88 89 90 91 92 93 94 95 96 97 98 99 100

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
        label: 'test',
      )
    ));

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

102
    // make no changes
103
    await tester.pumpWidget(
104 105 106 107 108 109
      new Container(
        child: new Semantics(
          checked: true,
          child: new Container(
            child: new Semantics(
              label: 'test'
Hixie's avatar
Hixie committed
110 111 112
            )
          )
        )
113 114
      )
    );
115 116 117 118

    expect(changeCount, 0);

    semantics.dispose();
Hixie's avatar
Hixie committed
119 120
  });
}