simple_semantics_test.dart 2.51 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// 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';

7 8 9 10 11 12 13
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'semantics_tester.dart';

void main() {
  testWidgets('Simple tree is simple', (WidgetTester tester) async {
14
    final SemanticsTester semantics = SemanticsTester(tester);
15 16 17

    await tester.pumpWidget(
      const Center(
18
          child: Text('Hello!', textDirection: TextDirection.ltr),
19 20 21
      ),
    );

22
    expect(semantics, hasSemantics(TestSemantics.root(
23
      children: <TestSemantics>[
24
        TestSemantics.rootChild(
25 26 27
          id: 1,
          label: 'Hello!',
          textDirection: TextDirection.ltr,
Dan Field's avatar
Dan Field committed
28
          rect: const Rect.fromLTRB(0.0, 0.0, 84.0, 14.0),
29
          transform: Matrix4.translationValues(358.0, 293.0, 0.0),
30
        ),
31 32 33 34
      ],
    )));

    semantics.dispose();
35
  });
36 37

  testWidgets('Simple tree is simple - material', (WidgetTester tester) async {
38
    final SemanticsTester semantics = SemanticsTester(tester);
39 40

    // Not using Text widget because of https://github.com/flutter/flutter/issues/12357.
41 42 43
    await tester.pumpWidget(MaterialApp(
      home: Center(
        child: Semantics(
44
          label: 'Hello!',
45
          child: const SizedBox(
46 47 48 49 50 51 52
            width: 10.0,
            height: 10.0,
          ),
        ),
      ),
    ));

53
    expect(semantics, hasSemantics(TestSemantics.root(
54
      children: <TestSemantics>[
55
        TestSemantics.rootChild(
56
          id: 1,
Dan Field's avatar
Dan Field committed
57
          rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
58
          children: <TestSemantics>[
59
            TestSemantics(
60
              id: 2,
Dan Field's avatar
Dan Field committed
61
              rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
62
              children: <TestSemantics>[
63
                TestSemantics(
64
                  id: 3,
65 66 67 68 69 70 71 72 73 74 75
                  rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
                      id: 4,
                      label: 'Hello!',
                      textDirection: TextDirection.ltr,
                      rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
                      transform: Matrix4.translationValues(395.0, 295.0, 0.0),
                    ),
                  ],
76
                ),
77 78
              ],
            ),
79 80
          ],
        ),
81 82 83 84
      ],
    )));

    semantics.dispose();
85
  });
86
}