| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // Trigger once to show the bubble. | 337 // Trigger once to show the bubble. |
| 338 ewh->HandleAccelerator(); | 338 ewh->HandleAccelerator(); |
| 339 EXPECT_FALSE(is_idle(ewh)); | 339 EXPECT_FALSE(is_idle(ewh)); |
| 340 EXPECT_TRUE(is_ui_shown(ewh)); | 340 EXPECT_TRUE(is_ui_shown(ewh)); |
| 341 | 341 |
| 342 // Exit ash and there should be no crash | 342 // Exit ash and there should be no crash |
| 343 } | 343 } |
| 344 #endif // !defined(OS_WIN) | 344 #endif // !defined(OS_WIN) |
| 345 | 345 |
| 346 TEST_F(AcceleratorControllerTest, Register) { | 346 TEST_F(AcceleratorControllerTest, Register) { |
| 347 TestTarget target; |
| 347 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 348 TestTarget target; | 349 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 349 GetController()->Register(accelerator_a, &target); | 350 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 351 const ui::Accelerator accelerator_d(ui::VKEY_D, ui::EF_NONE); |
| 350 | 352 |
| 351 // The registered accelerator is processed. | 353 GetController()->Register( |
| 354 {accelerator_a, accelerator_b, accelerator_c, accelerator_d}, &target); |
| 355 |
| 356 // The registered accelerators are processed. |
| 352 EXPECT_TRUE(ProcessInController(accelerator_a)); | 357 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 353 EXPECT_EQ(1, target.accelerator_pressed_count()); | 358 EXPECT_TRUE(ProcessInController(accelerator_b)); |
| 359 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 360 EXPECT_TRUE(ProcessInController(accelerator_d)); |
| 361 EXPECT_EQ(4, target.accelerator_pressed_count()); |
| 354 } | 362 } |
| 355 | 363 |
| 356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 364 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 365 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 358 TestTarget target1; | 366 TestTarget target1; |
| 359 GetController()->Register(accelerator_a, &target1); | 367 GetController()->Register({accelerator_a}, &target1); |
| 368 |
| 360 TestTarget target2; | 369 TestTarget target2; |
| 361 GetController()->Register(accelerator_a, &target2); | 370 GetController()->Register({accelerator_a}, &target2); |
| 362 | 371 |
| 363 // If multiple targets are registered with the same accelerator, the target | 372 // If multiple targets are registered with the same accelerator, the target |
| 364 // registered later processes the accelerator. | 373 // registered later processes the accelerator. |
| 365 EXPECT_TRUE(ProcessInController(accelerator_a)); | 374 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 366 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 375 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 367 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 376 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 368 } | 377 } |
| 369 | 378 |
| 370 TEST_F(AcceleratorControllerTest, Unregister) { | 379 TEST_F(AcceleratorControllerTest, Unregister) { |
| 380 TestTarget target; |
| 371 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 381 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 372 TestTarget target; | |
| 373 GetController()->Register(accelerator_a, &target); | |
| 374 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 382 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 375 GetController()->Register(accelerator_b, &target); | 383 GetController()->Register({accelerator_a, accelerator_b}, &target); |
| 376 | 384 |
| 377 // Unregistering a different accelerator does not affect the other | 385 // Unregistering a different accelerator does not affect the other |
| 378 // accelerator. | 386 // accelerator. |
| 379 GetController()->Unregister(accelerator_b, &target); | 387 GetController()->Unregister(accelerator_b, &target); |
| 380 EXPECT_TRUE(ProcessInController(accelerator_a)); | 388 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 381 EXPECT_EQ(1, target.accelerator_pressed_count()); | 389 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 382 | 390 |
| 383 // The unregistered accelerator is no longer processed. | 391 // The unregistered accelerator is no longer processed. |
| 384 target.reset(); | 392 target.reset(); |
| 385 GetController()->Unregister(accelerator_a, &target); | 393 GetController()->Unregister(accelerator_a, &target); |
| 386 EXPECT_FALSE(ProcessInController(accelerator_a)); | 394 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 387 EXPECT_EQ(0, target.accelerator_pressed_count()); | 395 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 388 } | 396 } |
| 389 | 397 |
| 390 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 398 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 399 TestTarget target1; |
| 391 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 400 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 392 TestTarget target1; | |
| 393 GetController()->Register(accelerator_a, &target1); | |
| 394 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 401 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 395 GetController()->Register(accelerator_b, &target1); | 402 GetController()->Register({accelerator_a, accelerator_b}, &target1); |
| 396 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 403 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 397 TestTarget target2; | 404 TestTarget target2; |
| 398 GetController()->Register(accelerator_c, &target2); | 405 GetController()->Register({accelerator_c}, &target2); |
| 399 GetController()->UnregisterAll(&target1); | 406 GetController()->UnregisterAll(&target1); |
| 400 | 407 |
| 401 // All the accelerators registered for |target1| are no longer processed. | 408 // All the accelerators registered for |target1| are no longer processed. |
| 402 EXPECT_FALSE(ProcessInController(accelerator_a)); | 409 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 403 EXPECT_FALSE(ProcessInController(accelerator_b)); | 410 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 404 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 411 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 405 | 412 |
| 406 // UnregisterAll with a different target does not affect the other target. | 413 // UnregisterAll with a different target does not affect the other target. |
| 407 EXPECT_TRUE(ProcessInController(accelerator_c)); | 414 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 408 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 415 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 409 } | 416 } |
| 410 | 417 |
| 411 TEST_F(AcceleratorControllerTest, Process) { | 418 TEST_F(AcceleratorControllerTest, Process) { |
| 412 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 419 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 413 TestTarget target1; | 420 TestTarget target1; |
| 414 GetController()->Register(accelerator_a, &target1); | 421 GetController()->Register({accelerator_a}, &target1); |
| 415 | 422 |
| 416 // The registered accelerator is processed. | 423 // The registered accelerator is processed. |
| 417 EXPECT_TRUE(ProcessInController(accelerator_a)); | 424 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 418 EXPECT_EQ(1, target1.accelerator_pressed_count()); | 425 EXPECT_EQ(1, target1.accelerator_pressed_count()); |
| 419 | 426 |
| 420 // The non-registered accelerator is not processed. | 427 // The non-registered accelerator is not processed. |
| 421 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 428 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 422 EXPECT_FALSE(ProcessInController(accelerator_b)); | 429 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 423 } | 430 } |
| 424 | 431 |
| 425 TEST_F(AcceleratorControllerTest, IsRegistered) { | 432 TEST_F(AcceleratorControllerTest, IsRegistered) { |
| 426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 433 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 427 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); | 434 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
| 428 TestTarget target; | 435 TestTarget target; |
| 429 GetController()->Register(accelerator_a, &target); | 436 GetController()->Register({accelerator_a}, &target); |
| 430 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 437 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 438 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 432 GetController()->UnregisterAll(&target); | 439 GetController()->UnregisterAll(&target); |
| 433 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 440 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 434 } | 441 } |
| 435 | 442 |
| 436 TEST_F(AcceleratorControllerTest, WindowSnap) { | 443 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 437 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); | 444 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
| 438 WmWindow* window = WmWindow::Get(aura_window); | 445 WmWindow* window = WmWindow::Get(aura_window); |
| 439 wm::WindowState* window_state = window->GetWindowState(); | 446 wm::WindowState* window_state = window->GetWindowState(); |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 EXPECT_TRUE(IsMessageCenterEmpty()); | 1465 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1459 | 1466 |
| 1460 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1467 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1461 // screen before we proceed testing the rest of accelerators. | 1468 // screen before we proceed testing the rest of accelerators. |
| 1462 ResetStateIfNeeded(); | 1469 ResetStateIfNeeded(); |
| 1463 } | 1470 } |
| 1464 } | 1471 } |
| 1465 #endif // defined(OS_CHROMEOS) | 1472 #endif // defined(OS_CHROMEOS) |
| 1466 | 1473 |
| 1467 } // namespace ash | 1474 } // namespace ash |
| OLD | NEW |