semantics_1_test.dart 3.88 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
    SemanticsTester semantics = new SemanticsTester(tester);
Hixie's avatar
Hixie committed
15

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

    expect(semantics, hasSemantics(new TestSemantics(id: 0, label: 'test1')));
Hixie's avatar
Hixie committed
27

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

    expect(semantics, hasSemantics(new TestSemantics(id: 0, label: 'child1')));
Hixie's avatar
Hixie committed
49

50
    // forking semantics
51
    await tester.pumpWidget(
52
      new Column(
53
        crossAxisAlignment: CrossAxisAlignment.stretch,
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        children: <Widget>[
          new Container(
            height: 10.0,
            child: new Semantics(label: 'child1')
          ),
          new Container(
            height: 10.0,
            child: new IgnorePointer(
              ignoring: false,
              child: new Semantics(label: 'child2')
            )
          ),
        ],
      )
    );
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        children: <TestSemantics>[
          new TestSemantics(
            id: 1,
            label: 'child1',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
          ),
          new TestSemantics(
            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 96 97 98 99 100 101 102 103 104 105 106 107
        children: <Widget>[
          new Container(
            height: 10.0,
            child: new Semantics(label: 'child1')
          ),
          new Container(
            height: 10.0,
            child: new IgnorePointer(
              ignoring: true,
              child: new Semantics(label: 'child2')
            )
          ),
        ],
      )
    );
108 109

    expect(semantics, hasSemantics(new TestSemantics(id: 0, label: 'child1')));
Hixie's avatar
Hixie committed
110

111
    // toggle a branch back on
112
    await tester.pumpWidget(
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
      new Column(
        children: <Widget>[
          new Container(
            height: 10.0,
            child: new Semantics(label: 'child1')
          ),
          new Container(
            height: 10.0,
            child: new IgnorePointer(
              ignoring: false,
              child: new Semantics(label: 'child2')
            )
          ),
        ],
        crossAxisAlignment: CrossAxisAlignment.stretch
      )
    );
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        children: <TestSemantics>[
          new TestSemantics(
            id: 3,
            label: 'child1',
            rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
          ),
          new TestSemantics(
            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
151 152
  });
}