| 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/common/accelerators/accelerator_table.h" | 7 #include "ash/common/accelerators/accelerator_table.h" |
| 8 #include "ash/common/accessibility_delegate.h" | 8 #include "ash/common/accessibility_delegate.h" |
| 9 #include "ash/common/accessibility_types.h" | 9 #include "ash/common/accessibility_types.h" |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ewh->HandleAccelerator(); | 330 ewh->HandleAccelerator(); |
| 331 EXPECT_FALSE(is_idle(ewh)); | 331 EXPECT_FALSE(is_idle(ewh)); |
| 332 EXPECT_TRUE(is_ui_shown(ewh)); | 332 EXPECT_TRUE(is_ui_shown(ewh)); |
| 333 | 333 |
| 334 // Exit ash and there should be no crash | 334 // Exit ash and there should be no crash |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST_F(AcceleratorControllerTest, Register) { | 337 TEST_F(AcceleratorControllerTest, Register) { |
| 338 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 338 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 339 TestTarget target; | 339 TestTarget target; |
| 340 GetController()->Register(accelerator_a, &target); | 340 GetController()->Register({accelerator_a}, &target); |
| 341 | 341 |
| 342 // The registered accelerator is processed. | 342 // The registered accelerator is processed. |
| 343 EXPECT_TRUE(ProcessInController(accelerator_a)); | 343 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 344 EXPECT_EQ(1, target.accelerator_pressed_count()); | 344 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 347 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 349 TestTarget target1; | 349 TestTarget target1; |
| 350 GetController()->Register(accelerator_a, &target1); | 350 GetController()->Register({accelerator_a}, &target1); |
| 351 TestTarget target2; | 351 TestTarget target2; |
| 352 GetController()->Register(accelerator_a, &target2); | 352 GetController()->Register({accelerator_a}, &target2); |
| 353 | 353 |
| 354 // If multiple targets are registered with the same accelerator, the target | 354 // If multiple targets are registered with the same accelerator, the target |
| 355 // registered later processes the accelerator. | 355 // registered later processes the accelerator. |
| 356 EXPECT_TRUE(ProcessInController(accelerator_a)); | 356 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 357 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 357 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 358 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 358 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 TEST_F(AcceleratorControllerTest, Unregister) { | 361 TEST_F(AcceleratorControllerTest, Unregister) { |
| 362 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); |
| 363 TestTarget target; | 364 TestTarget target; |
| 364 GetController()->Register(accelerator_a, &target); | 365 GetController()->Register({accelerator_a, accelerator_b}, &target); |
| 365 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | |
| 366 GetController()->Register(accelerator_b, &target); | |
| 367 | 366 |
| 368 // Unregistering a different accelerator does not affect the other | 367 // Unregistering a different accelerator does not affect the other |
| 369 // accelerator. | 368 // accelerator. |
| 370 GetController()->Unregister(accelerator_b, &target); | 369 GetController()->Unregister(accelerator_b, &target); |
| 371 EXPECT_TRUE(ProcessInController(accelerator_a)); | 370 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 372 EXPECT_EQ(1, target.accelerator_pressed_count()); | 371 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 373 | 372 |
| 374 // The unregistered accelerator is no longer processed. | 373 // The unregistered accelerator is no longer processed. |
| 375 target.reset(); | 374 target.reset(); |
| 376 GetController()->Unregister(accelerator_a, &target); | 375 GetController()->Unregister(accelerator_a, &target); |
| 377 EXPECT_FALSE(ProcessInController(accelerator_a)); | 376 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 378 EXPECT_EQ(0, target.accelerator_pressed_count()); | 377 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 379 } | 378 } |
| 380 | 379 |
| 381 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 380 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 382 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 381 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 382 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 383 TestTarget target1; | 383 TestTarget target1; |
| 384 GetController()->Register(accelerator_a, &target1); | 384 GetController()->Register({accelerator_a, accelerator_b}, &target1); |
| 385 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 385 |
| 386 GetController()->Register(accelerator_b, &target1); | |
| 387 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 386 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 388 TestTarget target2; | 387 TestTarget target2; |
| 389 GetController()->Register(accelerator_c, &target2); | 388 GetController()->Register({accelerator_c}, &target2); |
| 390 GetController()->UnregisterAll(&target1); | 389 GetController()->UnregisterAll(&target1); |
| 391 | 390 |
| 392 // All the accelerators registered for |target1| are no longer processed. | 391 // All the accelerators registered for |target1| are no longer processed. |
| 393 EXPECT_FALSE(ProcessInController(accelerator_a)); | 392 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 394 EXPECT_FALSE(ProcessInController(accelerator_b)); | 393 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 395 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 394 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 396 | 395 |
| 397 // UnregisterAll with a different target does not affect the other target. | 396 // UnregisterAll with a different target does not affect the other target. |
| 398 EXPECT_TRUE(ProcessInController(accelerator_c)); | 397 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 399 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 398 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 400 } | 399 } |
| 401 | 400 |
| 402 TEST_F(AcceleratorControllerTest, Process) { | 401 TEST_F(AcceleratorControllerTest, Process) { |
| 403 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 402 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 404 TestTarget target1; | 403 TestTarget target1; |
| 405 GetController()->Register(accelerator_a, &target1); | 404 GetController()->Register({accelerator_a}, &target1); |
| 406 | 405 |
| 407 // The registered accelerator is processed. | 406 // The registered accelerator is processed. |
| 408 EXPECT_TRUE(ProcessInController(accelerator_a)); | 407 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 409 EXPECT_EQ(1, target1.accelerator_pressed_count()); | 408 EXPECT_EQ(1, target1.accelerator_pressed_count()); |
| 410 | 409 |
| 411 // The non-registered accelerator is not processed. | 410 // The non-registered accelerator is not processed. |
| 412 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 411 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 413 EXPECT_FALSE(ProcessInController(accelerator_b)); | 412 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 414 } | 413 } |
| 415 | 414 |
| 416 TEST_F(AcceleratorControllerTest, IsRegistered) { | 415 TEST_F(AcceleratorControllerTest, IsRegistered) { |
| 417 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 416 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 418 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); | 417 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
| 419 TestTarget target; | 418 TestTarget target; |
| 420 GetController()->Register(accelerator_a, &target); | 419 GetController()->Register({accelerator_a}, &target); |
| 421 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 420 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 421 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 423 GetController()->UnregisterAll(&target); | 422 GetController()->UnregisterAll(&target); |
| 424 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 423 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 425 } | 424 } |
| 426 | 425 |
| 427 TEST_F(AcceleratorControllerTest, WindowSnap) { | 426 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 428 std::unique_ptr<aura::Window> window( | 427 std::unique_ptr<aura::Window> window( |
| 429 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 428 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 430 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 429 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | 709 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); |
| 711 // It should not get centered and should remain docked. | 710 // It should not get centered and should remain docked. |
| 712 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 711 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 713 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 712 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 714 } | 713 } |
| 715 | 714 |
| 716 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 715 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
| 717 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 716 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 718 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 717 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
| 719 TestTarget target_a; | 718 TestTarget target_a; |
| 720 GetController()->Register(accelerator_a, &target_a); | 719 GetController()->Register({accelerator_a}, &target_a); |
| 721 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 720 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
| 722 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 721 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
| 723 TestTarget target_b; | 722 TestTarget target_b; |
| 724 GetController()->Register(accelerator_b, &target_b); | 723 |
| 724 GetController()->Register({accelerator_b}, &target_b); |
| 725 | 725 |
| 726 ui::test::EventGenerator& generator = GetEventGenerator(); | 726 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 727 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 727 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 728 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 728 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 729 | 729 |
| 730 EXPECT_EQ(1, target_a.accelerator_pressed_count()); | 730 EXPECT_EQ(1, target_a.accelerator_pressed_count()); |
| 731 EXPECT_EQ(0, target_a.accelerator_repeat_count()); | 731 EXPECT_EQ(0, target_a.accelerator_repeat_count()); |
| 732 | 732 |
| 733 // Long press should generate one | 733 // Long press should generate one |
| 734 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 734 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 } | 806 } |
| 807 | 807 |
| 808 // TODO(oshima): Fix this test to use EventGenerator. | 808 // TODO(oshima): Fix this test to use EventGenerator. |
| 809 #if defined(USE_X11) | 809 #if defined(USE_X11) |
| 810 TEST_F(AcceleratorControllerTest, ProcessOnce) { | 810 TEST_F(AcceleratorControllerTest, ProcessOnce) { |
| 811 // The IME event filter interferes with the basic key event propagation we | 811 // The IME event filter interferes with the basic key event propagation we |
| 812 // attempt to do here, so we disable it. | 812 // attempt to do here, so we disable it. |
| 813 DisableIME(); | 813 DisableIME(); |
| 814 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 814 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 815 TestTarget target; | 815 TestTarget target; |
| 816 GetController()->Register(accelerator_a, &target); | 816 |
| 817 GetController()->Register({accelerator_a}, &target); |
| 817 | 818 |
| 818 // The accelerator is processed only once. | 819 // The accelerator is processed only once. |
| 819 ui::EventProcessor* dispatcher = | 820 ui::EventProcessor* dispatcher = |
| 820 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | 821 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 821 | 822 |
| 822 ui::ScopedXI2Event key_event; | 823 ui::ScopedXI2Event key_event; |
| 823 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 824 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
| 824 ui::KeyEvent key_event1(key_event); | 825 ui::KeyEvent key_event1(key_event); |
| 825 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | 826 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); |
| 826 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | 827 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 // Expect no notifications from the new accelerators. | 1437 // Expect no notifications from the new accelerators. |
| 1437 EXPECT_TRUE(IsMessageCenterEmpty()); | 1438 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1438 | 1439 |
| 1439 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1440 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1440 // screen before we proceed testing the rest of accelerators. | 1441 // screen before we proceed testing the rest of accelerators. |
| 1441 ResetStateIfNeeded(); | 1442 ResetStateIfNeeded(); |
| 1442 } | 1443 } |
| 1443 } | 1444 } |
| 1444 | 1445 |
| 1445 } // namespace ash | 1446 } // namespace ash |
| OLD | NEW |