| Index: ui/keyboard/keyboard_controller_unittest.cc
|
| diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc
|
| index fd5b0878434191e3fc1861abdc291463d6fc06c8..c43e25a7ef04b72fe720dea74190faec7688e151 100644
|
| --- a/ui/keyboard/keyboard_controller_unittest.cc
|
| +++ b/ui/keyboard/keyboard_controller_unittest.cc
|
| @@ -37,6 +37,13 @@
|
| namespace keyboard {
|
| namespace {
|
|
|
| +// Verify if the |keyboard| window covers the |container| window completely.
|
| +void VerifyKeyboardWindowSize(aura::Window* container, aura::Window* keyboard) {
|
| + ASSERT_EQ(gfx::Rect(0, 0, container->bounds().width(),
|
| + container->bounds().height()),
|
| + keyboard->bounds());
|
| +}
|
| +
|
| // Steps a layer animation until it is completed. Animations must be enabled.
|
| void RunAnimationForLayer(ui::Layer* layer) {
|
| // Animations must be enabled for stepping to work.
|
| @@ -215,8 +222,7 @@ class KeyboardControllerTest : public testing::Test {
|
| if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
|
| // Set initial bounds for test keyboard window.
|
| proxy_->GetKeyboardWindow()->SetBounds(
|
| - KeyboardBoundsFromWindowBounds(
|
| - controller()->GetContainerWindow()->bounds(), 100));
|
| + KeyboardBoundsFromWindowBounds(root_window()->bounds(), 100));
|
| }
|
| }
|
| }
|
| @@ -243,26 +249,52 @@ class KeyboardControllerTest : public testing::Test {
|
| TEST_F(KeyboardControllerTest, KeyboardSize) {
|
| aura::Window* container(controller()->GetContainerWindow());
|
| aura::Window* keyboard(proxy()->GetKeyboardWindow());
|
| - container->SetBounds(gfx::Rect(0, 0, 200, 100));
|
| -
|
| + gfx::Rect screen_bounds = root_window()->bounds();
|
| + root_window()->AddChild(container);
|
| container->AddChild(keyboard);
|
| - const gfx::Rect& before_bounds = keyboard->bounds();
|
| - // The initial keyboard should be positioned at the bottom of container and
|
| - // has 0 height.
|
| - ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds);
|
| + const gfx::Rect& initial_bounds = container->bounds();
|
| + // The container should be positioned at the bottom of screen and has 0
|
| + // height.
|
| + ASSERT_EQ(gfx::Rect(0, screen_bounds.height(), screen_bounds.width(), 0),
|
| + initial_bounds);
|
| + VerifyKeyboardWindowSize(container, keyboard);
|
|
|
| - gfx::Rect new_bounds(
|
| - before_bounds.x(), before_bounds.y() - 50,
|
| - before_bounds.width(), 50);
|
| + gfx::Rect new_bounds(initial_bounds.x(), initial_bounds.y(),
|
| + initial_bounds.width() - 50, 50);
|
| +
|
| + // In FULL_WIDTH mode, attempt to change window width or move window up from
|
| + // the bottom are ignored. Changing window height is supported.
|
| + gfx::Rect expected_bounds(initial_bounds.x(), initial_bounds.y() - 50,
|
| + initial_bounds.width(), 50);
|
|
|
| keyboard->SetBounds(new_bounds);
|
| - ASSERT_EQ(new_bounds, keyboard->bounds());
|
| + ASSERT_EQ(expected_bounds, container->bounds());
|
| + VerifyKeyboardWindowSize(container, keyboard);
|
|
|
| // Mock a screen rotation.
|
| - container->SetBounds(gfx::Rect(0, 0, 100, 200));
|
| + controller()->OnRootWindowResized(
|
| + gfx::Rect(0, 0, screen_bounds.height(), screen_bounds.width()));
|
| // The above call should resize keyboard to new width while keeping the old
|
| // height.
|
| - ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds());
|
| + ASSERT_EQ(gfx::Rect(0, screen_bounds.width() - 50,
|
| + root_window()->bounds().height(), 50),
|
| + container->bounds());
|
| + VerifyKeyboardWindowSize(container, keyboard);
|
| +}
|
| +
|
| +TEST_F(KeyboardControllerTest, FloatingKeyboardSize) {
|
| + aura::Window* container(controller()->GetContainerWindow());
|
| + aura::Window* keyboard(proxy()->GetKeyboardWindow());
|
| + gfx::Rect screen_bounds = root_window()->bounds();
|
| + root_window()->AddChild(container);
|
| + controller()->SetKeyboardMode(FLOATING);
|
| +
|
| + container->AddChild(keyboard);
|
| +
|
| + gfx::Rect new_bounds(0, 50, 50, 50);
|
| + keyboard->SetBounds(new_bounds);
|
| + ASSERT_EQ(new_bounds, container->bounds());
|
| + VerifyKeyboardWindowSize(container, keyboard);
|
| }
|
|
|
| // Tests that tapping/clicking inside the keyboard does not give it focus.
|
| @@ -277,7 +309,6 @@ TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
|
| window->Focus();
|
|
|
| aura::Window* keyboard_container(controller()->GetContainerWindow());
|
| - keyboard_container->SetBounds(root_bounds);
|
|
|
| root_window()->AddChild(keyboard_container);
|
| keyboard_container->Show();
|
| @@ -295,7 +326,7 @@ TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
|
| keyboard_container->AddPreTargetHandler(&observer);
|
|
|
| ui::test::EventGenerator generator(root_window());
|
| - generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint());
|
| + generator.MoveMouseTo(keyboard_container->bounds().CenterPoint());
|
| generator.ClickLeftButton();
|
| EXPECT_TRUE(window->HasFocus());
|
| EXPECT_FALSE(keyboard_container->HasFocus());
|
| @@ -321,7 +352,6 @@ TEST_F(KeyboardControllerTest, EventHitTestingInContainer) {
|
| window->Focus();
|
|
|
| aura::Window* keyboard_container(controller()->GetContainerWindow());
|
| - keyboard_container->SetBounds(root_bounds);
|
|
|
| root_window()->AddChild(keyboard_container);
|
| keyboard_container->Show();
|
| @@ -337,12 +367,12 @@ TEST_F(KeyboardControllerTest, EventHitTestingInContainer) {
|
| aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
|
| ui::EventTarget* root = root_window();
|
| ui::EventTargeter* targeter = root->GetEventTargeter();
|
| - gfx::Point location = keyboard_window->bounds().CenterPoint();
|
| + gfx::Point location = keyboard_container->bounds().CenterPoint();
|
| ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location,
|
| ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
|
| EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1));
|
|
|
| - location.set_y(keyboard_window->bounds().y() - 5);
|
| + location.set_y(keyboard_container->bounds().y() - 5);
|
| ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location,
|
| ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
|
| EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2));
|
| @@ -382,8 +412,6 @@ TEST_F(KeyboardControllerTest, KeyboardWindowCreation) {
|
| }
|
|
|
| TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
|
| - const gfx::Rect& root_bounds = root_window()->bounds();
|
| -
|
| ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
|
| ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
|
| ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
|
| @@ -393,7 +421,6 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
|
| aura::Window* keyboard_container(controller()->GetContainerWindow());
|
| scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
|
| new KeyboardContainerObserver(keyboard_container));
|
| - keyboard_container->SetBounds(root_bounds);
|
| root_window()->AddChild(keyboard_container);
|
|
|
| SetFocus(&input_client_0);
|
| @@ -425,13 +452,10 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
|
| // Test to prevent spurious overscroll boxes when changing tabs during keyboard
|
| // hide. Refer to crbug.com/401670 for more context.
|
| TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
|
| - const gfx::Rect& root_bounds = root_window()->bounds();
|
| -
|
| ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
|
| ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
|
|
|
| aura::Window* keyboard_container(controller()->GetContainerWindow());
|
| - keyboard_container->SetBounds(root_bounds);
|
| root_window()->AddChild(keyboard_container);
|
|
|
| // Enable touch keyboard / overscroll mode to test insets.
|
| @@ -450,8 +474,6 @@ TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
|
| }
|
|
|
| TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
|
| - const gfx::Rect& root_bounds = root_window()->bounds();
|
| -
|
| ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
|
| ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
|
| ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
|
| @@ -460,7 +482,6 @@ TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
|
| aura::Window* keyboard_container(controller()->GetContainerWindow());
|
| scoped_ptr<KeyboardContainerObserver> keyboard_container_observer(
|
| new KeyboardContainerObserver(keyboard_container));
|
| - keyboard_container->SetBounds(root_bounds);
|
| root_window()->AddChild(keyboard_container);
|
|
|
| SetFocus(&input_client_0);
|
| @@ -557,9 +578,9 @@ TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
|
| float show_end_opacity = layer->opacity();
|
| EXPECT_LT(show_start_opacity, show_end_opacity);
|
| EXPECT_EQ(gfx::Transform(), layer->transform());
|
| - // KeyboardController should notify the bounds of keyboard window to its
|
| + // KeyboardController should notify the bounds of container window to its
|
| // observers after show animation finished.
|
| - EXPECT_EQ(keyboard_window()->bounds(), notified_bounds());
|
| + EXPECT_EQ(keyboard_container()->bounds(), notified_bounds());
|
|
|
| // Directly hide keyboard without delay.
|
| controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC);
|
|
|