semantics_owner_test.dart 1.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';

import '../widgets/semantics_tester.dart';

void main() {
12
  testWidgets('Performing SemanticsAction.showOnScreen does not crash if node no longer exist', (WidgetTester tester) async {
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    // Regression test for https://github.com/flutter/flutter/issues/100358.

    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Semantics(
          explicitChildNodes: true,
          child: const Text('Hello World'),
        ),
      ),
    );

    final int nodeId = tester.semantics.find(find.bySemanticsLabel('Hello World')).id;

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Container(),
      ),
    );

    // Node with $nodeId is no longer in the tree.
    expect(semantics, isNot(hasSemantics(TestSemantics(id: nodeId))));

    // Executing SemanticsAction.showOnScreen on that node does not crash.
    // (A platform may not have processed the semantics update yet and send
    // actions for no longer existing nodes.)
    tester.binding.performSemanticsAction(SemanticsActionEvent(
      type: SemanticsAction.showOnScreen,
      nodeId: nodeId,
45
      viewId: tester.view.viewId,
46
    ));
47
    semantics.dispose();
48 49
  });
}