traversal_order_test.dart 2.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2018 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/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import '../widgets/semantics_tester.dart';

void main() {
  testWidgets('Traversal order handles touching elements', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
14
    await tester.pumpWidget(
15 16 17
      MaterialApp(
        home: Column(
          children: List<Widget>.generate(3, (int column) {
18 19 20 21 22 23 24 25 26 27 28 29 30
            return Row(
              children: List<Widget>.generate(3, (int row) {
                return Semantics(
                  child: SizedBox(
                    width: 50.0,
                    height: 50.0,
                    child: Text('$column - $row'),
                  ),
                );
              }),
            );
          }),
        ),
31
      ),
32
    );
33

34
    final TestSemantics expected = TestSemantics.root(
35
      children: <TestSemantics>[
36
        TestSemantics(
37 38 39
          id: 1,
          textDirection: TextDirection.ltr,
          children: <TestSemantics>[
40
            TestSemantics(
41 42 43
              id: 2,
              flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
              children: <TestSemantics>[
44
                TestSemantics(
45 46 47 48
                  id: 3,
                  label: '0 - 0',
                  textDirection: TextDirection.ltr,
                ),
49
                TestSemantics(
50 51 52 53
                  id: 4,
                  label: '0 - 1',
                  textDirection: TextDirection.ltr,
                ),
54
                TestSemantics(
55 56 57 58
                  id: 5,
                  label: '0 - 2',
                  textDirection: TextDirection.ltr,
                ),
59
                TestSemantics(
60 61 62 63
                  id: 6,
                  label: '1 - 0',
                  textDirection: TextDirection.ltr,
                ),
64
                TestSemantics(
65 66 67 68
                  id: 7,
                  label: '1 - 1',
                  textDirection: TextDirection.ltr,
                ),
69
                TestSemantics(
70 71 72 73
                  id: 8,
                  label: '1 - 2',
                  textDirection: TextDirection.ltr,
                ),
74
                TestSemantics(
75 76 77 78
                  id: 9,
                  label: '2 - 0',
                  textDirection: TextDirection.ltr,
                ),
79
                TestSemantics(
80 81 82 83
                  id: 10,
                  label: '2 - 1',
                  textDirection: TextDirection.ltr,
                ),
84
                TestSemantics(
85 86 87 88 89 90 91 92 93 94 95 96 97 98
                  id: 11,
                  label: '2 - 2',
                  textDirection: TextDirection.ltr,
                ),
              ],
            ),
          ],
        ),
      ],
    );
    expect(semantics, hasSemantics(expected, ignoreRect: true, ignoreTransform: true));
    semantics.dispose();
  });
}