| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/common/accelerators/accelerator_controller.h" | 5 #include "ash/common/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/accelerators/accelerator_table.h" | 8 #include "ash/common/accelerators/accelerator_table.h" |
| 9 #include "ash/common/accessibility_delegate.h" | 9 #include "ash/common/accessibility_delegate.h" |
| 10 #include "ash/common/accessibility_types.h" | 10 #include "ash/common/accessibility_types.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ewh->HandleAccelerator(); | 327 ewh->HandleAccelerator(); |
| 328 EXPECT_FALSE(is_idle(ewh)); | 328 EXPECT_FALSE(is_idle(ewh)); |
| 329 EXPECT_TRUE(is_ui_shown(ewh)); | 329 EXPECT_TRUE(is_ui_shown(ewh)); |
| 330 | 330 |
| 331 // Exit ash and there should be no crash | 331 // Exit ash and there should be no crash |
| 332 } | 332 } |
| 333 #endif // !defined(OS_WIN) | 333 #endif // !defined(OS_WIN) |
| 334 | 334 |
| 335 TEST_F(AcceleratorControllerTest, Register) { | 335 TEST_F(AcceleratorControllerTest, Register) { |
| 336 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 336 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 337 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 337 TestTarget target; | 338 TestTarget target; |
| 338 GetController()->Register(accelerator_a, &target); | 339 GetController()->Register(accelerators, &target); |
| 339 | 340 |
| 340 // The registered accelerator is processed. | 341 // The registered accelerator is processed. |
| 341 EXPECT_TRUE(ProcessInController(accelerator_a)); | 342 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 342 EXPECT_EQ(1, target.accelerator_pressed_count()); | 343 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 343 } | 344 } |
| 344 | 345 |
| 345 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 346 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 346 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 347 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 348 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 349 |
| 347 TestTarget target1; | 350 TestTarget target1; |
| 348 GetController()->Register(accelerator_a, &target1); | 351 GetController()->Register(accelerators, &target1); |
| 349 TestTarget target2; | 352 TestTarget target2; |
| 350 GetController()->Register(accelerator_a, &target2); | 353 GetController()->Register(accelerators, &target2); |
| 351 | 354 |
| 352 // If multiple targets are registered with the same accelerator, the target | 355 // If multiple targets are registered with the same accelerator, the target |
| 353 // registered later processes the accelerator. | 356 // registered later processes the accelerator. |
| 354 EXPECT_TRUE(ProcessInController(accelerator_a)); | 357 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 355 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 358 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 356 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 359 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 357 } | 360 } |
| 358 | 361 |
| 359 TEST_F(AcceleratorControllerTest, Unregister) { | 362 TEST_F(AcceleratorControllerTest, Unregister) { |
| 360 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 363 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 364 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 365 const std::vector<ui::Accelerator>& accelerators = {accelerator_a, |
| 366 accelerator_b}; |
| 367 |
| 361 TestTarget target; | 368 TestTarget target; |
| 362 GetController()->Register(accelerator_a, &target); | 369 GetController()->Register(accelerators, &target); |
| 363 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | |
| 364 GetController()->Register(accelerator_b, &target); | |
| 365 | 370 |
| 366 // Unregistering a different accelerator does not affect the other | 371 // Unregistering a different accelerator does not affect the other |
| 367 // accelerator. | 372 // accelerator. |
| 368 GetController()->Unregister(accelerator_b, &target); | 373 GetController()->Unregister(accelerator_b, &target); |
| 369 EXPECT_TRUE(ProcessInController(accelerator_a)); | 374 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 370 EXPECT_EQ(1, target.accelerator_pressed_count()); | 375 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 371 | 376 |
| 372 // The unregistered accelerator is no longer processed. | 377 // The unregistered accelerator is no longer processed. |
| 373 target.reset(); | 378 target.reset(); |
| 374 GetController()->Unregister(accelerator_a, &target); | 379 GetController()->Unregister(accelerator_a, &target); |
| 375 EXPECT_FALSE(ProcessInController(accelerator_a)); | 380 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 376 EXPECT_EQ(0, target.accelerator_pressed_count()); | 381 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 377 } | 382 } |
| 378 | 383 |
| 379 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 384 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 380 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 385 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 386 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 387 const std::vector<ui::Accelerator>& accelerators = {accelerator_a, |
| 388 accelerator_b}; |
| 381 TestTarget target1; | 389 TestTarget target1; |
| 382 GetController()->Register(accelerator_a, &target1); | 390 GetController()->Register(accelerators, &target1); |
| 383 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 391 |
| 384 GetController()->Register(accelerator_b, &target1); | |
| 385 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 392 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 393 const std::vector<ui::Accelerator>& accelerators_2 = {accelerator_c}; |
| 386 TestTarget target2; | 394 TestTarget target2; |
| 387 GetController()->Register(accelerator_c, &target2); | 395 GetController()->Register(accelerators_2, &target2); |
| 388 GetController()->UnregisterAll(&target1); | 396 GetController()->UnregisterAll(&target1); |
| 389 | 397 |
| 390 // All the accelerators registered for |target1| are no longer processed. | 398 // All the accelerators registered for |target1| are no longer processed. |
| 391 EXPECT_FALSE(ProcessInController(accelerator_a)); | 399 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 392 EXPECT_FALSE(ProcessInController(accelerator_b)); | 400 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 393 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 401 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 394 | 402 |
| 395 // UnregisterAll with a different target does not affect the other target. | 403 // UnregisterAll with a different target does not affect the other target. |
| 396 EXPECT_TRUE(ProcessInController(accelerator_c)); | 404 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 397 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 405 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 398 } | 406 } |
| 399 | 407 |
| 400 TEST_F(AcceleratorControllerTest, Process) { | 408 TEST_F(AcceleratorControllerTest, Process) { |
| 401 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 409 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 410 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 402 TestTarget target1; | 411 TestTarget target1; |
| 403 GetController()->Register(accelerator_a, &target1); | 412 GetController()->Register(accelerators, &target1); |
| 404 | 413 |
| 405 // The registered accelerator is processed. | 414 // The registered accelerator is processed. |
| 406 EXPECT_TRUE(ProcessInController(accelerator_a)); | 415 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 407 EXPECT_EQ(1, target1.accelerator_pressed_count()); | 416 EXPECT_EQ(1, target1.accelerator_pressed_count()); |
| 408 | 417 |
| 409 // The non-registered accelerator is not processed. | 418 // The non-registered accelerator is not processed. |
| 410 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 419 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 411 EXPECT_FALSE(ProcessInController(accelerator_b)); | 420 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 412 } | 421 } |
| 413 | 422 |
| 414 TEST_F(AcceleratorControllerTest, IsRegistered) { | 423 TEST_F(AcceleratorControllerTest, IsRegistered) { |
| 415 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 424 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 416 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); | 425 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
| 426 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 427 |
| 417 TestTarget target; | 428 TestTarget target; |
| 418 GetController()->Register(accelerator_a, &target); | 429 GetController()->Register(accelerators, &target); |
| 419 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 430 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 420 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 421 GetController()->UnregisterAll(&target); | 432 GetController()->UnregisterAll(&target); |
| 422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 433 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 423 } | 434 } |
| 424 | 435 |
| 425 TEST_F(AcceleratorControllerTest, WindowSnap) { | 436 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 426 std::unique_ptr<aura::Window> window( | 437 std::unique_ptr<aura::Window> window( |
| 427 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 438 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 428 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 439 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 gfx::Rect docked_bounds = window->GetBoundsInScreen(); | 657 gfx::Rect docked_bounds = window->GetBoundsInScreen(); |
| 647 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | 658 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); |
| 648 // It should not get centered and should remain docked. | 659 // It should not get centered and should remain docked. |
| 649 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 660 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 650 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 661 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 651 } | 662 } |
| 652 | 663 |
| 653 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 664 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
| 654 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 665 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 655 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 666 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
| 667 |
| 668 const std::vector<ui::Accelerator>& accelerators_a = {accelerator_a}; |
| 669 |
| 656 TestTarget target_a; | 670 TestTarget target_a; |
| 657 GetController()->Register(accelerator_a, &target_a); | 671 GetController()->Register(accelerators_a, &target_a); |
| 658 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 672 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
| 659 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 673 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
| 660 TestTarget target_b; | 674 TestTarget target_b; |
| 661 GetController()->Register(accelerator_b, &target_b); | 675 |
| 676 const std::vector<ui::Accelerator>& accelerators_b = {accelerator_b}; |
| 677 GetController()->Register(accelerators_b, &target_b); |
| 662 | 678 |
| 663 ui::test::EventGenerator& generator = GetEventGenerator(); | 679 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 664 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 680 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 665 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 681 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 666 | 682 |
| 667 EXPECT_EQ(1, target_a.accelerator_pressed_count()); | 683 EXPECT_EQ(1, target_a.accelerator_pressed_count()); |
| 668 EXPECT_EQ(0, target_a.accelerator_repeat_count()); | 684 EXPECT_EQ(0, target_a.accelerator_repeat_count()); |
| 669 | 685 |
| 670 // Long press should generate one | 686 // Long press should generate one |
| 671 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 687 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 #define MAYBE_ProcessOnce ProcessOnce | 766 #define MAYBE_ProcessOnce ProcessOnce |
| 751 #endif | 767 #endif |
| 752 | 768 |
| 753 #if defined(OS_WIN) || defined(USE_X11) | 769 #if defined(OS_WIN) || defined(USE_X11) |
| 754 TEST_F(AcceleratorControllerTest, MAYBE_ProcessOnce) { | 770 TEST_F(AcceleratorControllerTest, MAYBE_ProcessOnce) { |
| 755 // The IME event filter interferes with the basic key event propagation we | 771 // The IME event filter interferes with the basic key event propagation we |
| 756 // attempt to do here, so we disable it. | 772 // attempt to do here, so we disable it. |
| 757 DisableIME(); | 773 DisableIME(); |
| 758 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 774 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 759 TestTarget target; | 775 TestTarget target; |
| 760 GetController()->Register(accelerator_a, &target); | 776 |
| 777 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 778 GetController()->Register(accelerators, &target); |
| 761 | 779 |
| 762 // The accelerator is processed only once. | 780 // The accelerator is processed only once. |
| 763 ui::EventProcessor* dispatcher = | 781 ui::EventProcessor* dispatcher = |
| 764 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | 782 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 765 #if defined(OS_WIN) | 783 #if defined(OS_WIN) |
| 766 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; | 784 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; |
| 767 ui::KeyEvent key_event1(msg1); | 785 ui::KeyEvent key_event1(msg1); |
| 768 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | 786 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); |
| 769 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | 787 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); |
| 770 | 788 |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 EXPECT_TRUE(IsMessageCenterEmpty()); | 1431 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1414 | 1432 |
| 1415 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1433 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1416 // screen before we proceed testing the rest of accelerators. | 1434 // screen before we proceed testing the rest of accelerators. |
| 1417 ResetStateIfNeeded(); | 1435 ResetStateIfNeeded(); |
| 1418 } | 1436 } |
| 1419 } | 1437 } |
| 1420 #endif // defined(OS_CHROMEOS) | 1438 #endif // defined(OS_CHROMEOS) |
| 1421 | 1439 |
| 1422 } // namespace ash | 1440 } // namespace ash |
| OLD | NEW |