semantics_2_test.dart 3.21 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 2', (WidgetTester tester) async {
14
    SemanticsTester semantics = new SemanticsTester(tester);
Hixie's avatar
Hixie committed
15

16 17 18
    // this test is the same as the test in Semantics 1, but
    // starting with the second branch being ignored and then
    // switching to not ignoring it.
Hixie's avatar
Hixie committed
19

20
    // forking semantics
21
    await tester.pumpWidget(
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
      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
      )
    );
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

    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
58

59
    // toggle a branch off
60
    await tester.pumpWidget(
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
      new Column(
        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')
            )
          ),
        ],
        crossAxisAlignment: CrossAxisAlignment.stretch
      )
    );
78 79

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

81
    // toggle a branch back on
82
    await tester.pumpWidget(
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      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
      )
    );
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

    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
121 122
  });
}