Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions shell/platform/windows/flutter_windows_view_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,38 +116,6 @@ TEST(FlutterWindowsViewTest, KeySequence) {
key_event_logs.clear();
}

TEST(FlutterWindowsViewTest, RestartClearsKeyboardState) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();

auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(std::move(engine));

test_response = false;

// Receives a KeyA down. Events are dispatched and decided unhandled. Now the
// keyboard key handler is waiting for the redispatched event.
view.OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
[](bool handled) {});
EXPECT_EQ(key_event_logs.size(), 2);
EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
key_event_logs.clear();

// Resets state so that the keyboard key handler is no longer waiting.
view.OnPreEngineRestart();
Copy link
Member Author

@loic-sharma loic-sharma Feb 3, 2023

Choose a reason for hiding this comment

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

This test would pass even if you removed this line. The logic that ignores redispatched messages does not happen in FlutterView.OnKey - it happens before, in the KeyboardManager.


// Receives another KeyA down. If the state had not been cleared, this event
// will be considered the redispatched event and ignored.
view.OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
[](bool handled) {});
EXPECT_EQ(key_event_logs.size(), 2);
EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
key_event_logs.clear();
}

TEST(FlutterWindowsViewTest, EnableSemantics) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
EngineModifier modifier(engine.get());
Expand Down
60 changes: 60 additions & 0 deletions shell/platform/windows/keyboard_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,66 @@ TEST_F(KeyboardTest, MetaRightUnhandled) {
EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
}

// Press and hold A. This should generate a repeat event.
TEST_F(KeyboardTest, RepeatA) {
KeyboardTester tester{GetContext()};
tester.Responding(true);

// Press A
tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
kWmResultZero),
WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
kWmResultZero)});

// Hold A
tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
kWmResultZero),
WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
kWmResultZero)});

EXPECT_EQ(key_calls.size(), 2);
EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA,
kLogicalKeyA, "a", kNotSynthesized);
EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeRepeat, kPhysicalKeyA,
kLogicalKeyA, "a", kNotSynthesized);
EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
}

// Press A, hot restart the engine, and hold A.
// This should reset the keyboard's state and generate
// two separate key down events.
TEST_F(KeyboardTest, RestartClearsKeyboardState) {
KeyboardTester tester{GetContext()};
tester.Responding(true);

// Press A
tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
kWmResultZero),
WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
kWmResultZero)});

// Send the "hot restart" signal. This should reset the keyboard's state.
tester.GetView().OnPreEngineRestart();

// Hold A. Notice the message declares the key is already down, however, the
// the keyboard does not send a repeat event as its state was reset.
tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
kWmResultZero),
WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
kWmResultZero)});

EXPECT_EQ(key_calls.size(), 2);
EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA,
kLogicalKeyA, "a", kNotSynthesized);
EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeDown, kPhysicalKeyA,
kLogicalKeyA, "a", kNotSynthesized);
EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
}

// Press Shift-A. This is special because Win32 gives 'A' as character for the
// KeyA press.
TEST_F(KeyboardTest, ShiftLeftKeyA) {
Expand Down