Chromium Code Reviews| 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 347 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 348 | |
|
mfomitchev
2017/01/24 22:56:02
nit: we are adding a lot of empty lines in this fi
thanhph1
2017/01/25 20:12:37
Done.
| |
| 348 TestTarget target; | 349 TestTarget target; |
| 349 GetController()->Register(accelerator_a, &target); | 350 GetController()->Register({accelerator_a}, &target); |
| 350 | 351 |
| 351 // The registered accelerator is processed. | 352 // The registered accelerator is processed. |
| 352 EXPECT_TRUE(ProcessInController(accelerator_a)); | 353 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 353 EXPECT_EQ(1, target.accelerator_pressed_count()); | 354 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 354 } | 355 } |
| 355 | 356 |
| 356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 357 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 358 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 358 TestTarget target1; | 359 TestTarget target1; |
| 359 GetController()->Register(accelerator_a, &target1); | 360 GetController()->Register({accelerator_a}, &target1); |
| 361 | |
| 360 TestTarget target2; | 362 TestTarget target2; |
| 361 GetController()->Register(accelerator_a, &target2); | 363 GetController()->Register({accelerator_a}, &target2); |
| 362 | 364 |
| 363 // If multiple targets are registered with the same accelerator, the target | 365 // If multiple targets are registered with the same accelerator, the target |
| 364 // registered later processes the accelerator. | 366 // registered later processes the accelerator. |
| 365 EXPECT_TRUE(ProcessInController(accelerator_a)); | 367 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 366 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 368 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 367 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 369 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 368 } | 370 } |
| 369 | 371 |
| 370 TEST_F(AcceleratorControllerTest, Unregister) { | 372 TEST_F(AcceleratorControllerTest, Unregister) { |
| 373 TestTarget target; | |
| 374 | |
| 371 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 375 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); | 376 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 375 GetController()->Register(accelerator_b, &target); | 377 |
| 378 GetController()->Register({accelerator_a, accelerator_b}, &target); | |
| 376 | 379 |
| 377 // Unregistering a different accelerator does not affect the other | 380 // Unregistering a different accelerator does not affect the other |
| 378 // accelerator. | 381 // accelerator. |
| 379 GetController()->Unregister(accelerator_b, &target); | 382 GetController()->Unregister(accelerator_b, &target); |
| 380 EXPECT_TRUE(ProcessInController(accelerator_a)); | 383 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 381 EXPECT_EQ(1, target.accelerator_pressed_count()); | 384 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 382 | 385 |
| 383 // The unregistered accelerator is no longer processed. | 386 // The unregistered accelerator is no longer processed. |
| 384 target.reset(); | 387 target.reset(); |
| 385 GetController()->Unregister(accelerator_a, &target); | 388 GetController()->Unregister(accelerator_a, &target); |
| 386 EXPECT_FALSE(ProcessInController(accelerator_a)); | 389 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 387 EXPECT_EQ(0, target.accelerator_pressed_count()); | 390 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 388 } | 391 } |
| 389 | 392 |
| 390 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 393 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 394 TestTarget target1; | |
| 395 | |
| 391 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 396 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); | 397 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 395 GetController()->Register(accelerator_b, &target1); | 398 |
| 399 GetController()->Register({accelerator_a, accelerator_b}, &target1); | |
| 400 | |
| 396 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 401 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 402 | |
| 397 TestTarget target2; | 403 TestTarget target2; |
| 398 GetController()->Register(accelerator_c, &target2); | 404 GetController()->Register({accelerator_c}, &target2); |
| 405 | |
| 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); |
| 437 | |
| 430 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 438 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 439 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 432 GetController()->UnregisterAll(&target); | 440 GetController()->UnregisterAll(&target); |
| 433 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 441 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 434 } | 442 } |
| 435 | 443 |
| 436 TEST_F(AcceleratorControllerTest, WindowSnap) { | 444 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 437 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); | 445 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
| 438 WmWindow* window = WmWindow::Get(aura_window); | 446 WmWindow* window = WmWindow::Get(aura_window); |
| 439 wm::WindowState* window_state = window->GetWindowState(); | 447 wm::WindowState* window_state = window->GetWindowState(); |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 EXPECT_TRUE(IsMessageCenterEmpty()); | 1468 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1461 | 1469 |
| 1462 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1470 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1463 // screen before we proceed testing the rest of accelerators. | 1471 // screen before we proceed testing the rest of accelerators. |
| 1464 ResetStateIfNeeded(); | 1472 ResetStateIfNeeded(); |
| 1465 } | 1473 } |
| 1466 } | 1474 } |
| 1467 #endif // defined(OS_CHROMEOS) | 1475 #endif // defined(OS_CHROMEOS) |
| 1468 | 1476 |
| 1469 } // namespace ash | 1477 } // namespace ash |
| OLD | NEW |