Commit 8ade81f
authored
[flutter_test] Change KeyEventSimulator default transit mode (#143847)
## Description
This PRs changes the default value transit mode for key event simulation.
The default transit mode for key event simulation is currently `KeyDataTransitMode.rawKeyData` while on the framework side `KeyDataTransitMode.keyDataThenRawKeyData` is the preferred transit mode.
`KeyDataTransitMode.keyDataThenRawKeyData` is more accurate and can help detect issues.
For instance the following test will fail with `KeyDataTransitMode.rawKeyData` because raw keyboard logic for modifier keys is less accurate:
```dart
testWidgets('Press control left once', (WidgetTester tester) async {
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
final List<KeyEvent> events = <KeyEvent>[];
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
await tester.pumpWidget(
Focus(
focusNode: focusNode,
autofocus: true,
onKeyEvent: (_, KeyEvent event) {
events.add(event);
return KeyEventResult.handled;
},
child: Container(),
),
);
await simulateKeyDownEvent(LogicalKeyboardKey.controlLeft);
// This will fail when transit mode is KeyDataTransitMode.rawKeyData
// because a down event for controlRight is synthesized.
expect(events.length, 1);
debugKeyEventSimulatorTransitModeOverride = null;
});
```
And the following this test is ok with `KeyDataTransitMode.rawKeyData` but rightly fails with `KeyDataTransitMode.keyDataThenRawKeyData`:
```dart
testWidgets('Simulates consecutive key down events', (WidgetTester tester) async {
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.rawKeyData;
// Simulating several key down events without key up in between is tolerated
// when transit mode is KeyDataTransitMode.rawKeyData, it will trigger an
// assert on KeyDataTransitMode.keyDataThenRawKeyData.
await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown);
debugKeyEventSimulatorTransitModeOverride = null;
});
```
## Related Issue
Related to flutter/flutter#143845
## Tests
Adds two tests.1 parent f677027 commit 8ade81f
File tree
6 files changed
+101
-39
lines changed- packages
- flutter_test
- lib/src
- test
- flutter/test
- cupertino
- material
- services
6 files changed
+101
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8507 | 8507 | | |
8508 | 8508 | | |
8509 | 8509 | | |
8510 | | - | |
8511 | 8510 | | |
8512 | 8511 | | |
8513 | 8512 | | |
8514 | 8513 | | |
8515 | 8514 | | |
8516 | 8515 | | |
8517 | | - | |
8518 | 8516 | | |
8519 | 8517 | | |
8520 | 8518 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
697 | | - | |
| 697 | + | |
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
| |||
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
708 | | - | |
| 708 | + | |
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| |||
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
738 | | - | |
| 738 | + | |
739 | 739 | | |
740 | 740 | | |
741 | 741 | | |
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
| 749 | + | |
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
782 | | - | |
| 782 | + | |
783 | 783 | | |
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
| 787 | + | |
788 | 788 | | |
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
792 | | - | |
| 792 | + | |
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
813 | | - | |
| 813 | + | |
814 | 814 | | |
815 | 815 | | |
816 | 816 | | |
817 | 817 | | |
818 | | - | |
| 818 | + | |
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
823 | | - | |
| 823 | + | |
824 | 824 | | |
825 | 825 | | |
826 | 826 | | |
| |||
849 | 849 | | |
850 | 850 | | |
851 | 851 | | |
852 | | - | |
| 852 | + | |
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
| |||
859 | 859 | | |
860 | 860 | | |
861 | 861 | | |
862 | | - | |
| 862 | + | |
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
| |||
941 | 941 | | |
942 | 942 | | |
943 | 943 | | |
| 944 | + | |
944 | 945 | | |
945 | 946 | | |
946 | 947 | | |
| |||
952 | 953 | | |
953 | 954 | | |
954 | 955 | | |
| 956 | + | |
955 | 957 | | |
956 | 958 | | |
957 | 959 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15933 | 15933 | | |
15934 | 15934 | | |
15935 | 15935 | | |
15936 | | - | |
15937 | 15936 | | |
15938 | 15937 | | |
15939 | 15938 | | |
15940 | 15939 | | |
15941 | 15940 | | |
15942 | 15941 | | |
15943 | | - | |
15944 | 15942 | | |
15945 | 15943 | | |
15946 | 15944 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
| |||
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
201 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
| |||
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
225 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
226 | 235 | | |
227 | 236 | | |
228 | 237 | | |
| |||
246 | 255 | | |
247 | 256 | | |
248 | 257 | | |
249 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
250 | 262 | | |
251 | 263 | | |
252 | 264 | | |
| |||
270 | 282 | | |
271 | 283 | | |
272 | 284 | | |
273 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
274 | 289 | | |
275 | 290 | | |
276 | 291 | | |
| |||
294 | 309 | | |
295 | 310 | | |
296 | 311 | | |
297 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
298 | 316 | | |
299 | 317 | | |
300 | 318 | | |
| |||
318 | 336 | | |
319 | 337 | | |
320 | 338 | | |
321 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
322 | 343 | | |
323 | 344 | | |
324 | 345 | | |
| |||
348 | 369 | | |
349 | 370 | | |
350 | 371 | | |
351 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
352 | 376 | | |
353 | 377 | | |
354 | 378 | | |
| |||
397 | 421 | | |
398 | 422 | | |
399 | 423 | | |
400 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
401 | 428 | | |
402 | 429 | | |
403 | 430 | | |
| |||
414 | 441 | | |
415 | 442 | | |
416 | 443 | | |
417 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
418 | 448 | | |
419 | 449 | | |
420 | 450 | | |
| |||
447 | 477 | | |
448 | 478 | | |
449 | 479 | | |
450 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
451 | 484 | | |
452 | 485 | | |
453 | 486 | | |
| |||
572 | 605 | | |
573 | 606 | | |
574 | 607 | | |
575 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
576 | 612 | | |
577 | 613 | | |
578 | 614 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
| 687 | + | |
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
696 | | - | |
697 | | - | |
| 696 | + | |
| 697 | + | |
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
| |||
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
708 | 714 | | |
709 | 715 | | |
710 | 716 | | |
| |||
965 | 971 | | |
966 | 972 | | |
967 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
968 | 983 | | |
969 | 984 | | |
970 | 985 | | |
| |||
0 commit comments