limited_box_test.dart 5.95 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 45
        ' │ minWidth: 0.0\n'
        ' │ maxWidth: Infinity\n'
        ' │ minHeight: 0.0\n'
        ' │ maxHeight: Infinity\n'
        ' │\n'
46
        ' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
47 48 49 50 51 52 53 54 55 56 57 58 59
        '   │ 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',
      ),
    );
60 61
  });

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

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

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

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

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

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

    expect(parent, hasAGoodToStringDeep);
    expect(
156
      parent.toStringDeep(minLevel: DiagnosticLevel.info),
157
      equalsIgnoringHashCodes(
158
        'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
159 160 161
        ' │ parentData: <none>\n'
        ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
        ' │ size: Size(800.0, 600.0)\n'
162
        ' │ alignment: Alignment.center\n'
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
}