overflow_test.dart 1.73 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/rendering.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8 9 10

import 'rendering_tester.dart';

void main() {
11 12
  TestRenderingFlutterBinding.ensureInitialized();

Ian Hickson's avatar
Ian Hickson committed
13
  test('overflow should not affect baseline', () {
14
    RenderBox root, child, text;
15
    late double baseline1, baseline2, height1, height2;
16

17 18 19
    root = RenderPositionedBox(
      child: RenderCustomPaint(
        child: child = text = RenderParagraph(
Ian Hickson's avatar
Ian Hickson committed
20 21 22
          const TextSpan(text: 'Hello World'),
          textDirection: TextDirection.ltr,
        ),
23
        painter: TestCallbackPainter(
24
          onPaint: () {
25
            baseline1 = child.getDistanceToBaseline(TextBaseline.alphabetic)!;
26
            height1 = text.size.height;
27 28 29
          },
        ),
      ),
30 31 32
    );
    layout(root, phase: EnginePhase.paint);

33 34 35 36
    root = RenderPositionedBox(
      child: RenderCustomPaint(
        child: child = RenderConstrainedOverflowBox(
          child: text = RenderParagraph(
Ian Hickson's avatar
Ian Hickson committed
37 38 39
            const TextSpan(text: 'Hello World'),
            textDirection: TextDirection.ltr,
          ),
40
          maxHeight: height1 / 2.0,
41
          alignment: Alignment.topLeft,
42
        ),
43
        painter: TestCallbackPainter(
44
          onPaint: () {
45
            baseline2 = child.getDistanceToBaseline(TextBaseline.alphabetic)!;
46
            height2 = text.size.height;
47 48 49
          },
        ),
      ),
50 51 52 53 54 55 56 57 58
    );
    layout(root, phase: EnginePhase.paint);

    expect(baseline1, lessThan(height1));
    expect(height2, equals(height1 / 2.0));
    expect(baseline2, equals(baseline1));
    expect(baseline2, greaterThan(height2));
  });
}