Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/aura/client/focus_client.h" | 10 #include "ui/aura/client/focus_client.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); | 189 DISALLOW_COPY_AND_ASSIGN(KeyboardContainerObserver); |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 class KeyboardControllerTest : public testing::Test { | 194 class KeyboardControllerTest : public testing::Test { |
| 195 public: | 195 public: |
| 196 KeyboardControllerTest() {} | 196 KeyboardControllerTest() {} |
| 197 virtual ~KeyboardControllerTest() {} | 197 virtual ~KeyboardControllerTest() {} |
| 198 | 198 |
| 199 static void SetUpForTesting() { | |
| 200 static bool initialized = false; | |
| 201 if (!initialized) { | |
| 202 ui::SetUpInputMethodFactoryForTesting(); | |
|
Seigo Nonaka
2014/01/09 06:08:43
I think this function can be called multiple times
kevers
2014/01/09 15:29:09
This change is to address 331690.
Actually would
| |
| 203 initialized = true; | |
| 204 } | |
| 205 } | |
| 206 | |
| 199 virtual void SetUp() OVERRIDE { | 207 virtual void SetUp() OVERRIDE { |
| 200 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 208 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
| 201 aura_test_helper_->SetUp(); | 209 aura_test_helper_->SetUp(); |
| 202 ui::SetUpInputMethodFactoryForTesting(); | 210 SetUpForTesting(); |
| 203 focus_controller_.reset(new TestFocusController(root_window())); | 211 focus_controller_.reset(new TestFocusController(root_window())); |
| 204 proxy_ = new TestKeyboardControllerProxy(); | 212 proxy_ = new TestKeyboardControllerProxy(); |
| 205 controller_.reset(new KeyboardController(proxy_)); | 213 controller_.reset(new KeyboardController(proxy_)); |
| 206 } | 214 } |
| 207 | 215 |
| 208 virtual void TearDown() OVERRIDE { | 216 virtual void TearDown() OVERRIDE { |
| 209 focus_controller_.reset(); | 217 focus_controller_.reset(); |
| 210 aura_test_helper_->TearDown(); | 218 aura_test_helper_->TearDown(); |
| 211 } | 219 } |
| 212 | 220 |
| 213 aura::Window* root_window() { return aura_test_helper_->root_window(); } | 221 aura::Window* root_window() { return aura_test_helper_->root_window(); } |
| 214 KeyboardControllerProxy* proxy() { return proxy_; } | 222 KeyboardControllerProxy* proxy() { return proxy_; } |
| 215 KeyboardController* controller() { return controller_.get(); } | 223 KeyboardController* controller() { return controller_.get(); } |
| 216 | 224 |
| 217 void ShowKeyboard() { | 225 void ShowKeyboard() { |
| 218 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); | 226 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 219 controller_->OnTextInputStateChanged(&test_text_input_client); | 227 SetFocus(&test_text_input_client); |
| 220 } | 228 } |
| 221 | 229 |
| 222 protected: | 230 protected: |
| 231 void SetFocus(ui::TextInputClient* client) { | |
| 232 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 233 input_method->SetFocusedTextInputClient(client); | |
| 234 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) | |
| 235 input_method->ShowImeIfNeeded(); | |
| 236 } | |
| 237 | |
| 223 bool WillHideKeyboard() { | 238 bool WillHideKeyboard() { |
| 224 return controller_->WillHideKeyboard(); | 239 return controller_->WillHideKeyboard(); |
| 225 } | 240 } |
| 226 | 241 |
| 227 base::MessageLoopForUI message_loop_; | 242 base::MessageLoopForUI message_loop_; |
| 228 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 243 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 229 scoped_ptr<TestFocusController> focus_controller_; | 244 scoped_ptr<TestFocusController> focus_controller_; |
| 230 | 245 |
| 231 private: | 246 private: |
| 232 KeyboardControllerProxy* proxy_; | 247 KeyboardControllerProxy* proxy_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 305 |
| 291 // Click outside of the keyboard. It should reach the window behind. | 306 // Click outside of the keyboard. It should reach the window behind. |
| 292 generator.MoveMouseTo(gfx::Point()); | 307 generator.MoveMouseTo(gfx::Point()); |
| 293 generator.ClickLeftButton(); | 308 generator.ClickLeftButton(); |
| 294 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 309 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 295 } | 310 } |
| 296 | 311 |
| 297 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 312 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 298 const gfx::Rect& root_bounds = root_window()->bounds(); | 313 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 299 | 314 |
| 300 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 301 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 315 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 302 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 316 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 303 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 317 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 304 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 318 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 305 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 319 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 306 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 307 | 320 |
| 308 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 321 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 309 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 322 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 310 new KeyboardContainerObserver(keyboard_container)); | 323 new KeyboardContainerObserver(keyboard_container)); |
| 311 keyboard_container->SetBounds(root_bounds); | 324 keyboard_container->SetBounds(root_bounds); |
| 312 root_window()->AddChild(keyboard_container); | 325 root_window()->AddChild(keyboard_container); |
| 313 | 326 |
| 327 SetFocus(&input_client_0); | |
| 328 | |
| 314 EXPECT_TRUE(keyboard_container->IsVisible()); | 329 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 315 | 330 |
| 316 input_method->SetFocusedTextInputClient(&no_input_client_0); | 331 SetFocus(&no_input_client_0); |
| 317 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 332 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
| 318 // flicker when the focus of input field quickly change. | 333 // flicker when the focus of input field quickly change. |
| 319 EXPECT_TRUE(keyboard_container->IsVisible()); | 334 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 320 EXPECT_TRUE(WillHideKeyboard()); | 335 EXPECT_TRUE(WillHideKeyboard()); |
| 321 // Wait for hide keyboard to finish. | 336 // Wait for hide keyboard to finish. |
| 322 base::MessageLoop::current()->Run(); | 337 base::MessageLoop::current()->Run(); |
| 323 EXPECT_FALSE(keyboard_container->IsVisible()); | 338 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 324 | 339 |
| 325 input_method->SetFocusedTextInputClient(&input_client_1); | 340 SetFocus(&input_client_1); |
| 326 EXPECT_TRUE(keyboard_container->IsVisible()); | 341 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 327 | 342 |
| 328 // Schedule to hide keyboard. | 343 // Schedule to hide keyboard. |
| 329 input_method->SetFocusedTextInputClient(&no_input_client_1); | 344 SetFocus(&no_input_client_1); |
| 330 EXPECT_TRUE(WillHideKeyboard()); | 345 EXPECT_TRUE(WillHideKeyboard()); |
| 331 // Cancel keyboard hide. | 346 // Cancel keyboard hide. |
| 332 input_method->SetFocusedTextInputClient(&input_client_2); | 347 SetFocus(&input_client_2); |
| 333 | 348 |
| 334 EXPECT_FALSE(WillHideKeyboard()); | 349 EXPECT_FALSE(WillHideKeyboard()); |
| 335 EXPECT_TRUE(keyboard_container->IsVisible()); | 350 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 336 } | 351 } |
| 337 | 352 |
| 353 | |
| 338 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 354 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 339 const gfx::Rect& root_bounds = root_window()->bounds(); | 355 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 340 | 356 |
| 341 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 342 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 357 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 343 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 358 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 344 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 359 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 345 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 360 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 346 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 347 | 361 |
| 348 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 362 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 349 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 363 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 350 new KeyboardContainerObserver(keyboard_container)); | 364 new KeyboardContainerObserver(keyboard_container)); |
| 351 keyboard_container->SetBounds(root_bounds); | 365 keyboard_container->SetBounds(root_bounds); |
| 352 root_window()->AddChild(keyboard_container); | 366 root_window()->AddChild(keyboard_container); |
| 353 | 367 |
| 368 SetFocus(&input_client_0); | |
| 369 | |
| 354 EXPECT_TRUE(keyboard_container->IsVisible()); | 370 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 355 | 371 |
| 356 // Lock keyboard. | 372 // Lock keyboard. |
| 357 controller()->set_lock_keyboard(true); | 373 controller()->set_lock_keyboard(true); |
| 358 | 374 |
| 359 input_method->SetFocusedTextInputClient(&no_input_client_0); | 375 SetFocus(&no_input_client_0); |
| 360 // Keyboard should not try to hide itself as it is locked. | 376 // Keyboard should not try to hide itself as it is locked. |
| 361 EXPECT_TRUE(keyboard_container->IsVisible()); | 377 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 362 EXPECT_FALSE(WillHideKeyboard()); | 378 EXPECT_FALSE(WillHideKeyboard()); |
| 363 | 379 |
| 364 input_method->SetFocusedTextInputClient(&input_client_1); | 380 SetFocus(&input_client_1); |
| 365 EXPECT_TRUE(keyboard_container->IsVisible()); | 381 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 366 | 382 |
| 367 // Unlock keyboard. | 383 // Unlock keyboard. |
| 368 controller()->set_lock_keyboard(false); | 384 controller()->set_lock_keyboard(false); |
| 369 | 385 |
| 370 // Keyboard should hide when focus on no input client. | 386 // Keyboard should hide when focus on no input client. |
| 371 input_method->SetFocusedTextInputClient(&no_input_client_1); | 387 SetFocus(&no_input_client_1); |
| 372 EXPECT_TRUE(WillHideKeyboard()); | 388 EXPECT_TRUE(WillHideKeyboard()); |
| 373 | 389 |
| 374 // Wait for hide keyboard to finish. | 390 // Wait for hide keyboard to finish. |
| 375 base::MessageLoop::current()->Run(); | 391 base::MessageLoop::current()->Run(); |
| 376 EXPECT_FALSE(keyboard_container->IsVisible()); | 392 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 377 } | 393 } |
| 378 | 394 |
| 379 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { | 395 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { |
| 380 aura::Window* keyboard_container = controller()->GetContainerWindow(); | 396 aura::Window* keyboard_container = controller()->GetContainerWindow(); |
| 381 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | 397 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 KeyboardControllerTest::SetUp(); | 431 KeyboardControllerTest::SetUp(); |
| 416 } | 432 } |
| 417 | 433 |
| 418 private: | 434 private: |
| 419 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); | 435 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); |
| 420 }; | 436 }; |
| 421 | 437 |
| 422 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { | 438 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { |
| 423 const gfx::Rect& root_bounds = root_window()->bounds(); | 439 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 424 | 440 |
| 425 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 426 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 441 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 427 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 442 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 428 input_method->SetFocusedTextInputClient(&input_client); | |
| 429 | 443 |
| 430 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 444 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 431 keyboard_container->SetBounds(root_bounds); | 445 keyboard_container->SetBounds(root_bounds); |
| 432 root_window()->AddChild(keyboard_container); | 446 root_window()->AddChild(keyboard_container); |
| 433 | 447 |
| 448 SetFocus(&input_client); | |
| 434 EXPECT_TRUE(keyboard_container->IsVisible()); | 449 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 435 | 450 |
| 436 input_method->SetFocusedTextInputClient(&no_input_client); | 451 SetFocus(&no_input_client); |
| 437 // Keyboard should not hide itself after lost focus. | 452 // Keyboard should not hide itself after lost focus. |
| 438 EXPECT_TRUE(keyboard_container->IsVisible()); | 453 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 439 EXPECT_FALSE(WillHideKeyboard()); | 454 EXPECT_FALSE(WillHideKeyboard()); |
| 440 } | 455 } |
| 441 | 456 |
| 442 } // namespace keyboard | 457 } // namespace keyboard |
| OLD | NEW |