semantics_1_test.dart 4.23 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6 7 8 9
// 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.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

10
import 'semantics_tester.dart';
Hixie's avatar
Hixie committed
11 12

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

16
    // smoketest
17
    await tester.pumpWidget(
18 19 20
      new Container(
        child: new Semantics(
          label: 'test1',
Ian Hickson's avatar
Ian Hickson committed
21
          textDirection: TextDirection.ltr,
22
          child: new Container()
Hixie's avatar
Hixie committed
23
        )
24 25
      )
    );
26

27
    expect(semantics, hasSemantics(new TestSemantics.root(label: 'test1')));
Hixie's avatar
Hixie committed
28

29
    // control for forking
30
    await tester.pumpWidget(
31
      new Column(
32
        crossAxisAlignment: CrossAxisAlignment.stretch,
33 34 35
        children: <Widget>[
          new Container(
            height: 10.0,
Ian Hickson's avatar
Ian Hickson committed
36
            child: const Semantics(label: 'child1', textDirection: TextDirection.ltr),
37 38 39
          ),
          new Container(
            height: 10.0,
40
            child: const IgnorePointer(
41
              ignoring: true,
Ian Hickson's avatar
Ian Hickson committed
42
              child: const Semantics(label: 'child2', textDirection: TextDirection.ltr),
43 44 45 46 47
            )
          ),
        ],
      )
    );
48

49
    expect(semantics, hasSemantics(new TestSemantics.root(label: 'child1')));
Hixie's avatar
Hixie committed
50

51
    // forking semantics
52
    await tester.pumpWidget(
53
      new Column(
54
        crossAxisAlignment: CrossAxisAlignment.stretch,
55 56 57
        children: <Widget>[
          new Container(
            height: 10.0,
Ian Hickson's avatar
Ian Hickson committed
58
            child: const Semantics(label: 'child1', textDirection: TextDirection.ltr),
59 60 61
          ),
          new Container(
            height: 10.0,
62
            child: const IgnorePointer(
63
              ignoring: false,
Ian Hickson's avatar
Ian Hickson committed
64
              child: const Semantics(label: 'child2', textDirection: TextDirection.ltr),
65 66 67 68 69
            )
          ),
        ],
      )
    );
70 71

    expect(semantics, hasSemantics(
72
      new TestSemantics.root(
73
        children: <TestSemantics>[
74
          new TestSemantics.rootChild(
75 76 77 78
            id: 1,
            label: 'child1',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
          ),
79
          new TestSemantics.rootChild(
80 81 82 83 84 85 86 87
            id: 2,
            label: 'child2',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
            transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
          ),
        ],
      )
    ));
Hixie's avatar
Hixie committed
88

89
    // toggle a branch off
90
    await tester.pumpWidget(
91
      new Column(
92
        crossAxisAlignment: CrossAxisAlignment.stretch,
93 94 95
        children: <Widget>[
          new Container(
            height: 10.0,
Ian Hickson's avatar
Ian Hickson committed
96
            child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
97 98 99
          ),
          new Container(
            height: 10.0,
100
            child: const IgnorePointer(
101
              ignoring: true,
Ian Hickson's avatar
Ian Hickson committed
102
              child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
103 104 105 106 107
            )
          ),
        ],
      )
    );
108

109
    expect(semantics, hasSemantics(new TestSemantics.root(label: 'child1')));
Hixie's avatar
Hixie committed
110

111
    // toggle a branch back on
112
    await tester.pumpWidget(
113 114 115 116
      new Column(
        children: <Widget>[
          new Container(
            height: 10.0,
Ian Hickson's avatar
Ian Hickson committed
117
            child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
118 119 120
          ),
          new Container(
            height: 10.0,
121
            child: const IgnorePointer(
122
              ignoring: false,
Ian Hickson's avatar
Ian Hickson committed
123
              child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
124 125 126 127 128 129
            )
          ),
        ],
        crossAxisAlignment: CrossAxisAlignment.stretch
      )
    );
130 131

    expect(semantics, hasSemantics(
132
      new TestSemantics.root(
133
        children: <TestSemantics>[
134
          new TestSemantics.rootChild(
135 136 137 138
            id: 3,
            label: 'child1',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
          ),
139
          new TestSemantics.rootChild(
140 141 142 143 144 145 146 147 148 149
            id: 2,
            label: 'child2',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
            transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
          ),
        ],
      )
    ));

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