| Index: services/ui/ime/ime_unittest.cc
|
| diff --git a/services/ui/ime/ime_unittest.cc b/services/ui/ime/ime_unittest.cc
|
| index 9c235494c5db9799f26e696cf273a3b04fede61a..da199c05a2b1c1cdcb9b81b1d6bf929ab14bd61f 100644
|
| --- a/services/ui/ime/ime_unittest.cc
|
| +++ b/services/ui/ime/ime_unittest.cc
|
| @@ -19,35 +19,25 @@ class TestTextInputClient : public ui::mojom::TextInputClient {
|
| : binding_(this, std::move(request)) {}
|
|
|
| ui::mojom::CompositionEventPtr WaitUntilCompositionEvent() {
|
| - run_loop_.reset(new base::RunLoop);
|
| - run_loop_->Run();
|
| - run_loop_.reset();
|
| + if (!receieved_composition_event_) {
|
| + run_loop_.reset(new base::RunLoop);
|
| + run_loop_->Run();
|
| + run_loop_.reset();
|
| + }
|
|
|
| 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();
|
| + if (run_loop_)
|
| + 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);
|
| };
|
| @@ -65,9 +55,29 @@ class IMEAppTest : public service_manager::test::ServiceTest {
|
| connector()->ConnectToInterface("service:ui", &ime_server_);
|
| }
|
|
|
| + bool ProcessKeyEvent(ui::mojom::InputMethodPtr* input_method,
|
| + std::unique_ptr<ui::Event> event) {
|
| + (*input_method)
|
| + ->ProcessKeyEvent(std::move(event),
|
| + base::Bind(&IMEAppTest::ProcessKeyEventCallback,
|
| + base::Unretained(this)));
|
| +
|
| + run_loop_.reset(new base::RunLoop);
|
| + run_loop_->Run();
|
| + run_loop_.reset();
|
| +
|
| + return handled_;
|
| + }
|
| +
|
| protected:
|
| + void ProcessKeyEventCallback(bool handled) {
|
| + handled_ = handled;
|
| + run_loop_->Quit();
|
| + }
|
| +
|
| ui::mojom::IMEServerPtr ime_server_;
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
| + bool handled_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(IMEAppTest);
|
| };
|
| @@ -82,7 +92,7 @@ TEST_F(IMEAppTest, ProcessKeyEvent) {
|
|
|
| // Send character key event.
|
| ui::KeyEvent char_event('A', ui::VKEY_A, 0);
|
| - input_method->ProcessKeyEvent(ui::Event::Clone(char_event));
|
| + EXPECT_TRUE(ProcessKeyEvent(&input_method, ui::Event::Clone(char_event)));
|
|
|
| ui::mojom::CompositionEventPtr composition_event =
|
| client.WaitUntilCompositionEvent();
|
| @@ -99,13 +109,5 @@ TEST_F(IMEAppTest, ProcessKeyEvent) {
|
|
|
| // 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());
|
| + EXPECT_FALSE(ProcessKeyEvent(&input_method, ui::Event::Clone(nonchar_event)));
|
| }
|
|
|