OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ui/aura/mus/input_method_mus.h" | 5 #include "ui/aura/mus/input_method_mus.h" |
6 | 6 |
7 #include "services/ui/public/interfaces/ime/ime.mojom.h" | 7 #include "services/ui/public/interfaces/ime/ime.mojom.h" |
8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
9 #include "ui/aura/test/mus/input_method_mus_test_api.h" | 9 #include "ui/aura/test/mus/input_method_mus_test_api.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override { | 24 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override { |
25 return ui::EventDispatchDetails(); | 25 return ui::EventDispatchDetails(); |
26 } | 26 } |
27 | 27 |
28 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(TestInputMethodDelegate); | 29 DISALLOW_COPY_AND_ASSIGN(TestInputMethodDelegate); |
30 }; | 30 }; |
31 | 31 |
32 using ProcessKeyEventCallback = base::Callback<void(bool)>; | 32 using ProcessKeyEventCallback = base::Callback<void(bool)>; |
33 using ProcessKeyEventCallbacks = std::vector<ProcessKeyEventCallback>; | 33 using ProcessKeyEventCallbacks = std::vector<ProcessKeyEventCallback>; |
34 using EventResultCallback = base::Callback<void(ui::mojom::EventResult)>; | |
35 | 34 |
36 // InputMethod implementation that queues up the callbacks supplied to | 35 // InputMethod implementation that queues up the callbacks supplied to |
37 // ProcessKeyEvent(). | 36 // ProcessKeyEvent(). |
38 class TestInputMethod : public ui::mojom::InputMethod { | 37 class TestInputMethod : public ui::mojom::InputMethod { |
39 public: | 38 public: |
40 TestInputMethod() {} | 39 TestInputMethod() {} |
41 ~TestInputMethod() override {} | 40 ~TestInputMethod() override {} |
42 | 41 |
43 ProcessKeyEventCallbacks* process_key_event_callbacks() { | 42 ProcessKeyEventCallbacks* process_key_event_callbacks() { |
44 return &process_key_event_callbacks_; | 43 return &process_key_event_callbacks_; |
(...skipping 14 matching lines...) Expand all Loading... |
59 DISALLOW_COPY_AND_ASSIGN(TestInputMethod); | 58 DISALLOW_COPY_AND_ASSIGN(TestInputMethod); |
60 }; | 59 }; |
61 | 60 |
62 } // namespace | 61 } // namespace |
63 | 62 |
64 using InputMethodMusTest = test::AuraTestBaseMus; | 63 using InputMethodMusTest = test::AuraTestBaseMus; |
65 | 64 |
66 namespace { | 65 namespace { |
67 | 66 |
68 // Used in closure supplied to processing the event. | 67 // Used in closure supplied to processing the event. |
69 void RunFunctionWithEventResult(bool* was_run, ui::mojom::EventResult result) { | 68 void RunFunctionWithHandled(bool* was_run, bool handled) { |
70 *was_run = true; | 69 *was_run = true; |
71 } | 70 } |
72 | 71 |
73 } // namespace | 72 } // namespace |
74 | 73 |
75 TEST_F(InputMethodMusTest, PendingCallbackRunFromDestruction) { | 74 TEST_F(InputMethodMusTest, PendingCallbackRunFromDestruction) { |
76 aura::Window window(nullptr); | 75 aura::Window window(nullptr); |
77 window.Init(ui::LAYER_NOT_DRAWN); | 76 window.Init(ui::LAYER_NOT_DRAWN); |
78 bool was_event_result_callback_run = false; | 77 bool was_event_result_callback_run = false; |
79 // Create an InputMethodMus and foward an event to it. | 78 // Create an InputMethodMus and foward an event to it. |
80 { | 79 { |
81 TestInputMethodDelegate input_method_delegate; | 80 TestInputMethodDelegate input_method_delegate; |
82 InputMethodMus input_method_mus(&input_method_delegate, &window); | 81 InputMethodMus input_method_mus(&input_method_delegate, &window); |
83 TestInputMethod test_input_method; | 82 TestInputMethod test_input_method; |
84 InputMethodMusTestApi::SetInputMethod(&input_method_mus, | 83 InputMethodMusTestApi::SetInputMethod(&input_method_mus, |
85 &test_input_method); | 84 &test_input_method); |
86 std::unique_ptr<EventResultCallback> callback = | 85 std::unique_ptr<InputMethodMus::AckCallback> callback = |
87 base::MakeUnique<EventResultCallback>(base::Bind( | 86 base::MakeUnique<InputMethodMus::AckCallback>(base::Bind( |
88 &RunFunctionWithEventResult, &was_event_result_callback_run)); | 87 &RunFunctionWithHandled, &was_event_result_callback_run)); |
89 InputMethodMusTestApi::CallSendKeyEventToInputMethod( | 88 InputMethodMusTestApi::CallSendKeyEventToInputMethod( |
90 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), | 89 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), |
91 std::move(callback)); | 90 std::move(callback)); |
92 // Add a null callback as well, to make sure null is deal with. | 91 // Add a null callback as well, to make sure null is deal with. |
93 InputMethodMusTestApi::CallSendKeyEventToInputMethod( | 92 InputMethodMusTestApi::CallSendKeyEventToInputMethod( |
94 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), | 93 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), |
95 nullptr); | 94 nullptr); |
96 // The event should have been queued. | 95 // The event should have been queued. |
97 EXPECT_EQ(2u, test_input_method.process_key_event_callbacks()->size()); | 96 EXPECT_EQ(2u, test_input_method.process_key_event_callbacks()->size()); |
98 // Callback should not have been run yet. | 97 // Callback should not have been run yet. |
99 EXPECT_FALSE(was_event_result_callback_run); | 98 EXPECT_FALSE(was_event_result_callback_run); |
100 } | 99 } |
101 | 100 |
102 // When the destructor is run the callback should be run. | 101 // When the destructor is run the callback should be run. |
103 EXPECT_TRUE(was_event_result_callback_run); | 102 EXPECT_TRUE(was_event_result_callback_run); |
104 } | 103 } |
105 | 104 |
106 TEST_F(InputMethodMusTest, PendingCallbackRunFromOnDidChangeFocusedClient) { | 105 TEST_F(InputMethodMusTest, PendingCallbackRunFromOnDidChangeFocusedClient) { |
107 aura::Window window(nullptr); | 106 aura::Window window(nullptr); |
108 window.Init(ui::LAYER_NOT_DRAWN); | 107 window.Init(ui::LAYER_NOT_DRAWN); |
109 bool was_event_result_callback_run = false; | 108 bool was_event_result_callback_run = false; |
110 ui::DummyTextInputClient test_input_client; | 109 ui::DummyTextInputClient test_input_client; |
111 // Create an InputMethodMus and foward an event to it. | 110 // Create an InputMethodMus and foward an event to it. |
112 TestInputMethodDelegate input_method_delegate; | 111 TestInputMethodDelegate input_method_delegate; |
113 InputMethodMus input_method_mus(&input_method_delegate, &window); | 112 InputMethodMus input_method_mus(&input_method_delegate, &window); |
114 TestInputMethod test_input_method; | 113 TestInputMethod test_input_method; |
115 InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method); | 114 InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method); |
116 std::unique_ptr<EventResultCallback> callback = | 115 std::unique_ptr<InputMethodMus::AckCallback> callback = |
117 base::MakeUnique<EventResultCallback>(base::Bind( | 116 base::MakeUnique<InputMethodMus::AckCallback>( |
118 &RunFunctionWithEventResult, &was_event_result_callback_run)); | 117 base::Bind(&RunFunctionWithHandled, &was_event_result_callback_run)); |
119 InputMethodMusTestApi::CallSendKeyEventToInputMethod( | 118 InputMethodMusTestApi::CallSendKeyEventToInputMethod( |
120 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), | 119 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0), |
121 std::move(callback)); | 120 std::move(callback)); |
122 // The event should have been queued. | 121 // The event should have been queued. |
123 EXPECT_EQ(1u, test_input_method.process_key_event_callbacks()->size()); | 122 EXPECT_EQ(1u, test_input_method.process_key_event_callbacks()->size()); |
124 // Callback should not have been run yet. | 123 // Callback should not have been run yet. |
125 EXPECT_FALSE(was_event_result_callback_run); | 124 EXPECT_FALSE(was_event_result_callback_run); |
126 | 125 |
127 InputMethodMusTestApi::CallOnDidChangeFocusedClient( | 126 InputMethodMusTestApi::CallOnDidChangeFocusedClient( |
128 &input_method_mus, nullptr, &test_input_client); | 127 &input_method_mus, nullptr, &test_input_client); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 window.Init(ui::LAYER_NOT_DRAWN); | 168 window.Init(ui::LAYER_NOT_DRAWN); |
170 bool was_event_result_callback_run = false; | 169 bool was_event_result_callback_run = false; |
171 ui::DummyTextInputClient test_input_client; | 170 ui::DummyTextInputClient test_input_client; |
172 // Create an InputMethodMus and foward an event to it. | 171 // Create an InputMethodMus and foward an event to it. |
173 TestInputMethodDelegate2 input_method_delegate; | 172 TestInputMethodDelegate2 input_method_delegate; |
174 InputMethodMus input_method_mus(&input_method_delegate, &window); | 173 InputMethodMus input_method_mus(&input_method_delegate, &window); |
175 input_method_delegate.SetInputMethodAndClient(&input_method_mus, | 174 input_method_delegate.SetInputMethodAndClient(&input_method_mus, |
176 &test_input_client); | 175 &test_input_client); |
177 TestInputMethod test_input_method; | 176 TestInputMethod test_input_method; |
178 InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method); | 177 InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method); |
179 std::unique_ptr<EventResultCallback> callback = | 178 std::unique_ptr<InputMethodMus::AckCallback> callback = |
180 base::MakeUnique<EventResultCallback>(base::Bind( | 179 base::MakeUnique<InputMethodMus::AckCallback>( |
181 &RunFunctionWithEventResult, &was_event_result_callback_run)); | 180 base::Bind(&RunFunctionWithHandled, &was_event_result_callback_run)); |
182 const ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); | 181 const ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); |
183 InputMethodMusTestApi::CallSendKeyEventToInputMethod( | 182 InputMethodMusTestApi::CallSendKeyEventToInputMethod( |
184 &input_method_mus, key_event, std::move(callback)); | 183 &input_method_mus, key_event, std::move(callback)); |
185 // The event should have been queued. | 184 // The event should have been queued. |
186 ASSERT_EQ(1u, test_input_method.process_key_event_callbacks()->size()); | 185 ASSERT_EQ(1u, test_input_method.process_key_event_callbacks()->size()); |
187 // Callback should not have been run yet. | 186 // Callback should not have been run yet. |
188 EXPECT_FALSE(was_event_result_callback_run); | 187 EXPECT_FALSE(was_event_result_callback_run); |
189 (*test_input_method.process_key_event_callbacks())[0].Run(false); | 188 (*test_input_method.process_key_event_callbacks())[0].Run(false); |
190 | 189 |
191 // Callback should have been run. | 190 // Callback should have been run. |
192 EXPECT_TRUE(was_event_result_callback_run); | 191 EXPECT_TRUE(was_event_result_callback_run); |
193 EXPECT_TRUE(input_method_delegate.was_dispatch_key_event_post_ime_called()); | 192 EXPECT_TRUE(input_method_delegate.was_dispatch_key_event_post_ime_called()); |
194 } | 193 } |
195 | 194 |
196 } // namespace aura | 195 } // namespace aura |
OLD | NEW |