semantics_clipping_test.dart 3.71 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 8 9 10 11 12 13
// 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
    final dynamic exception = tester.takeException();
Dan Field's avatar
Dan Field committed
43
    expect(exception, isFlutterError);
44 45
    expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
    expect(exception.diagnostics.first.toString(), contains('overflowed'));
46

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

    semantics.dispose();
66
  }, skip: isBrowser);
67 68

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

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

104
    final dynamic exception = tester.takeException();
Dan Field's avatar
Dan Field committed
105
    expect(exception, isFlutterError);
106 107
    expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
    expect(exception.diagnostics.first.toString(), contains('overflowed'));
108

109
    expect(semantics, hasSemantics(
110
      TestSemantics.root(
111
        children: <TestSemantics>[
112
          TestSemantics(
113
            label: '1',
Dan Field's avatar
Dan Field committed
114
            rect: const Rect.fromLTRB(0.0, 0.0, 75.0, 14.0),
115
          ),
116
          TestSemantics(
117
            label: '2\n3',
Dan Field's avatar
Dan Field committed
118
            rect: const Rect.fromLTRB(0.0, 0.0, 25.0, 14.0), // clipped form original 75.0 to 25.0
119 120 121 122
          ),
        ],
      ),
      ignoreTransform: true,
123
      ignoreId: true,
124 125 126
    ));

    semantics.dispose();
127
  }, skip: isBrowser);
128
}