diff --git a/packages/flutter/test/material/ink_paint_test.dart b/packages/flutter/test/material/ink_paint_test.dart new file mode 100644 index 0000000000..7d4d5e455d --- /dev/null +++ b/packages/flutter/test/material/ink_paint_test.dart @@ -0,0 +1,53 @@ +// 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/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../rendering/mock_canvas.dart'; + +void main() { + testWidgets('Does the ink widget render a border radius', (WidgetTester tester) async { + final Color highlightColor = new Color(0xAAFF0000); + final Color splashColor = new Color(0xAA0000FF); + final BorderRadius borderRadius = new BorderRadius.circular(6.0); + + await tester.pumpWidget( + new Material( + child: new Center( + child: new Container( + width: 200.0, + height: 60.0, + child: new InkWell( + borderRadius: borderRadius, + highlightColor: highlightColor, + splashColor: splashColor, + onTap: () { }, + ), + ), + ), + ), + ); + + final Point center = tester.getCenter(find.byType(InkWell)); + final TestGesture gesture = await tester.startGesture(center); + await tester.pump(); // start gesture + await tester.pump(new Duration(milliseconds: 200)); // wait for splash to be well under way + + final RenderBox box = tester.renderObject(find.byType(PhysicalModel)).child; + expect( + box, + paints + ..clipRRect(rrect: new RRect.fromLTRBR(300.0, 270.0, 500.0, 330.0, new Radius.circular(6.0))) + ..circle(x: 400.0, y: 300.0, radius: 21.0, color: splashColor) + ..rrect( + rrect: new RRect.fromLTRBR(300.0, 270.0, 500.0, 330.0, new Radius.circular(6.0)), + color: highlightColor, + ) + ); + + await gesture.up(); + }); +} diff --git a/packages/flutter/test/rendering/mock_canvas.dart b/packages/flutter/test/rendering/mock_canvas.dart index 080efcfff5..4f65f02a93 100644 --- a/packages/flutter/test/rendering/mock_canvas.dart +++ b/packages/flutter/test/rendering/mock_canvas.dart @@ -111,7 +111,7 @@ abstract class PaintPattern { /// See also: [save], [restore]. void saveRestore(); - /// Indicates that a rectangular clip. + /// Indicates that a rectangular clip is expected next. /// /// The next rectangular clip is examined. Any arguments that are passed to /// this method are compared to the actual [Canvas.clipRect] call's argument @@ -135,6 +135,18 @@ abstract class PaintPattern { /// [Canvas.drawRect] call are ignored. void rect({ Rect rect, Color color }); + /// Indicates that a rounded rectangle clip is expected next. + /// + /// The next rounded rectangle clip is examined. Any arguments that are passed + /// to this method are compared to the actual [Canvas.clipRRect] call's + /// argument and any mismatches result in failure. + /// + /// If no call to [Canvas.clipRRect] was made, then this results in failure. + /// + /// Any calls made between the last matched call (if any) and the + /// [Canvas.clipRRect] call are ignored. + void clipRRect({ RRect rrect }); + /// Indicates that a rounded rectangle is expected next. /// /// The next rounded rectangle is examined. Any arguments that are passed to @@ -262,6 +274,11 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern _predicates.add(new _RectPaintPredicate(rect: rect, color: color, hasMaskFilter: hasMaskFilter, style: style)); } + @override + void clipRRect({ RRect rrect }) { + _predicates.add(new _FunctionPaintPredicate(#clipRRect, [rrect])); + } + @override void rrect({ RRect rrect, Color color, bool hasMaskFilter, PaintingStyle style }) { _predicates.add(new _RRectPaintPredicate(rrect: rrect, color: color, hasMaskFilter: hasMaskFilter, style: style)); @@ -331,6 +348,8 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern @override Description describe(Description description) { + if (_predicates.isEmpty) + return description.add('An object or closure and a paint pattern.'); description.add('Object or closure painting: '); return description.addAll( '', ', ', '', @@ -351,8 +370,13 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern bool _evaluatePredicates(Iterable calls, StringBuffer description) { // If we ever want to have a matcher for painting nothing, create a separate // paintsNothing matcher. - if (_predicates.isEmpty) - throw new Exception('You must add a pattern to the paints matcher.'); + if (_predicates.isEmpty) { + description.write( + 'painted something, but you must now add a pattern to the paints matcher ' + 'in the test to verify that it matches the important parts of the following.' + ); + return false; + } if (calls.isEmpty) { description.write('painted nothing.'); return false; diff --git a/packages/flutter/test/widgets/ink_test.dart b/packages/flutter/test/widgets/ink_test.dart deleted file mode 100644 index 1261427259..0000000000 --- a/packages/flutter/test/widgets/ink_test.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:flutter_test/src/widget_tester.dart'; - -void main() { - testWidgets('Does the ink widget render a border radius', (WidgetTester tester) async { - final Color highlightColor = new Color(0xAAFF0000); - final Color splashColor = new Color(0xAA0000FF); - - final Key materialKey = new UniqueKey(); - final Key inkKey = new UniqueKey(); - final BorderRadius borderRadius = new BorderRadius.circular(6.0); - - await tester.pumpWidget( - new Material( - key: materialKey, - child: new Center( - child: new Container( - width: 200.0, - height: 60.0, - child: new InkWell( - key: inkKey, - borderRadius: borderRadius, - highlightColor: highlightColor, - splashColor: splashColor, - onTap: () {}, - ), - ), - ), - ), - ); - - final Point center = tester.getCenter(find.byKey(materialKey)); - final TestGesture gesture = await tester.startGesture(center); - await tester.pump(new Duration(milliseconds: 200)); - - // TODO(ianh) - stub. needs to be completed. - - await gesture.up(); - }); -} \ No newline at end of file