mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[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.
This commit is contained in:
parent
39b3515496
commit
ab6ce71402
@ -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'))));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user