Commit 81624da0 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: make InputMethodMus ack events when resetting connection

Now that we reset the connection when nothing is focused we need to ack
any pending events.

BUG=681563
TEST=covered by test

Change-Id: I1fc3219a04a49f911434ea8def7d9eca223c4ab6
Reviewed-on: https://chromium-review.googlesource.com/1089885Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565100}
parent 7330d8ff
......@@ -1274,6 +1274,8 @@ void WindowServiceClient::OnWindowInputEventAck(uint32_t event_id,
window_service_->delegate()->OnUnhandledKeyEvent(
*(in_flight_event->event->AsKeyEvent()));
}
} else if (event_id != kDefaultEventId) {
DVLOG(1) << "OnWindowInputEventAck supplied unexpected id " << event_id;
}
}
......
......@@ -150,6 +150,11 @@ void InputMethodMus::OnDidChangeFocusedClient(
InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
UpdateTextInputType();
// We are about to close the pipe with pending callbacks. Closing the pipe
// results in none of the callbacks being run. We have to run the callbacks
// else mus won't process the next event immediately.
AckPendingCallbacksUnhandled();
if (!focused) {
input_method_ = nullptr;
input_method_ptr_.reset();
......@@ -160,11 +165,6 @@ void InputMethodMus::OnDidChangeFocusedClient(
text_input_client_ =
std::make_unique<TextInputClientImpl>(focused, delegate());
// We are about to close the pipe with pending callbacks. Closing the pipe
// results in none of the callbacks being run. We have to run the callbacks
// else mus won't process the next event immediately.
AckPendingCallbacksUnhandled();
if (ime_driver_) {
ui::mojom::StartSessionDetailsPtr details =
ui::mojom::StartSessionDetails::New();
......
......@@ -158,6 +158,35 @@ TEST_F(InputMethodMusTest, PendingCallbackRunFromOnDidChangeFocusedClient) {
EXPECT_TRUE(was_event_result_callback_run);
}
TEST_F(InputMethodMusTest,
PendingCallbackRunFromOnDidChangeFocusedClientToNull) {
aura::Window window(nullptr);
window.Init(ui::LAYER_NOT_DRAWN);
bool was_event_result_callback_run = false;
// Create an InputMethodMus and foward an event to it.
TestInputMethodDelegate input_method_delegate;
InputMethodMus input_method_mus(&input_method_delegate, &window);
TestInputMethod test_input_method;
InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method);
EventResultCallback callback = base::BindOnce(&RunFunctionWithEventResult,
&was_event_result_callback_run);
ui::EventDispatchDetails details =
InputMethodMusTestApi::CallSendKeyEventToInputMethod(
&input_method_mus,
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0),
std::move(callback));
ASSERT_TRUE(!details.dispatcher_destroyed && !details.target_destroyed);
// The event should have been queued.
EXPECT_EQ(1u, test_input_method.process_key_event_callbacks()->size());
// Callback should not have been run yet.
EXPECT_FALSE(was_event_result_callback_run);
InputMethodMusTestApi::CallOnDidChangeFocusedClient(&input_method_mus,
nullptr, nullptr);
// Changing the focused client should trigger running the callback.
EXPECT_TRUE(was_event_result_callback_run);
}
// See description of ChangeTextInputTypeWhileProcessingCallback for details.
class TestInputMethodDelegate2 : public ui::internal::InputMethodDelegate {
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment