limited_box_test.dart 5.83 KB
Newer Older
1 2 3 4 5 6
// Copyright 2016 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.

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

import 'rendering_tester.dart';

void main() {
Ian Hickson's avatar
Ian Hickson committed
12
  test('LimitedBox: parent max size is unconstrained', () {
13
    final RenderBox child = new RenderConstrainedBox(
14
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
15
    );
16
    final RenderBox parent = new RenderConstrainedOverflowBox(
17
      minWidth: 0.0,
18
      maxWidth: double.infinity,
19
      minHeight: 0.0,
20
      maxHeight: double.infinity,
21 22 23 24 25 26 27 28 29
      child: new RenderLimitedBox(
        maxWidth: 100.0,
        maxHeight: 200.0,
        child: child
      )
    );
    layout(parent);
    expect(child.size.width, 100.0);
    expect(child.size.height, 200.0);
30 31 32

    expect(parent, hasAGoodToStringDeep);
    expect(
33
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
34 35 36 37 38
      equalsIgnoringHashCodes(
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
39
        ' │ alignment: center\n'
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        ' │ minWidth: 0.0\n'
        ' │ maxWidth: Infinity\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
        ' │\n'
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
        '   │ parentData: offset=Offset(350.0, 200.0) (can use size)\n'
        '   │ constraints: BoxConstraints(unconstrained)\n'
        '   │ size: Size(100.0, 200.0)\n'
        '   │ maxWidth: 100.0\n'
        '   │ maxHeight: 200.0\n'
        '   │\n'
        '   └─child: RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
        '       parentData: <none> (can use size)\n'
        '       constraints: BoxConstraints(0.0<=w<=100.0, 0.0<=h<=200.0)\n'
        '       size: Size(100.0, 200.0)\n'
        '       additionalConstraints: BoxConstraints(w=300.0, h=400.0)\n',
      ),
    );
59 60
  });

Ian Hickson's avatar
Ian Hickson committed
61
  test('LimitedBox: parent maxWidth is unconstrained', () {
62
    final RenderBox child = new RenderConstrainedBox(
63
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
64
    );
65
    final RenderBox parent = new RenderConstrainedOverflowBox(
66
      minWidth: 0.0,
67
      maxWidth: double.infinity,
68 69 70 71 72 73 74 75 76 77 78 79 80
      minHeight: 500.0,
      maxHeight: 500.0,
      child: new RenderLimitedBox(
        maxWidth: 100.0,
        maxHeight: 200.0,
        child: child
      )
    );
    layout(parent);
    expect(child.size.width, 100.0);
    expect(child.size.height, 500.0);
  });

Ian Hickson's avatar
Ian Hickson committed
81
  test('LimitedBox: parent maxHeight is unconstrained', () {
82
    final RenderBox child = new RenderConstrainedBox(
83
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
84
    );
85
    final RenderBox parent = new RenderConstrainedOverflowBox(
86 87 88
      minWidth: 500.0,
      maxWidth: 500.0,
      minHeight: 0.0,
89
      maxHeight: double.infinity,
90 91 92 93 94 95 96 97 98 99 100
      child: new RenderLimitedBox(
        maxWidth: 100.0,
        maxHeight: 200.0,
        child: child
      )
    );
    layout(parent);

    expect(child.size.width, 500.0);
    expect(child.size.height, 200.0);
  });
Ian Hickson's avatar
Ian Hickson committed
101 102 103

  test('LimitedBox: no child', () {
    RenderBox box;
104
    final RenderBox parent = new RenderConstrainedOverflowBox(
Ian Hickson's avatar
Ian Hickson committed
105 106 107
      minWidth: 10.0,
      maxWidth: 500.0,
      minHeight: 0.0,
108
      maxHeight: double.infinity,
Ian Hickson's avatar
Ian Hickson committed
109 110 111 112 113 114 115
      child: box = new RenderLimitedBox(
        maxWidth: 100.0,
        maxHeight: 200.0,
      )
    );
    layout(parent);
    expect(box.size, const Size(10.0, 0.0));
116 117 118

    expect(parent, hasAGoodToStringDeep);
    expect(
119
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
120 121 122 123 124
      equalsIgnoringHashCodes(
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
125
        ' │ alignment: center\n'
126 127 128 129 130 131 132 133 134 135 136 137 138
        ' │ minWidth: 10.0\n'
        ' │ maxWidth: 500.0\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
        ' │\n'
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
        '     parentData: offset=Offset(395.0, 300.0) (can use size)\n'
        '     constraints: BoxConstraints(10.0<=w<=500.0, 0.0<=h<=Infinity)\n'
        '     size: Size(10.0, 0.0)\n'
        '     maxWidth: 100.0\n'
        '     maxHeight: 200.0\n',
      ),
    );
Ian Hickson's avatar
Ian Hickson committed
139
  });
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

  test('LimitedBox: no child use parent', () {
    RenderBox box;
    final RenderBox parent = new RenderConstrainedOverflowBox(
        minWidth: 10.0,
        child: box = new RenderLimitedBox(
          maxWidth: 100.0,
          maxHeight: 200.0,
        )
    );
    layout(parent);
    expect(box.size, const Size(10.0, 600.0));

    expect(parent, hasAGoodToStringDeep);
    expect(
155
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
156 157 158 159 160
      equalsIgnoringHashCodes(
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
161
        ' │ alignment: center\n'
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        ' │ minWidth: 10.0\n'
        ' │ maxWidth: use parent maxWidth constraint\n'
        ' │ minHeight: use parent minHeight constraint\n'
        ' │ maxHeight: use parent maxHeight constraint\n'
        ' │\n'
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
        '     parentData: offset=Offset(395.0, 0.0) (can use size)\n'
        '     constraints: BoxConstraints(10.0<=w<=800.0, h=600.0)\n'
        '     size: Size(10.0, 600.0)\n'
        '     maxWidth: 100.0\n'
        '     maxHeight: 200.0\n',
      ),
    );
  });

177
}