limited_box_test.dart 5.93 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// 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 = RenderConstrainedBox(
14
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
15
    );
16
    final RenderBox parent = RenderConstrainedOverflowBox(
17
      minWidth: 0.0,
18
      maxWidth: double.infinity,
19
      minHeight: 0.0,
20
      maxHeight: double.infinity,
21
      child: RenderLimitedBox(
22 23
        maxWidth: 100.0,
        maxHeight: 200.0,
24 25
        child: child,
      ),
26 27 28 29
    );
    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
      equalsIgnoringHashCodes(
35
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
36 37 38
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
39
        ' │ alignment: Alignment.center\n'
40 41 42 43 44
        ' │ minWidth: 0.0\n'
        ' │ maxWidth: Infinity\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
        ' │\n'
45
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
46 47 48 49 50 51 52 53 54 55 56 57 58
        '   │ 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 = RenderConstrainedBox(
63
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
64
    );
65
    final RenderBox parent = RenderConstrainedOverflowBox(
66
      minWidth: 0.0,
67
      maxWidth: double.infinity,
68 69
      minHeight: 500.0,
      maxHeight: 500.0,
70
      child: RenderLimitedBox(
71 72
        maxWidth: 100.0,
        maxHeight: 200.0,
73 74
        child: child,
      ),
75 76 77 78 79 80
    );
    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 = RenderConstrainedBox(
83
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
84
    );
85
    final RenderBox parent = RenderConstrainedOverflowBox(
86 87 88
      minWidth: 500.0,
      maxWidth: 500.0,
      minHeight: 0.0,
89
      maxHeight: double.infinity,
90
      child: RenderLimitedBox(
91 92
        maxWidth: 100.0,
        maxHeight: 200.0,
93 94
        child: child,
      ),
95 96 97 98 99 100
    );
    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 = RenderConstrainedOverflowBox(
Ian Hickson's avatar
Ian Hickson committed
105 106 107
      minWidth: 10.0,
      maxWidth: 500.0,
      minHeight: 0.0,
108
      maxHeight: double.infinity,
109
      child: box = RenderLimitedBox(
Ian Hickson's avatar
Ian Hickson committed
110 111
        maxWidth: 100.0,
        maxHeight: 200.0,
112
      ),
Ian Hickson's avatar
Ian Hickson committed
113 114 115
    );
    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
      equalsIgnoringHashCodes(
121
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
122 123 124
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
125
        ' │ alignment: 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

  test('LimitedBox: no child use parent', () {
    RenderBox box;
143
    final RenderBox parent = RenderConstrainedOverflowBox(
144
        minWidth: 10.0,
145
        child: box = RenderLimitedBox(
146 147
          maxWidth: 100.0,
          maxHeight: 200.0,
148
        ),
149 150 151 152 153 154
    );
    layout(parent);
    expect(box.size, const Size(10.0, 600.0));

    expect(parent, hasAGoodToStringDeep);
    expect(
155
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
156
      equalsIgnoringHashCodes(
157
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
158 159 160
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
161
        ' │ alignment: Alignment.center\n'
162 163 164 165 166 167 168 169 170 171 172 173 174 175
        ' │ 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',
      ),
    );
  });
176
}