Allow setting of TestWidgetsFlutterBinding.pointerEventSource (#107976)

This commit is contained in:
Sai Sandeep Mutyala 2022-07-20 21:49:17 +05:30 committed by GitHub
parent c05d47998f
commit 641f4e2403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -494,8 +494,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
///
/// When [handlePointerEvent] is called directly, [pointerEventSource]
/// is [TestBindingEventSource.device].
TestBindingEventSource get pointerEventSource => _pointerEventSource;
TestBindingEventSource _pointerEventSource = TestBindingEventSource.device;
TestBindingEventSource pointerEventSource = TestBindingEventSource.device;
/// Dispatch an event to the targets found by a hit test on its position,
/// and remember its source as [pointerEventSource].
@ -530,12 +529,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
/// to the previous value.
@protected
void withPointerEventSource(TestBindingEventSource source, VoidCallback task) {
final TestBindingEventSource previousSource = _pointerEventSource;
_pointerEventSource = source;
final TestBindingEventSource previousSource = pointerEventSource;
pointerEventSource = source;
try {
task();
} finally {
_pointerEventSource = previousSource;
pointerEventSource = previousSource;
}
}

View file

@ -31,6 +31,11 @@ void main() {
binding.defaultTestTimeout = const test_package.Timeout(Duration(minutes: 5));
expect(binding.defaultTestTimeout.duration, const Duration(minutes: 5));
});
test('allows setting pointerEventSource to TestBindingEventSource.test', () {
binding.pointerEventSource = TestBindingEventSource.test;
expect(binding.pointerEventSource, TestBindingEventSource.test);
});
});
// The next three tests must run in order -- first using `test`, then `testWidgets`, then `test` again.