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 "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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 // Multiple steps are required to complete complex animations. | 57 // Multiple steps are required to complete complex animations. |
| 58 // TODO(vollick): This should not be necessary. crbug.com/154017 | 58 // TODO(vollick): This should not be necessary. crbug.com/154017 |
| 59 while (controller.animator()->is_animating()) { | 59 while (controller.animator()->is_animating()) { |
| 60 controller.StartThreadedAnimationsIfNeeded(); | 60 controller.StartThreadedAnimationsIfNeeded(); |
| 61 base::TimeTicks step_time = controller.animator()->last_step_time(); | 61 base::TimeTicks step_time = controller.animator()->last_step_time(); |
| 62 controller.animator()->Step(step_time + | 62 controller.animator()->Step(step_time + |
| 63 base::TimeDelta::FromMilliseconds(1000)); | 63 base::TimeDelta::FromMilliseconds(1000)); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 class ScopedTouchKeyboardEnabler { | |
| 68 public: | |
| 69 ScopedTouchKeyboardEnabler() : enabled_(keyboard::GetTouchKeyboardEnabled()) { | |
| 70 keyboard::SetTouchKeyboardEnabled(true); | |
| 71 } | |
| 72 | |
| 73 ~ScopedTouchKeyboardEnabler() { keyboard::SetTouchKeyboardEnabled(enabled_); } | |
| 74 | |
| 75 private: | |
| 76 const bool enabled_; | |
| 77 }; | |
| 78 | |
| 79 class ScopedAccessibilityKeyboardEnabler { | |
| 80 public: | |
| 81 ScopedAccessibilityKeyboardEnabler() | |
| 82 : enabled_(keyboard::GetAccessibilityKeyboardEnabled()) { | |
| 83 keyboard::SetAccessibilityKeyboardEnabled(true); | |
| 84 } | |
| 85 | |
| 86 ~ScopedAccessibilityKeyboardEnabler() { | |
| 87 keyboard::SetAccessibilityKeyboardEnabled(enabled_); | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 const bool enabled_; | |
| 92 }; | |
| 93 | |
| 67 // An event handler that focuses a window when it is clicked/touched on. This is | 94 // An event handler that focuses a window when it is clicked/touched on. This is |
| 68 // used to match the focus manger behaviour in ash and views. | 95 // used to match the focus manger behaviour in ash and views. |
| 69 class TestFocusController : public ui::EventHandler { | 96 class TestFocusController : public ui::EventHandler { |
| 70 public: | 97 public: |
| 71 explicit TestFocusController(aura::Window* root) | 98 explicit TestFocusController(aura::Window* root) |
| 72 : root_(root) { | 99 : root_(root) { |
| 73 root_->AddPreTargetHandler(this); | 100 root_->AddPreTargetHandler(this); |
| 74 } | 101 } |
| 75 | 102 |
| 76 ~TestFocusController() override { root_->RemovePreTargetHandler(this); } | 103 ~TestFocusController() override { root_->RemovePreTargetHandler(this); } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 controller()->SetKeyboardMode(FLOATING); | 395 controller()->SetKeyboardMode(FLOATING); |
| 369 container->AddChild(keyboard); | 396 container->AddChild(keyboard); |
| 370 gfx::Rect new_bounds(0, 50, 50, 50); | 397 gfx::Rect new_bounds(0, 50, 50, 50); |
| 371 keyboard->SetBounds(new_bounds); | 398 keyboard->SetBounds(new_bounds); |
| 372 ASSERT_EQ(new_bounds, container->bounds()); | 399 ASSERT_EQ(new_bounds, container->bounds()); |
| 373 VerifyKeyboardWindowSize(container, keyboard); | 400 VerifyKeyboardWindowSize(container, keyboard); |
| 374 } | 401 } |
| 375 | 402 |
| 376 // Tests that tapping/clicking inside the keyboard does not give it focus. | 403 // Tests that tapping/clicking inside the keyboard does not give it focus. |
| 377 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 404 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
| 378 keyboard::SetAccessibilityKeyboardEnabled(true); | 405 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 379 const gfx::Rect& root_bounds = root_window()->bounds(); | 406 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 380 aura::test::EventCountDelegate delegate; | 407 aura::test::EventCountDelegate delegate; |
| 381 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); | 408 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 382 window->Init(ui::LAYER_NOT_DRAWN); | 409 window->Init(ui::LAYER_NOT_DRAWN); |
| 383 window->SetBounds(root_bounds); | 410 window->SetBounds(root_bounds); |
| 384 root_window()->AddChild(window.get()); | 411 root_window()->AddChild(window.get()); |
| 385 window->Show(); | 412 window->Show(); |
| 386 window->Focus(); | 413 window->Focus(); |
| 387 | 414 |
| 388 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 415 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 409 EXPECT_FALSE(keyboard_container->HasFocus()); | 436 EXPECT_FALSE(keyboard_container->HasFocus()); |
| 410 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); | 437 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); |
| 411 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); | 438 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 412 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); | 439 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); |
| 413 | 440 |
| 414 // Click outside of the keyboard. It should reach the window behind. | 441 // Click outside of the keyboard. It should reach the window behind. |
| 415 generator.MoveMouseTo(gfx::Point()); | 442 generator.MoveMouseTo(gfx::Point()); |
| 416 generator.ClickLeftButton(); | 443 generator.ClickLeftButton(); |
| 417 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 444 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 418 keyboard_container->RemovePreTargetHandler(&observer); | 445 keyboard_container->RemovePreTargetHandler(&observer); |
| 419 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 420 } | 446 } |
| 421 | 447 |
| 422 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 448 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 423 keyboard::SetAccessibilityKeyboardEnabled(true); | 449 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 424 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 450 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 425 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 451 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 426 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 452 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 427 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 453 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 428 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 454 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 429 | 455 |
| 430 base::RunLoop run_loop; | 456 base::RunLoop run_loop; |
| 431 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 457 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 432 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 458 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 433 new KeyboardContainerObserver(keyboard_container, &run_loop)); | 459 new KeyboardContainerObserver(keyboard_container, &run_loop)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 450 EXPECT_TRUE(keyboard_container->IsVisible()); | 476 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 451 | 477 |
| 452 // Schedule to hide keyboard. | 478 // Schedule to hide keyboard. |
| 453 SetFocus(&no_input_client_1); | 479 SetFocus(&no_input_client_1); |
| 454 EXPECT_TRUE(WillHideKeyboard()); | 480 EXPECT_TRUE(WillHideKeyboard()); |
| 455 // Cancel keyboard hide. | 481 // Cancel keyboard hide. |
| 456 SetFocus(&input_client_2); | 482 SetFocus(&input_client_2); |
| 457 | 483 |
| 458 EXPECT_FALSE(WillHideKeyboard()); | 484 EXPECT_FALSE(WillHideKeyboard()); |
| 459 EXPECT_TRUE(keyboard_container->IsVisible()); | 485 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 460 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 461 } | 486 } |
| 462 | 487 |
| 463 // Test to prevent spurious overscroll boxes when changing tabs during keyboard | 488 // Test to prevent spurious overscroll boxes when changing tabs during keyboard |
| 464 // hide. Refer to crbug.com/401670 for more context. | 489 // hide. Refer to crbug.com/401670 for more context. |
| 465 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { | 490 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { |
| 466 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 491 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 467 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 492 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 468 | 493 |
| 469 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 494 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 470 root_window()->AddChild(keyboard_container); | 495 root_window()->AddChild(keyboard_container); |
| 471 | 496 |
| 472 // Enable touch keyboard / overscroll mode to test insets. | 497 // Enable touch keyboard / overscroll mode to test insets. |
| 473 keyboard::SetTouchKeyboardEnabled(true); | 498 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 474 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 499 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
| 475 | 500 |
| 476 SetFocus(&input_client); | 501 SetFocus(&input_client); |
| 477 SetFocus(&no_input_client); | 502 SetFocus(&no_input_client); |
| 478 // Insets should not be enabled for new windows while keyboard is in the | 503 // Insets should not be enabled for new windows while keyboard is in the |
| 479 // process of hiding when overscroll is enabled. | 504 // process of hiding when overscroll is enabled. |
| 480 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 505 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 481 // Cancel keyboard hide. | 506 // Cancel keyboard hide. |
| 482 SetFocus(&input_client); | 507 SetFocus(&input_client); |
| 483 // Insets should be enabled for new windows as hide was cancelled. | 508 // Insets should be enabled for new windows as hide was cancelled. |
| 484 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 509 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 485 } | 510 } |
| 486 | 511 |
| 487 // Verify switch to FLOATING mode will reset the overscroll or resize and when | 512 // Verify switch to FLOATING mode will reset the overscroll or resize and when |
| 488 // in FLOATING mode, overscroll or resize wont be triggered. | 513 // in FLOATING mode, overscroll or resize wont be triggered. |
| 489 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { | 514 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { |
| 490 keyboard::SetAccessibilityKeyboardEnabled(true); | 515 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 491 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 516 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 492 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 517 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 493 | 518 |
| 494 base::RunLoop run_loop; | 519 base::RunLoop run_loop; |
| 495 aura::Window* container(controller()->GetContainerWindow()); | 520 aura::Window* container(controller()->GetContainerWindow()); |
| 496 root_window()->AddChild(container); | 521 root_window()->AddChild(container); |
| 497 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 522 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 498 new KeyboardContainerObserver(container, &run_loop)); | 523 new KeyboardContainerObserver(container, &run_loop)); |
| 499 gfx::Rect screen_bounds = root_window()->bounds(); | 524 gfx::Rect screen_bounds = root_window()->bounds(); |
|
bshe
2017/01/18 20:52:33
ScopedTouchKeyboardEnabler scoped_keyboard_enabler
yhanada
2017/01/18 23:16:02
Done.
| |
| 500 keyboard::SetTouchKeyboardEnabled(true); | |
| 501 | 525 |
| 502 SetFocus(&input_client); | 526 SetFocus(&input_client); |
| 503 gfx::Rect expected_bounds( | 527 gfx::Rect expected_bounds( |
| 504 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 528 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 505 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 529 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 506 // Verify overscroll or resize is in effect. | 530 // Verify overscroll or resize is in effect. |
| 507 EXPECT_EQ(expected_bounds, notified_bounds()); | 531 EXPECT_EQ(expected_bounds, notified_bounds()); |
| 508 EXPECT_EQ(1, number_of_calls()); | 532 EXPECT_EQ(1, number_of_calls()); |
| 509 | 533 |
| 510 controller()->SetKeyboardMode(FLOATING); | 534 controller()->SetKeyboardMode(FLOATING); |
| 511 // Switch to FLOATING should clear overscroll or resize. | 535 // Switch to FLOATING should clear overscroll or resize. |
| 512 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 536 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 513 EXPECT_EQ(2, number_of_calls()); | 537 EXPECT_EQ(2, number_of_calls()); |
| 514 SetFocus(&no_input_client); | 538 SetFocus(&no_input_client); |
| 515 run_loop.Run(); | 539 run_loop.Run(); |
| 516 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 540 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 517 EXPECT_EQ(3, number_of_calls()); | 541 EXPECT_EQ(3, number_of_calls()); |
| 518 SetFocus(&input_client); | 542 SetFocus(&input_client); |
| 519 // In FLOATING mode, no overscroll or resize should be triggered. | 543 // In FLOATING mode, no overscroll or resize should be triggered. |
| 520 EXPECT_EQ(3, number_of_calls()); | 544 EXPECT_EQ(3, number_of_calls()); |
| 521 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 545 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 522 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 523 } | 546 } |
| 524 | 547 |
| 525 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right | 548 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right |
| 526 // place and sets the correct overscroll. | 549 // place and sets the correct overscroll. |
| 527 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { | 550 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { |
| 551 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | |
| 528 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 552 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 529 | 553 |
| 530 aura::Window* container(controller()->GetContainerWindow()); | 554 aura::Window* container(controller()->GetContainerWindow()); |
| 531 root_window()->AddChild(container); | 555 root_window()->AddChild(container); |
| 532 gfx::Rect screen_bounds = root_window()->bounds(); | 556 gfx::Rect screen_bounds = root_window()->bounds(); |
| 533 keyboard::SetTouchKeyboardEnabled(true); | |
| 534 SetFocus(&input_client); | 557 SetFocus(&input_client); |
| 535 | 558 |
| 536 controller()->SetKeyboardMode(FLOATING); | 559 controller()->SetKeyboardMode(FLOATING); |
| 537 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 560 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 538 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 561 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 539 | 562 |
| 540 controller()->SetKeyboardMode(FULL_WIDTH); | 563 controller()->SetKeyboardMode(FULL_WIDTH); |
| 541 gfx::Rect expected_bounds( | 564 gfx::Rect expected_bounds( |
| 542 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 565 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 543 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 566 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 544 EXPECT_EQ(expected_bounds, notified_bounds()); | 567 EXPECT_EQ(expected_bounds, notified_bounds()); |
| 545 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); | 568 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); |
| 546 } | 569 } |
| 547 | 570 |
| 548 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 571 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 549 keyboard::SetAccessibilityKeyboardEnabled(true); | 572 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 550 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 573 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 551 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 574 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 552 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 575 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 553 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 576 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 554 | 577 |
| 555 base::RunLoop run_loop; | 578 base::RunLoop run_loop; |
| 556 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 579 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 557 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 580 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 558 new KeyboardContainerObserver(keyboard_container, &run_loop)); | 581 new KeyboardContainerObserver(keyboard_container, &run_loop)); |
| 559 root_window()->AddChild(keyboard_container); | 582 root_window()->AddChild(keyboard_container); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 576 // Unlock keyboard. | 599 // Unlock keyboard. |
| 577 controller()->set_keyboard_locked(false); | 600 controller()->set_keyboard_locked(false); |
| 578 | 601 |
| 579 // Keyboard should hide when focus on no input client. | 602 // Keyboard should hide when focus on no input client. |
| 580 SetFocus(&no_input_client_1); | 603 SetFocus(&no_input_client_1); |
| 581 EXPECT_TRUE(WillHideKeyboard()); | 604 EXPECT_TRUE(WillHideKeyboard()); |
| 582 | 605 |
| 583 // Wait for hide keyboard to finish. | 606 // Wait for hide keyboard to finish. |
| 584 run_loop.Run(); | 607 run_loop.Run(); |
| 585 EXPECT_FALSE(keyboard_container->IsVisible()); | 608 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 586 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 587 } | 609 } |
| 588 | 610 |
| 589 // Tests that deactivates keyboard will get closed event. | 611 // Tests that deactivates keyboard will get closed event. |
| 590 TEST_F(KeyboardControllerTest, CloseKeyboard) { | 612 TEST_F(KeyboardControllerTest, CloseKeyboard) { |
| 591 keyboard::SetAccessibilityKeyboardEnabled(true); | 613 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 592 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 614 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 593 root_window()->AddChild(keyboard_container); | 615 root_window()->AddChild(keyboard_container); |
| 594 keyboard_container->Show(); | 616 keyboard_container->Show(); |
| 595 | 617 |
| 596 ShowKeyboard(); | 618 ShowKeyboard(); |
| 597 EXPECT_TRUE(keyboard_container->IsVisible()); | 619 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 598 EXPECT_FALSE(IsKeyboardClosed()); | 620 EXPECT_FALSE(IsKeyboardClosed()); |
| 599 | 621 |
| 600 root_window()->RemoveChild(keyboard_container); | 622 root_window()->RemoveChild(keyboard_container); |
| 601 ResetController(); | 623 ResetController(); |
| 602 EXPECT_TRUE(IsKeyboardClosed()); | 624 EXPECT_TRUE(IsKeyboardClosed()); |
| 603 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 604 } | 625 } |
| 605 | 626 |
| 606 class KeyboardControllerAnimationTest : public KeyboardControllerTest { | 627 class KeyboardControllerAnimationTest : public KeyboardControllerTest { |
| 607 public: | 628 public: |
| 608 KeyboardControllerAnimationTest() {} | 629 KeyboardControllerAnimationTest() {} |
| 609 ~KeyboardControllerAnimationTest() override {} | 630 ~KeyboardControllerAnimationTest() override {} |
| 610 | 631 |
| 611 void SetUp() override { | 632 void SetUp() override { |
| 612 // We cannot short-circuit animations for this test. | 633 // We cannot short-circuit animations for this test. |
| 613 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 634 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 632 aura::Window* keyboard_window() { | 653 aura::Window* keyboard_window() { |
| 633 return ui()->GetKeyboardWindow(); | 654 return ui()->GetKeyboardWindow(); |
| 634 } | 655 } |
| 635 | 656 |
| 636 private: | 657 private: |
| 637 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); | 658 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); |
| 638 }; | 659 }; |
| 639 | 660 |
| 640 // Tests virtual keyboard has correct show and hide animation. | 661 // Tests virtual keyboard has correct show and hide animation. |
| 641 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { | 662 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { |
| 663 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; | |
| 642 ui::Layer* layer = keyboard_container()->layer(); | 664 ui::Layer* layer = keyboard_container()->layer(); |
| 643 keyboard::SetAccessibilityKeyboardEnabled(true); | |
| 644 ShowKeyboard(); | 665 ShowKeyboard(); |
| 645 | 666 |
| 646 // Keyboard container and window should immediately become visible before | 667 // Keyboard container and window should immediately become visible before |
| 647 // animation starts. | 668 // animation starts. |
| 648 EXPECT_TRUE(keyboard_container()->IsVisible()); | 669 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 649 EXPECT_TRUE(keyboard_window()->IsVisible()); | 670 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 650 float show_start_opacity = layer->opacity(); | 671 float show_start_opacity = layer->opacity(); |
| 651 gfx::Transform transform; | 672 gfx::Transform transform; |
| 652 transform.Translate(0, kAnimationDistance); | 673 transform.Translate(0, kAnimationDistance); |
| 653 EXPECT_EQ(transform, layer->transform()); | 674 EXPECT_EQ(transform, layer->transform()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 674 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 695 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 675 | 696 |
| 676 RunAnimationForLayer(layer); | 697 RunAnimationForLayer(layer); |
| 677 EXPECT_FALSE(keyboard_container()->IsVisible()); | 698 EXPECT_FALSE(keyboard_container()->IsVisible()); |
| 678 EXPECT_FALSE(keyboard_container()->layer()->visible()); | 699 EXPECT_FALSE(keyboard_container()->layer()->visible()); |
| 679 EXPECT_FALSE(keyboard_window()->IsVisible()); | 700 EXPECT_FALSE(keyboard_window()->IsVisible()); |
| 680 float hide_end_opacity = layer->opacity(); | 701 float hide_end_opacity = layer->opacity(); |
| 681 EXPECT_GT(hide_start_opacity, hide_end_opacity); | 702 EXPECT_GT(hide_start_opacity, hide_end_opacity); |
| 682 EXPECT_EQ(transform, layer->transform()); | 703 EXPECT_EQ(transform, layer->transform()); |
| 683 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 704 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 684 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 685 } | 705 } |
| 686 | 706 |
| 687 // Show keyboard during keyboard hide animation should abort the hide animation | 707 // Show keyboard during keyboard hide animation should abort the hide animation |
| 688 // and the keyboard should animate in. | 708 // and the keyboard should animate in. |
| 689 // Test for crbug.com/333284. | 709 // Test for crbug.com/333284. |
| 690 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { | 710 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { |
| 691 keyboard::SetAccessibilityKeyboardEnabled(true); | 711 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 692 ui::Layer* layer = keyboard_container()->layer(); | 712 ui::Layer* layer = keyboard_container()->layer(); |
| 693 ShowKeyboard(); | 713 ShowKeyboard(); |
| 694 RunAnimationForLayer(layer); | 714 RunAnimationForLayer(layer); |
| 695 | 715 |
| 696 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); | 716 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); |
| 697 // Before hide animation finishes, show keyboard again. | 717 // Before hide animation finishes, show keyboard again. |
| 698 ShowKeyboard(); | 718 ShowKeyboard(); |
| 699 RunAnimationForLayer(layer); | 719 RunAnimationForLayer(layer); |
| 700 EXPECT_TRUE(keyboard_container()->IsVisible()); | 720 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 701 EXPECT_TRUE(keyboard_window()->IsVisible()); | 721 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 702 EXPECT_EQ(1.0, layer->opacity()); | 722 EXPECT_EQ(1.0, layer->opacity()); |
| 703 EXPECT_EQ(gfx::Transform(), layer->transform()); | 723 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 704 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 705 } | 724 } |
| 706 | 725 |
| 707 // Test for crbug.com/568274. | 726 // Test for crbug.com/568274. |
| 708 TEST_F(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { | 727 TEST_F(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { |
| 728 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | |
| 709 aura::Window* container(controller()->GetContainerWindow()); | 729 aura::Window* container(controller()->GetContainerWindow()); |
| 710 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 730 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 711 root_window()->AddChild(container); | 731 root_window()->AddChild(container); |
| 712 | 732 |
| 713 keyboard::SetTouchKeyboardEnabled(true); | |
| 714 controller()->SetKeyboardMode(FLOATING); | 733 controller()->SetKeyboardMode(FLOATING); |
| 715 container->AddChild(keyboard); | 734 container->AddChild(keyboard); |
| 716 // Mock focus on an input field. | 735 // Mock focus on an input field. |
| 717 ui()->GetInputMethod()->ShowImeIfNeeded(); | 736 ui()->GetInputMethod()->ShowImeIfNeeded(); |
| 718 // Mock set keyboard size from javascript side. In floating mode, virtual | 737 // Mock set keyboard size from javascript side. In floating mode, virtual |
| 719 // keyboard's size is decided by client. | 738 // keyboard's size is decided by client. |
| 720 gfx::Rect new_bounds(0, 50, 50, 50); | 739 gfx::Rect new_bounds(0, 50, 50, 50); |
| 721 keyboard->SetBounds(new_bounds); | 740 keyboard->SetBounds(new_bounds); |
| 722 ASSERT_EQ(new_bounds, container->bounds()); | 741 ASSERT_EQ(new_bounds, container->bounds()); |
| 723 EXPECT_TRUE(keyboard->IsVisible()); | 742 EXPECT_TRUE(keyboard->IsVisible()); |
| 724 EXPECT_TRUE(container->IsVisible()); | 743 EXPECT_TRUE(container->IsVisible()); |
| 725 } | 744 } |
| 726 | 745 |
| 727 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { | 746 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { |
| 747 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; | |
| 728 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 748 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 729 | 749 |
| 730 aura::Window* container(controller()->GetContainerWindow()); | 750 aura::Window* container(controller()->GetContainerWindow()); |
| 731 root_window()->AddChild(container); | 751 root_window()->AddChild(container); |
| 732 | 752 |
| 733 keyboard::SetTouchKeyboardEnabled(true); | |
| 734 controller()->SetKeyboardMode(FULL_WIDTH); | 753 controller()->SetKeyboardMode(FULL_WIDTH); |
| 735 SetFocus(&input_client); | 754 SetFocus(&input_client); |
| 736 gfx::Rect new_bounds(0, 0, 1280, 800); | 755 gfx::Rect new_bounds(0, 0, 1280, 800); |
| 737 ASSERT_NE(new_bounds, root_window()->bounds()); | 756 ASSERT_NE(new_bounds, root_window()->bounds()); |
| 738 EXPECT_EQ(1, number_of_calls()); | 757 EXPECT_EQ(1, number_of_calls()); |
| 739 root_window()->SetBounds(new_bounds); | 758 root_window()->SetBounds(new_bounds); |
| 740 EXPECT_EQ(2, number_of_calls()); | 759 EXPECT_EQ(2, number_of_calls()); |
| 741 MockRotateScreen(); | 760 MockRotateScreen(); |
| 742 EXPECT_EQ(3, number_of_calls()); | 761 EXPECT_EQ(3, number_of_calls()); |
| 743 } | 762 } |
| 744 | 763 |
| 745 } // namespace keyboard | 764 } // namespace keyboard |
| OLD | NEW |