proxy_box tests (#7658)
This commit is contained in:
@@ -197,7 +197,7 @@ class RenderConstrainedBox extends RenderProxyBox {
|
||||
/// The [additionalConstraints] argument must not be null and must be valid.
|
||||
RenderConstrainedBox({
|
||||
RenderBox child,
|
||||
BoxConstraints additionalConstraints
|
||||
@required BoxConstraints additionalConstraints,
|
||||
}) : _additionalConstraints = additionalConstraints, super(child) {
|
||||
assert(additionalConstraints != null);
|
||||
assert(additionalConstraints.debugAssertIsValid());
|
||||
@@ -386,7 +386,7 @@ class RenderAspectRatio extends RenderProxyBox {
|
||||
/// The [aspectRatio] argument must be a finite, positive value.
|
||||
RenderAspectRatio({
|
||||
RenderBox child,
|
||||
double aspectRatio
|
||||
@required double aspectRatio,
|
||||
}) : _aspectRatio = aspectRatio, super(child) {
|
||||
assert(aspectRatio != null);
|
||||
assert(aspectRatio > 0.0);
|
||||
@@ -776,9 +776,9 @@ class RenderShaderMask extends RenderProxyBox {
|
||||
///
|
||||
/// The [shaderCallback] and [blendMode] arguments must not be null.
|
||||
RenderShaderMask({
|
||||
ShaderCallback shaderCallback,
|
||||
RenderBox child,
|
||||
@required ShaderCallback shaderCallback,
|
||||
BlendMode blendMode: BlendMode.modulate,
|
||||
RenderBox child
|
||||
}) : _shaderCallback = shaderCallback, _blendMode = blendMode, super(child) {
|
||||
assert(shaderCallback != null);
|
||||
assert(blendMode != null);
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Intrinsic sizing 2.0', () {
|
||||
test('RenderAspectRatio: Intrinsic sizing 2.0', () {
|
||||
RenderAspectRatio box = new RenderAspectRatio(aspectRatio: 2.0);
|
||||
|
||||
expect(box.getMinIntrinsicWidth(200.0), 400.0);
|
||||
@@ -28,7 +29,7 @@ void main() {
|
||||
expect(box.getMaxIntrinsicHeight(double.INFINITY), 0.0);
|
||||
});
|
||||
|
||||
test('Intrinsic sizing 0.5', () {
|
||||
test('RenderAspectRatio: Intrinsic sizing 0.5', () {
|
||||
RenderAspectRatio box = new RenderAspectRatio(aspectRatio: 0.5);
|
||||
|
||||
expect(box.getMinIntrinsicWidth(200.0), 100.0);
|
||||
@@ -49,7 +50,7 @@ void main() {
|
||||
expect(box.getMaxIntrinsicHeight(double.INFINITY), 0.0);
|
||||
});
|
||||
|
||||
test('Intrinsic sizing 2.0', () {
|
||||
test('RenderAspectRatio: Intrinsic sizing 2.0', () {
|
||||
RenderAspectRatio box = new RenderAspectRatio(
|
||||
aspectRatio: 2.0,
|
||||
child: new RenderSizedBox(const Size(90.0, 70.0))
|
||||
@@ -73,7 +74,7 @@ void main() {
|
||||
expect(box.getMaxIntrinsicHeight(double.INFINITY), 70.0);
|
||||
});
|
||||
|
||||
test('Intrinsic sizing 0.5', () {
|
||||
test('RenderAspectRatio: Intrinsic sizing 0.5', () {
|
||||
RenderAspectRatio box = new RenderAspectRatio(
|
||||
aspectRatio: 0.5,
|
||||
child: new RenderSizedBox(const Size(90.0, 70.0))
|
||||
@@ -96,4 +97,101 @@ void main() {
|
||||
expect(box.getMinIntrinsicHeight(double.INFINITY), 70.0);
|
||||
expect(box.getMaxIntrinsicHeight(double.INFINITY), 70.0);
|
||||
});
|
||||
|
||||
test('RenderAspectRatio: Unbounded', () {
|
||||
bool hadError = false;
|
||||
FlutterExceptionHandler oldHandler = FlutterError.onError;
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
hadError = true;
|
||||
};
|
||||
RenderBox box = new RenderConstrainedOverflowBox(
|
||||
maxWidth: double.INFINITY,
|
||||
maxHeight: double.INFINITY,
|
||||
child: new RenderAspectRatio(
|
||||
aspectRatio: 0.5,
|
||||
child: new RenderSizedBox(const Size(90.0, 70.0))
|
||||
),
|
||||
);
|
||||
expect(hadError, false);
|
||||
layout(box);
|
||||
expect(hadError, true);
|
||||
FlutterError.onError = oldHandler;
|
||||
});
|
||||
|
||||
test('RenderAspectRatio: Sizing', () {
|
||||
RenderConstrainedOverflowBox outside;
|
||||
RenderAspectRatio inside;
|
||||
layout(outside = new RenderConstrainedOverflowBox(
|
||||
child: inside = new RenderAspectRatio(aspectRatio: 1.0),
|
||||
));
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(800.0, 600.0));
|
||||
outside.minWidth = 0.0;
|
||||
outside.minHeight = 0.0;
|
||||
|
||||
outside.maxWidth = 100.0;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 90.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = 100.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 90.0));
|
||||
|
||||
outside.maxWidth = double.INFINITY;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 90.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = double.INFINITY;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 90.0));
|
||||
|
||||
inside.aspectRatio = 2.0;
|
||||
|
||||
outside.maxWidth = 100.0;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(100.0, 50.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = 100.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 45.0));
|
||||
|
||||
outside.maxWidth = double.INFINITY;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(180.0, 90.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = double.INFINITY;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 45.0));
|
||||
|
||||
outside.minWidth = 80.0;
|
||||
outside.minHeight = 80.0;
|
||||
|
||||
outside.maxWidth = 100.0;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(100.0, 80.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = 100.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 80.0));
|
||||
|
||||
outside.maxWidth = double.INFINITY;
|
||||
outside.maxHeight = 90.0;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(180.0, 90.0));
|
||||
|
||||
outside.maxWidth = 90.0;
|
||||
outside.maxHeight = double.INFINITY;
|
||||
pumpFrame();
|
||||
expect(inside.size, const Size(90.0, 80.0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,6 +79,40 @@ void main() {
|
||||
expect(parent.getMaxIntrinsicHeight(double.INFINITY), equals(200.0));
|
||||
});
|
||||
|
||||
test('IntrinsicWidth without a child', () {
|
||||
RenderBox parent = new RenderIntrinsicWidth();
|
||||
layout(parent,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 5.0,
|
||||
minHeight: 8.0,
|
||||
maxWidth: 500.0,
|
||||
maxHeight: 800.0
|
||||
)
|
||||
);
|
||||
expect(parent.size.width, equals(5.0));
|
||||
expect(parent.size.height, equals(8.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(0.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(0.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(0.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(0.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(10.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(10.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(10.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(10.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(80.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(80.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(80.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(80.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(double.INFINITY), equals(0.0));
|
||||
});
|
||||
|
||||
test('Shrink-wrapping width (stepped width)', () {
|
||||
RenderBox child = new RenderTestBox(const BoxConstraints(minWidth: 10.0, maxWidth: 100.0, minHeight: 20.0, maxHeight: 200.0));
|
||||
RenderBox parent = new RenderIntrinsicWidth(child: child, stepWidth: 47.0);
|
||||
@@ -219,6 +253,40 @@ void main() {
|
||||
expect(parent.getMaxIntrinsicHeight(double.INFINITY), equals(200.0));
|
||||
});
|
||||
|
||||
test('IntrinsicHeight without a child', () {
|
||||
RenderBox parent = new RenderIntrinsicHeight();
|
||||
layout(parent,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 5.0,
|
||||
minHeight: 8.0,
|
||||
maxWidth: 500.0,
|
||||
maxHeight: 800.0
|
||||
)
|
||||
);
|
||||
expect(parent.size.width, equals(5.0));
|
||||
expect(parent.size.height, equals(8.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(0.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(0.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(0.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(0.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(10.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(10.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(10.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(10.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(80.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(80.0), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(80.0), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(80.0), equals(0.0));
|
||||
|
||||
expect(parent.getMinIntrinsicWidth(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicWidth(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMinIntrinsicHeight(double.INFINITY), equals(0.0));
|
||||
expect(parent.getMaxIntrinsicHeight(double.INFINITY), equals(0.0));
|
||||
});
|
||||
|
||||
test('Padding and boring intrinsics', () {
|
||||
RenderBox box = new RenderPadding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'package:test/test.dart';
|
||||
import 'rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('parent max size is unconstrained', () {
|
||||
test('LimitedBox: parent max size is unconstrained', () {
|
||||
RenderBox child = new RenderConstrainedBox(
|
||||
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
|
||||
);
|
||||
@@ -29,7 +29,7 @@ void main() {
|
||||
expect(child.size.height, 200.0);
|
||||
});
|
||||
|
||||
test('parent maxWidth is unconstrained', () {
|
||||
test('LimitedBox: parent maxWidth is unconstrained', () {
|
||||
RenderBox child = new RenderConstrainedBox(
|
||||
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
|
||||
);
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
expect(child.size.height, 500.0);
|
||||
});
|
||||
|
||||
test('parent maxHeight is unconstrained', () {
|
||||
test('LimitedBox: parent maxHeight is unconstrained', () {
|
||||
RenderBox child = new RenderConstrainedBox(
|
||||
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
|
||||
);
|
||||
@@ -69,4 +69,20 @@ void main() {
|
||||
expect(child.size.width, 500.0);
|
||||
expect(child.size.height, 200.0);
|
||||
});
|
||||
|
||||
test('LimitedBox: no child', () {
|
||||
RenderBox box;
|
||||
RenderBox parent = new RenderConstrainedOverflowBox(
|
||||
minWidth: 10.0,
|
||||
maxWidth: 500.0,
|
||||
minHeight: 0.0,
|
||||
maxHeight: double.INFINITY,
|
||||
child: box = new RenderLimitedBox(
|
||||
maxWidth: 100.0,
|
||||
maxHeight: 200.0,
|
||||
)
|
||||
);
|
||||
layout(parent);
|
||||
expect(box.size, const Size(10.0, 0.0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('RenderConstrainedBox getters and setters', () {
|
||||
RenderConstrainedBox box = new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(height: 10.0));
|
||||
expect(box.additionalConstraints, new BoxConstraints(minHeight: 10.0, maxHeight: 10.0));
|
||||
box.additionalConstraints = new BoxConstraints.tightFor(width: 10.0);
|
||||
expect(box.additionalConstraints, new BoxConstraints(minWidth: 10.0, maxWidth: 10.0));
|
||||
});
|
||||
|
||||
test('RenderLimitedBox getters and setters', () {
|
||||
RenderLimitedBox box = new RenderLimitedBox();
|
||||
expect(box.maxWidth, double.INFINITY);
|
||||
expect(box.maxHeight, double.INFINITY);
|
||||
box.maxWidth = 0.0;
|
||||
box.maxHeight = 1.0;
|
||||
expect(box.maxHeight, 1.0);
|
||||
expect(box.maxWidth, 0.0);
|
||||
});
|
||||
|
||||
test('RenderAspectRatio getters and setters', () {
|
||||
RenderAspectRatio box = new RenderAspectRatio(aspectRatio: 1.0);
|
||||
expect(box.aspectRatio, 1.0);
|
||||
box.aspectRatio = 0.2;
|
||||
expect(box.aspectRatio, 0.2);
|
||||
box.aspectRatio = 1.2;
|
||||
expect(box.aspectRatio, 1.2);
|
||||
});
|
||||
|
||||
test('RenderIntrinsicWidth getters and setters', () {
|
||||
RenderIntrinsicWidth box = new RenderIntrinsicWidth();
|
||||
expect(box.stepWidth, isNull);
|
||||
box.stepWidth = 10.0;
|
||||
expect(box.stepWidth, 10.0);
|
||||
expect(box.stepHeight, isNull);
|
||||
box.stepHeight = 10.0;
|
||||
expect(box.stepHeight, 10.0);
|
||||
});
|
||||
|
||||
test('RenderOpacity getters and setters', () {
|
||||
RenderOpacity box = new RenderOpacity();
|
||||
expect(box.opacity, 1.0);
|
||||
box.opacity = 0.0;
|
||||
expect(box.opacity, 0.0);
|
||||
});
|
||||
|
||||
test('RenderShaderMask getters and setters', () {
|
||||
ShaderCallback callback1 = (Rect bounds) => null;
|
||||
ShaderCallback callback2 = (Rect bounds) => null;
|
||||
RenderShaderMask box = new RenderShaderMask(shaderCallback: callback1);
|
||||
expect(box.shaderCallback, equals(callback1));
|
||||
box.shaderCallback = callback2;
|
||||
expect(box.shaderCallback, equals(callback2));
|
||||
expect(box.blendMode, BlendMode.modulate);
|
||||
box.blendMode = BlendMode.colorBurn;
|
||||
expect(box.blendMode, BlendMode.colorBurn);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
int countSemanticsChildren(RenderObject object) {
|
||||
int count = 0;
|
||||
object.visitChildrenForSemantics((RenderObject child) {
|
||||
count += 1;
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('RenderOpacity and children and semantics', () {
|
||||
RenderOpacity box = new RenderOpacity(child: new RenderParagraph(new TextSpan()));
|
||||
expect(countSemanticsChildren(box), 1);
|
||||
box.opacity = 0.5;
|
||||
expect(countSemanticsChildren(box), 1);
|
||||
box.opacity = 0.25;
|
||||
expect(countSemanticsChildren(box), 1);
|
||||
box.opacity = 0.125;
|
||||
expect(countSemanticsChildren(box), 1);
|
||||
box.opacity = 0.0;
|
||||
expect(countSemanticsChildren(box), 0);
|
||||
box.opacity = 0.125;
|
||||
expect(countSemanticsChildren(box), 1);
|
||||
box.opacity = 0.0;
|
||||
expect(countSemanticsChildren(box), 0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user