| 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 |
| 345 |
| 338 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 346 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 339 const gfx::Rect& root_bounds = root_window()->bounds(); | 347 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 340 | 348 |
| 341 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 342 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 349 TestTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 343 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 350 TestTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 344 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 351 TestTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 345 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 352 TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 346 input_method->SetFocusedTextInputClient(&input_client_0); | |
| 347 | 353 |
| 348 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 354 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 349 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 355 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 350 new KeyboardContainerObserver(keyboard_container)); | 356 new KeyboardContainerObserver(keyboard_container)); |
| 351 keyboard_container->SetBounds(root_bounds); | 357 keyboard_container->SetBounds(root_bounds); |
| 352 root_window()->AddChild(keyboard_container); | 358 root_window()->AddChild(keyboard_container); |
| 353 | 359 |
| 360 SetFocus(&input_client_0); |
| 361 |
| 354 EXPECT_TRUE(keyboard_container->IsVisible()); | 362 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 355 | 363 |
| 356 // Lock keyboard. | 364 // Lock keyboard. |
| 357 controller()->set_lock_keyboard(true); | 365 controller()->set_lock_keyboard(true); |
| 358 | 366 |
| 359 input_method->SetFocusedTextInputClient(&no_input_client_0); | 367 SetFocus(&no_input_client_0); |
| 360 // Keyboard should not try to hide itself as it is locked. | 368 // Keyboard should not try to hide itself as it is locked. |
| 361 EXPECT_TRUE(keyboard_container->IsVisible()); | 369 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 362 EXPECT_FALSE(WillHideKeyboard()); | 370 EXPECT_FALSE(WillHideKeyboard()); |
| 363 | 371 |
| 364 input_method->SetFocusedTextInputClient(&input_client_1); | 372 SetFocus(&input_client_1); |
| 365 EXPECT_TRUE(keyboard_container->IsVisible()); | 373 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 366 | 374 |
| 367 // Unlock keyboard. | 375 // Unlock keyboard. |
| 368 controller()->set_lock_keyboard(false); | 376 controller()->set_lock_keyboard(false); |
| 369 | 377 |
| 370 // Keyboard should hide when focus on no input client. | 378 // Keyboard should hide when focus on no input client. |
| 371 input_method->SetFocusedTextInputClient(&no_input_client_1); | 379 SetFocus(&no_input_client_1); |
| 372 EXPECT_TRUE(WillHideKeyboard()); | 380 EXPECT_TRUE(WillHideKeyboard()); |
| 373 | 381 |
| 374 // Wait for hide keyboard to finish. | 382 // Wait for hide keyboard to finish. |
| 375 base::MessageLoop::current()->Run(); | 383 base::MessageLoop::current()->Run(); |
| 376 EXPECT_FALSE(keyboard_container->IsVisible()); | 384 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 377 } | 385 } |
| 378 | 386 |
| 379 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { | 387 TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) { |
| 380 aura::Window* keyboard_container = controller()->GetContainerWindow(); | 388 aura::Window* keyboard_container = controller()->GetContainerWindow(); |
| 381 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | 389 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 KeyboardControllerTest::SetUp(); | 423 KeyboardControllerTest::SetUp(); |
| 416 } | 424 } |
| 417 | 425 |
| 418 private: | 426 private: |
| 419 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); | 427 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerUsabilityTest); |
| 420 }; | 428 }; |
| 421 | 429 |
| 422 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { | 430 TEST_F(KeyboardControllerUsabilityTest, KeyboardAlwaysVisibleInUsabilityTest) { |
| 423 const gfx::Rect& root_bounds = root_window()->bounds(); | 431 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 424 | 432 |
| 425 ui::InputMethod* input_method = proxy()->GetInputMethod(); | |
| 426 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 433 TestTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 427 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 434 TestTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 428 input_method->SetFocusedTextInputClient(&input_client); | |
| 429 | 435 |
| 430 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 436 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 431 keyboard_container->SetBounds(root_bounds); | 437 keyboard_container->SetBounds(root_bounds); |
| 432 root_window()->AddChild(keyboard_container); | 438 root_window()->AddChild(keyboard_container); |
| 433 | 439 |
| 440 SetFocus(&input_client); |
| 434 EXPECT_TRUE(keyboard_container->IsVisible()); | 441 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 435 | 442 |
| 436 input_method->SetFocusedTextInputClient(&no_input_client); | 443 SetFocus(&no_input_client); |
| 437 // Keyboard should not hide itself after lost focus. | 444 // Keyboard should not hide itself after lost focus. |
| 438 EXPECT_TRUE(keyboard_container->IsVisible()); | 445 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 439 EXPECT_FALSE(WillHideKeyboard()); | 446 EXPECT_FALSE(WillHideKeyboard()); |
| 440 } | 447 } |
| 441 | 448 |
| 442 } // namespace keyboard | 449 } // namespace keyboard |
| OLD | NEW |