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