simple_semantics_test.dart 2.62 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
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
9
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
10 11 12 13

import 'semantics_tester.dart';

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

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

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

    semantics.dispose();
36
  });
37

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

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

54
    expect(semantics, hasSemantics(TestSemantics.root(
55
      children: <TestSemantics>[
56
        TestSemantics.rootChild(
57
          id: 1,
Dan Field's avatar
Dan Field committed
58
          rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
59
          children: <TestSemantics>[
60
            TestSemantics(
61
              id: 2,
Dan Field's avatar
Dan Field committed
62
              rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
63
              children: <TestSemantics>[
64
                TestSemantics(
65
                  id: 3,
66 67 68 69 70 71 72 73 74 75 76
                  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),
                    ),
                  ],
77
                ),
78 79
              ],
            ),
80 81
          ],
        ),
82 83 84 85
      ],
    )));

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