absorb_pointer_test.dart 1.79 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

8 9
import 'semantics_tester.dart';

10 11 12 13
void main() {
  testWidgets('AbsorbPointers do not block siblings', (WidgetTester tester) async {
    bool tapped = false;
    await tester.pumpWidget(
14
      Column(
15
        children: <Widget>[
16 17
          Expanded(
            child: GestureDetector(
18 19 20 21
              onTap: () => tapped = true,
            ),
          ),
          const Expanded(
22
            child: AbsorbPointer(
23 24 25 26 27 28 29 30 31 32
              absorbing: true,
            ),
          ),
        ],
      ),
    );

    await tester.tap(find.byType(GestureDetector));
    expect(tapped, true);
  });
33 34

  testWidgets('AbsorbPointers semantics', (WidgetTester tester) async {
35
    final SemanticsTester semantics = SemanticsTester(tester);
36
    await tester.pumpWidget(
37
      AbsorbPointer(
38
        absorbing: true,
39
        child: Semantics(
40 41 42 43 44 45
          label: 'test',
          textDirection: TextDirection.ltr,
        ),
      ),
    );
    expect(semantics, hasSemantics(
46
      TestSemantics.root(), ignoreId: true, ignoreRect: true, ignoreTransform: true));
47 48

    await tester.pumpWidget(
49
      AbsorbPointer(
50
        absorbing: false,
51
        child: Semantics(
52 53 54 55 56 57 58
          label: 'test',
          textDirection: TextDirection.ltr,
        ),
      ),
    );

    expect(semantics, hasSemantics(
59
      TestSemantics.root(
60
        children: <TestSemantics>[
61
          TestSemantics.rootChild(
62 63 64 65 66 67 68 69 70
            label: 'test',
            textDirection: TextDirection.ltr,
          ),
        ],
      ),
      ignoreId: true, ignoreRect: true, ignoreTransform: true));
    semantics.dispose();
  });
}