| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 focus_controller_.reset(); | 209 focus_controller_.reset(); |
| 210 aura_test_helper_->TearDown(); | 210 aura_test_helper_->TearDown(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 aura::Window* root_window() { return aura_test_helper_->root_window(); } | 213 aura::Window* root_window() { return aura_test_helper_->root_window(); } |
| 214 KeyboardControllerProxy* proxy() { return proxy_; } | 214 KeyboardControllerProxy* proxy() { return proxy_; } |
| 215 KeyboardController* controller() { return controller_.get(); } | 215 KeyboardController* controller() { return controller_.get(); } |
| 216 | 216 |
| 217 void ShowKeyboard() { | 217 void ShowKeyboard() { |
| 218 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); | 218 TestTextInputClient test_text_input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 219 controller_->OnTextInputStateChanged(&test_text_input_client); | 219 SetFocus(&test_text_input_client); |
| 220 } | 220 } |
| 221 | 221 |
| 222 protected: | 222 protected: |
| 223 void SetFocus(ui::TextInputClient* client) { |
| 224 ui::InputMethod* input_method = proxy()->GetInputMethod(); |
| 225 input_method->SetFocusedTextInputClient(client); |
| 226 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) |
| 227 input_method->ShowImeIfNeeded(); |
| 228 } |
| 229 |
| 223 bool WillHideKeyboard() { | 230 bool WillHideKeyboard() { |
| 224 return controller_->WillHideKeyboard(); | 231 return controller_->WillHideKeyboard(); |
| 225 } | 232 } |
| 226 | 233 |
| 227 base::MessageLoopForUI message_loop_; | 234 base::MessageLoopForUI message_loop_; |
| 228 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 235 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 229 scoped_ptr<TestFocusController> focus_controller_; | 236 scoped_ptr<TestFocusController> focus_controller_; |
| 230 | 237 |
| 231 private: | 238 private: |
| 232 KeyboardControllerProxy* proxy_; | 239 KeyboardControllerProxy* proxy_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 297 |
| 291 // Click outside of the keyboard. It should reach the window behind. | 298 // Click outside of the keyboard. It should reach the window behind. |
| 292 generator.MoveMouseTo(gfx::Point()); | 299 generator.MoveMouseTo(gfx::Point()); |
| 293 generator.ClickLeftButton(); | 300 generator.ClickLeftButton(); |
| 294 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 301 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 295 } | 302 } |
| 296 | 303 |
| 297 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 304 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 298 const gfx::Rect& root_bounds = root_window()->bounds(); | 305 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 299 | 306 |
| 300 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 301 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 307 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 302 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 308 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 303 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 309 TestTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 304 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 310 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 305 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 311 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 306 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 307 | 312 |
| 308 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 313 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 309 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 314 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 310 new KeyboardContainerObserver(keyboard_container)); | 315 new KeyboardContainerObserver(keyboard_container)); |
| 311 keyboard_container->SetBounds(root_bounds); | 316 keyboard_container->SetBounds(root_bounds); |
| 312 root_window()->AddChild(keyboard_container); | 317 root_window()->AddChild(keyboard_container); |
| 313 | 318 |
| 319 SetFocus(&input_client_0); |
| 320 |
| 314 EXPECT_TRUE(keyboard_container->IsVisible()); | 321 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 315 | 322 |
| 316 input_method->SetFocusedTextInputClient(&no_input_client_0); | 323 SetFocus(&no_input_client_0); |
| 317 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 324 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
| 318 // flicker when the focus of input field quickly change. | 325 // flicker when the focus of input field quickly change. |
| 319 EXPECT_TRUE(keyboard_container->IsVisible()); | 326 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 320 EXPECT_TRUE(WillHideKeyboard()); | 327 EXPECT_TRUE(WillHideKeyboard()); |
| 321 // Wait for hide keyboard to finish. | 328 // Wait for hide keyboard to finish. |
| 322 base::MessageLoop::current()->Run(); | 329 base::MessageLoop::current()->Run(); |
| 323 EXPECT_FALSE(keyboard_container->IsVisible()); | 330 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 324 | 331 |
| 325 input_method->SetFocusedTextInputClient(&input_client_1); | 332 SetFocus(&input_client_1); |
| 326 EXPECT_TRUE(keyboard_container->IsVisible()); | 333 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 327 | 334 |
| 328 // Schedule to hide keyboard. | 335 // Schedule to hide keyboard. |
| 329 input_method->SetFocusedTextInputClient(&no_input_client_1); | 336 SetFocus(&no_input_client_1); |
| 330 EXPECT_TRUE(WillHideKeyboard()); | 337 EXPECT_TRUE(WillHideKeyboard()); |
| 331 // Cancel keyboard hide. | 338 // Cancel keyboard hide. |
| 332 input_method->SetFocusedTextInputClient(&input_client_2); | 339 SetFocus(&input_client_2); |
| 333 | 340 |
| 334 EXPECT_FALSE(WillHideKeyboard()); | 341 EXPECT_FALSE(WillHideKeyboard()); |
| 335 EXPECT_TRUE(keyboard_container->IsVisible()); | 342 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 336 } | 343 } |
| 337 | 344 |
| 338 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 345 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 339 const gfx::Rect& root_bounds = root_window()->bounds(); | 346 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 340 | 347 |
| 341 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 342 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 348 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 343 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 349 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 344 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 350 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 345 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 351 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 346 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 347 | 352 |
| 348 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 353 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 349 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 354 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 350 new KeyboardContainerObserver(keyboard_container)); | 355 new KeyboardContainerObserver(keyboard_container)); |
| 351 keyboard_container->SetBounds(root_bounds); | 356 keyboard_container->SetBounds(root_bounds); |
| 352 root_window()->AddChild(keyboard_container); | 357 root_window()->AddChild(keyboard_container); |
| 353 | 358 |
| 359 SetFocus(&input_client_0); |
| 360 |
| 354 EXPECT_TRUE(keyboard_container->IsVisible()); | 361 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 355 | 362 |
| 356 // Lock keyboard. | 363 // Lock keyboard. |
| 357 controller()->set_lock_keyboard(true); | 364 controller()->set_lock_keyboard(true); |
| 358 | 365 |
| 359 input_method->SetFocusedTextInputClient(&no_input_client_0); | 366 SetFocus(&no_input_client_0); |
| 360 // Keyboard should not try to hide itself as it is locked. | 367 // Keyboard should not try to hide itself as it is locked. |
| 361 EXPECT_TRUE(keyboard_container->IsVisible()); | 368 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 362 EXPECT_FALSE(WillHideKeyboard()); | 369 EXPECT_FALSE(WillHideKeyboard()); |
| 363 | 370 |
| 364 input_method->SetFocusedTextInputClient(&input_client_1); | 371 SetFocus(&input_client_1); |
| 365 EXPECT_TRUE(keyboard_container->IsVisible()); | 372 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 366 | 373 |
| 367 // Unlock keyboard. | 374 // Unlock keyboard. |
| 368 controller()->set_lock_keyboard(false); | 375 controller()->set_lock_keyboard(false); |
| 369 | 376 |
| 370 // Keyboard should hide when focus on no input client. | 377 // Keyboard should hide when focus on no input client. |
| 371 input_method->SetFocusedTextInputClient(&no_input_client_1); | 378 SetFocus(&no_input_client_1); |
| 372 EXPECT_TRUE(WillHideKeyboard()); | 379 EXPECT_TRUE(WillHideKeyboard()); |
| 373 | 380 |
| 374 // Wait for hide keyboard to finish. | 381 // Wait for hide keyboard to finish. |
| 375 base::MessageLoop::current()->Run(); | 382 base::MessageLoop::current()->Run(); |
| 376 EXPECT_FALSE(keyboard_container->IsVisible()); | 383 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 377 } | 384 } |
| 378 | 385 |
| 379 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { | 386 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { |
| 380 aura::Window* keyboard_container = controller()->GetContainerWindow(); | 387 aura::Window* keyboard_container = controller()->GetContainerWindow(); |
| 381 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | 388 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 KeyboardControllerTest::SetUp(); | 422 KeyboardControllerTest::SetUp(); |
| 416 } | 423 } |
| 417 | 424 |
| 418 private: | 425 private: |
| 419 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); | 426 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); |
| 420 }; | 427 }; |
| 421 | 428 |
| 422 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { | 429 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { |
| 423 const gfx::Rect& root_bounds = root_window()->bounds(); | 430 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 424 | 431 |
| 425 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 426 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 432 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 427 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 433 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 428 input_method->SetFocusedTextInputClient(&input_client); | |
| 429 | 434 |
| 430 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 435 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 431 keyboard_container->SetBounds(root_bounds); | 436 keyboard_container->SetBounds(root_bounds); |
| 432 root_window()->AddChild(keyboard_container); | 437 root_window()->AddChild(keyboard_container); |
| 433 | 438 |
| 439 SetFocus(&input_client); |
| 434 EXPECT_TRUE(keyboard_container->IsVisible()); | 440 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 435 | 441 |
| 436 input_method->SetFocusedTextInputClient(&no_input_client); | 442 SetFocus(&no_input_client); |
| 437 // Keyboard should not hide itself after lost focus. | 443 // Keyboard should not hide itself after lost focus. |
| 438 EXPECT_TRUE(keyboard_container->IsVisible()); | 444 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 439 EXPECT_FALSE(WillHideKeyboard()); | 445 EXPECT_FALSE(WillHideKeyboard()); |
| 440 } | 446 } |
| 441 | 447 |
| 442 } // namespace keyboard | 448 } // namespace keyboard |
| OLD | NEW |