diff --git a/packages/flutter/lib/src/material/typography.dart b/packages/flutter/lib/src/material/typography.dart index 15dfc7899f..07180f721c 100644 --- a/packages/flutter/lib/src/material/typography.dart +++ b/packages/flutter/lib/src/material/typography.dart @@ -277,6 +277,43 @@ class TextTheme { button: TextStyle.lerp(begin.button, end.button, t) ); } + + @override + bool operator ==(dynamic other) { + if (identical(this, other)) + return true; + if (other is! TextTheme) + return false; + final TextTheme typedOther = other; + return display4 == typedOther.display4 && + display3 == typedOther.display3 && + display2 == typedOther.display2 && + display1 == typedOther.display1 && + headline == typedOther.headline && + title == typedOther.title && + subhead == typedOther.subhead && + body2 == typedOther.body2 && + body1 == typedOther.body1 && + caption == typedOther.caption && + button == typedOther.button; + } + + @override + int get hashCode { + return hashValues( + display4, + display3, + display2, + display1, + headline, + title, + subhead, + body2, + body1, + caption, + button, + ); + } } /// The two material design text themes. diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index 311af3c2d3..d6fc3bd37b 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/theme_test.dart @@ -6,6 +6,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + test('ThemeDataTween control test', () { + ThemeData light = new ThemeData.light(); + ThemeData dark = new ThemeData.light(); + ThemeDataTween tween = new ThemeDataTween(begin: light, end: dark); + expect(tween.lerp(0.25), equals(ThemeData.lerp(light, dark, 0.25))); + }); + testWidgets('PopupMenu inherits app theme', (WidgetTester tester) async { final Key popupMenuButtonKey = new UniqueKey(); await tester.pumpWidget( diff --git a/packages/flutter/test/material/typography_test.dart b/packages/flutter/test/material/typography_test.dart index 88d99d77ac..c18048a064 100644 --- a/packages/flutter/test/material/typography_test.dart +++ b/packages/flutter/test/material/typography_test.dart @@ -6,6 +6,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + test('TextTheme control test', () { + Typography typography = new Typography(platform: TargetPlatform.android); + expect(typography.black, equals(typography.black.copyWith())); + expect(typography.black, equals(typography.black.apply())); + expect(typography.black.hashCode, equals(typography.black.copyWith().hashCode)); + expect(typography.black, isNot(equals(typography.white))); + }); + test('Typography is defined for all target platforms', () { for (TargetPlatform platform in TargetPlatform.values) { Typography typography = new Typography(platform: platform); diff --git a/packages/flutter/test/rendering/mock_canvas.dart b/packages/flutter/test/rendering/mock_canvas.dart index 150089c885..455786f22c 100644 --- a/packages/flutter/test/rendering/mock_canvas.dart +++ b/packages/flutter/test/rendering/mock_canvas.dart @@ -89,17 +89,17 @@ abstract class PaintPattern { /// See also: [save], [restore]. void saveRestore(); - /// Indicates that a circle is expected next. + /// Indicates that a rectangle is expected next. /// - /// The next circle is examined. Any arguments that are passed to this method - /// are compared to the actual [Canvas.drawCircle] call's arguments and any - /// mismatches result in failure. + /// The next rectangle is examined. Any arguments that are passed to this + /// method are compared to the actual [Canvas.drawRect] call's arguments + /// and any mismatches result in failure. /// - /// If no call to [Canvas.drawCircle] was made, then this results in failure. + /// If no call to [Canvas.drawRect] was made, then this results in failure. /// /// Any calls made between the last matched call (if any) and the - /// [Canvas.drawCircle] call are ignored. - void circle({ double x, double y, double radius, Color color, bool hasMaskFilter, PaintingStyle style }); + /// [Canvas.drawRect] call are ignored. + void rect({ Rect rect, Color color }); /// Indicates that a rounded rectangle is expected next. /// @@ -113,6 +113,18 @@ abstract class PaintPattern { /// [Canvas.drawRRect] call are ignored. void rrect({ RRect rrect, Color color, bool hasMaskFilter, PaintingStyle style }); + /// Indicates that a circle is expected next. + /// + /// The next circle is examined. Any arguments that are passed to this method + /// are compared to the actual [Canvas.drawCircle] call's arguments and any + /// mismatches result in failure. + /// + /// If no call to [Canvas.drawCircle] was made, then this results in failure. + /// + /// Any calls made between the last matched call (if any) and the + /// [Canvas.drawCircle] call are ignored. + void circle({ double x, double y, double radius, Color color, bool hasMaskFilter, PaintingStyle style }); + /// Provides a custom matcher. /// /// Each method call after the last matched call (if any) will be passed to @@ -171,8 +183,8 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern } @override - void circle({ double x, double y, double radius, Color color, bool hasMaskFilter, PaintingStyle style }) { - _predicates.add(new _CirclePaintPredicate(x: x, y: y, radius: radius, color: color, hasMaskFilter: hasMaskFilter, style: style)); + void rect({ Rect rect, Color color, bool hasMaskFilter, PaintingStyle style }) { + _predicates.add(new _RectPaintPredicate(rect: rect, color: color, hasMaskFilter: hasMaskFilter, style: style)); } @override @@ -180,6 +192,12 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern _predicates.add(new _RRectPaintPredicate(rrect: rrect, color: color, hasMaskFilter: hasMaskFilter, style: style)); } + + @override + void circle({ double x, double y, double radius, Color color, bool hasMaskFilter, PaintingStyle style }) { + _predicates.add(new _CirclePaintPredicate(x: x, y: y, radius: radius, color: color, hasMaskFilter: hasMaskFilter, style: style)); + } + @override void something(PaintPatternPredicate predicate) { _predicates.add(new _SomethingPaintPredicate(predicate)); @@ -306,6 +324,11 @@ class _TestRecordingPaintingContext implements PaintingContext { @override final Canvas canvas; + @override + void paintChild(RenderObject child, Offset offset) { + child.paint(this, offset); + } + @override void noSuchMethod(Invocation invocation) { } @@ -392,6 +415,56 @@ abstract class _DrawCommandPaintPredicate extends _PaintPredicate { } } +class _OneParameterPaintPredicate extends _DrawCommandPaintPredicate { + _OneParameterPaintPredicate(Symbol symbol, String name, { + @required this.expected, + @required Color color, + @required bool hasMaskFilter, + @required PaintingStyle style + }) : super( + symbol, name, 2, 1, color: color, hasMaskFilter: hasMaskFilter, style: style); + + final T expected; + + @override + void verifyArguments(List arguments) { + super.verifyArguments(arguments); + final T actual = arguments[0]; + if (expected != null && actual != expected) + throw 'called $methodName with ${T.runtimeType}, $actual, which was not exactly the expected ${T.runtimeType} ($expected).'; + } + + @override + void debugFillDescription(List description) { + super.debugFillDescription(description); + if (expected != null) + description.add('${T.runtimeType}: $expected'); + } +} + + +class _RectPaintPredicate extends _OneParameterPaintPredicate { + _RectPaintPredicate({ Rect rect, Color color, bool hasMaskFilter, PaintingStyle style }) : super( + #drawRect, + 'a rectangle', + expected: rect, + color: color, + hasMaskFilter: hasMaskFilter, + style: style, + ); +} + +class _RRectPaintPredicate extends _OneParameterPaintPredicate { + _RRectPaintPredicate({ RRect rrect, Color color, bool hasMaskFilter, PaintingStyle style }) : super( + #drawRRect, + 'a rounded rectangle', + expected: rrect, + color: color, + hasMaskFilter: hasMaskFilter, + style: style, + ); +} + class _CirclePaintPredicate extends _DrawCommandPaintPredicate { _CirclePaintPredicate({ this.x, this.y, this.radius, Color color, bool hasMaskFilter, PaintingStyle style }) : super( #drawCircle, 'a circle', 3, 2, color: color, hasMaskFilter: hasMaskFilter, style: style @@ -436,29 +509,6 @@ class _CirclePaintPredicate extends _DrawCommandPaintPredicate { } } -class _RRectPaintPredicate extends _DrawCommandPaintPredicate { - _RRectPaintPredicate({ this.rrect, Color color, bool hasMaskFilter, PaintingStyle style }) : super( - #drawRRect, 'a rounded rectangle', 2, 1, color: color, hasMaskFilter: hasMaskFilter, style: style - ); - - final RRect rrect; - - @override - void verifyArguments(List arguments) { - super.verifyArguments(arguments); - final RRect rrectArgument = arguments[0]; - if (rrect != null && rrectArgument != rrect) - throw 'called $methodName with an rrect, $rrectArgument, which was not exactly the expected rrect ($rrect).'; - } - - @override - void debugFillDescription(List description) { - super.debugFillDescription(description); - if (rrect != null) - description.add('$rrect'); - } -} - class _SomethingPaintPredicate extends _PaintPredicate { _SomethingPaintPredicate(this.predicate); @@ -593,4 +643,4 @@ String _describeInvocation(Invocation call) { buffer.write(')'); } return buffer.toString(); -} \ No newline at end of file +} diff --git a/packages/flutter/test/widgets/animated_container_test.dart b/packages/flutter/test/widgets/animated_container_test.dart index 6841c60660..af9b9fd02b 100644 --- a/packages/flutter/test/widgets/animated_container_test.dart +++ b/packages/flutter/test/widgets/animated_container_test.dart @@ -7,6 +7,23 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; void main() { + testWidgets('AnimatedContainer.debugFillDescription', (WidgetTester tester) async { + AnimatedContainer container = new AnimatedContainer( + constraints: const BoxConstraints.tightFor(width: 17.0, height: 23.0), + decoration: const BoxDecoration(backgroundColor: const Color(0xFF00FF00)), + foregroundDecoration: const BoxDecoration(backgroundColor: const Color(0x7F0000FF)), + margin: const EdgeInsets.all(10.0), + padding: const EdgeInsets.all(7.0), + transform: new Matrix4.translationValues(4.0, 3.0, 0.0), + width: 50.0, + height: 75.0, + curve: Curves.ease, + duration: const Duration(milliseconds: 200), + ); + + expect(container, hasOneLineDescription); + }); + testWidgets('AnimatedContainer control test', (WidgetTester tester) async { GlobalKey key = new GlobalKey(); diff --git a/packages/flutter/test/widgets/animated_positioned_test.dart b/packages/flutter/test/widgets/animated_positioned_test.dart index 1b986b63fa..a549e82add 100644 --- a/packages/flutter/test/widgets/animated_positioned_test.dart +++ b/packages/flutter/test/widgets/animated_positioned_test.dart @@ -7,6 +7,19 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; void main() { + testWidgets('AnimatedPositioned.fromRect control test', (WidgetTester tester) async { + AnimatedPositioned positioned = new AnimatedPositioned.fromRect( + rect: new Rect.fromLTWH(7.0, 5.0, 12.0, 16.0), + duration: const Duration(milliseconds: 200), + ); + + expect(positioned.left, equals(7.0)); + expect(positioned.top, equals(5.0)); + expect(positioned.width, equals(12.0)); + expect(positioned.height, equals(16.0)); + expect(positioned, hasOneLineDescription); + }); + testWidgets('AnimatedPositioned - basics', (WidgetTester tester) async { GlobalKey key = new GlobalKey(); diff --git a/packages/flutter/test/widgets/container_test.dart b/packages/flutter/test/widgets/container_test.dart index b1805ef44c..ec250f9f37 100644 --- a/packages/flutter/test/widgets/container_test.dart +++ b/packages/flutter/test/widgets/container_test.dart @@ -5,7 +5,50 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; +import '../rendering/mock_canvas.dart'; + void main() { + testWidgets('Container control test', (WidgetTester tester) async { + Container container = new Container( + alignment: FractionalOffset.bottomRight, + padding: const EdgeInsets.all(7.0), + decoration: const BoxDecoration(backgroundColor: const Color(0xFF00FF00)), + foregroundDecoration: const BoxDecoration(backgroundColor: const Color(0x7F0000FF)), + width: 53.0, + height: 76.0, + constraints: const BoxConstraints( + minWidth: 50.0, + maxWidth: 55.0, + minHeight: 78.0, + maxHeight: 82.0, + ), + margin: const EdgeInsets.all(5.0), + child: new SizedBox( + width: 25.0, + height: 33.0, + child: new DecoratedBox( + decoration: const BoxDecoration(backgroundColor: const Color(0xFFFFFF00)), + ), + ), + ); + + expect(container, hasOneLineDescription); + + await tester.pumpWidget(new Align( + alignment: FractionalOffset.topLeft, + child: container + )); + + RenderBox box = tester.renderObject(find.byType(Container)); + expect(box, isNotNull); + + expect(box, paints + ..rect(rect: new Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0xFF00FF00)) + ..rect(rect: new Rect.fromLTWH(26.0, 43.0, 25.0, 33.0), color: const Color(0xFFFFFF00)) + ..rect(rect: new Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0x7F0000FF)) + ); + }); + testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { await tester.pumpWidget(new Block(children: [new Container()])); }); diff --git a/packages/flutter/test/widgets/locale_query_test.dart b/packages/flutter/test/widgets/locale_query_test.dart new file mode 100644 index 0000000000..49e9b3727b --- /dev/null +++ b/packages/flutter/test/widgets/locale_query_test.dart @@ -0,0 +1,32 @@ +// Copyright 2017 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_test/flutter_test.dart'; +import 'package:flutter/widgets.dart'; + +class TestLocaleQueryData extends LocaleQueryData { + @override + String toString() => 'Test data'; +} + +void main() { + testWidgets('LocaleQuery control test', (WidgetTester tester) async { + await tester.pumpWidget(new Container()); + + expect(LocaleQuery.of(tester.element(find.byType(Container))), isNull); + + LocaleQueryData data = new TestLocaleQueryData(); + Widget widget = new LocaleQuery( + data: data, + child: new Container(), + ); + + expect(widget, hasOneLineDescription); + expect(widget.toString(), contains('Test data')); + + await tester.pumpWidget(widget); + + expect(LocaleQuery.of(tester.element(find.byType(Container))), equals(data)); + }); +}