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 ReceiveCompositionEvent() { | 21 ui::mojom::CompositionEventPtr WaitUntilCompositionEvent() { |
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 |
29 private: | 37 private: |
30 void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override { | 38 void OnCompositionEvent(ui::mojom::CompositionEventPtr event) override { |
31 receieved_composition_event_ = std::move(event); | 39 receieved_composition_event_ = std::move(event); |
32 run_loop_->Quit(); | 40 run_loop_->Quit(); |
33 } | 41 } |
| 42 void OnUnhandledEvent(std::unique_ptr<ui::Event> char_event) override { |
| 43 unhandled_event_ = std::move(char_event); |
| 44 run_loop_->Quit(); |
| 45 } |
34 | 46 |
35 mojo::Binding<ui::mojom::TextInputClient> binding_; | 47 mojo::Binding<ui::mojom::TextInputClient> binding_; |
36 std::unique_ptr<base::RunLoop> run_loop_; | 48 std::unique_ptr<base::RunLoop> run_loop_; |
37 ui::mojom::CompositionEventPtr receieved_composition_event_; | 49 ui::mojom::CompositionEventPtr receieved_composition_event_; |
| 50 std::unique_ptr<ui::Event> unhandled_event_; |
38 | 51 |
39 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); | 52 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); |
40 }; | 53 }; |
41 | 54 |
42 class IMEAppTest : public shell::test::ServiceTest { | 55 class IMEAppTest : public shell::test::ServiceTest { |
43 public: | 56 public: |
44 IMEAppTest() : ServiceTest("exe:mus_ime_unittests") {} | 57 IMEAppTest() : ServiceTest("exe:mus_ime_unittests") {} |
45 ~IMEAppTest() override {} | 58 ~IMEAppTest() override {} |
46 | 59 |
47 // shell::test::ServiceTest: | 60 // shell::test::ServiceTest: |
(...skipping 12 matching lines...) Expand all Loading... |
60 }; | 73 }; |
61 | 74 |
62 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEServer. | 75 // Tests sending a KeyEvent to the IMEDriver through the Mus IMEServer. |
63 TEST_F(IMEAppTest, ProcessKeyEvent) { | 76 TEST_F(IMEAppTest, ProcessKeyEvent) { |
64 ui::mojom::TextInputClientPtr client_ptr; | 77 ui::mojom::TextInputClientPtr client_ptr; |
65 TestTextInputClient client(GetProxy(&client_ptr)); | 78 TestTextInputClient client(GetProxy(&client_ptr)); |
66 | 79 |
67 ui::mojom::InputMethodPtr input_method; | 80 ui::mojom::InputMethodPtr input_method; |
68 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); | 81 ime_server_->StartSession(std::move(client_ptr), GetProxy(&input_method)); |
69 | 82 |
70 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 83 // Send character key event. |
71 | 84 ui::KeyEvent char_event('A', ui::VKEY_A, 0); |
72 input_method->ProcessKeyEvent(ui::Event::Clone(key_event)); | 85 input_method->ProcessKeyEvent(ui::Event::Clone(char_event)); |
73 | 86 |
74 ui::mojom::CompositionEventPtr composition_event = | 87 ui::mojom::CompositionEventPtr composition_event = |
75 client.ReceiveCompositionEvent(); | 88 client.WaitUntilCompositionEvent(); |
76 ASSERT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR, | 89 EXPECT_EQ(ui::mojom::CompositionEventType::INSERT_CHAR, |
77 composition_event->type); | 90 composition_event->type); |
78 ASSERT_TRUE(composition_event->key_event); | 91 EXPECT_TRUE(composition_event->key_event); |
79 ASSERT_TRUE(composition_event->key_event.value()->IsKeyEvent()); | 92 EXPECT_TRUE(composition_event->key_event.value()->IsKeyEvent()); |
80 | 93 |
81 ui::KeyEvent* received_key_event = | 94 ui::KeyEvent* received_key_event = |
82 composition_event->key_event.value()->AsKeyEvent(); | 95 composition_event->key_event.value()->AsKeyEvent(); |
83 ASSERT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); | 96 EXPECT_EQ(ui::ET_KEY_PRESSED, received_key_event->type()); |
84 ASSERT_EQ(key_event.GetCharacter(), received_key_event->GetCharacter()); | 97 EXPECT_TRUE(received_key_event->is_char()); |
| 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()); |
85 } | 111 } |
OLD | NEW |