Fill in the test for rounded rectangle splash and highlights (#9092)
Fixes https://github.com/flutter/flutter/issues/9031 Also some updates to mock_canvas that were needed to do this.
This commit is contained in:
parent
57b3422795
commit
9be0fc7422
53
packages/flutter/test/material/ink_paint_test.dart
Normal file
53
packages/flutter/test/material/ink_paint_test.dart
Normal file
@ -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<RenderPhysicalModel>(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();
|
||||||
|
});
|
||||||
|
}
|
@ -111,7 +111,7 @@ abstract class PaintPattern {
|
|||||||
/// See also: [save], [restore].
|
/// See also: [save], [restore].
|
||||||
void saveRestore();
|
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
|
/// The next rectangular clip is examined. Any arguments that are passed to
|
||||||
/// this method are compared to the actual [Canvas.clipRect] call's argument
|
/// this method are compared to the actual [Canvas.clipRect] call's argument
|
||||||
@ -135,6 +135,18 @@ abstract class PaintPattern {
|
|||||||
/// [Canvas.drawRect] call are ignored.
|
/// [Canvas.drawRect] call are ignored.
|
||||||
void rect({ Rect rect, Color color });
|
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.
|
/// Indicates that a rounded rectangle is expected next.
|
||||||
///
|
///
|
||||||
/// The next rounded rectangle is examined. Any arguments that are passed to
|
/// 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));
|
_predicates.add(new _RectPaintPredicate(rect: rect, color: color, hasMaskFilter: hasMaskFilter, style: style));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void clipRRect({ RRect rrect }) {
|
||||||
|
_predicates.add(new _FunctionPaintPredicate(#clipRRect, <dynamic>[rrect]));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void rrect({ RRect rrect, Color color, bool hasMaskFilter, PaintingStyle style }) {
|
void rrect({ RRect rrect, Color color, bool hasMaskFilter, PaintingStyle style }) {
|
||||||
_predicates.add(new _RRectPaintPredicate(rrect: rrect, color: color, hasMaskFilter: hasMaskFilter, style: style));
|
_predicates.add(new _RRectPaintPredicate(rrect: rrect, color: color, hasMaskFilter: hasMaskFilter, style: style));
|
||||||
@ -331,6 +348,8 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Description describe(Description description) {
|
Description describe(Description description) {
|
||||||
|
if (_predicates.isEmpty)
|
||||||
|
return description.add('An object or closure and a paint pattern.');
|
||||||
description.add('Object or closure painting: ');
|
description.add('Object or closure painting: ');
|
||||||
return description.addAll(
|
return description.addAll(
|
||||||
'', ', ', '',
|
'', ', ', '',
|
||||||
@ -351,8 +370,13 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern
|
|||||||
bool _evaluatePredicates(Iterable<Invocation> calls, StringBuffer description) {
|
bool _evaluatePredicates(Iterable<Invocation> calls, StringBuffer description) {
|
||||||
// If we ever want to have a matcher for painting nothing, create a separate
|
// If we ever want to have a matcher for painting nothing, create a separate
|
||||||
// paintsNothing matcher.
|
// paintsNothing matcher.
|
||||||
if (_predicates.isEmpty)
|
if (_predicates.isEmpty) {
|
||||||
throw new Exception('You must add a pattern to the paints matcher.');
|
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) {
|
if (calls.isEmpty) {
|
||||||
description.write('painted nothing.');
|
description.write('painted nothing.');
|
||||||
return false;
|
return false;
|
||||||
|
@ -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();
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user