| 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" |
| 11 #include "services/service_manager/public/cpp/service_context.h" | 11 #include "services/service_manager/public/cpp/service_context.h" |
| 12 #include "services/service_manager/public/cpp/service_test.h" | 12 #include "services/service_manager/public/cpp/service_test.h" |
| 13 #include "services/ui/public/interfaces/constants.mojom.h" | 13 #include "services/ui/public/interfaces/constants.mojom.h" |
| 14 #include "services/ui/public/interfaces/ime.mojom.h" | 14 #include "services/ui/public/interfaces/ime/ime.mojom.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 | 16 |
| 17 class TestTextInputClient : public ui::mojom::TextInputClient { | 17 class TestTextInputClient : public ui::mojom::TextInputClient { |
| 18 public: | 18 public: |
| 19 explicit TestTextInputClient(ui::mojom::TextInputClientRequest request) | 19 explicit TestTextInputClient(ui::mojom::TextInputClientRequest request) |
| 20 : binding_(this, std::move(request)) {} | 20 : binding_(this, std::move(request)) {} |
| 21 | 21 |
| 22 ui::mojom::CompositionEventPtr WaitUntilCompositionEvent() { | 22 std::unique_ptr<ui::Event> WaitUntilInsertChar() { |
| 23 if (!receieved_composition_event_) { | 23 if (!receieved_event_) { |
| 24 run_loop_.reset(new base::RunLoop); | 24 run_loop_.reset(new base::RunLoop); |
| 25 run_loop_->Run(); | 25 run_loop_->Run(); |
| 26 run_loop_.reset(); | 26 run_loop_.reset(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 return std::move(receieved_composition_event_); | 29 return std::move(receieved_event_); |
| 30 } | 30 } |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override { | 33 void SetCompositionText(const ui::CompositionText& composition) override {} |
| 34 receieved_composition_event_ = std::move(event); | 34 void ConfirmCompositionText() override {} |
| 35 void ClearCompositionText() override {} |
| 36 void InsertText(const std::string& text) override {} |
| 37 void InsertChar(std::unique_ptr<ui::Event> event) override { |
| 38 receieved_event_ = std::move(event); |
| 35 if (run_loop_) | 39 if (run_loop_) |
| 36 run_loop_->Quit(); | 40 run_loop_->Quit(); |
| 37 } | 41 } |
| 38 | 42 |
| 39 mojo::Binding<ui::mojom::TextInputClient> binding_; | 43 mojo::Binding<ui::mojom::TextInputClient> binding_; |
| 40 std::unique_ptr<base::RunLoop> run_loop_; | 44 std::unique_ptr<base::RunLoop> run_loop_; |
| 41 ui::mojom::CompositionEventPtr receieved_composition_event_; | 45 std::unique_ptr<ui::Event> receieved_event_; |
| 42 | 46 |
| 43 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); | 47 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); |
| 44 }; | 48 }; |
| 45 | 49 |
| 46 class IMEAppTest : public service_manager::test::ServiceTest { | 50 class IMEAppTest : public service_manager::test::ServiceTest { |
| 47 public: | 51 public: |
| 48 IMEAppTest() : ServiceTest("mus_ime_unittests") {} | 52 IMEAppTest() : ServiceTest("mus_ime_unittests") {} |
| 49 ~IMEAppTest() override {} | 53 ~IMEAppTest() override {} |
| 50 | 54 |
| 51 // service_manager::test::ServiceTest: | 55 // service_manager::test::ServiceTest: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ui::mojom::TextInputClientPtr client_ptr; | 92 ui::mojom::TextInputClientPtr client_ptr; |
| 89 TestTextInputClient client(GetProxy(&client_ptr)); | 93 TestTextInputClient client(GetProxy(&client_ptr)); |
| 90 | 94 |
| 91 ui::mojom::InputMethodPtr input_method; | 95 ui::mojom::InputMethodPtr input_method; |
| 92 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); | 96 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); |
| 93 | 97 |
| 94 // Send character key event. | 98 // Send character key event. |
| 95 ui::KeyEvent char_event('A', ui::VKEY_A, 0); | 99 ui::KeyEvent char_event('A', ui::VKEY_A, 0); |
| 96 EXPECT_TRUE(ProcessKeyEvent(&input_method, ui::Event::Clone(char_event))); | 100 EXPECT_TRUE(ProcessKeyEvent(&input_method, ui::Event::Clone(char_event))); |
| 97 | 101 |
| 98 ui::mojom::CompositionEventPtr composition_event = | 102 std::unique_ptr<ui::Event> received_event = client.WaitUntilInsertChar(); |
| 99 client.WaitUntilCompositionEvent(); | 103 ASSERT_TRUE(received_event && received_event->IsKeyEvent()); |
| 100 EXPECT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR, | |
| 101 composition_event->type); | |
| 102 EXPECT_TRUE(composition_event->key_event); | |
| 103 EXPECT_TRUE(composition_event->key_event.value()->IsKeyEvent()); | |
| 104 | 104 |
| 105 ui::KeyEvent* received_key_event = | 105 ui::KeyEvent* received_key_event = received_event->AsKeyEvent(); |
| 106 composition_event->key_event.value()->AsKeyEvent(); | |
| 107 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); | 106 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); |
| 108 EXPECT_TRUE(received_key_event->is_char()); | 107 EXPECT_TRUE(received_key_event->is_char()); |
| 109 EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter()); | 108 EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter()); |
| 110 | 109 |
| 111 // Send non-character key event. | 110 // Send non-character key event. |
| 112 ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0); | 111 ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0); |
| 113 EXPECT_FALSE(ProcessKeyEvent(&input_method, ui::Event::Clone(nonchar_event))); | 112 EXPECT_FALSE(ProcessKeyEvent(&input_method, ui::Event::Clone(nonchar_event))); |
| 114 } | 113 } |
| OLD | NEW |