Unverified Commit ab6ce714 authored by Cody Goldberg's avatar Cody Goldberg Committed by GitHub

[flutter_test/integration_test] added setSurfaceSize test coverage (#82712)

This PR includes an updated test case for integration_test and a new test case for flutter_test to ensure that hit tests transform properly when using setSurfaceSize, for both the IntegrationTestWidgetsFlutterBinding and LiveTestWidgetsFlutterBinding bindings.
parent 39b35154
......@@ -36,4 +36,62 @@ void main() {
expect(hoverEvent!.position, location);
await gesture.removePointer();
});
testWidgets('hitTesting works when using setSurfaceSize', (WidgetTester tester) async {
int invocations = 0;
await tester.pumpWidget(
MaterialApp(
home: Center(
child: GestureDetector(
onTap: () {
invocations++;
},
child: const Text('Test'),
),
),
),
);
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 1);
await tester.binding.setSurfaceSize(const Size(200, 300));
await tester.pump();
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 2);
await tester.binding.setSurfaceSize(null);
await tester.pump();
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 3);
});
testWidgets('setSurfaceSize works', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: Text('Test'))));
final Size windowCenter = tester.binding.window.physicalSize /
tester.binding.window.devicePixelRatio /
2;
final double windowCenterX = windowCenter.width;
final double windowCenterY = windowCenter.height;
Offset widgetCenter = tester.getRect(find.byType(Text)).center;
expect(widgetCenter.dx, windowCenterX);
expect(widgetCenter.dy, windowCenterY);
await tester.binding.setSurfaceSize(const Size(200, 300));
await tester.pump();
widgetCenter = tester.getRect(find.byType(Text)).center;
expect(widgetCenter.dx, 100);
expect(widgetCenter.dy, 150);
await tester.binding.setSurfaceSize(null);
await tester.pump();
widgetCenter = tester.getRect(find.byType(Text)).center;
expect(widgetCenter.dx, windowCenterX);
expect(widgetCenter.dy, windowCenterY);
});
}
......@@ -43,6 +43,38 @@ Future<void> main() async {
integrationBinding.reportData = <String, dynamic>{'answer': 42};
});
testWidgets('hitTesting works when using setSurfaceSize', (WidgetTester tester) async {
int invocations = 0;
await tester.pumpWidget(
MaterialApp(
home: Center(
child: GestureDetector(
onTap: () {
invocations++;
},
child: const Text('Test'),
),
),
),
);
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 1);
await tester.binding.setSurfaceSize(const Size(200, 300));
await tester.pump();
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 2);
await tester.binding.setSurfaceSize(null);
await tester.pump();
await tester.tap(find.byType(Text));
await tester.pump();
expect(invocations, 3);
});
testWidgets('setSurfaceSize works', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: Text('Test'))));
......
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