Unverified Commit b83749ca authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Golden file tests for clip (#18056)

Also, fixes "flutter run" for golden tests, and some docs.
parent 72c459bc
298b585e6eb2bf51b12cd0ea9261a1b7a83c9a29 95f60c7e328b53dd65de18a608830a872a92e3cd
...@@ -1004,10 +1004,10 @@ class RenderBackdropFilter extends RenderProxyBox { ...@@ -1004,10 +1004,10 @@ class RenderBackdropFilter extends RenderProxyBox {
/// ///
/// See also: /// See also:
/// ///
/// * [ClipRect], which can be customized with a [CustomClipper]. /// * [ClipRect], which can be customized with a [CustomClipper<Rect>].
/// * [ClipRRect], which can be customized with a [CustomClipper]. /// * [ClipRRect], which can be customized with a [CustomClipper<RRect>].
/// * [ClipOval], which can be customized with a [CustomClipper]. /// * [ClipOval], which can be customized with a [CustomClipper<Rect>].
/// * [ClipPath], which can be customized with a [CustomClipper]. /// * [ClipPath], which can be customized with a [CustomClipper<Path>].
abstract class CustomClipper<T> { abstract class CustomClipper<T> {
/// Creates a custom clipper. /// Creates a custom clipper.
/// ///
......
...@@ -247,4 +247,275 @@ void main() { ...@@ -247,4 +247,275 @@ void main() {
); );
debugPaintSizeEnabled = false; 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 { ...@@ -60,9 +60,9 @@ abstract class GoldenFileComparator {
/// When using `flutter test --update-goldens`, the [LocalFileComparator] /// When using `flutter test --update-goldens`, the [LocalFileComparator]
/// updates the files on disk to match the rendering. /// updates the files on disk to match the rendering.
/// ///
/// When using `flutter run`, the default comparator (null) is used. It prints /// When using `flutter run`, the default comparator ([TrivialComparator])
/// a message to the console but otherwise does nothing. This allows tests to /// is used. It prints a message to the console but otherwise does nothing. This
/// be developed visually on a real device. /// allows tests to be developed visually on a real device.
/// ///
/// Callers may choose to override the default comparator by setting this to a /// Callers may choose to override the default comparator by setting this to a
/// custom comparator during test set-up (or using directory-level test /// custom comparator during test set-up (or using directory-level test
...@@ -75,12 +75,11 @@ abstract class GoldenFileComparator { ...@@ -75,12 +75,11 @@ abstract class GoldenFileComparator {
/// ///
/// * [flutter_test] for more information about how to configure tests at the /// * [flutter_test] for more information about how to configure tests at the
/// directory-level. /// directory-level.
GoldenFileComparator get goldenFileComparator { GoldenFileComparator get goldenFileComparator => _goldenFileComparator;
return _goldenFileComparator == const _UninitializedComparator() ? null : _goldenFileComparator; GoldenFileComparator _goldenFileComparator = const TrivialComparator._();
} set goldenFileComparator(GoldenFileComparator value) {
GoldenFileComparator _goldenFileComparator = const _UninitializedComparator(); assert(value != null);
set goldenFileComparator(GoldenFileComparator comparator) { _goldenFileComparator = value;
_goldenFileComparator = comparator ?? const _UninitializedComparator();
} }
/// Whether golden files should be automatically updated during tests rather /// Whether golden files should be automatically updated during tests rather
...@@ -111,8 +110,11 @@ bool autoUpdateGoldenFiles = false; ...@@ -111,8 +110,11 @@ bool autoUpdateGoldenFiles = false;
/// via `flutter run`. In this case, the [compare] method will just print a /// 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 /// message that it would have otherwise run a real comparison, and it will
/// return trivial success. /// 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 @override
Future<bool> compare(Uint8List imageBytes, Uri golden) { Future<bool> compare(Uint8List imageBytes, Uri golden) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment