| OLD | NEW |
| 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" | |
| 17 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 18 | 16 |
| 19 namespace ui { | 17 namespace ui { |
| 20 namespace { | 18 namespace { |
| 21 | 19 |
| 22 class ClientChangeVerifier { | 20 class ClientChangeVerifier { |
| 23 public: | 21 public: |
| 24 ClientChangeVerifier() | 22 ClientChangeVerifier() |
| 25 : previous_client_(NULL), | 23 : previous_client_(NULL), |
| 26 next_client_(NULL), | 24 next_client_(NULL), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 47 previous_client_ = previous_client; | 45 previous_client_ = previous_client; |
| 48 next_client_ = next_client; | 46 next_client_ = next_client; |
| 49 call_expected_ = true; | 47 call_expected_ = true; |
| 50 on_will_change_focused_client_called_ = false; | 48 on_will_change_focused_client_called_ = false; |
| 51 on_did_change_focused_client_called_ = false; | 49 on_did_change_focused_client_called_ = false; |
| 52 on_text_input_state_changed_ = false; | 50 on_text_input_state_changed_ = false; |
| 53 } | 51 } |
| 54 | 52 |
| 55 // Verifies the result satisfies the expectation or not. | 53 // Verifies the result satisfies the expectation or not. |
| 56 void Verify() { | 54 void Verify() { |
| 57 if (switches::IsTextInputFocusManagerEnabled()) { | 55 EXPECT_EQ(call_expected_, on_will_change_focused_client_called_); |
| 58 EXPECT_FALSE(on_will_change_focused_client_called_); | 56 EXPECT_EQ(call_expected_, on_did_change_focused_client_called_); |
| 59 EXPECT_FALSE(on_did_change_focused_client_called_); | 57 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 } | 58 } |
| 67 | 59 |
| 68 void OnWillChangeFocusedClient(TextInputClient* focused_before, | 60 void OnWillChangeFocusedClient(TextInputClient* focused_before, |
| 69 TextInputClient* focused) { | 61 TextInputClient* focused) { |
| 70 EXPECT_TRUE(call_expected_); | 62 EXPECT_TRUE(call_expected_); |
| 71 | 63 |
| 72 // Check arguments | 64 // Check arguments |
| 73 EXPECT_EQ(previous_client_, focused_before); | 65 EXPECT_EQ(previous_client_, focused_before); |
| 74 EXPECT_EQ(next_client_, focused); | 66 EXPECT_EQ(next_client_, focused); |
| 75 | 67 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 188 |
| 197 ClientChangeVerifier* verifier_; | 189 ClientChangeVerifier* verifier_; |
| 198 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); | 190 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); |
| 199 }; | 191 }; |
| 200 | 192 |
| 201 typedef ScopedObserver<InputMethod, InputMethodObserver> | 193 typedef ScopedObserver<InputMethod, InputMethodObserver> |
| 202 InputMethodScopedObserver; | 194 InputMethodScopedObserver; |
| 203 | 195 |
| 204 void SetFocusedTextInputClient(InputMethod* input_method, | 196 void SetFocusedTextInputClient(InputMethod* input_method, |
| 205 TextInputClient* text_input_client) { | 197 TextInputClient* text_input_client) { |
| 206 if (switches::IsTextInputFocusManagerEnabled()) { | 198 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 } | 199 } |
| 213 | 200 |
| 214 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) { | 201 TEST_F(InputMethodBaseTest, SetFocusedTextInputClient) { |
| 215 DummyTextInputClient text_input_client_1st; | 202 DummyTextInputClient text_input_client_1st; |
| 216 DummyTextInputClient text_input_client_2nd; | 203 DummyTextInputClient text_input_client_2nd; |
| 217 | 204 |
| 218 ClientChangeVerifier verifier; | 205 ClientChangeVerifier verifier; |
| 219 MockInputMethodBase input_method(&verifier); | 206 MockInputMethodBase input_method(&verifier); |
| 220 MockInputMethodObserver input_method_observer(&verifier); | 207 MockInputMethodObserver input_method_observer(&verifier); |
| 221 InputMethodScopedObserver scoped_observer(&input_method_observer); | 208 InputMethodScopedObserver scoped_observer(&input_method_observer); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 251 |
| 265 { | 252 { |
| 266 SCOPED_TRACE("Redundant focus events must be ignored"); | 253 SCOPED_TRACE("Redundant focus events must be ignored"); |
| 267 verifier.ExpectClientDoesNotChange(); | 254 verifier.ExpectClientDoesNotChange(); |
| 268 SetFocusedTextInputClient(&input_method, NULL); | 255 SetFocusedTextInputClient(&input_method, NULL); |
| 269 verifier.Verify(); | 256 verifier.Verify(); |
| 270 } | 257 } |
| 271 } | 258 } |
| 272 | 259 |
| 273 TEST_F(InputMethodBaseTest, DetachTextInputClient) { | 260 TEST_F(InputMethodBaseTest, DetachTextInputClient) { |
| 274 // DetachTextInputClient is not supported when IsTextInputFocusManagerEnabled. | |
| 275 if (switches::IsTextInputFocusManagerEnabled()) | |
| 276 return; | |
| 277 | |
| 278 DummyTextInputClient text_input_client; | 261 DummyTextInputClient text_input_client; |
| 279 DummyTextInputClient text_input_client_the_other; | 262 DummyTextInputClient text_input_client_the_other; |
| 280 | 263 |
| 281 ClientChangeVerifier verifier; | 264 ClientChangeVerifier verifier; |
| 282 MockInputMethodBase input_method(&verifier); | 265 MockInputMethodBase input_method(&verifier); |
| 283 MockInputMethodObserver input_method_observer(&verifier); | 266 MockInputMethodObserver input_method_observer(&verifier); |
| 284 InputMethodScopedObserver scoped_observer(&input_method_observer); | 267 InputMethodScopedObserver scoped_observer(&input_method_observer); |
| 285 scoped_observer.Add(&input_method); | 268 scoped_observer.Add(&input_method); |
| 286 | 269 |
| 287 // Assume that the top-level-widget gains focus. | 270 // Assume that the top-level-widget gains focus. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 312 input_method.OnFocus(); | 295 input_method.OnFocus(); |
| 313 verifier.ExpectClientChange(&text_input_client, NULL); | 296 verifier.ExpectClientChange(&text_input_client, NULL); |
| 314 input_method.DetachTextInputClient(&text_input_client); | 297 input_method.DetachTextInputClient(&text_input_client); |
| 315 EXPECT_EQ(NULL, input_method.GetTextInputClient()); | 298 EXPECT_EQ(NULL, input_method.GetTextInputClient()); |
| 316 verifier.Verify(); | 299 verifier.Verify(); |
| 317 } | 300 } |
| 318 } | 301 } |
| 319 | 302 |
| 320 } // namespace | 303 } // namespace |
| 321 } // namespace ui | 304 } // namespace ui |
| OLD | NEW |