semantics_clipping_test.dart 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2017 The Chromium 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/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'semantics_tester.dart';

void main() {
  testWidgets('SemanticNode.rect is clipped', (WidgetTester tester) async {
14
    final SemanticsTester semantics = SemanticsTester(tester);
15

16
    await tester.pumpWidget(Directionality(
17
      textDirection: TextDirection.ltr,
18 19
      child: Center(
        child: Container(
20
          width: 100.0,
21
          child: Flex(
22 23
            direction: Axis.horizontal,
            children: <Widget>[
24
              Container(
25 26 27
                width: 75.0,
                child: const Text('1'),
              ),
28
              Container(
29 30 31
                width: 75.0,
                child: const Text('2'),
              ),
32
              Container(
33 34 35 36 37 38 39 40 41
                width: 75.0,
                child: const Text('3'),
              ),
            ],
          ),
        ),
      ),
    ));

42 43
    expect(tester.takeException(), contains('overflowed'));

44
    expect(semantics, hasSemantics(
45
      TestSemantics.root(
46
        children: <TestSemantics>[
47
          TestSemantics(
48
            label: '1',
49
            rect: Rect.fromLTRB(0.0, 0.0, 75.0, 14.0),
50
          ),
51
          TestSemantics(
52
            label: '2',
53
            rect: Rect.fromLTRB(0.0, 0.0, 25.0, 14.0), // clipped form original 75.0 to 25.0
54 55 56 57 58
          ),
          // node with Text 3 not present.
        ],
      ),
      ignoreTransform: true,
59
      ignoreId: true,
60 61 62 63 64 65
    ));

    semantics.dispose();
  });

  testWidgets('SemanticsNode is not removed if out of bounds and merged into something within bounds', (WidgetTester tester) async {
66
    final SemanticsTester semantics = SemanticsTester(tester);
67

68
    await tester.pumpWidget(Directionality(
69
      textDirection: TextDirection.ltr,
70 71
      child: Center(
        child: Container(
72
          width: 100.0,
73
          child: Flex(
74 75
            direction: Axis.horizontal,
            children: <Widget>[
76
              Container(
77 78 79
                width: 75.0,
                child: const Text('1'),
              ),
80 81
              MergeSemantics(
                child: Flex(
82 83
                  direction: Axis.horizontal,
                  children: <Widget>[
84
                    Container(
85 86 87
                      width: 75.0,
                      child: const Text('2'),
                    ),
88
                    Container(
89 90 91 92 93 94 95 96 97 98 99 100
                      width: 75.0,
                      child: const Text('3'),
                    ),
                  ]
                )
              ),
            ],
          ),
        ),
      ),
    ));

101 102
    expect(tester.takeException(), contains('overflowed'));

103
    expect(semantics, hasSemantics(
104
      TestSemantics.root(
105
        children: <TestSemantics>[
106
          TestSemantics(
107
            label: '1',
108
            rect: Rect.fromLTRB(0.0, 0.0, 75.0, 14.0),
109
          ),
110
          TestSemantics(
111
            label: '2\n3',
112
            rect: Rect.fromLTRB(0.0, 0.0, 25.0, 14.0), // clipped form original 75.0 to 25.0
113 114 115 116
          ),
        ],
      ),
      ignoreTransform: true,
117
      ignoreId: true,
118 119 120 121 122
    ));

    semantics.dispose();
  });
}