| 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/ime_control_delegate.h" | 10 #include "ash/common/ime_control_delegate.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 ewh->HandleAccelerator(); | 336 ewh->HandleAccelerator(); |
| 337 EXPECT_FALSE(is_idle(ewh)); | 337 EXPECT_FALSE(is_idle(ewh)); |
| 338 EXPECT_TRUE(is_ui_shown(ewh)); | 338 EXPECT_TRUE(is_ui_shown(ewh)); |
| 339 | 339 |
| 340 // Exit ash and there should be no crash | 340 // Exit ash and there should be no crash |
| 341 } | 341 } |
| 342 #endif // !defined(OS_WIN) | 342 #endif // !defined(OS_WIN) |
| 343 | 343 |
| 344 TEST_F(AcceleratorControllerTest, Register) { | 344 TEST_F(AcceleratorControllerTest, Register) { |
| 345 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 345 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 346 |
| 347 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 346 TestTarget target; | 348 TestTarget target; |
| 347 GetController()->Register(accelerator_a, &target); | 349 GetController()->Register(accelerators, &target); |
| 348 | 350 |
| 349 // The registered accelerator is processed. | 351 // The registered accelerator is processed. |
| 350 EXPECT_TRUE(ProcessInController(accelerator_a)); | 352 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 351 EXPECT_EQ(1, target.accelerator_pressed_count()); | 353 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 352 } | 354 } |
| 353 | 355 |
| 354 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
| 355 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 358 const std::vector<ui::Accelerator>& accelerators = {accelerator_a}; |
| 359 |
| 356 TestTarget target1; | 360 TestTarget target1; |
| 357 GetController()->Register(accelerator_a, &target1); | 361 GetController()->Register(accelerators, &target1); |
| 362 |
| 358 TestTarget target2; | 363 TestTarget target2; |
| 359 GetController()->Register(accelerator_a, &target2); | 364 GetController()->Register(accelerators, &target2); |
| 360 | 365 |
| 361 // If multiple targets are registered with the same accelerator, the target | 366 // If multiple targets are registered with the same accelerator, the target |
| 362 // registered later processes the accelerator. | 367 // registered later processes the accelerator. |
| 363 EXPECT_TRUE(ProcessInController(accelerator_a)); | 368 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 364 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 369 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 365 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 370 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 366 } | 371 } |
| 367 | 372 |
| 368 TEST_F(AcceleratorControllerTest, Unregister) { | 373 TEST_F(AcceleratorControllerTest, Unregister) { |
| 374 std::vector<ui::Accelerator> ui_accelerators; |
| 375 TestTarget target; |
| 376 |
| 369 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 377 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 370 TestTarget target; | |
| 371 GetController()->Register(accelerator_a, &target); | |
| 372 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 378 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 373 GetController()->Register(accelerator_b, &target); | 379 const std::vector<ui::Accelerator>& accelerators = {accelerator_a, |
| 380 accelerator_b}; |
| 381 |
| 382 GetController()->Register(accelerators, &target); |
| 374 | 383 |
| 375 // Unregistering a different accelerator does not affect the other | 384 // Unregistering a different accelerator does not affect the other |
| 376 // accelerator. | 385 // accelerator. |
| 377 GetController()->Unregister(accelerator_b, &target); | 386 GetController()->Unregister(accelerator_b, &target); |
| 378 EXPECT_TRUE(ProcessInController(accelerator_a)); | 387 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 379 EXPECT_EQ(1, target.accelerator_pressed_count()); | 388 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 380 | 389 |
| 381 // The unregistered accelerator is no longer processed. | 390 // The unregistered accelerator is no longer processed. |
| 382 target.reset(); | 391 target.reset(); |
| 383 GetController()->Unregister(accelerator_a, &target); | 392 GetController()->Unregister(accelerator_a, &target); |
| 384 EXPECT_FALSE(ProcessInController(accelerator_a)); | 393 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 385 EXPECT_EQ(0, target.accelerator_pressed_count()); | 394 EXPECT_EQ(0, target.accelerator_pressed_count()); |
| 386 } | 395 } |
| 387 | 396 |
| 388 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 397 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
| 398 TestTarget target1; |
| 399 |
| 389 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 400 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 390 TestTarget target1; | |
| 391 GetController()->Register(accelerator_a, &target1); | |
| 392 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 401 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 393 GetController()->Register(accelerator_b, &target1); | 402 const std::vector<ui::Accelerator> accelerators = {accelerator_a, |
| 403 accelerator_b}; |
| 404 |
| 405 GetController()->Register(accelerators, &target1); |
| 406 |
| 394 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 407 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
| 408 |
| 409 const std::vector<ui::Accelerator> accelerators_2 = {accelerator_c}; |
| 395 TestTarget target2; | 410 TestTarget target2; |
| 396 GetController()->Register(accelerator_c, &target2); | 411 GetController()->Register(accelerators_2, &target2); |
| 412 |
| 397 GetController()->UnregisterAll(&target1); | 413 GetController()->UnregisterAll(&target1); |
| 398 | 414 |
| 399 // All the accelerators registered for |target1| are no longer processed. | 415 // All the accelerators registered for |target1| are no longer processed. |
| 400 EXPECT_FALSE(ProcessInController(accelerator_a)); | 416 EXPECT_FALSE(ProcessInController(accelerator_a)); |
| 401 EXPECT_FALSE(ProcessInController(accelerator_b)); | 417 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 402 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 418 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
| 403 | 419 |
| 404 // UnregisterAll with a different target does not affect the other target. | 420 // UnregisterAll with a different target does not affect the other target. |
| 405 EXPECT_TRUE(ProcessInController(accelerator_c)); | 421 EXPECT_TRUE(ProcessInController(accelerator_c)); |
| 406 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 422 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
| 407 } | 423 } |
| 408 | 424 |
| 409 TEST_F(AcceleratorControllerTest, Process) { | 425 TEST_F(AcceleratorControllerTest, Process) { |
| 410 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 427 const std::vector<ui::Accelerator> accelerators = {accelerator_a}; |
| 411 TestTarget target1; | 428 TestTarget target1; |
| 412 GetController()->Register(accelerator_a, &target1); | 429 GetController()->Register(accelerators, &target1); |
| 413 | 430 |
| 414 // The registered accelerator is processed. | 431 // The registered accelerator is processed. |
| 415 EXPECT_TRUE(ProcessInController(accelerator_a)); | 432 EXPECT_TRUE(ProcessInController(accelerator_a)); |
| 416 EXPECT_EQ(1, target1.accelerator_pressed_count()); | 433 EXPECT_EQ(1, target1.accelerator_pressed_count()); |
| 417 | 434 |
| 418 // The non-registered accelerator is not processed. | 435 // The non-registered accelerator is not processed. |
| 419 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 436 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 420 EXPECT_FALSE(ProcessInController(accelerator_b)); | 437 EXPECT_FALSE(ProcessInController(accelerator_b)); |
| 421 } | 438 } |
| 422 | 439 |
| 423 TEST_F(AcceleratorControllerTest, IsRegistered) { | 440 TEST_F(AcceleratorControllerTest, IsRegistered) { |
| 424 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 441 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 425 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); | 442 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
| 426 TestTarget target; | 443 TestTarget target; |
| 427 GetController()->Register(accelerator_a, &target); | 444 const std::vector<ui::Accelerator> accelerators = {accelerator_a}; |
| 445 GetController()->Register(accelerators, &target); |
| 446 |
| 428 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 447 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
| 429 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 448 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 430 GetController()->UnregisterAll(&target); | 449 GetController()->UnregisterAll(&target); |
| 431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 450 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 432 } | 451 } |
| 433 | 452 |
| 434 TEST_F(AcceleratorControllerTest, WindowSnap) { | 453 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 435 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); | 454 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
| 436 WmWindow* window = mus::WmWindowMus::Get(aura_window); | 455 WmWindow* window = mus::WmWindowMus::Get(aura_window); |
| 437 wm::WindowState* window_state = window->GetWindowState(); | 456 wm::WindowState* window_state = window->GetWindowState(); |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 EXPECT_TRUE(IsMessageCenterEmpty()); | 1423 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1405 | 1424 |
| 1406 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1425 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1407 // screen before we proceed testing the rest of accelerators. | 1426 // screen before we proceed testing the rest of accelerators. |
| 1408 ResetStateIfNeeded(); | 1427 ResetStateIfNeeded(); |
| 1409 } | 1428 } |
| 1410 } | 1429 } |
| 1411 #endif // defined(OS_CHROMEOS) | 1430 #endif // defined(OS_CHROMEOS) |
| 1412 | 1431 |
| 1413 } // namespace ash | 1432 } // namespace ash |
| OLD | NEW |