simple_semantics_test.dart 2.38 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 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,
Dan Field's avatar
Dan Field committed
30
          rect: const Rect.fromLTRB(0.0, 0.0, 84.0, 14.0),
31
          transform: Matrix4.translationValues(358.0, 293.0, 0.0),
32
        ),
33 34 35 36
      ],
    )));

    semantics.dispose();
37
  }, skip: isBrowser);
38 39

  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: 1,
Dan Field's avatar
Dan Field committed
59
          rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
60
          children: <TestSemantics>[
61
            TestSemantics(
62
              id: 2,
Dan Field's avatar
Dan Field committed
63
              rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
64 65
              flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
              children: <TestSemantics>[
66
                TestSemantics(
67
                  id: 3,
68 69
                  label: 'Hello!',
                  textDirection: TextDirection.ltr,
Dan Field's avatar
Dan Field committed
70
                  rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
71
                  transform: Matrix4.translationValues(395.0, 295.0, 0.0),
72
                ),
73 74
              ],
            ),
75 76
          ],
        ),
77 78 79 80
      ],
    )));

    semantics.dispose();
81
  }, skip: isBrowser);
82
}