| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 TestTarget target; | 337 TestTarget target; |
| 338 GetController()->Register(accelerator_a, &target); | 338 GetController()->Register({accelerator_a}, &target); |
| 339 | 339 |
| 340 // The registered accelerator is processed. | 340 // The registered accelerator is processed. |
| 341 EXPECT_TRUE(ProcessInController(accelerator_a)); | 341 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 342 EXPECT_EQ(1, target.accelerator_pressed_count()); | 342 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 345 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 346 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 346 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 347 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 348 |
| 347 TestTarget target1; | 349 TestTarget target1; |
| 348 GetController()->Register(accelerator_a, &target1); | 350 GetController()->Register(accelerators, &target1); |
| 349 TestTarget target2; | 351 TestTarget target2; |
| 350 GetController()->Register(accelerator_a, &target2); | 352 GetController()->Register(accelerators, &target2); |
| 351 | 353 |
| 352 // If multiple targets are registered with the same accelerator, the target | 354 // If multiple targets are registered with the same accelerator, the target |
| 353 // registered later processes the accelerator. | 355 // registered later processes the accelerator. |
| 354 EXPECT_TRUE(ProcessInController(accelerator_a)); | 356 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 355 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 357 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 356 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 358 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 357 } | 359 } |
| 358 | 360 |
| 359 TEST_F(AcceleratorControllerTest, Unregister) { | 361 TEST_F(AcceleratorControllerTest, Unregister) { |
| 360 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 362 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 363 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 364 |
| 361 TestTarget target; | 365 TestTarget target; |
| 362 GetController()->Register(accelerator_a, &target); | 366 GetController()->Register({accelerator_a, accelerator_b}, &target); |
| 363 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | |
| 364 GetController()->Register(accelerator_b, &target); | |
| 365 | 367 |
| 366 // Unregistering a different accelerator does not affect the other | 368 // Unregistering a different accelerator does not affect the other |
| 367 // accelerator. | 369 // accelerator. |
| 368 GetController()->Unregister(accelerator_b, &target); | 370 GetController()->Unregister(accelerator_b, &target); |
| 369 EXPECT_TRUE(ProcessInController(accelerator_a)); | 371 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 370 EXPECT_EQ(1, target.accelerator_pressed_count()); | 372 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 371 | 373 |
| 372 // The unregistered accelerator is no longer processed. | 374 // The unregistered accelerator is no longer processed. |
| 373 target.reset(); | 375 target.reset(); |
| 374 GetController()->Unregister(accelerator_a, &target); | 376 GetController()->Unregister(accelerator_a, &target); |
| 375 EXPECT_FALSE(ProcessInController(accelerator_a)); | 377 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 376 EXPECT_EQ(0, target.accelerator_pressed_count()); | 378 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 377 } | 379 } |
| 378 | 380 |
| 379 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 381 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 380 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 382 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 383 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 384 |
| 381 TestTarget target1; | 385 TestTarget target1; |
| 382 GetController()->Register(accelerator_a, &target1); | 386 GetController()->Register({accelerator_a, accelerator_b}, &target1); |
| 383 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 387 |
| 384 GetController()->Register(accelerator_b, &target1); | |
| 385 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 388 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 386 TestTarget target2; | 389 TestTarget target2; |
| 387 GetController()->Register(accelerator_c, &target2); | 390 GetController()->Register({accelerator_c}, &target2); |
| 388 GetController()->UnregisterAll(&target1); | 391 GetController()->UnregisterAll(&target1); |
| 389 | 392 |
| 390 // All the accelerators registered for |target1| are no longer processed. | 393 // All the accelerators registered for |target1| are no longer processed. |
| 391 EXPECT_FALSE(ProcessInController(accelerator_a)); | 394 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 392 EXPECT_FALSE(ProcessInController(accelerator_b)); | 395 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 393 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 396 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 394 | 397 |
| 395 // UnregisterAll with a different target does not affect the other target. | 398 // UnregisterAll with a different target does not affect the other target. |
| 396 EXPECT_TRUE(ProcessInController(accelerator_c)); | 399 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 397 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 400 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 398 } | 401 } |
| 399 | 402 |
| 400 TEST_F(AcceleratorControllerTest, Process) { | 403 TEST_F(AcceleratorControllerTest, Process) { |
| 401 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 404 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 402 TestTarget target1; | 405 TestTarget target1; |
| 403 GetController()->Register(accelerator_a, &target1); | 406 GetController()->Register({accelerator_a}, &target1); |
| 404 | 407 |
| 405 // The registered accelerator is processed. | 408 // The registered accelerator is processed. |
| 406 EXPECT_TRUE(ProcessInController(accelerator_a)); | 409 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 407 EXPECT_EQ(1, target1.accelerator_pressed_count()); | 410 EXPECT_EQ(1, target1.accelerator_pressed_count()); |
| 408 | 411 |
| 409 // The non-registered accelerator is not processed. | 412 // The non-registered accelerator is not processed. |
| 410 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 413 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 411 EXPECT_FALSE(ProcessInController(accelerator_b)); | 414 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 412 } | 415 } |
| 413 | 416 |
| 414 TEST_F(AcceleratorControllerTest, IsRegistered) { | 417 TEST_F(AcceleratorControllerTest, IsRegistered) { |
| 415 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 418 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); | 419 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
| 420 |
| 417 TestTarget target; | 421 TestTarget target; |
| 418 GetController()->Register(accelerator_a, &target); | 422 GetController()->Register({accelerator_a}, &target); |
| 419 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 423 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 420 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 424 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 421 GetController()->UnregisterAll(&target); | 425 GetController()->UnregisterAll(&target); |
| 422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 426 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 423 } | 427 } |
| 424 | 428 |
| 425 TEST_F(AcceleratorControllerTest, WindowSnap) { | 429 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 426 std::unique_ptr<aura::Window> window( | 430 std::unique_ptr<aura::Window> window( |
| 427 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 431 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 428 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 432 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(); | 650 gfx::Rect docked_bounds = window->GetBoundsInScreen(); |
| 647 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | 651 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); |
| 648 // It should not get centered and should remain docked. | 652 // It should not get centered and should remain docked. |
| 649 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 653 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 650 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 654 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 651 } | 655 } |
| 652 | 656 |
| 653 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 657 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
| 654 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 658 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 655 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 659 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
| 660 |
| 656 TestTarget target_a; | 661 TestTarget target_a; |
| 657 GetController()->Register(accelerator_a, &target_a); | 662 GetController()->Register({accelerator_a}, &target_a); |
| 658 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 663 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
| 659 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 664 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
| 660 TestTarget target_b; | 665 TestTarget target_b; |
| 661 GetController()->Register(accelerator_b, &target_b); | 666 |
| 667 GetController()->Register({accelerator_b}, &target_b); |
| 662 | 668 |
| 663 ui::test::EventGenerator& generator = GetEventGenerator(); | 669 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 664 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 670 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 665 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 671 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 666 | 672 |
| 667 EXPECT_EQ(1, target_a.accelerator_pressed_count()); | 673 EXPECT_EQ(1, target_a.accelerator_pressed_count()); |
| 668 EXPECT_EQ(0, target_a.accelerator_repeat_count()); | 674 EXPECT_EQ(0, target_a.accelerator_repeat_count()); |
| 669 | 675 |
| 670 // Long press should generate one | 676 // Long press should generate one |
| 671 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 677 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 | 756 #define MAYBE_ProcessOnce ProcessOnce |
| 751 #endif | 757 #endif |
| 752 | 758 |
| 753 #if defined(OS_WIN) || defined(USE_X11) | 759 #if defined(OS_WIN) || defined(USE_X11) |
| 754 TEST_F(AcceleratorControllerTest, MAYBE_ProcessOnce) { | 760 TEST_F(AcceleratorControllerTest, MAYBE_ProcessOnce) { |
| 755 // The IME event filter interferes with the basic key event propagation we | 761 // The IME event filter interferes with the basic key event propagation we |
| 756 // attempt to do here, so we disable it. | 762 // attempt to do here, so we disable it. |
| 757 DisableIME(); | 763 DisableIME(); |
| 758 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 764 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 759 TestTarget target; | 765 TestTarget target; |
| 760 GetController()->Register(accelerator_a, &target); | 766 |
| 767 GetController()->Register({accelerator_a}, &target); |
| 761 | 768 |
| 762 // The accelerator is processed only once. | 769 // The accelerator is processed only once. |
| 763 ui::EventProcessor* dispatcher = | 770 ui::EventProcessor* dispatcher = |
| 764 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | 771 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 765 #if defined(OS_WIN) | 772 #if defined(OS_WIN) |
| 766 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; | 773 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; |
| 767 ui::KeyEvent key_event1(msg1); | 774 ui::KeyEvent key_event1(msg1); |
| 768 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | 775 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); |
| 769 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | 776 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); |
| 770 | 777 |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 EXPECT_TRUE(IsMessageCenterEmpty()); | 1420 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1414 | 1421 |
| 1415 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1422 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1416 // screen before we proceed testing the rest of accelerators. | 1423 // screen before we proceed testing the rest of accelerators. |
| 1417 ResetStateIfNeeded(); | 1424 ResetStateIfNeeded(); |
| 1418 } | 1425 } |
| 1419 } | 1426 } |
| 1420 #endif // defined(OS_CHROMEOS) | 1427 #endif // defined(OS_CHROMEOS) |
| 1421 | 1428 |
| 1422 } // namespace ash | 1429 } // namespace ash |
| OLD | NEW |