simple_semantics_test.dart 2.32 KB
Newer Older
1 2 3 4
// Copyright 2017 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.

5 6
import 'dart:ui';

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

import 'semantics_tester.dart';

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

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

24
    expect(semantics, hasSemantics(TestSemantics.root(
25
      children: <TestSemantics>[
26
        TestSemantics.rootChild(
27 28 29
          id: 1,
          label: 'Hello!',
          textDirection: TextDirection.ltr,
30 31
          rect: Rect.fromLTRB(0.0, 0.0, 84.0, 14.0),
          transform: Matrix4.translationValues(358.0, 293.0, 0.0),
32
        ),
33 34 35 36 37 38 39
      ],
    )));

    semantics.dispose();
  });

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

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

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

    semantics.dispose();
  });
}