| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "mojo/public/cpp/bindings/interface_request.h" | 10 #include "mojo/public/cpp/bindings/interface_request.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 class IMEAppTest : public service_manager::test::ServiceTest { | 50 class IMEAppTest : public service_manager::test::ServiceTest { |
| 51 public: | 51 public: |
| 52 IMEAppTest() : ServiceTest("ime_unittests") {} | 52 IMEAppTest() : ServiceTest("ime_unittests") {} |
| 53 ~IMEAppTest() override {} | 53 ~IMEAppTest() override {} |
| 54 | 54 |
| 55 // service_manager::test::ServiceTest: | 55 // service_manager::test::ServiceTest: |
| 56 void SetUp() override { | 56 void SetUp() override { |
| 57 ServiceTest::SetUp(); | 57 ServiceTest::SetUp(); |
| 58 // test_ime_driver will register itself as the current IMEDriver. | 58 // test_ime_driver will register itself as the current IMEDriver. |
| 59 connector()->StartService("test_ime_driver"); | 59 connector()->StartService("test_ime_driver"); |
| 60 connector()->BindInterface(ui::mojom::kServiceName, &ime_server_); | 60 connector()->BindInterface(ui::mojom::kServiceName, &ime_driver_); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool ProcessKeyEvent(ui::mojom::InputMethodPtr* input_method, | 63 bool ProcessKeyEvent(ui::mojom::InputMethodPtr* input_method, |
| 64 std::unique_ptr<ui::Event> event) { | 64 std::unique_ptr<ui::Event> event) { |
| 65 (*input_method) | 65 (*input_method) |
| 66 ->ProcessKeyEvent(std::move(event), | 66 ->ProcessKeyEvent(std::move(event), |
| 67 base::Bind(&IMEAppTest::ProcessKeyEventCallback, | 67 base::Bind(&IMEAppTest::ProcessKeyEventCallback, |
| 68 base::Unretained(this))); | 68 base::Unretained(this))); |
| 69 | 69 |
| 70 run_loop_.reset(new base::RunLoop); | 70 run_loop_.reset(new base::RunLoop); |
| 71 run_loop_->Run(); | 71 run_loop_->Run(); |
| 72 run_loop_.reset(); | 72 run_loop_.reset(); |
| 73 | 73 |
| 74 return handled_; | 74 return handled_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 void ProcessKeyEventCallback(bool handled) { | 78 void ProcessKeyEventCallback(bool handled) { |
| 79 handled_ = handled; | 79 handled_ = handled; |
| 80 run_loop_->Quit(); | 80 run_loop_->Quit(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 ui::mojom::IMEServerPtr ime_server_; | 83 ui::mojom::IMEDriverPtr ime_driver_; |
| 84 std::unique_ptr<base::RunLoop> run_loop_; | 84 std::unique_ptr<base::RunLoop> run_loop_; |
| 85 bool handled_; | 85 bool handled_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(IMEAppTest); | 87 DISALLOW_COPY_AND_ASSIGN(IMEAppTest); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEServer. | 90 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEDriver. |
| 91 TEST_F(IMEAppTest, ProcessKeyEvent) { | 91 TEST_F(IMEAppTest, ProcessKeyEvent) { |
| 92 ui::mojom::TextInputClientPtr client_ptr; | 92 ui::mojom::TextInputClientPtr client_ptr; |
| 93 TestTextInputClient client(MakeRequest(&client_ptr)); | 93 TestTextInputClient client(MakeRequest(&client_ptr)); |
| 94 | 94 |
| 95 ui::mojom::InputMethodPtr input_method; | 95 ui::mojom::InputMethodPtr input_method; |
| 96 ui::mojom::StartSessionDetailsPtr details = | 96 ui::mojom::StartSessionDetailsPtr details = |
| 97 ui::mojom::StartSessionDetails::New(); | 97 ui::mojom::StartSessionDetails::New(); |
| 98 details->client = std::move(client_ptr); | 98 details->client = std::move(client_ptr); |
| 99 details->input_method_request = MakeRequest(&input_method); | 99 details->input_method_request = MakeRequest(&input_method); |
| 100 ime_server_->StartSession(std::move(details)); | 100 ime_driver_->StartSession(std::move(details)); |
| 101 | 101 |
| 102 // Send character key event. | 102 // Send character key event. |
| 103 ui::KeyEvent char_event('A', ui::VKEY_A, 0); | 103 ui::KeyEvent char_event('A', ui::VKEY_A, 0); |
| 104 EXPECT_TRUE(ProcessKeyEvent(&input_method, ui::Event::Clone(char_event))); | 104 EXPECT_TRUE(ProcessKeyEvent(&input_method, ui::Event::Clone(char_event))); |
| 105 | 105 |
| 106 std::unique_ptr<ui::Event> received_event = client.WaitUntilInsertChar(); | 106 std::unique_ptr<ui::Event> received_event = client.WaitUntilInsertChar(); |
| 107 ASSERT_TRUE(received_event && received_event->IsKeyEvent()); | 107 ASSERT_TRUE(received_event && received_event->IsKeyEvent()); |
| 108 | 108 |
| 109 ui::KeyEvent* received_key_event = received_event->AsKeyEvent(); | 109 ui::KeyEvent* received_key_event = received_event->AsKeyEvent(); |
| 110 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); | 110 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); |
| 111 EXPECT_TRUE(received_key_event->is_char()); | 111 EXPECT_TRUE(received_key_event->is_char()); |
| 112 EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter()); | 112 EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter()); |
| 113 | 113 |
| 114 // Send non-character key event. | 114 // Send non-character key event. |
| 115 ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0); | 115 ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0); |
| 116 EXPECT_FALSE(ProcessKeyEvent(&input_method, ui::Event::Clone(nonchar_event))); | 116 EXPECT_FALSE(ProcessKeyEvent(&input_method, ui::Event::Clone(nonchar_event))); |
| 117 } | 117 } |
| OLD | NEW |