| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 focus_controller_.reset(); | 211 focus_controller_.reset(); |
| 212 aura_test_helper_->TearDown(); | 212 aura_test_helper_->TearDown(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 aura::Window* root_window() { return aura_test_helper_->root_window(); } | 215 aura::Window* root_window() { return aura_test_helper_->root_window(); } |
| 216 KeyboardControllerProxy* proxy() { return proxy_; } | 216 KeyboardControllerProxy* proxy() { return proxy_; } |
| 217 KeyboardController* controller() { return controller_.get(); } | 217 KeyboardController* controller() { return controller_.get(); } |
| 218 | 218 |
| 219 void ShowKeyboard() { | 219 void ShowKeyboard() { |
| 220 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); | 220 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 221 controller_->OnTextInputStateChanged(&test_text_input_client); | 221 SetFocus(&test_text_input_client); |
| 222 } | 222 } |
| 223 | 223 |
| 224 protected: | 224 protected: |
| 225 void SetFocus(ui::TextInputClient* client) { |
| 226 ui::InputMethod* input_method = proxy()->GetInputMethod(); |
| 227 input_method->SetFocusedTextInputClient(client); |
| 228 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) |
| 229 input_method->ShowImeIfNeeded(); |
| 230 } |
| 231 |
| 225 bool WillHideKeyboard() { | 232 bool WillHideKeyboard() { |
| 226 return controller_->WillHideKeyboard(); | 233 return controller_->WillHideKeyboard(); |
| 227 } | 234 } |
| 228 | 235 |
| 229 base::MessageLoopForUI message_loop_; | 236 base::MessageLoopForUI message_loop_; |
| 230 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 237 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 231 scoped_ptr<TestFocusController> focus_controller_; | 238 scoped_ptr<TestFocusController> focus_controller_; |
| 232 | 239 |
| 233 private: | 240 private: |
| 234 KeyboardControllerProxy* proxy_; | 241 KeyboardControllerProxy* proxy_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 339 |
| 333 location.set_y(keyboard_window->bounds().y() - 5); | 340 location.set_y(keyboard_window->bounds().y() - 5); |
| 334 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, | 341 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, |
| 335 ui::EF_NONE); | 342 ui::EF_NONE); |
| 336 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); | 343 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); |
| 337 } | 344 } |
| 338 | 345 |
| 339 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 346 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 340 const gfx::Rect& root_bounds = root_window()->bounds(); | 347 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 341 | 348 |
| 342 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 343 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 349 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 344 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 350 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 345 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 351 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 346 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 352 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 347 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 353 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 348 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 349 | 354 |
| 350 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 355 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 351 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 356 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 352 new KeyboardContainerObserver(keyboard_container)); | 357 new KeyboardContainerObserver(keyboard_container)); |
| 353 keyboard_container->SetBounds(root_bounds); | 358 keyboard_container->SetBounds(root_bounds); |
| 354 root_window()->AddChild(keyboard_container); | 359 root_window()->AddChild(keyboard_container); |
| 355 | 360 |
| 361 SetFocus(&input_client_0); |
| 362 |
| 356 EXPECT_TRUE(keyboard_container->IsVisible()); | 363 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 357 | 364 |
| 358 input_method->SetFocusedTextInputClient(&no_input_client_0); | 365 SetFocus(&no_input_client_0); |
| 359 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 366 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
| 360 // flicker when the focus of input field quickly change. | 367 // flicker when the focus of input field quickly change. |
| 361 EXPECT_TRUE(keyboard_container->IsVisible()); | 368 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 362 EXPECT_TRUE(WillHideKeyboard()); | 369 EXPECT_TRUE(WillHideKeyboard()); |
| 363 // Wait for hide keyboard to finish. | 370 // Wait for hide keyboard to finish. |
| 364 base::MessageLoop::current()->Run(); | 371 base::MessageLoop::current()->Run(); |
| 365 EXPECT_FALSE(keyboard_container->IsVisible()); | 372 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 366 | 373 |
| 367 input_method->SetFocusedTextInputClient(&input_client_1); | 374 SetFocus(&input_client_1); |
| 368 EXPECT_TRUE(keyboard_container->IsVisible()); | 375 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 369 | 376 |
| 370 // Schedule to hide keyboard. | 377 // Schedule to hide keyboard. |
| 371 input_method->SetFocusedTextInputClient(&no_input_client_1); | 378 SetFocus(&no_input_client_1); |
| 372 EXPECT_TRUE(WillHideKeyboard()); | 379 EXPECT_TRUE(WillHideKeyboard()); |
| 373 // Cancel keyboard hide. | 380 // Cancel keyboard hide. |
| 374 input_method->SetFocusedTextInputClient(&input_client_2); | 381 SetFocus(&input_client_2); |
| 375 | 382 |
| 376 EXPECT_FALSE(WillHideKeyboard()); | 383 EXPECT_FALSE(WillHideKeyboard()); |
| 377 EXPECT_TRUE(keyboard_container->IsVisible()); | 384 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 378 } | 385 } |
| 379 | 386 |
| 380 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 387 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 381 const gfx::Rect& root_bounds = root_window()->bounds(); | 388 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 382 | 389 |
| 383 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 384 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 390 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 385 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 391 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 386 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 392 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 387 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 393 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 388 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 389 | 394 |
| 390 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 395 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 391 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 396 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 392 new KeyboardContainerObserver(keyboard_container)); | 397 new KeyboardContainerObserver(keyboard_container)); |
| 393 keyboard_container->SetBounds(root_bounds); | 398 keyboard_container->SetBounds(root_bounds); |
| 394 root_window()->AddChild(keyboard_container); | 399 root_window()->AddChild(keyboard_container); |
| 395 | 400 |
| 401 SetFocus(&input_client_0); |
| 402 |
| 396 EXPECT_TRUE(keyboard_container->IsVisible()); | 403 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 397 | 404 |
| 398 // Lock keyboard. | 405 // Lock keyboard. |
| 399 controller()->set_lock_keyboard(true); | 406 controller()->set_lock_keyboard(true); |
| 400 | 407 |
| 401 input_method->SetFocusedTextInputClient(&no_input_client_0); | 408 SetFocus(&no_input_client_0); |
| 402 // Keyboard should not try to hide itself as it is locked. | 409 // Keyboard should not try to hide itself as it is locked. |
| 403 EXPECT_TRUE(keyboard_container->IsVisible()); | 410 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 404 EXPECT_FALSE(WillHideKeyboard()); | 411 EXPECT_FALSE(WillHideKeyboard()); |
| 405 | 412 |
| 406 input_method->SetFocusedTextInputClient(&input_client_1); | 413 SetFocus(&input_client_1); |
| 407 EXPECT_TRUE(keyboard_container->IsVisible()); | 414 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 408 | 415 |
| 409 // Unlock keyboard. | 416 // Unlock keyboard. |
| 410 controller()->set_lock_keyboard(false); | 417 controller()->set_lock_keyboard(false); |
| 411 | 418 |
| 412 // Keyboard should hide when focus on no input client. | 419 // Keyboard should hide when focus on no input client. |
| 413 input_method->SetFocusedTextInputClient(&no_input_client_1); | 420 SetFocus(&no_input_client_1); |
| 414 EXPECT_TRUE(WillHideKeyboard()); | 421 EXPECT_TRUE(WillHideKeyboard()); |
| 415 | 422 |
| 416 // Wait for hide keyboard to finish. | 423 // Wait for hide keyboard to finish. |
| 417 base::MessageLoop::current()->Run(); | 424 base::MessageLoop::current()->Run(); |
| 418 EXPECT_FALSE(keyboard_container->IsVisible()); | 425 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 419 } | 426 } |
| 420 | 427 |
| 421 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { | 428 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { |
| 422 aura::Window* keyboard_container = controller()->GetContainerWindow(); | 429 aura::Window* keyboard_container = controller()->GetContainerWindow(); |
| 423 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | 430 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 KeyboardControllerTest::SetUp(); | 464 KeyboardControllerTest::SetUp(); |
| 458 } | 465 } |
| 459 | 466 |
| 460 private: | 467 private: |
| 461 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); | 468 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); |
| 462 }; | 469 }; |
| 463 | 470 |
| 464 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { | 471 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { |
| 465 const gfx::Rect& root_bounds = root_window()->bounds(); | 472 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 466 | 473 |
| 467 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 468 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 474 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 469 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 475 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 470 input_method->SetFocusedTextInputClient(&input_client); | |
| 471 | 476 |
| 472 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 477 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 473 keyboard_container->SetBounds(root_bounds); | 478 keyboard_container->SetBounds(root_bounds); |
| 474 root_window()->AddChild(keyboard_container); | 479 root_window()->AddChild(keyboard_container); |
| 475 | 480 |
| 481 SetFocus(&input_client); |
| 476 EXPECT_TRUE(keyboard_container->IsVisible()); | 482 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 477 | 483 |
| 478 input_method->SetFocusedTextInputClient(&no_input_client); | 484 SetFocus(&no_input_client); |
| 479 // Keyboard should not hide itself after lost focus. | 485 // Keyboard should not hide itself after lost focus. |
| 480 EXPECT_TRUE(keyboard_container->IsVisible()); | 486 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 481 EXPECT_FALSE(WillHideKeyboard()); | 487 EXPECT_FALSE(WillHideKeyboard()); |
| 482 } | 488 } |
| 483 | 489 |
| 484 } // namespace keyboard | 490 } // namespace keyboard |
| OLD | NEW |