| 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 "ui/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" | 13 #include "base/test/scoped_task_environment.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/client/focus_client.h" | 15 #include "ui/aura/client/focus_client.h" |
| 16 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
| 17 #include "ui/aura/test/aura_test_helper.h" | 17 #include "ui/aura/test/aura_test_helper.h" |
| 18 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/base/ime/dummy_text_input_client.h" | 21 #include "ui/base/ime/dummy_text_input_client.h" |
| 22 #include "ui/base/ime/input_method.h" | 22 #include "ui/base/ime/input_method.h" |
| 23 #include "ui/base/ime/input_method_factory.h" | 23 #include "ui/base/ime/input_method_factory.h" |
| 24 #include "ui/base/ime/text_input_client.h" | 24 #include "ui/base/ime/text_input_client.h" |
| 25 #include "ui/base/ui_base_switches.h" |
| 25 #include "ui/compositor/compositor.h" | 26 #include "ui/compositor/compositor.h" |
| 26 #include "ui/compositor/layer_type.h" | 27 #include "ui/compositor/layer_type.h" |
| 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 28 #include "ui/compositor/test/context_factories_for_test.h" | 29 #include "ui/compositor/test/context_factories_for_test.h" |
| 29 #include "ui/compositor/test/layer_animator_test_controller.h" | 30 #include "ui/compositor/test/layer_animator_test_controller.h" |
| 30 #include "ui/events/event_utils.h" | 31 #include "ui/events/event_utils.h" |
| 31 #include "ui/events/test/event_generator.h" | 32 #include "ui/events/test/event_generator.h" |
| 32 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/keyboard/keyboard_controller_observer.h" | 34 #include "ui/keyboard/keyboard_controller_observer.h" |
| 34 #include "ui/keyboard/keyboard_ui.h" | 35 #include "ui/keyboard/keyboard_ui.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Overridden from keyboard::KeyboardLayoutDelegate | 202 // Overridden from keyboard::KeyboardLayoutDelegate |
| 202 void MoveKeyboardToDisplay(int64_t /* display_id */) override {} | 203 void MoveKeyboardToDisplay(int64_t /* display_id */) override {} |
| 203 void MoveKeyboardToTouchableDisplay() override {} | 204 void MoveKeyboardToTouchableDisplay() override {} |
| 204 | 205 |
| 205 private: | 206 private: |
| 206 DISALLOW_COPY_AND_ASSIGN(TestKeyboardLayoutDelegate); | 207 DISALLOW_COPY_AND_ASSIGN(TestKeyboardLayoutDelegate); |
| 207 }; | 208 }; |
| 208 | 209 |
| 209 } // namespace | 210 } // namespace |
| 210 | 211 |
| 211 class KeyboardControllerTest : public testing::Test, | 212 // Test parameter indicates if the new window behavior for the accessibility |
| 213 // keyboard should be used. |
| 214 class KeyboardControllerTest : public testing::TestWithParam<bool>, |
| 212 public KeyboardControllerObserver { | 215 public KeyboardControllerObserver { |
| 213 public: | 216 public: |
| 214 KeyboardControllerTest() | 217 KeyboardControllerTest() |
| 215 : scoped_task_environment_( | 218 : scoped_task_environment_( |
| 216 base::test::ScopedTaskEnvironment::MainThreadType::UI), | 219 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 217 number_of_calls_(0), | 220 number_of_calls_(0), |
| 218 ui_(nullptr), | 221 ui_(nullptr), |
| 219 keyboard_closed_(false) {} | 222 keyboard_closed_(false) {} |
| 220 ~KeyboardControllerTest() override {} | 223 ~KeyboardControllerTest() override {} |
| 221 | 224 |
| 222 void SetUp() override { | 225 void SetUp() override { |
| 223 // The ContextFactory must exist before any Compositors are created. | 226 // The ContextFactory must exist before any Compositors are created. |
| 224 bool enable_pixel_output = false; | 227 bool enable_pixel_output = false; |
| 225 ui::ContextFactory* context_factory = nullptr; | 228 ui::ContextFactory* context_factory = nullptr; |
| 226 ui::ContextFactoryPrivate* context_factory_private = nullptr; | 229 ui::ContextFactoryPrivate* context_factory_private = nullptr; |
| 227 | 230 |
| 228 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, | 231 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, |
| 229 &context_factory_private); | 232 &context_factory_private); |
| 230 | 233 |
| 231 ui::SetUpInputMethodFactoryForTesting(); | 234 ui::SetUpInputMethodFactoryForTesting(); |
| 232 aura_test_helper_.reset(new aura::test::AuraTestHelper()); | 235 aura_test_helper_.reset(new aura::test::AuraTestHelper()); |
| 233 aura_test_helper_->SetUp(context_factory, context_factory_private); | 236 aura_test_helper_->SetUp(context_factory, context_factory_private); |
| 234 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 237 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
| 235 focus_controller_.reset(new TestFocusController(root_window())); | 238 focus_controller_.reset(new TestFocusController(root_window())); |
| 236 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); | 239 ui_ = new TestKeyboardUI(aura_test_helper_->host()->GetInputMethod()); |
| 237 layout_delegate_.reset(new TestKeyboardLayoutDelegate()); | 240 layout_delegate_.reset(new TestKeyboardLayoutDelegate()); |
| 238 controller_.reset(new KeyboardController(ui_, layout_delegate_.get())); | 241 controller_.reset(new KeyboardController(ui_, layout_delegate_.get())); |
| 239 controller()->AddObserver(this); | 242 controller()->AddObserver(this); |
| 243 |
| 244 if (GetParam()) { |
| 245 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 246 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 247 } |
| 240 } | 248 } |
| 241 | 249 |
| 242 void TearDown() override { | 250 void TearDown() override { |
| 243 if (controller()) | 251 if (controller()) |
| 244 controller()->RemoveObserver(this); | 252 controller()->RemoveObserver(this); |
| 245 controller_.reset(); | 253 controller_.reset(); |
| 246 focus_controller_.reset(); | 254 focus_controller_.reset(); |
| 247 aura_test_helper_->TearDown(); | 255 aura_test_helper_->TearDown(); |
| 248 ui::TerminateContextFactoryForTests(); | 256 ui::TerminateContextFactoryForTests(); |
| 249 } | 257 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 int number_of_calls_; | 322 int number_of_calls_; |
| 315 gfx::Rect notified_bounds_; | 323 gfx::Rect notified_bounds_; |
| 316 KeyboardUI* ui_; | 324 KeyboardUI* ui_; |
| 317 std::unique_ptr<KeyboardLayoutDelegate> layout_delegate_; | 325 std::unique_ptr<KeyboardLayoutDelegate> layout_delegate_; |
| 318 std::unique_ptr<KeyboardController> controller_; | 326 std::unique_ptr<KeyboardController> controller_; |
| 319 std::unique_ptr<ui::TextInputClient> test_text_input_client_; | 327 std::unique_ptr<ui::TextInputClient> test_text_input_client_; |
| 320 bool keyboard_closed_; | 328 bool keyboard_closed_; |
| 321 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 329 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
| 322 }; | 330 }; |
| 323 | 331 |
| 324 TEST_F(KeyboardControllerTest, KeyboardSize) { | 332 // Run all KeyboardControllerTest with and without |
| 333 // "use-new-virtual-keyboard-behavior" flag. |
| 334 INSTANTIATE_TEST_CASE_P(NewAndOldBehavior, |
| 335 KeyboardControllerTest, |
| 336 testing::Bool()); |
| 337 |
| 338 TEST_P(KeyboardControllerTest, KeyboardSize) { |
| 325 aura::Window* container(controller()->GetContainerWindow()); | 339 aura::Window* container(controller()->GetContainerWindow()); |
| 326 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 340 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 327 gfx::Rect screen_bounds = root_window()->bounds(); | 341 gfx::Rect screen_bounds = root_window()->bounds(); |
| 328 root_window()->AddChild(container); | 342 root_window()->AddChild(container); |
| 329 container->AddChild(keyboard); | 343 container->AddChild(keyboard); |
| 330 const gfx::Rect& initial_bounds = container->bounds(); | 344 const gfx::Rect& initial_bounds = container->bounds(); |
| 331 // The container should be positioned at the bottom of screen and has 0 | 345 // The container should be positioned at the bottom of screen and has 0 |
| 332 // height. | 346 // height. |
| 333 ASSERT_EQ(0, initial_bounds.height()); | 347 ASSERT_EQ(0, initial_bounds.height()); |
| 334 ASSERT_EQ(screen_bounds.height(), initial_bounds.y()); | 348 ASSERT_EQ(screen_bounds.height(), initial_bounds.y()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 353 // The above call should resize keyboard to new width while keeping the old | 367 // The above call should resize keyboard to new width while keeping the old |
| 354 // height. | 368 // height. |
| 355 ASSERT_EQ(gfx::Rect(0, | 369 ASSERT_EQ(gfx::Rect(0, |
| 356 screen_bounds.width() - 50, | 370 screen_bounds.width() - 50, |
| 357 screen_bounds.height(), | 371 screen_bounds.height(), |
| 358 50), | 372 50), |
| 359 container->bounds()); | 373 container->bounds()); |
| 360 VerifyKeyboardWindowSize(container, keyboard); | 374 VerifyKeyboardWindowSize(container, keyboard); |
| 361 } | 375 } |
| 362 | 376 |
| 363 TEST_F(KeyboardControllerTest, KeyboardSizeMultiRootWindow) { | 377 TEST_P(KeyboardControllerTest, KeyboardSizeMultiRootWindow) { |
| 364 aura::Window* container(controller()->GetContainerWindow()); | 378 aura::Window* container(controller()->GetContainerWindow()); |
| 365 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 379 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 366 gfx::Rect screen_bounds = root_window()->bounds(); | 380 gfx::Rect screen_bounds = root_window()->bounds(); |
| 367 root_window()->AddChild(container); | 381 root_window()->AddChild(container); |
| 368 container->AddChild(keyboard); | 382 container->AddChild(keyboard); |
| 369 const gfx::Rect& initial_bounds = container->bounds(); | 383 const gfx::Rect& initial_bounds = container->bounds(); |
| 370 // The container should be positioned at the bottom of screen and has 0 | 384 // The container should be positioned at the bottom of screen and has 0 |
| 371 // height. | 385 // height. |
| 372 ASSERT_EQ(0, initial_bounds.height()); | 386 ASSERT_EQ(0, initial_bounds.height()); |
| 373 ASSERT_EQ(screen_bounds.height(), initial_bounds.y()); | 387 ASSERT_EQ(screen_bounds.height(), initial_bounds.y()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 385 controller()->HideKeyboard( | 399 controller()->HideKeyboard( |
| 386 KeyboardController::HideReason::HIDE_REASON_AUTOMATIC); | 400 KeyboardController::HideReason::HIDE_REASON_AUTOMATIC); |
| 387 root_window()->RemoveChild(container); | 401 root_window()->RemoveChild(container); |
| 388 secondary_tree_host->window()->AddChild(container); | 402 secondary_tree_host->window()->AddChild(container); |
| 389 | 403 |
| 390 const gfx::Rect& new_bounds = container->bounds(); | 404 const gfx::Rect& new_bounds = container->bounds(); |
| 391 EXPECT_EQ(500, new_bounds.y()); | 405 EXPECT_EQ(500, new_bounds.y()); |
| 392 VerifyKeyboardWindowSize(container, keyboard); | 406 VerifyKeyboardWindowSize(container, keyboard); |
| 393 } | 407 } |
| 394 | 408 |
| 395 TEST_F(KeyboardControllerTest, FloatingKeyboardSize) { | 409 TEST_P(KeyboardControllerTest, FloatingKeyboardSize) { |
| 396 aura::Window* container(controller()->GetContainerWindow()); | 410 aura::Window* container(controller()->GetContainerWindow()); |
| 397 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 411 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 398 root_window()->AddChild(container); | 412 root_window()->AddChild(container); |
| 399 controller()->SetKeyboardMode(FLOATING); | 413 controller()->SetKeyboardMode(FLOATING); |
| 400 container->AddChild(keyboard); | 414 container->AddChild(keyboard); |
| 401 gfx::Rect new_bounds(0, 50, 50, 50); | 415 gfx::Rect new_bounds(0, 50, 50, 50); |
| 402 keyboard->SetBounds(new_bounds); | 416 keyboard->SetBounds(new_bounds); |
| 403 ASSERT_EQ(new_bounds, container->bounds()); | 417 ASSERT_EQ(new_bounds, container->bounds()); |
| 404 VerifyKeyboardWindowSize(container, keyboard); | 418 VerifyKeyboardWindowSize(container, keyboard); |
| 405 } | 419 } |
| 406 | 420 |
| 407 // Tests that tapping/clicking inside the keyboard does not give it focus. | 421 // Tests that tapping/clicking inside the keyboard does not give it focus. |
| 408 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 422 TEST_P(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
| 409 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 423 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 410 const gfx::Rect& root_bounds = root_window()->bounds(); | 424 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 411 aura::test::EventCountDelegate delegate; | 425 aura::test::EventCountDelegate delegate; |
| 412 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); | 426 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 413 window->Init(ui::LAYER_NOT_DRAWN); | 427 window->Init(ui::LAYER_NOT_DRAWN); |
| 414 window->SetBounds(root_bounds); | 428 window->SetBounds(root_bounds); |
| 415 root_window()->AddChild(window.get()); | 429 root_window()->AddChild(window.get()); |
| 416 window->Show(); | 430 window->Show(); |
| 417 window->Focus(); | 431 window->Focus(); |
| 418 | 432 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 442 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); | 456 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 443 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); | 457 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); |
| 444 | 458 |
| 445 // Click outside of the keyboard. It should reach the window behind. | 459 // Click outside of the keyboard. It should reach the window behind. |
| 446 generator.MoveMouseTo(gfx::Point()); | 460 generator.MoveMouseTo(gfx::Point()); |
| 447 generator.ClickLeftButton(); | 461 generator.ClickLeftButton(); |
| 448 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 462 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 449 keyboard_container->RemovePreTargetHandler(&observer); | 463 keyboard_container->RemovePreTargetHandler(&observer); |
| 450 } | 464 } |
| 451 | 465 |
| 452 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 466 TEST_P(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 453 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 467 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 454 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 468 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 455 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 469 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 456 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 470 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 457 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 471 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 458 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 472 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 459 | 473 |
| 460 base::RunLoop run_loop; | 474 base::RunLoop run_loop; |
| 461 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 475 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 462 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 476 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 484 EXPECT_TRUE(WillHideKeyboard()); | 498 EXPECT_TRUE(WillHideKeyboard()); |
| 485 // Cancel keyboard hide. | 499 // Cancel keyboard hide. |
| 486 SetFocus(&input_client_2); | 500 SetFocus(&input_client_2); |
| 487 | 501 |
| 488 EXPECT_FALSE(WillHideKeyboard()); | 502 EXPECT_FALSE(WillHideKeyboard()); |
| 489 EXPECT_TRUE(keyboard_container->IsVisible()); | 503 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 490 } | 504 } |
| 491 | 505 |
| 492 // Test to prevent spurious overscroll boxes when changing tabs during keyboard | 506 // Test to prevent spurious overscroll boxes when changing tabs during keyboard |
| 493 // hide. Refer to crbug.com/401670 for more context. | 507 // hide. Refer to crbug.com/401670 for more context. |
| 494 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { | 508 TEST_P(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { |
| 495 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 509 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 496 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 510 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 497 | 511 |
| 498 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 512 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 499 root_window()->AddChild(keyboard_container); | 513 root_window()->AddChild(keyboard_container); |
| 500 | 514 |
| 501 // Enable touch keyboard / overscroll mode to test insets. | 515 // Enable touch keyboard / overscroll mode to test insets. |
| 502 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | 516 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 503 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 517 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
| 504 | 518 |
| 505 SetFocus(&input_client); | 519 SetFocus(&input_client); |
| 506 SetFocus(&no_input_client); | 520 SetFocus(&no_input_client); |
| 507 // Insets should not be enabled for new windows while keyboard is in the | 521 // Insets should not be enabled for new windows while keyboard is in the |
| 508 // process of hiding when overscroll is enabled. | 522 // process of hiding when overscroll is enabled. |
| 509 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 523 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 510 // Cancel keyboard hide. | 524 // Cancel keyboard hide. |
| 511 SetFocus(&input_client); | 525 SetFocus(&input_client); |
| 512 // Insets should be enabled for new windows as hide was cancelled. | 526 // Insets should be enabled for new windows as hide was cancelled. |
| 513 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 527 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 514 } | 528 } |
| 515 | 529 |
| 516 // Verify switch to FLOATING mode will reset the overscroll or resize and when | 530 // Verify switch to FLOATING mode will reset the overscroll or resize and when |
| 517 // in FLOATING mode, overscroll or resize wont be triggered. | 531 // in FLOATING mode, overscroll or resize wont be triggered. |
| 518 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { | 532 TEST_P(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { |
| 519 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 533 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 520 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 534 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 521 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 535 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 522 | 536 |
| 523 base::RunLoop run_loop; | 537 base::RunLoop run_loop; |
| 524 aura::Window* container(controller()->GetContainerWindow()); | 538 aura::Window* container(controller()->GetContainerWindow()); |
| 525 root_window()->AddChild(container); | 539 root_window()->AddChild(container); |
| 526 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 540 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 527 new KeyboardContainerObserver(container, &run_loop)); | 541 new KeyboardContainerObserver(container, &run_loop)); |
| 528 gfx::Rect screen_bounds = root_window()->bounds(); | 542 gfx::Rect screen_bounds = root_window()->bounds(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 545 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 559 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 546 EXPECT_EQ(3, number_of_calls()); | 560 EXPECT_EQ(3, number_of_calls()); |
| 547 SetFocus(&input_client); | 561 SetFocus(&input_client); |
| 548 // In FLOATING mode, no overscroll or resize should be triggered. | 562 // In FLOATING mode, no overscroll or resize should be triggered. |
| 549 EXPECT_EQ(3, number_of_calls()); | 563 EXPECT_EQ(3, number_of_calls()); |
| 550 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 564 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 551 } | 565 } |
| 552 | 566 |
| 553 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right | 567 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right |
| 554 // place and sets the correct overscroll. | 568 // place and sets the correct overscroll. |
| 555 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { | 569 TEST_P(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { |
| 556 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | 570 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 557 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 571 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 558 | 572 |
| 559 aura::Window* container(controller()->GetContainerWindow()); | 573 aura::Window* container(controller()->GetContainerWindow()); |
| 560 root_window()->AddChild(container); | 574 root_window()->AddChild(container); |
| 561 gfx::Rect screen_bounds = root_window()->bounds(); | 575 gfx::Rect screen_bounds = root_window()->bounds(); |
| 562 SetFocus(&input_client); | 576 SetFocus(&input_client); |
| 563 | 577 |
| 564 controller()->SetKeyboardMode(FLOATING); | 578 controller()->SetKeyboardMode(FLOATING); |
| 565 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 579 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 566 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 580 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 567 | 581 |
| 568 controller()->SetKeyboardMode(FULL_WIDTH); | 582 controller()->SetKeyboardMode(FULL_WIDTH); |
| 569 gfx::Rect expected_bounds( | 583 gfx::Rect expected_bounds( |
| 570 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 584 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 571 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 585 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 572 EXPECT_EQ(expected_bounds, notified_bounds()); | 586 EXPECT_EQ(expected_bounds, notified_bounds()); |
| 573 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); | 587 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); |
| 574 } | 588 } |
| 575 | 589 |
| 576 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 590 TEST_P(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 577 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 591 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 578 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 592 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 579 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 593 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 580 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 594 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 581 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 595 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 582 | 596 |
| 583 base::RunLoop run_loop; | 597 base::RunLoop run_loop; |
| 584 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 598 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 585 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 599 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 586 new KeyboardContainerObserver(keyboard_container, &run_loop)); | 600 new KeyboardContainerObserver(keyboard_container, &run_loop)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 607 // Keyboard should hide when focus on no input client. | 621 // Keyboard should hide when focus on no input client. |
| 608 SetFocus(&no_input_client_1); | 622 SetFocus(&no_input_client_1); |
| 609 EXPECT_TRUE(WillHideKeyboard()); | 623 EXPECT_TRUE(WillHideKeyboard()); |
| 610 | 624 |
| 611 // Wait for hide keyboard to finish. | 625 // Wait for hide keyboard to finish. |
| 612 run_loop.Run(); | 626 run_loop.Run(); |
| 613 EXPECT_FALSE(keyboard_container->IsVisible()); | 627 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 614 } | 628 } |
| 615 | 629 |
| 616 // Tests that deactivates keyboard will get closed event. | 630 // Tests that deactivates keyboard will get closed event. |
| 617 TEST_F(KeyboardControllerTest, CloseKeyboard) { | 631 TEST_P(KeyboardControllerTest, CloseKeyboard) { |
| 618 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 632 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 619 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 633 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 620 root_window()->AddChild(keyboard_container); | 634 root_window()->AddChild(keyboard_container); |
| 621 keyboard_container->Show(); | 635 keyboard_container->Show(); |
| 622 | 636 |
| 623 ShowKeyboard(); | 637 ShowKeyboard(); |
| 624 EXPECT_TRUE(keyboard_container->IsVisible()); | 638 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 625 EXPECT_FALSE(IsKeyboardClosed()); | 639 EXPECT_FALSE(IsKeyboardClosed()); |
| 626 | 640 |
| 627 root_window()->RemoveChild(keyboard_container); | 641 root_window()->RemoveChild(keyboard_container); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 656 } | 670 } |
| 657 | 671 |
| 658 aura::Window* keyboard_window() { | 672 aura::Window* keyboard_window() { |
| 659 return ui()->GetKeyboardWindow(); | 673 return ui()->GetKeyboardWindow(); |
| 660 } | 674 } |
| 661 | 675 |
| 662 private: | 676 private: |
| 663 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); | 677 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); |
| 664 }; | 678 }; |
| 665 | 679 |
| 680 // Run all KeyboardControllerAnimationTest with and without |
| 681 // "use-new-virtual-keyboard-behavior flag. |
| 682 INSTANTIATE_TEST_CASE_P(NewAndOldBehavior, |
| 683 KeyboardControllerAnimationTest, |
| 684 testing::Bool()); |
| 685 |
| 666 // Tests virtual keyboard has correct show and hide animation. | 686 // Tests virtual keyboard has correct show and hide animation. |
| 667 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { | 687 TEST_P(KeyboardControllerAnimationTest, ContainerAnimation) { |
| 668 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 688 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 669 ui::Layer* layer = keyboard_container()->layer(); | 689 ui::Layer* layer = keyboard_container()->layer(); |
| 670 ShowKeyboard(); | 690 ShowKeyboard(); |
| 671 | 691 |
| 672 // Keyboard container and window should immediately become visible before | 692 // Keyboard container and window should immediately become visible before |
| 673 // animation starts. | 693 // animation starts. |
| 674 EXPECT_TRUE(keyboard_container()->IsVisible()); | 694 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 675 EXPECT_TRUE(keyboard_window()->IsVisible()); | 695 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 676 float show_start_opacity = layer->opacity(); | 696 float show_start_opacity = layer->opacity(); |
| 677 gfx::Transform transform; | 697 gfx::Transform transform; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 705 EXPECT_FALSE(keyboard_window()->IsVisible()); | 725 EXPECT_FALSE(keyboard_window()->IsVisible()); |
| 706 float hide_end_opacity = layer->opacity(); | 726 float hide_end_opacity = layer->opacity(); |
| 707 EXPECT_GT(hide_start_opacity, hide_end_opacity); | 727 EXPECT_GT(hide_start_opacity, hide_end_opacity); |
| 708 EXPECT_EQ(transform, layer->transform()); | 728 EXPECT_EQ(transform, layer->transform()); |
| 709 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 729 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 710 } | 730 } |
| 711 | 731 |
| 712 // Show keyboard during keyboard hide animation should abort the hide animation | 732 // Show keyboard during keyboard hide animation should abort the hide animation |
| 713 // and the keyboard should animate in. | 733 // and the keyboard should animate in. |
| 714 // Test for crbug.com/333284. | 734 // Test for crbug.com/333284. |
| 715 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { | 735 TEST_P(KeyboardControllerAnimationTest, ContainerShowWhileHide) { |
| 716 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | 736 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 717 ui::Layer* layer = keyboard_container()->layer(); | 737 ui::Layer* layer = keyboard_container()->layer(); |
| 718 ShowKeyboard(); | 738 ShowKeyboard(); |
| 719 RunAnimationForLayer(layer); | 739 RunAnimationForLayer(layer); |
| 720 | 740 |
| 721 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); | 741 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); |
| 722 // Before hide animation finishes, show keyboard again. | 742 // Before hide animation finishes, show keyboard again. |
| 723 ShowKeyboard(); | 743 ShowKeyboard(); |
| 724 RunAnimationForLayer(layer); | 744 RunAnimationForLayer(layer); |
| 725 EXPECT_TRUE(keyboard_container()->IsVisible()); | 745 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 726 EXPECT_TRUE(keyboard_window()->IsVisible()); | 746 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 727 EXPECT_EQ(1.0, layer->opacity()); | 747 EXPECT_EQ(1.0, layer->opacity()); |
| 728 EXPECT_EQ(gfx::Transform(), layer->transform()); | 748 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 729 } | 749 } |
| 730 | 750 |
| 731 // Test for crbug.com/568274. | 751 // Test for crbug.com/568274. |
| 732 TEST_F(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { | 752 TEST_P(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { |
| 733 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | 753 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 734 aura::Window* container(controller()->GetContainerWindow()); | 754 aura::Window* container(controller()->GetContainerWindow()); |
| 735 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 755 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 736 root_window()->AddChild(container); | 756 root_window()->AddChild(container); |
| 737 | 757 |
| 738 controller()->SetKeyboardMode(FLOATING); | 758 controller()->SetKeyboardMode(FLOATING); |
| 739 container->AddChild(keyboard); | 759 container->AddChild(keyboard); |
| 740 // Mock focus on an input field. | 760 // Mock focus on an input field. |
| 741 ui()->GetInputMethod()->ShowImeIfNeeded(); | 761 ui()->GetInputMethod()->ShowImeIfNeeded(); |
| 742 // Mock set keyboard size from javascript side. In floating mode, virtual | 762 // Mock set keyboard size from javascript side. In floating mode, virtual |
| 743 // keyboard's size is decided by client. | 763 // keyboard's size is decided by client. |
| 744 gfx::Rect new_bounds(0, 50, 50, 50); | 764 gfx::Rect new_bounds(0, 50, 50, 50); |
| 745 keyboard->SetBounds(new_bounds); | 765 keyboard->SetBounds(new_bounds); |
| 746 ASSERT_EQ(new_bounds, container->bounds()); | 766 ASSERT_EQ(new_bounds, container->bounds()); |
| 747 EXPECT_TRUE(keyboard->IsVisible()); | 767 EXPECT_TRUE(keyboard->IsVisible()); |
| 748 EXPECT_TRUE(container->IsVisible()); | 768 EXPECT_TRUE(container->IsVisible()); |
| 749 } | 769 } |
| 750 | 770 |
| 751 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { | 771 TEST_P(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { |
| 752 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | 772 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 753 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 773 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 754 | 774 |
| 755 aura::Window* container(controller()->GetContainerWindow()); | 775 aura::Window* container(controller()->GetContainerWindow()); |
| 756 root_window()->AddChild(container); | 776 root_window()->AddChild(container); |
| 757 | 777 |
| 758 controller()->SetKeyboardMode(FULL_WIDTH); | 778 controller()->SetKeyboardMode(FULL_WIDTH); |
| 759 SetFocus(&input_client); | 779 SetFocus(&input_client); |
| 760 gfx::Rect new_bounds(0, 0, 1280, 800); | 780 gfx::Rect new_bounds(0, 0, 1280, 800); |
| 761 ASSERT_NE(new_bounds, root_window()->bounds()); | 781 ASSERT_NE(new_bounds, root_window()->bounds()); |
| 762 EXPECT_EQ(1, number_of_calls()); | 782 EXPECT_EQ(1, number_of_calls()); |
| 763 root_window()->SetBounds(new_bounds); | 783 root_window()->SetBounds(new_bounds); |
| 764 EXPECT_EQ(2, number_of_calls()); | 784 EXPECT_EQ(2, number_of_calls()); |
| 765 MockRotateScreen(); | 785 MockRotateScreen(); |
| 766 EXPECT_EQ(3, number_of_calls()); | 786 EXPECT_EQ(3, number_of_calls()); |
| 767 } | 787 } |
| 768 | 788 |
| 769 } // namespace keyboard | 789 } // namespace keyboard |
| OLD | NEW |