overflow_test.dart 1.74 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 7 8 9 10 11
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';

import 'rendering_tester.dart';

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

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

    root = new RenderPositionedBox(
      child: new RenderCustomPaint(
34
        child: child = new RenderConstrainedOverflowBox(
Ian Hickson's avatar
Ian Hickson committed
35 36 37 38
          child: text = new RenderParagraph(
            const TextSpan(text: 'Hello World'),
            textDirection: TextDirection.ltr,
          ),
39
          maxHeight: height1 / 2.0,
40
          alignment: Alignment.topLeft,
41
        ),
42 43 44 45
        painter: new TestCallbackPainter(
          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));
  });
}