Skip to content

[flutter_test] Default transit mode for key events simulation is not the same as framework #143845

Closed

Description

@bleroux

Steps to reproduce

Run the test provided in code sample.

Expected results

The test succeeds without forcing debugKeyEventSimulatorTransitModeOverride or relying on KeySimulationModeVariant.

Actual results

The test fails because the transit mode defaults to KeyDataTransitMode.rawKeyData whose modifiers logic can not distinguish modifier keys side (and generates both a control left and control right down event when asked to simulate a control left down event).

Code sample

Code sample
testWidgets('Press control left once', (WidgetTester tester) async {
  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, in addition of the control left key down event, a down event
  // for control right is synthesized
  expect(events.length, 1);
});

Logs

Logs
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: <1>
  Actual: <2>

Flutter Doctor output

Doctor output
console
[!] Flutter (Channel [user-branch], 3.19.0-3.0.pre.776, on Ubuntu 23.10
    6.5.0-17-generic, locale fr_FR.UTF-8)
    ! Flutter version 3.19.0-3.0.pre.776 on channel [user-branch] at
      /home/bruno/Nevercode/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions
      at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not the same as FLUTTER_GIT_URL
    • FLUTTER_GIT_URL = [email protected]:NevercodeHQ/flutter.git
    • Framework revision 3a6384ec61 (il y a 2 heures), 2024-02-21 12:21:09 +0100
    • Engine revision ed49634486
    • Dart version 3.4.0 (build 3.4.0-157.0.dev)
    • DevTools version 2.33.0-dev.6
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /media/oldhome/Android/Sdk
    • Platform android-34, build-tools 33.0.2
    • ANDROID_HOME = /media/oldhome/Android/Sdk
    • Java binary at: /media/oldhome/Produits/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 16.0.6 (15)
    • cmake version 3.27.4
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2021.3)
    • Android Studio at /media/oldhome/Produits/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.86.2)
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension version 3.82.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 23.10 6.5.0-17-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 120.0.6099.199

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.```

</details>

Activity

  1. added
    in triagePresently being triaged by the triage team
    a: tests"flutter test", flutter_test, or one of our tests
    a: text inputEntering text in a text field or keyboard related problems
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Feb 21, 2024
  2. self-assigned this
    on Feb 21, 2024
  3. added
    P2Important issues not at the top of the work list
    on Feb 21, 2024
  4. moved this from To do to PR submitted in Nevercodeon Feb 26, 2024
  5. bleroux commented on Mar 9, 2024

    @bleroux
    ContributorAuthor

    Fixed in #143847

  6. moved this from PR submitted to Done (PR merged) in Nevercodeon Mar 9, 2024
  7. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 9, 2024
  8. github-actions commented on Mar 23, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsa: text inputEntering text in a text field or keyboard related problemsfound in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions