semantics_clipping_test.dart 3.61 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
// 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/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'semantics_tester.dart';

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

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

41
    final dynamic exception = tester.takeException();
Dan Field's avatar
Dan Field committed
42
    expect(exception, isFlutterError);
43 44
    expect(exception.diagnostics.first.level, DiagnosticLevel.summary);
    expect(exception.diagnostics.first.toString(), contains('overflowed'));
45

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

    semantics.dispose();
65
  });
66 67

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

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

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

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

    semantics.dispose();
126
  });
127
}