From d0a72752ac3bcb9f531256ba2e3c29809e3a015e Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Tue, 6 Feb 2018 10:23:24 -0800 Subject: [PATCH] update buttons_test to expect clipPath instead of clipRRect --- .../flutter/test/material/buttons_test.dart | 16 ++++++++++++++-- .../flutter/test/rendering/mock_canvas.dart | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/flutter/test/material/buttons_test.dart b/packages/flutter/test/material/buttons_test.dart index 34c1bf171c..291c4f9698 100644 --- a/packages/flutter/test/material/buttons_test.dart +++ b/packages/flutter/test/material/buttons_test.dart @@ -200,10 +200,19 @@ void main() { await tester.pump(); // start gesture await tester.pump(const Duration(milliseconds: 200)); // wait for splash to be well under way + final Rect expectedClipRect = new Rect.fromLTRB(356.0, 282.0, 444.0, 318.0); + final Path expectedClipPath = new Path() + ..addRRect(new RRect.fromRectAndRadius( + expectedClipRect, + const Radius.circular(2.0), + )); expect( Material.of(tester.element(find.byType(MaterialButton))), paints - ..clipRRect(rrect: new RRect.fromLTRBR(356.0, 282.0, 444.0, 318.0, const Radius.circular(2.0))) + ..clipPath(pathMatcher: coversSameAreaAs( + expectedClipPath, + areaToCompare: expectedClipRect.inflate(10.0), + )) ..circle(color: directSplashColor) ..rect(color: directHighlightColor) ); @@ -235,7 +244,10 @@ void main() { expect( Material.of(tester.element(find.byType(MaterialButton))), paints - ..clipRRect(rrect: new RRect.fromLTRBR(356.0, 282.0, 444.0, 318.0, const Radius.circular(2.0))) + ..clipPath(pathMatcher: coversSameAreaAs( + expectedClipPath, + areaToCompare: expectedClipRect.inflate(10.0), + )) ..circle(color: themeSplashColor1) ..rect(color: themeHighlightColor1) ); diff --git a/packages/flutter/test/rendering/mock_canvas.dart b/packages/flutter/test/rendering/mock_canvas.dart index 394888b26f..4469065fed 100644 --- a/packages/flutter/test/rendering/mock_canvas.dart +++ b/packages/flutter/test/rendering/mock_canvas.dart @@ -148,6 +148,18 @@ abstract class PaintPattern { /// [Canvas.clipRect] call are ignored. void clipRect({ Rect rect }); + /// Indicates that a path clip is expected next. + /// + /// The next path clip is examined. + /// The path that is passed to the actual [Canvas.clipPath] call is matched + /// using [pathMatcher]. + /// + /// If no call to [Canvas.clipPath] was made, then this results in failure. + /// + /// Any calls made between the last matched call (if any) and the + /// [Canvas.clipPath] call are ignored. + void clipPath({Matcher pathMatcher}); + /// Indicates that a rectangle is expected next. /// /// The next rectangle is examined. Any arguments that are passed to this @@ -629,6 +641,11 @@ class _TestRecordingCanvasPatternMatcher extends _TestRecordingCanvasMatcher imp _predicates.add(new _FunctionPaintPredicate(#clipRect, [rect])); } + @override + void clipPath({Matcher pathMatcher}) { + _predicates.add(new _FunctionPaintPredicate(#clipPath, [pathMatcher])); + } + @override void rect({ Rect rect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { _predicates.add(new _RectPaintPredicate(rect: rect, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style));