semantics_11_test.dart 2.66 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
// @dart = 2.8

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

import 'semantics_tester.dart';

void main() {
  testWidgets('markNeedsSemanticsUpdate() called on non-boundary with non-boundary parent', (WidgetTester tester) async {
16
    final SemanticsTester semantics = SemanticsTester(tester);
17 18

    await tester.pumpWidget(
19
      Semantics(
20 21
        container: true,
        onTap: dummyTapHandler,
22
        child: Semantics(
23
          onTap: dummyTapHandler,
24
          child: Semantics(
25 26 27 28 29 30 31 32
            onTap: dummyTapHandler,
            textDirection: TextDirection.ltr,
            label: 'foo',
          ),
        ),
      ),
    );

33
    expect(semantics, hasSemantics(TestSemantics.root(
34
      children: <TestSemantics>[
35
        TestSemantics.rootChild(
36 37 38
          id: 1,
          actions: SemanticsAction.tap.index,
          children: <TestSemantics>[
39
            TestSemantics(
40 41 42
              id: 2,
              actions: SemanticsAction.tap.index,
              children: <TestSemantics>[
43
                TestSemantics(
44 45 46
                  id: 3,
                  actions: SemanticsAction.tap.index,
                  label: 'foo',
47
                ),
48 49 50
              ],
            ),
          ],
51
        ),
52 53 54 55 56 57 58
      ],
    ), ignoreRect: true, ignoreTransform: true));

    // make a change causing call to markNeedsSemanticsUpdate()

    // This should not throw an assert.
    await tester.pumpWidget(
59
      Semantics(
60 61
        container: true,
        onTap: dummyTapHandler,
62
        child: Semantics(
63
          onTap: dummyTapHandler,
64
          child: Semantics(
65 66
            onTap: dummyTapHandler,
            textDirection: TextDirection.ltr,
67
            label: 'bar', // <-- only change
68 69 70 71 72
          ),
        ),
      ),
    );

73
    expect(semantics, hasSemantics(TestSemantics.root(
74
      children: <TestSemantics>[
75
        TestSemantics.rootChild(
76 77 78
          id: 1,
          actions: SemanticsAction.tap.index,
          children: <TestSemantics>[
79
            TestSemantics(
80 81 82
              id: 2,
              actions: SemanticsAction.tap.index,
              children: <TestSemantics>[
83
                TestSemantics(
84 85 86
                  id: 3,
                  actions: SemanticsAction.tap.index,
                  label: 'bar',
87
                ),
88 89 90
              ],
            ),
          ],
91
        ),
92 93 94 95 96 97 98 99
      ],
    ), ignoreRect: true, ignoreTransform: true));

    semantics.dispose();
  });
}

void dummyTapHandler() { }