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

Side by Side Diff: ui/base/ime/input_method_base_unittest.cc

Issue 1182523003: Removes TextInputFocusManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/base/ime/input_method_base.h" 5 #include "ui/base/ime/input_method_base.h"
6 6
7 #include "base/gtest_prod_util.h" 7 #include "base/gtest_prod_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/scoped_observer.h" 11 #include "base/scoped_observer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/ime/dummy_text_input_client.h" 13 #include "ui/base/ime/dummy_text_input_client.h"
14 #include "ui/base/ime/input_method_observer.h" 14 #include "ui/base/ime/input_method_observer.h"
15 #include "ui/base/ime/text_input_focus_manager.h"
16 #include "ui/base/ui_base_switches_util.h" 15 #include "ui/base/ui_base_switches_util.h"
17 #include "ui/events/event.h" 16 #include "ui/events/event.h"
18 17
19 namespace ui { 18 namespace ui {
20 namespace { 19 namespace {
21 20
22 class ClientChangeVerifier { 21 class ClientChangeVerifier {
23 public: 22 public:
24 ClientChangeVerifier() 23 ClientChangeVerifier()
25 : previous_client_(NULL), 24 : previous_client_(NULL),
(...skipping 21 matching lines...) Expand all
47 previous_client_ = previous_client; 46 previous_client_ = previous_client;
48 next_client_ = next_client; 47 next_client_ = next_client;
49 call_expected_ = true; 48 call_expected_ = true;
50 on_will_change_focused_client_called_ = false; 49 on_will_change_focused_client_called_ = false;
51 on_did_change_focused_client_called_ = false; 50 on_did_change_focused_client_called_ = false;
52 on_text_input_state_changed_ = false; 51 on_text_input_state_changed_ = false;
53 } 52 }
54 53
55 // Verifies the result satisfies the expectation or not. 54 // Verifies the result satisfies the expectation or not.
56 void Verify() { 55 void Verify() {
57 if (switches::IsTextInputFocusManagerEnabled()) { 56 EXPECT_EQ(call_expected_, on_will_change_focused_client_called_);
58 EXPECT_FALSE(on_will_change_focused_client_called_); 57 EXPECT_EQ(call_expected_, on_did_change_focused_client_called_);
59 EXPECT_FALSE(on_did_change_focused_client_called_); 58 EXPECT_EQ(call_expected_, on_text_input_state_changed_);
60 EXPECT_FALSE(on_text_input_state_changed_);
61 } else {
62 EXPECT_EQ(call_expected_, on_will_change_focused_client_called_);
63 EXPECT_EQ(call_expected_, on_did_change_focused_client_called_);
64 EXPECT_EQ(call_expected_, on_text_input_state_changed_);
65 }
66 } 59 }
67 60
68 void OnWillChangeFocusedClient(TextInputClient* focused_before, 61 void OnWillChangeFocusedClient(TextInputClient* focused_before,
69 TextInputClient* focused) { 62 TextInputClient* focused) {
70 EXPECT_TRUE(call_expected_); 63 EXPECT_TRUE(call_expected_);
71 64
72 // Check arguments 65 // Check arguments
73 EXPECT_EQ(previous_client_, focused_before); 66 EXPECT_EQ(previous_client_, focused_before);
74 EXPECT_EQ(next_client_, focused); 67 EXPECT_EQ(next_client_, focused);
75 68
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 189
197 ClientChangeVerifier* verifier_; 190 ClientChangeVerifier* verifier_;
198 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); 191 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver);
199 }; 192 };
200 193
201 typedef ScopedObserver<InputMethod, InputMethodObserver> 194 typedef ScopedObserver<InputMethod, InputMethodObserver>
202 InputMethodScopedObserver; 195 InputMethodScopedObserver;
203 196
204 void SetFocusedTextInputClient(InputMethod* input_method, 197 void SetFocusedTextInputClient(InputMethod* input_method,
205 TextInputClient* text_input_client) { 198 TextInputClient* text_input_client) {
206 if (switches::IsTextInputFocusManagerEnabled()) { 199 input_method->SetFocusedTextInputClient(text_input_client);
207 TextInputFocusManager::GetInstance()->FocusTextInputClient(
208 text_input_client);
209 } else {
210 input_method->SetFocusedTextInputClient(text_input_client);
211 }
212 } 200 }
213 201
214 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) { 202 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) {
215 DummyTextInputClient text_input_client_1st; 203 DummyTextInputClient text_input_client_1st;
216 DummyTextInputClient text_input_client_2nd; 204 DummyTextInputClient text_input_client_2nd;
217 205
218 ClientChangeVerifier verifier; 206 ClientChangeVerifier verifier;
219 MockInputMethodBase input_method(&verifier); 207 MockInputMethodBase input_method(&verifier);
220 MockInputMethodObserver input_method_observer(&verifier); 208 MockInputMethodObserver input_method_observer(&verifier);
221 InputMethodScopedObserver scoped_observer(&input_method_observer); 209 InputMethodScopedObserver scoped_observer(&input_method_observer);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 252
265 { 253 {
266 SCOPED_TRACE("Redundant focus events must be ignored"); 254 SCOPED_TRACE("Redundant focus events must be ignored");
267 verifier.ExpectClientDoesNotChange(); 255 verifier.ExpectClientDoesNotChange();
268 SetFocusedTextInputClient(&input_method, NULL); 256 SetFocusedTextInputClient(&input_method, NULL);
269 verifier.Verify(); 257 verifier.Verify();
270 } 258 }
271 } 259 }
272 260
273 TEST_F(InputMethodBaseTest, DetachTextInputClient) { 261 TEST_F(InputMethodBaseTest, DetachTextInputClient) {
274 // DetachTextInputClient is not supported when IsTextInputFocusManagerEnabled.
275 if (switches::IsTextInputFocusManagerEnabled())
276 return;
277
278 DummyTextInputClient text_input_client; 262 DummyTextInputClient text_input_client;
279 DummyTextInputClient text_input_client_the_other; 263 DummyTextInputClient text_input_client_the_other;
280 264
281 ClientChangeVerifier verifier; 265 ClientChangeVerifier verifier;
282 MockInputMethodBase input_method(&verifier); 266 MockInputMethodBase input_method(&verifier);
283 MockInputMethodObserver input_method_observer(&verifier); 267 MockInputMethodObserver input_method_observer(&verifier);
284 InputMethodScopedObserver scoped_observer(&input_method_observer); 268 InputMethodScopedObserver scoped_observer(&input_method_observer);
285 scoped_observer.Add(&input_method); 269 scoped_observer.Add(&input_method);
286 270
287 // Assume that the top-level-widget gains focus. 271 // Assume that the top-level-widget gains focus.
(...skipping 24 matching lines...) Expand all
312 input_method.OnFocus(); 296 input_method.OnFocus();
313 verifier.ExpectClientChange(&text_input_client, NULL); 297 verifier.ExpectClientChange(&text_input_client, NULL);
314 input_method.DetachTextInputClient(&text_input_client); 298 input_method.DetachTextInputClient(&text_input_client);
315 EXPECT_EQ(NULL, input_method.GetTextInputClient()); 299 EXPECT_EQ(NULL, input_method.GetTextInputClient());
316 verifier.Verify(); 300 verifier.Verify();
317 } 301 }
318 } 302 }
319 303
320 } // namespace 304 } // namespace
321 } // namespace ui 305 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698