Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: ui/aura/mus/input_method_mus_unittest.cc

Issue 2767103004: Makes InputMethodMus deal correctly with focus changes (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/input_method_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 EXPECT_EQ(1u, test_input_method.process_key_event_callbacks()->size()); 123 EXPECT_EQ(1u, test_input_method.process_key_event_callbacks()->size());
124 // Callback should not have been run yet. 124 // Callback should not have been run yet.
125 EXPECT_FALSE(was_event_result_callback_run); 125 EXPECT_FALSE(was_event_result_callback_run);
126 126
127 InputMethodMusTestApi::CallOnDidChangeFocusedClient( 127 InputMethodMusTestApi::CallOnDidChangeFocusedClient(
128 &input_method_mus, nullptr, &test_input_client); 128 &input_method_mus, nullptr, &test_input_client);
129 // Changing the focused client should trigger running the callback. 129 // Changing the focused client should trigger running the callback.
130 EXPECT_TRUE(was_event_result_callback_run); 130 EXPECT_TRUE(was_event_result_callback_run);
131 } 131 }
132 132
133 // See description of ChangeTextInputTypeWhileProcessingCallback for details.
134 class TestInputMethodDelegate2 : public ui::internal::InputMethodDelegate {
135 public:
136 TestInputMethodDelegate2() {}
137 ~TestInputMethodDelegate2() override {}
138
139 void SetInputMethodAndClient(InputMethodMus* input_method_mus,
140 ui::TextInputClient* text_input_client) {
141 input_method_mus_ = input_method_mus;
142 text_input_client_ = text_input_client;
143 }
144
145 bool was_dispatch_key_event_post_ime_called() const {
146 return was_dispatch_key_event_post_ime_called_;
147 }
148
149 // ui::internal::InputMethodDelegate:
150 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override {
151 was_dispatch_key_event_post_ime_called_ = true;
152 input_method_mus_->SetFocusedTextInputClient(text_input_client_);
153 return ui::EventDispatchDetails();
154 }
155
156 private:
157 InputMethodMus* input_method_mus_ = nullptr;
158 ui::TextInputClient* text_input_client_ = nullptr;
159 bool was_dispatch_key_event_post_ime_called_ = false;
160
161 DISALLOW_COPY_AND_ASSIGN(TestInputMethodDelegate2);
162 };
163
164 // This test setups the scenario where during processing an unhandled event
165 // SetFocusedTextInputClient() is called. This verifies we don't crash in this
166 // scenario and the callback is correctly called.
167 TEST_F(InputMethodMusTest, ChangeTextInputTypeWhileProcessingCallback) {
168 aura::Window window(nullptr);
169 window.Init(ui::LAYER_NOT_DRAWN);
170 bool was_event_result_callback_run = false;
171 ui::DummyTextInputClient test_input_client;
172 // Create an InputMethodMus and foward an event to it.
173 TestInputMethodDelegate2 input_method_delegate;
174 InputMethodMus input_method_mus(&input_method_delegate, &window);
175 input_method_delegate.SetInputMethodAndClient(&input_method_mus,
176 &test_input_client);
177 TestInputMethod test_input_method;
178 InputMethodMusTestApi::SetInputMethod(&input_method_mus, &test_input_method);
179 std::unique_ptr<EventResultCallback> callback =
180 base::MakeUnique<EventResultCallback>(base::Bind(
181 &RunFunctionWithEventResult, &was_event_result_callback_run));
182 const ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0);
183 InputMethodMusTestApi::CallSendKeyEventToInputMethod(
184 &input_method_mus, key_event, std::move(callback));
185 // The event should have been queued.
186 ASSERT_EQ(1u, test_input_method.process_key_event_callbacks()->size());
187 // Callback should not have been run yet.
188 EXPECT_FALSE(was_event_result_callback_run);
189 (*test_input_method.process_key_event_callbacks())[0].Run(false);
190
191 // Callback should have been run.
192 EXPECT_TRUE(was_event_result_callback_run);
193 EXPECT_TRUE(input_method_delegate.was_dispatch_key_event_post_ime_called());
194 }
195
133 } // namespace aura 196 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/input_method_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698