Unverified Commit 3e7fe378 authored by Ming Lyu (CareF)'s avatar Ming Lyu (CareF) Committed by GitHub

Reland "LiveTestWidgetsFlutterBinding support for non-touch event" (#61901)

parent aa9119e5
...@@ -1468,6 +1468,11 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1468,6 +1468,11 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// Events dispatched by [TestGesture] are not affected by this. /// Events dispatched by [TestGesture] are not affected by this.
HitTestDispatcher deviceEventDispatcher; HitTestDispatcher deviceEventDispatcher;
/// Dispatch an event to a hit test result's path.
///
/// Apart from forwarding the event to [GestureBinding.dispatchEvent],
/// This also paint all events that's down on the screen.
@override @override
void dispatchEvent( void dispatchEvent(
PointerEvent event, PointerEvent event,
...@@ -1476,20 +1481,19 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1476,20 +1481,19 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}) { }) {
switch (source) { switch (source) {
case TestBindingEventSource.test: case TestBindingEventSource.test:
if (!renderView._pointers.containsKey(event.pointer)) { if (renderView._pointers.containsKey(event.pointer)) {
assert(event.down || event is PointerAddedEvent); renderView._pointers[event.pointer].position = event.position;
if (event.down) { if (!event.down)
renderView._pointers[event.pointer].decay = _kPointerDecay;
_handleViewNeedsPaint();
} else if (event.down) {
assert(event is PointerDownEvent);
renderView._pointers[event.pointer] = _LiveTestPointerRecord( renderView._pointers[event.pointer] = _LiveTestPointerRecord(
event.pointer, event.pointer,
event.position, event.position,
); );
}
} else {
renderView._pointers[event.pointer].position = event.position;
if (!event.down)
renderView._pointers[event.pointer].decay = _kPointerDecay;
}
_handleViewNeedsPaint(); _handleViewNeedsPaint();
}
super.dispatchEvent(event, hitTestResult, source: source); super.dispatchEvent(event, hitTestResult, source: source);
break; break;
case TestBindingEventSource.device: case TestBindingEventSource.device:
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
// This file is for testings that require a `LiveTestWidgetsFlutterBinding` // This file is for testings that require a `LiveTestWidgetsFlutterBinding`
...@@ -15,5 +18,24 @@ void main() { ...@@ -15,5 +18,24 @@ void main() {
// This mimics the start of a gesture as seen on a device, where inputs // This mimics the start of a gesture as seen on a device, where inputs
// starts with a PointerAddedEvent. // starts with a PointerAddedEvent.
await gesture.addPointer(); await gesture.addPointer();
// The expected result of the test is not to trigger any assert.
});
testWidgets('Input PointerHoverEvent', (WidgetTester tester) async {
PointerHoverEvent hoverEvent;
await tester.pumpWidget(MaterialApp(home: MouseRegion(
child: const Text('Test'),
onHover: (PointerHoverEvent event){
hoverEvent = event;
},
)));
await tester.pump();
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
final Offset location = tester.getCenter(find.text('Test'));
// for mouse input without a down event, moveTo generates a hover event
await gesture.moveTo(location);
expect(hoverEvent, isNotNull);
expect(hoverEvent.position, location);
await gesture.removePointer();
}); });
} }
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