mirror of
https://github.com/flutter/flutter
synced 2024-09-21 09:11:56 +00:00
Golden file tests for clip (#18056)
Also, fixes "flutter run" for golden tests, and some docs.
This commit is contained in:
parent
72c459bcfc
commit
b83749cab0
|
@ -1 +1 @@
|
|||
298b585e6eb2bf51b12cd0ea9261a1b7a83c9a29
|
||||
95f60c7e328b53dd65de18a608830a872a92e3cd
|
||||
|
|
|
@ -1004,10 +1004,10 @@ class RenderBackdropFilter extends RenderProxyBox {
|
|||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [ClipRect], which can be customized with a [CustomClipper].
|
||||
/// * [ClipRRect], which can be customized with a [CustomClipper].
|
||||
/// * [ClipOval], which can be customized with a [CustomClipper].
|
||||
/// * [ClipPath], which can be customized with a [CustomClipper].
|
||||
/// * [ClipRect], which can be customized with a [CustomClipper<Rect>].
|
||||
/// * [ClipRRect], which can be customized with a [CustomClipper<RRect>].
|
||||
/// * [ClipOval], which can be customized with a [CustomClipper<Rect>].
|
||||
/// * [ClipPath], which can be customized with a [CustomClipper<Path>].
|
||||
abstract class CustomClipper<T> {
|
||||
/// Creates a custom clipper.
|
||||
///
|
||||
|
|
|
@ -247,4 +247,275 @@ void main() {
|
|||
);
|
||||
debugPaintSizeEnabled = false;
|
||||
});
|
||||
|
||||
testWidgets('ClipRect painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new ClipRect(
|
||||
child: new Container(
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.ClipRect.1.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('ClipRRect painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: const Radius.elliptical(10.0, 20.0),
|
||||
topRight: const Radius.elliptical(5.0, 30.0),
|
||||
bottomLeft: const Radius.elliptical(2.5, 12.0),
|
||||
bottomRight: const Radius.elliptical(15.0, 6.0),
|
||||
),
|
||||
child: new Container(
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.ClipRRect.1.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('ClipOval painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new ClipOval(
|
||||
child: new Container(
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.ClipOval.1.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('ClipPath painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new ClipPath(
|
||||
clipper: new ShapeBorderClipper(
|
||||
shape: new BeveledRectangleBorder(
|
||||
borderRadius: new BorderRadius.circular(20.0),
|
||||
),
|
||||
),
|
||||
child: new Container(
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.ClipPath.1.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('PhysicalModel painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new PhysicalModel(
|
||||
borderRadius: new BorderRadius.circular(20.0),
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.PhysicalModel.1.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('PhysicalShape painting', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new RepaintBoundary(
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.all(100.0),
|
||||
child: new SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: new Transform.rotate(
|
||||
angle: 1.0, // radians
|
||||
child: new PhysicalShape(
|
||||
clipper: new ShapeBorderClipper(
|
||||
shape: new BeveledRectangleBorder(
|
||||
borderRadius: new BorderRadius.circular(20.0),
|
||||
),
|
||||
),
|
||||
color: Colors.red,
|
||||
child: new Container(
|
||||
color: Colors.white,
|
||||
child: new RepaintBoundary(
|
||||
child: new Center(
|
||||
child: new Container(
|
||||
color: Colors.black,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byType(RepaintBoundary).first,
|
||||
matchesGoldenFile('clip.PhysicalShape.1.png'),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,9 +60,9 @@ abstract class GoldenFileComparator {
|
|||
/// When using `flutter test --update-goldens`, the [LocalFileComparator]
|
||||
/// updates the files on disk to match the rendering.
|
||||
///
|
||||
/// When using `flutter run`, the default comparator (null) is used. It prints
|
||||
/// a message to the console but otherwise does nothing. This allows tests to
|
||||
/// be developed visually on a real device.
|
||||
/// When using `flutter run`, the default comparator ([TrivialComparator])
|
||||
/// is used. It prints a message to the console but otherwise does nothing. This
|
||||
/// allows tests to be developed visually on a real device.
|
||||
///
|
||||
/// Callers may choose to override the default comparator by setting this to a
|
||||
/// custom comparator during test set-up (or using directory-level test
|
||||
|
@ -75,12 +75,11 @@ abstract class GoldenFileComparator {
|
|||
///
|
||||
/// * [flutter_test] for more information about how to configure tests at the
|
||||
/// directory-level.
|
||||
GoldenFileComparator get goldenFileComparator {
|
||||
return _goldenFileComparator == const _UninitializedComparator() ? null : _goldenFileComparator;
|
||||
}
|
||||
GoldenFileComparator _goldenFileComparator = const _UninitializedComparator();
|
||||
set goldenFileComparator(GoldenFileComparator comparator) {
|
||||
_goldenFileComparator = comparator ?? const _UninitializedComparator();
|
||||
GoldenFileComparator get goldenFileComparator => _goldenFileComparator;
|
||||
GoldenFileComparator _goldenFileComparator = const TrivialComparator._();
|
||||
set goldenFileComparator(GoldenFileComparator value) {
|
||||
assert(value != null);
|
||||
_goldenFileComparator = value;
|
||||
}
|
||||
|
||||
/// Whether golden files should be automatically updated during tests rather
|
||||
|
@ -111,8 +110,11 @@ bool autoUpdateGoldenFiles = false;
|
|||
/// via `flutter run`. In this case, the [compare] method will just print a
|
||||
/// message that it would have otherwise run a real comparison, and it will
|
||||
/// return trivial success.
|
||||
class _UninitializedComparator implements GoldenFileComparator {
|
||||
const _UninitializedComparator();
|
||||
///
|
||||
/// This class can't be constructed. It represents the default value of
|
||||
/// [goldenFileComparator].
|
||||
class TrivialComparator implements GoldenFileComparator {
|
||||
const TrivialComparator._();
|
||||
|
||||
@override
|
||||
Future<bool> compare(Uint8List imageBytes, Uri golden) {
|
||||
|
|
Loading…
Reference in a new issue