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

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('LimitedBox: parent max size is unconstrained', () {
14
    final RenderBox child = RenderConstrainedBox(
15
      additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0),
16
    );
17
    final RenderBox parent = RenderConstrainedOverflowBox(
18
      minWidth: 0.0,
19
      maxWidth: double.infinity,
20
      minHeight: 0.0,
21
      maxHeight: double.infinity,
22
      child: RenderLimitedBox(
23 24
        maxWidth: 100.0,
        maxHeight: 200.0,
25 26
        child: child,
      ),
27 28 29 30
    );
    layout(parent);
    expect(child.size.width, 100.0);
    expect(child.size.height, 200.0);
31 32 33

    expect(parent, hasAGoodToStringDeep);
    expect(
34
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
35
      equalsIgnoringHashCodes(
36
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
37 38 39
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
40
        ' │ alignment: Alignment.center\n'
41 42 43 44
        ' │ minWidth: 0.0\n'
        ' │ maxWidth: Infinity\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
45
        ' │ fit: max\n'
46
        ' │\n'
47
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
48 49 50 51 52 53 54 55 56 57 58 59 60
        '   │ 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',
      ),
    );
61 62
  });

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

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

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

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

    expect(parent, hasAGoodToStringDeep);
    expect(
121
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
122
      equalsIgnoringHashCodes(
123
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
124 125 126
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
127
        ' │ alignment: Alignment.center\n'
128 129 130 131
        ' │ minWidth: 10.0\n'
        ' │ maxWidth: 500.0\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
132
        ' │ fit: max\n'
133 134 135 136 137 138 139 140 141
        ' │\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
142
  });
143 144 145

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

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