overflow_test.dart 1.71 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
// Copyright 2015 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.

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

import 'rendering_tester.dart';

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

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

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

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