| 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/shell/public/cpp/service_context.h" | 11 #include "services/shell/public/cpp/service_context.h" |
| 12 #include "services/shell/public/cpp/service_test.h" | 12 #include "services/shell/public/cpp/service_test.h" |
| 13 #include "services/ui/public/interfaces/ime.mojom.h" | 13 #include "services/ui/public/interfaces/ime.mojom.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 | 15 |
| 16 class TestTextInputClient : public ui::mojom::TextInputClient { | 16 class TestTextInputClient : public ui::mojom::TextInputClient { |
| 17 public: | 17 public: |
| 18 explicit TestTextInputClient(ui::mojom::TextInputClientRequest request) | 18 explicit TestTextInputClient(ui::mojom::TextInputClientRequest request) |
| 19 : binding_(this, std::move(request)) {} | 19 : binding_(this, std::move(request)) {} |
| 20 | 20 |
| 21 ui::mojom::CompositionEventPtr WaitUntilCompositionEvent() { | 21 ui::mojom::CompositionEventPtr ReceiveCompositionEvent() { |
| 22 run_loop_.reset(new base::RunLoop); | 22 run_loop_.reset(new base::RunLoop); |
| 23 run_loop_->Run(); | 23 run_loop_->Run(); |
| 24 run_loop_.reset(); | 24 run_loop_.reset(); |
| 25 | 25 |
| 26 return std::move(receieved_composition_event_); | 26 return std::move(receieved_composition_event_); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ui::Event* WaitUntilUnhandledEvent() { | |
| 30 run_loop_.reset(new base::RunLoop); | |
| 31 run_loop_->Run(); | |
| 32 run_loop_.reset(); | |
| 33 | |
| 34 return unhandled_event_.get(); | |
| 35 } | |
| 36 | |
| 37 private: | 29 private: |
| 38 void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override { | 30 void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override { |
| 39 receieved_composition_event_ = std::move(event); | 31 receieved_composition_event_ = std::move(event); |
| 40 run_loop_->Quit(); | 32 run_loop_->Quit(); |
| 41 } | 33 } |
| 42 void OnUnhandledEvent(std::unique_ptr<ui::Event> char_event) override { | |
| 43 unhandled_event_ = std::move(char_event); | |
| 44 run_loop_->Quit(); | |
| 45 } | |
| 46 | 34 |
| 47 mojo::Binding<ui::mojom::TextInputClient> binding_; | 35 mojo::Binding<ui::mojom::TextInputClient> binding_; |
| 48 std::unique_ptr<base::RunLoop> run_loop_; | 36 std::unique_ptr<base::RunLoop> run_loop_; |
| 49 ui::mojom::CompositionEventPtr receieved_composition_event_; | 37 ui::mojom::CompositionEventPtr receieved_composition_event_; |
| 50 std::unique_ptr<ui::Event> unhandled_event_; | |
| 51 | 38 |
| 52 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); | 39 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); |
| 53 }; | 40 }; |
| 54 | 41 |
| 55 class IMEAppTest : public shell::test::ServiceTest { | 42 class IMEAppTest : public shell::test::ServiceTest { |
| 56 public: | 43 public: |
| 57 IMEAppTest() : ServiceTest("exe:mus_ime_unittests") {} | 44 IMEAppTest() : ServiceTest("exe:mus_ime_unittests") {} |
| 58 ~IMEAppTest() override {} | 45 ~IMEAppTest() override {} |
| 59 | 46 |
| 60 // shell::test::ServiceTest: | 47 // shell::test::ServiceTest: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 }; | 60 }; |
| 74 | 61 |
| 75 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEServer. | 62 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEServer. |
| 76 TEST_F(IMEAppTest, ProcessKeyEvent) { | 63 TEST_F(IMEAppTest, ProcessKeyEvent) { |
| 77 ui::mojom::TextInputClientPtr client_ptr; | 64 ui::mojom::TextInputClientPtr client_ptr; |
| 78 TestTextInputClient client(GetProxy(&client_ptr)); | 65 TestTextInputClient client(GetProxy(&client_ptr)); |
| 79 | 66 |
| 80 ui::mojom::InputMethodPtr input_method; | 67 ui::mojom::InputMethodPtr input_method; |
| 81 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); | 68 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); |
| 82 | 69 |
| 83 // Send character key event. | 70 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
| 84 ui::KeyEvent char_event('A', ui::VKEY_A, 0); | 71 |
| 85 input_method->ProcessKeyEvent(ui::Event::Clone(char_event)); | 72 input_method->ProcessKeyEvent(ui::Event::Clone(key_event)); |
| 86 | 73 |
| 87 ui::mojom::CompositionEventPtr composition_event = | 74 ui::mojom::CompositionEventPtr composition_event = |
| 88 client.WaitUntilCompositionEvent(); | 75 client.ReceiveCompositionEvent(); |
| 89 EXPECT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR, | 76 ASSERT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR, |
| 90 composition_event->type); | 77 composition_event->type); |
| 91 EXPECT_TRUE(composition_event->key_event); | 78 ASSERT_TRUE(composition_event->key_event); |
| 92 EXPECT_TRUE(composition_event->key_event.value()->IsKeyEvent()); | 79 ASSERT_TRUE(composition_event->key_event.value()->IsKeyEvent()); |
| 93 | 80 |
| 94 ui::KeyEvent* received_key_event = | 81 ui::KeyEvent* received_key_event = |
| 95 composition_event->key_event.value()->AsKeyEvent(); | 82 composition_event->key_event.value()->AsKeyEvent(); |
| 96 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); | 83 ASSERT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); |
| 97 EXPECT_TRUE(received_key_event->is_char()); | 84 ASSERT_EQ(key_event.GetCharacter(), received_key_event->GetCharacter()); |
| 98 EXPECT_EQ(char_event.GetCharacter(), received_key_event->GetCharacter()); | |
| 99 | |
| 100 // Send non-character key event. | |
| 101 ui::KeyEvent nonchar_event(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, 0); | |
| 102 input_method->ProcessKeyEvent(ui::Event::Clone(nonchar_event)); | |
| 103 | |
| 104 ui::Event* unhandled_event = client.WaitUntilUnhandledEvent(); | |
| 105 EXPECT_TRUE(unhandled_event); | |
| 106 EXPECT_TRUE(unhandled_event->IsKeyEvent()); | |
| 107 EXPECT_FALSE(unhandled_event->AsKeyEvent()->is_char()); | |
| 108 EXPECT_EQ(ui::ET_KEY_PRESSED, unhandled_event->type()); | |
| 109 EXPECT_EQ(nonchar_event.key_code(), | |
| 110 unhandled_event->AsKeyEvent()->key_code()); | |
| 111 } | 85 } |
| OLD | NEW |