Add support in WidgetTester for an array of inputs#60796
Add support in WidgetTester for an array of inputs#60796CareF merged 17 commits intoflutter:masterfrom CareF:input_event_array_test
Conversation
|
Not directly related but I think |
|
I see. Then maybe just document `handlePointerEventPack` to state that a
`pump` is added after the handling of each `PointerEventPack`. (I replied
in email because I can't find the comment on Github...)
…On Tue, Jul 7, 2020 at 5:25 AM Ming Lyu (CareF) ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/flutter_test/lib/src/widget_tester.dart
<#60796 (comment)>:
> + }
+ }
+ else {
+ await binding.executeLater(timeDiff, () async {
+ for (final PointerEvent event in pack.events) {
+ _handlePointerEvent(event, hitTestHistory);
+ }
+ });
+ // TODO(CareF): delete the if sentence when
+ // #60739 is fixed
+ if (binding is LiveTestWidgetsFlutterBinding &&
+ (binding as LiveTestWidgetsFlutterBinding).framePolicy ==
+ LiveTestWidgetsFlutterBindingFramePolicy.fullyLive) {
+ continue;
+ }
+ await binding.pump();
framePolicy requires LiveTestWidgetsFlutterBinding, which is not what we
use for unit test. And my unit test also depends on this. If I have to
change the behavior here I would rather just pump, which is what we are
already doing for WidgetTester.drag anyway
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#60796 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFPMGMGACBV6ZMA3NFNQDPTR2MH4JANCNFSM4OPOKE7Q>
.
|
|
Thanks @Hixie so much for the helpful discussion! I landed what's discussed together with some updates in the comments and redo the description of this PR for the motivation and explaining the PR. Let me know what you think about the new version of description as the document you suggested. Another issue I discussed with @liyuqian shortly after our meeting is, probably I need to change the injected input class from |
|
A conclusion I can draw now about preparing for #60558 is:
With the above said, I'm reopening and ask for review for the current version. |
dnfield
left a comment
There was a problem hiding this comment.
LGTM with nits - most important one is filing the issue for the TODO :)
|
@dnfield Instead of filing an issue I decided to implement it. Though I don't have a very good use case for now of using this method under make it another PR. |
* Add input event array support * Add a tap test * remove unused import * remove extra assert
Description
Add support to use a stream of input
PointerEvents to drive a test.The motivation of this is to enable the use of
WidgetTesteras a tool to drive a live integration test app on a device, with e2e or simpleflutter run, for performance purposes. With this feature the long term goal is to provide a solution of host-independent test and migrating currentflutter_driverbased test to such solution, so that we can perform test on Firebase test lab and use the solution for shader warm up test runs. The short term goal is to have an e2e based scrolling test to catch #41118. For such purposes we need an API to drive the test app by a stream of inputs with some time duration.Use cases would be for example drive the app similar to
Scrollinflutter_driverwhich has adurationas parameter. Using device driven solution will do better thanflutter_driverbecause on the device time control is more accurate thanflutter_driver, and therefore input time can be controlled at sub-frame-interval level. Another demo of the use case is https://github.com/CareF/scroll_test/tree/external where I implement recording physical user inputs in one test app (by runningflutter drive -t test/using_record.dart --driver test_driver/scrolling_test_e2e_test.dart -d moto --trace-startup) to generate data for another test app replaying the recorded input (byflutter drive -t test/using_record.dart --driver test_driver/scrolling_test_e2e_test.dart -d moto --trace-startup --profile). The recording part of this demo will be published as a separate package.This was part of #60649 and #60741.
However currently our APIs in
WidgetTesterhave very limited design for inputs that's time stamped. This is needed for the above motivation, and implementing it is the main goal of this PR. Apart from that, this also enables us to customize the inputPointerEventsthat can be as faithful as the real world.To achieve this, we need:
TestWidgetsFlutterBinding, which means forAutomatedTestWidgetsFlutterBindingto advance the clock and forLiveTestWidgetsFlutterBindingto wait a period of time. The situations when an app binds to which of these two bindings, together withE2EWidgetsFlutterBindingwhich is a subclass ofLiveTestWidgetsFlutterBindingand_DriverBindingofflutter_driverare listed below:flutter testtestWidgets(...)AutomatedTestWidgetsFlutterBindingflutter testtestWidgets(...)LiveTestWidgetsFlutterBindingflutter testLiveTestWidgetsFlutterBinding();testWidgets(...)LiveTestWidgetsFlutterBindingflutter runtestWidgets(...)LiveTestWidgetsFlutterBindingflutter driveenableFlutterDriverExtension()_DriverBindingflutter driveE2EWidgetsFlutterBinding.ensureInitialized();testWidgets(...)E2EWidgetsFlutterBindingFLUTTER_TEST=[..] means the environment variable
FLUTTER_TESTbeing anything butfalseor empty.WidgetTesterthat accepts an array of inputs with timestamp. Note that this timestamp is not necessarily the timestamp tagged within the event, but the timestamp for when the packet of the event is received.These two corresponds to
TestWidgetsFlutterBinding.delayedandWidgetTester.handlePointerEventPacketin this PR.Related Issues
Resolves #60650
Tests
I added the following tests:
'Input event array'inpackages/flutter_test/test/widget_tester_test.dartChecklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.