| Index: services/ui/ime/ime_unittest.cc
|
| diff --git a/services/ui/ime/ime_unittest.cc b/services/ui/ime/ime_unittest.cc
|
| index a7754d1e657ae67ec224fa7e5420eee3914acc6a..651300c247b9c49a3cdf520ced6bb5e57bac8c01 100644
|
| --- a/services/ui/ime/ime_unittest.cc
|
| +++ b/services/ui/ime/ime_unittest.cc
|
| @@ -18,7 +18,7 @@ class TestTextInputClient : public ui::mojom::TextInputClient {
|
| explicit TestTextInputClient(ui::mojom::TextInputClientRequest request)
|
| : binding_(this, std::move(request)) {}
|
|
|
| - ui::mojom::CompositionEventPtr ReceiveCompositionEvent() {
|
| + ui::mojom::CompositionEventPtr WaitUntilCompositionEvent() {
|
| run_loop_.reset(new base::RunLoop);
|
| run_loop_->Run();
|
| run_loop_.reset();
|
| @@ -26,15 +26,28 @@ class TestTextInputClient : public ui::mojom::TextInputClient {
|
| return std::move(receieved_composition_event_);
|
| }
|
|
|
| + ui::Event* WaitUntilUnhandledEvent() {
|
| + run_loop_.reset(new base::RunLoop);
|
| + run_loop_->Run();
|
| + run_loop_.reset();
|
| +
|
| + return unhandled_event_.get();
|
| + }
|
| +
|
| private:
|
| void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override {
|
| receieved_composition_event_ = std::move(event);
|
| run_loop_->Quit();
|
| }
|
| + void OnUnhandledEvent(std::unique_ptr<ui::Event> char_event) override {
|
| + unhandled_event_ = std::move(char_event);
|
| + run_loop_->Quit();
|
| + }
|
|
|
| mojo::Binding<ui::mojom::TextInputClient> binding_;
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
| ui::mojom::CompositionEventPtr receieved_composition_event_;
|
| + std::unique_ptr<ui::Event> unhandled_event_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestTextInputClient);
|
| };
|
| @@ -67,19 +80,32 @@ TEST_F(IMEAppTest, ProcessKeyEvent) {
|
| ui::mojom::InputMethodPtr input_method;
|
| ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method));
|
|
|
| - ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
|
| -
|
| - input_method->ProcessKeyEvent(ui::Event::Clone(key_event));
|
| + // Send character key event.
|
| + ui::KeyEvent char_event('A', ui::VKEY_A, 0);
|
| + input_method->ProcessKeyEvent(ui::Event::Clone(char_event));
|
|
|
| ui::mojom::CompositionEventPtr composition_event =
|
| - client.ReceiveCompositionEvent();
|
| - ASSERT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR,
|
| + client.WaitUntilCompositionEvent();
|
| + EXPECT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR,
|
| composition_event->type);
|
| - ASSERT_TRUE(composition_event->key_event);
|
| - ASSERT_TRUE(composition_event->key_event.value()->IsKeyEvent());
|
| + EXPECT_TRUE(composition_event->key_event);
|
| + EXPECT_TRUE(composition_event->key_event.value()->IsKeyEvent());
|
|
|
| ui::KeyEvent* received_key_event =
|
| composition_event->key_event.value()->AsKeyEvent();
|
| - ASSERT_EQ(ui::ET_KEY_PRESSED, received_key_event->type());
|
| - ASSERT_EQ(key_event.GetCharacter(), received_key_event->GetCharacter());
|
| + EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type());
|
| + EXPECT_TRUE(received_key_event->is_char());
|
| + EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter());
|
| +
|
| + // Send non-character key event.
|
| + ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0);
|
| + input_method->ProcessKeyEvent(ui::Event::Clone(nonchar_event));
|
| +
|
| + ui::Event* unhandled_event = client.WaitUntilUnhandledEvent();
|
| + EXPECT_TRUE(unhandled_event);
|
| + EXPECT_TRUE(unhandled_event->IsKeyEvent());
|
| + EXPECT_FALSE(unhandled_event->AsKeyEvent()->is_char());
|
| + EXPECT_EQ(ui::ET_KEY_PRESSED, unhandled_event->type());
|
| + EXPECT_EQ(nonchar_event.key_code(),
|
| + unhandled_event->AsKeyEvent()->key_code());
|
| }
|
|
|