From 7c40446a69ec3ec2fdb2b2119929124326fd793c Mon Sep 17 00:00:00 2001
From: Ian Hickson <ian@hixie.ch>
Date: Thu, 26 Jan 2017 08:00:24 -0800
Subject: [PATCH] proxy_box tests (#7658)

---
 .../flutter/lib/src/rendering/proxy_box.dart  |   8 +-
 .../test/rendering/aspect_ratio_test.dart     | 106 +++++++++++++++++-
 .../test/rendering/intrinsic_width_test.dart  |  68 +++++++++++
 .../test/rendering/limited_box_test.dart      |  22 +++-
 .../proxy_getters_and_setters_test.dart       |  64 +++++++++++
 .../semantics_and_children_test.dart          |  34 ++++++
 6 files changed, 291 insertions(+), 11 deletions(-)
 create mode 100644 packages/flutter/test/rendering/proxy_getters_and_setters_test.dart
 create mode 100644 packages/flutter/test/rendering/semantics_and_children_test.dart

diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart
index 7e4aa4ef6f..da3b822b51 100644
--- a/packages/flutter/lib/src/rendering/proxy_box.dart
+++ b/packages/flutter/lib/src/rendering/proxy_box.dart
@@ -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);
diff --git a/packages/flutter/test/rendering/aspect_ratio_test.dart b/packages/flutter/test/rendering/aspect_ratio_test.dart
index d8f70de1bb..12f6d1dea1 100644
--- a/packages/flutter/test/rendering/aspect_ratio_test.dart
+++ b/packages/flutter/test/rendering/aspect_ratio_test.dart
@@ -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));
+  });
 }
diff --git a/packages/flutter/test/rendering/intrinsic_width_test.dart b/packages/flutter/test/rendering/intrinsic_width_test.dart
index f14aa66c12..0b6d3b93f5 100644
--- a/packages/flutter/test/rendering/intrinsic_width_test.dart
+++ b/packages/flutter/test/rendering/intrinsic_width_test.dart
@@ -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),
diff --git a/packages/flutter/test/rendering/limited_box_test.dart b/packages/flutter/test/rendering/limited_box_test.dart
index 0f65eed0ec..d227c4d0b7 100644
--- a/packages/flutter/test/rendering/limited_box_test.dart
+++ b/packages/flutter/test/rendering/limited_box_test.dart
@@ -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));
+  });
 }
diff --git a/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart b/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart
new file mode 100644
index 0000000000..794a2aec8e
--- /dev/null
+++ b/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart
@@ -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);
+  });
+}
diff --git a/packages/flutter/test/rendering/semantics_and_children_test.dart b/packages/flutter/test/rendering/semantics_and_children_test.dart
new file mode 100644
index 0000000000..cdc2e9d7e0
--- /dev/null
+++ b/packages/flutter/test/rendering/semantics_and_children_test.dart
@@ -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);
+  });
+}
-- 
2.21.0