Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Feb 21, 2024

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:

  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:

  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

Fixes #143845

Tests

Adds two tests.

@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Feb 21, 2024
@bleroux
Copy link
Contributor Author

bleroux commented Feb 21, 2024

@gspencergoog This will unblock #143579

This PR also updates some existing tests, because they triggered some asserts when the transit mode is KeyDataTransitMode.keyDataThenRawKeyData (they did not when the transit mode was KeyDataTransitMode.rawKeyData). Some were sending several key down events without key up events in between.

I also added KeySimulatorTransitModeVariant.rawKeyData() because some tests require this mode (especially the ones for RawKeyboard).

@bleroux
Copy link
Contributor Author

bleroux commented Feb 21, 2024

This PR surfaced some wrong key sequences in customer test.
See Flutter-Bounty-Hunters/flutter_test_robots#25 and Flutter-Bounty-Hunters/super_editor#1853.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Thanks, this is a good thing to do, I had forgotten to set that default when I deprecated the RawKeyEvent stuff.

@gspencergoog
Copy link
Contributor

This PR surfaced some wrong key sequences in customer test. See Flutter-Bounty-Hunters/flutter_test_robots#25 and superlistapp/super_editor#1853.

These will have to be fixed before we can commit this PR, since they're in customer tests.

@bleroux
Copy link
Contributor Author

bleroux commented Feb 22, 2024

This PR surfaced some wrong key sequences in customer test. See Flutter-Bounty-Hunters/flutter_test_robots#25 and superlistapp/super_editor#1853.

cc @matthew-carroll @angelosilvestre I'm not sure of the process on your side, if my PRs are not compliant with your process thank you for making those changes.

@matthew-carroll
Copy link
Contributor

@bleroux we'll need someone to open a PR in the super_editor repo with the appropriate fix, as mentioned in the policies for customer tests and breaking changes.

@bleroux
Copy link
Contributor Author

bleroux commented Feb 22, 2024

@bleroux we'll need someone to open a PR in the super_editor repo with the appropriate fix, as mentioned in the policies for customer tests and breaking changes.

@matthew-carroll
I filed two PRS:

@bleroux bleroux force-pushed the change_key_simulation_default_transit_mode branch 2 times, most recently from b7c51f2 to cf8d870 Compare February 24, 2024 06:19
@bleroux
Copy link
Contributor Author

bleroux commented Feb 27, 2024

@matthew-carroll The PRs on super_editor and flutter_test_robots are merged, thanks. Unfortunately the super editor customer tests are still failing because super_editor depends on flutter_test_robots v0.22 which does not contain my fix. Do you plan to release a new version for flutter_test_robots?

@gspencergoog The Google testing step is failing, it is probably related to some internal tests simulating wrong key sequences. Can you have a look to those failures?

@matthew-carroll
Copy link
Contributor

@bleroux for now you can put up a super_editor PR that adds a dependency override to use the GitHub version of flutter_test_robots.

@bleroux bleroux force-pushed the change_key_simulation_default_transit_mode branch from cf8d870 to e568575 Compare February 28, 2024 22:26
auto-submit bot pushed a commit to flutter/tests that referenced this pull request Feb 29, 2024
Roll super editor tests to a commit with the fix related to flutter/flutter#143847
@bleroux bleroux force-pushed the change_key_simulation_default_transit_mode branch 2 times, most recently from 918ee51 to 16a5691 Compare February 29, 2024 15:44
@bleroux
Copy link
Contributor Author

bleroux commented Feb 29, 2024

@gspencergoog Customer tests are ok now, unfortunately Google testing step is failing, are they many internal test failures or just a few of them?

@gspencergoog
Copy link
Contributor

It's just one. I'll see if I can fix it.

@gspencergoog
Copy link
Contributor

Okay, I fixed it, but the change needs to be reviewed and submitted. I'll restart the check here once it has been submitted internally.

@gspencergoog
Copy link
Contributor

(it's a trivial fix, but it'll probably be a day before approval because of the time zone the reviewers are in)

Co-authored-by: Greg Spencer <[email protected]>
@bleroux bleroux force-pushed the change_key_simulation_default_transit_mode branch from 16a5691 to e512a93 Compare March 6, 2024 08:13
@gspencergoog
Copy link
Contributor

Okay, Google tests fixed.

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 7, 2024
@auto-submit auto-submit bot merged commit 8ade81f into flutter:master Mar 7, 2024
@bleroux bleroux deleted the change_key_simulation_default_transit_mode branch March 7, 2024 07:25
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 7, 2024
flutter/flutter@8f84f3f...471a828

2024-03-07 [email protected] [flutter_test] Use defaultTargetPlatform for key events simulation (flutter/flutter#143579)
2024-03-07 [email protected] Roll Packages from 9b88dbc to 6701c9e (3 revisions) (flutter/flutter#144772)
2024-03-07 [email protected] Fix frameworks added to bundle multiple times instead of lipo (flutter/flutter#144688)
2024-03-07 [email protected] Roll Flutter Engine from 40a42796b129 to f8c3b2db8cd1 (1 revision) (flutter/flutter#144766)
2024-03-07 [email protected] Roll Flutter Engine from 0246484d2bae to 40a42796b129 (1 revision) (flutter/flutter#144765)
2024-03-07 [email protected] Roll Flutter Engine from 6c1751bd774e to 0246484d2bae (1 revision) (flutter/flutter#144756)
2024-03-07 [email protected] [flutter_test] Change KeyEventSimulator default transit mode (flutter/flutter#143847)
2024-03-07 [email protected] Roll Flutter Engine from 03ebd6460b83 to 6c1751bd774e (2 revisions) (flutter/flutter#144747)
2024-03-07 [email protected] Roll Flutter Engine from 8a859c5b3a2d to 03ebd6460b83 (2 revisions) (flutter/flutter#144746)
2024-03-07 [email protected] Roll Flutter Engine from 4f6ea31d1f25 to 8a859c5b3a2d (2 revisions) (flutter/flutter#144743)
2024-03-07 [email protected] Fix memory leak in `editable_gesture_test.dart` (flutter/flutter#144691)
2024-03-07 [email protected] Roll Flutter Engine from 53ddbdfc24e5 to 4f6ea31d1f25 (2 revisions) (flutter/flutter#144741)
2024-03-07 [email protected] Roll Flutter Engine from b2adf7471d3d to 53ddbdfc24e5 (1 revision) (flutter/flutter#144735)
2024-03-06 [email protected] Roll Flutter Engine from 31bbe61dfa0d to b2adf7471d3d (1 revision) (flutter/flutter#144732)
2024-03-06 [email protected] Roll Flutter Engine from 5bbac1a5c576 to 31bbe61dfa0d (3 revisions) (flutter/flutter#144724)
2024-03-06 [email protected] Run macOS test on `dev/integration_tests/ui` (flutter/flutter#142735)
2024-03-06 [email protected] Use wasm-compatible conditional import in timeline.dart, avoid emitting timeline events in SchedulerBinding (flutter/flutter#144682)
2024-03-06 [email protected] Roll Flutter Engine from 44405aedba13 to 5bbac1a5c576 (2 revisions) (flutter/flutter#144714)
2024-03-06 [email protected] Bring back firebase tests to prod (flutter/flutter#144703)
2024-03-06 [email protected] Roll Flutter Engine from 20037e385bda to 44405aedba13 (3 revisions) (flutter/flutter#144710)
2024-03-06 [email protected] Fix code sample failing in smoke test (flutter/flutter#144709)
2024-03-06 [email protected] Remove deprecated `errorColor` from `ThemeData` (flutter/flutter#144078)
2024-03-06 [email protected] make DevFSContent descendants immutable (flutter/flutter#144664)
2024-03-06 [email protected] [Impeller] measure GPU memory usage. (flutter/flutter#144575)
2024-03-06 [email protected] Roll Flutter Engine from 9aad0e93899b to 20037e385bda (1 revision) (flutter/flutter#144707)
2024-03-06 [email protected] Roll Flutter Engine from b6efe0dd88fe to 9aad0e93899b (2 revisions) (flutter/flutter#144702)
2024-03-06 [email protected] Update android templates to use target sdk 34 (flutter/flutter#144641)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@itsjustkevin itsjustkevin added the revert Autorevert PR (with "Reason for revert:" comment) label Mar 8, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 8, 2024

Time to revert pull request flutter/flutter/143847 has elapsed.
You need to open the revert manually and process as a regular pull request.

@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Mar 8, 2024
@itsjustkevin
Copy link
Contributor

Reverting due to issues reported in b/328788027.

@itsjustkevin
Copy link
Contributor

itsjustkevin commented Mar 8, 2024

@gspencergoog this PR does not revert cleanly can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants