semantics_11_test.dart 2.64 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// 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/rendering.dart';
7
import 'package:flutter/widgets.dart';
8 9 10 11 12 13
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 {
14
    final SemanticsTester semantics = SemanticsTester(tester);
15 16

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

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

    // make a change causing call to markNeedsSemanticsUpdate()

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

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

    semantics.dispose();
  });
}

void dummyTapHandler() { }