| 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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
| 6 #include "ash/accelerators/accelerator_table.h" | 6 #include "ash/accelerators/accelerator_table.h" |
| 7 #include "ash/caps_lock_delegate.h" | 7 #include "ash/caps_lock_delegate.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/ime_control_delegate.h" | 9 #include "ash/ime_control_delegate.h" |
| 10 #include "ash/screenshot_delegate.h" | 10 #include "ash/screenshot_delegate.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 protected: | 315 protected: |
| 316 void EnableInternalDisplay() { | 316 void EnableInternalDisplay() { |
| 317 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). | 317 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). |
| 318 SetFirstDisplayAsInternalDisplay(); | 318 SetFirstDisplayAsInternalDisplay(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 static AcceleratorController* GetController(); | 321 static AcceleratorController* GetController(); |
| 322 static bool ProcessWithContext(const ui::Accelerator& accelerator); | 322 static bool ProcessWithContext(const ui::Accelerator& accelerator); |
| 323 | 323 |
| 324 // Several functions to access ExitWarningHandler (as friend). | 324 // Several functions to access ExitWarningHandler (as friend). |
| 325 static void StubForTest(ExitWarningHandler& ewh) { | 325 static void StubForTest(ExitWarningHandler* ewh) { |
| 326 ewh.stub_timers_for_test_ = true; | 326 ewh->stub_timers_for_test_ = true; |
| 327 } | 327 } |
| 328 static void SimulateTimer1Expired(ExitWarningHandler& ewh) { | 328 static void Reset(ExitWarningHandler* ewh) { |
| 329 ewh.Timer1Action(); | 329 ewh->state_ = ExitWarningHandler::IDLE; |
| 330 } | 330 } |
| 331 static void SimulateTimer2Expired(ExitWarningHandler& ewh) { | 331 static void SimulateTimer1Expired(ExitWarningHandler* ewh) { |
| 332 ewh.Timer2Action(); | 332 ewh->Timer1Action(); |
| 333 } | 333 } |
| 334 static bool is_ui_shown(ExitWarningHandler& ewh) { | 334 static void SimulateTimer2Expired(ExitWarningHandler* ewh) { |
| 335 return !!ewh.widget_; | 335 ewh->Timer2Action(); |
| 336 } | 336 } |
| 337 static bool is_idle(ExitWarningHandler& ewh) { | 337 static bool is_ui_shown(ExitWarningHandler* ewh) { |
| 338 return ewh.state_ == ExitWarningHandler::IDLE; | 338 return !!ewh->widget_; |
| 339 } | 339 } |
| 340 static bool is_exiting(ExitWarningHandler& ewh) { | 340 static bool is_idle(ExitWarningHandler* ewh) { |
| 341 return ewh.state_ == ExitWarningHandler::EXITING; | 341 return ewh->state_ == ExitWarningHandler::IDLE; |
| 342 } |
| 343 static bool is_exiting(ExitWarningHandler* ewh) { |
| 344 return ewh->state_ == ExitWarningHandler::EXITING; |
| 342 } | 345 } |
| 343 | 346 |
| 344 private: | 347 private: |
| 345 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); | 348 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); |
| 346 }; | 349 }; |
| 347 | 350 |
| 348 AcceleratorController* AcceleratorControllerTest::GetController() { | 351 AcceleratorController* AcceleratorControllerTest::GetController() { |
| 349 return Shell::GetInstance()->accelerator_controller(); | 352 return Shell::GetInstance()->accelerator_controller(); |
| 350 } | 353 } |
| 351 | 354 |
| 352 bool AcceleratorControllerTest::ProcessWithContext( | 355 bool AcceleratorControllerTest::ProcessWithContext( |
| 353 const ui::Accelerator& accelerator) { | 356 const ui::Accelerator& accelerator) { |
| 354 AcceleratorController* controller = GetController(); | 357 AcceleratorController* controller = GetController(); |
| 355 controller->context()->UpdateContext(accelerator); | 358 controller->context()->UpdateContext(accelerator); |
| 356 return controller->Process(accelerator); | 359 return controller->Process(accelerator); |
| 357 } | 360 } |
| 358 | 361 |
| 359 // Quick double press of exit key => exiting | 362 #if !defined(OS_WIN) |
| 363 // Quick double press of exit shortcut => exiting |
| 360 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { | 364 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { |
| 361 ExitWarningHandler ewh; | 365 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
| 366 ui::Accelerator release(press); |
| 367 release.set_type(ui::ET_KEY_RELEASED); |
| 368 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
| 369 ASSERT_TRUE(!!ewh); |
| 362 StubForTest(ewh); | 370 StubForTest(ewh); |
| 363 EXPECT_TRUE(is_idle(ewh)); | 371 EXPECT_TRUE(is_idle(ewh)); |
| 364 EXPECT_FALSE(is_ui_shown(ewh)); | 372 EXPECT_FALSE(is_ui_shown(ewh)); |
| 365 | 373 EXPECT_TRUE(ProcessWithContext(press)); |
| 366 ewh.HandleExitKey(true); | 374 EXPECT_FALSE(ProcessWithContext(release)); |
| 367 EXPECT_TRUE(is_ui_shown(ewh)); | 375 EXPECT_TRUE(is_ui_shown(ewh)); |
| 368 ewh.HandleExitKey(false); | 376 EXPECT_TRUE(ProcessWithContext(press)); // double press |
| 369 ewh.HandleExitKey(true); // double press | 377 EXPECT_FALSE(ProcessWithContext(release)); |
| 370 SimulateTimer1Expired(ewh); // simulate double press timer expired | 378 SimulateTimer1Expired(ewh); // simulate double press timer expired |
| 371 SimulateTimer2Expired(ewh); // simulate long hold timer expired | 379 SimulateTimer2Expired(ewh); // simulate long hold timer expired |
| 372 ewh.HandleExitKey(false); | |
| 373 EXPECT_FALSE(is_ui_shown(ewh)); | 380 EXPECT_FALSE(is_ui_shown(ewh)); |
| 374 EXPECT_TRUE(is_exiting(ewh)); | 381 EXPECT_TRUE(is_exiting(ewh)); |
| 382 Reset(ewh); |
| 375 } | 383 } |
| 376 | 384 |
| 377 // Long hold of exit key => exiting | 385 // Long hold of exit shortcut => exiting |
| 378 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) { | 386 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) { |
| 379 ExitWarningHandler ewh; | 387 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
| 388 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
| 389 ASSERT_TRUE(!!ewh); |
| 380 StubForTest(ewh); | 390 StubForTest(ewh); |
| 381 EXPECT_TRUE(is_idle(ewh)); | 391 EXPECT_TRUE(is_idle(ewh)); |
| 382 EXPECT_FALSE(is_ui_shown(ewh)); | 392 EXPECT_FALSE(is_ui_shown(ewh)); |
| 383 | 393 EXPECT_TRUE(ProcessWithContext(press)); // hold |
| 384 ewh.HandleExitKey(true); | |
| 385 EXPECT_TRUE(is_ui_shown(ewh)); | 394 EXPECT_TRUE(is_ui_shown(ewh)); |
| 386 SimulateTimer1Expired(ewh); // simulate double press timer expired | 395 SimulateTimer1Expired(ewh); // simulate double press timer expired |
| 387 SimulateTimer2Expired(ewh); // simulate long hold timer expired | 396 SimulateTimer2Expired(ewh); // simulate long hold timer expired |
| 388 ewh.HandleExitKey(false); // release after long hold | |
| 389 EXPECT_FALSE(is_ui_shown(ewh)); | 397 EXPECT_FALSE(is_ui_shown(ewh)); |
| 390 EXPECT_TRUE(is_exiting(ewh)); | 398 EXPECT_TRUE(is_exiting(ewh)); |
| 399 Reset(ewh); |
| 391 } | 400 } |
| 392 | 401 |
| 393 // Release of exit key before hold time limit => cancel | 402 // Release of exit shortcut before hold time limit => cancel |
| 394 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) { | 403 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) { |
| 395 ExitWarningHandler ewh; | 404 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
| 405 ui::Accelerator release(press); |
| 406 release.set_type(ui::ET_KEY_RELEASED); |
| 407 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
| 408 ASSERT_TRUE(!!ewh); |
| 396 StubForTest(ewh); | 409 StubForTest(ewh); |
| 397 EXPECT_TRUE(is_idle(ewh)); | 410 EXPECT_TRUE(is_idle(ewh)); |
| 398 EXPECT_FALSE(is_ui_shown(ewh)); | 411 EXPECT_FALSE(is_ui_shown(ewh)); |
| 399 | 412 EXPECT_TRUE(ProcessWithContext(press)); |
| 400 ewh.HandleExitKey(true); | |
| 401 EXPECT_TRUE(is_ui_shown(ewh)); | 413 EXPECT_TRUE(is_ui_shown(ewh)); |
| 402 SimulateTimer1Expired(ewh); // simulate double press timer expired | 414 SimulateTimer1Expired(ewh); // simulate double press timer expired |
| 403 ewh.HandleExitKey(false); // release before long hold limit | 415 EXPECT_FALSE(ProcessWithContext(release)); |
| 404 SimulateTimer2Expired(ewh); // simulate long hold timer expired | 416 SimulateTimer2Expired(ewh); // simulate long hold timer expired |
| 405 EXPECT_FALSE(is_ui_shown(ewh)); | 417 EXPECT_FALSE(is_ui_shown(ewh)); |
| 406 EXPECT_TRUE(is_idle(ewh)); | 418 EXPECT_TRUE(is_idle(ewh)); |
| 419 Reset(ewh); |
| 407 } | 420 } |
| 408 | 421 |
| 409 // Release of exit key before double press limit => cancel. | 422 // Second Press after double press time limit => cancel |
| 410 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) { | 423 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) { |
| 411 ExitWarningHandler ewh; | 424 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
| 425 ui::Accelerator release(press); |
| 426 release.set_type(ui::ET_KEY_RELEASED); |
| 427 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
| 428 ASSERT_TRUE(!!ewh); |
| 412 StubForTest(ewh); | 429 StubForTest(ewh); |
| 413 EXPECT_TRUE(is_idle(ewh)); | 430 EXPECT_TRUE(is_idle(ewh)); |
| 414 EXPECT_FALSE(is_ui_shown(ewh)); | 431 EXPECT_FALSE(is_ui_shown(ewh)); |
| 415 | 432 EXPECT_TRUE(ProcessWithContext(press)); |
| 416 ewh.HandleExitKey(true); | 433 EXPECT_FALSE(ProcessWithContext(release)); |
| 417 EXPECT_TRUE(is_ui_shown(ewh)); | 434 EXPECT_TRUE(is_ui_shown(ewh)); |
| 418 ewh.HandleExitKey(false); // release before double press limit | |
| 419 SimulateTimer1Expired(ewh); // simulate double press timer expired | 435 SimulateTimer1Expired(ewh); // simulate double press timer expired |
| 436 EXPECT_TRUE(ProcessWithContext(press)); |
| 420 SimulateTimer2Expired(ewh); // simulate long hold timer expired | 437 SimulateTimer2Expired(ewh); // simulate long hold timer expired |
| 421 EXPECT_FALSE(is_ui_shown(ewh)); | 438 EXPECT_FALSE(is_ui_shown(ewh)); |
| 422 EXPECT_TRUE(is_idle(ewh)); | 439 EXPECT_TRUE(is_idle(ewh)); |
| 440 Reset(ewh); |
| 423 } | 441 } |
| 442 #endif // !defined(OS_WIN) |
| 424 | 443 |
| 425 TEST_F(AcceleratorControllerTest, Register) { | 444 TEST_F(AcceleratorControllerTest, Register) { |
| 426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 445 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 427 TestTarget target; | 446 TestTarget target; |
| 428 GetController()->Register(accelerator_a, &target); | 447 GetController()->Register(accelerator_a, &target); |
| 429 | 448 |
| 430 // The registered accelerator is processed. | 449 // The registered accelerator is processed. |
| 431 EXPECT_TRUE(ProcessWithContext(accelerator_a)); | 450 EXPECT_TRUE(ProcessWithContext(accelerator_a)); |
| 432 EXPECT_EQ(1, target.accelerator_pressed_count()); | 451 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 433 } | 452 } |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 // ToggleDesktopFullScreen (not implemented yet on Linux) | 960 // ToggleDesktopFullScreen (not implemented yet on Linux) |
| 942 EXPECT_TRUE(ProcessWithContext( | 961 EXPECT_TRUE(ProcessWithContext( |
| 943 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN))); | 962 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN))); |
| 944 #endif // OS_LINUX | 963 #endif // OS_LINUX |
| 945 #endif // !NDEBUG | 964 #endif // !NDEBUG |
| 946 | 965 |
| 947 #if !defined(OS_WIN) | 966 #if !defined(OS_WIN) |
| 948 // Exit | 967 // Exit |
| 949 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); | 968 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
| 950 ASSERT_TRUE(!!ewh); | 969 ASSERT_TRUE(!!ewh); |
| 951 StubForTest(*ewh); | 970 StubForTest(ewh); |
| 952 EXPECT_TRUE(is_idle(*ewh)); | 971 EXPECT_TRUE(is_idle(ewh)); |
| 953 EXPECT_FALSE(is_ui_shown(*ewh)); | 972 EXPECT_FALSE(is_ui_shown(ewh)); |
| 954 EXPECT_TRUE(ProcessWithContext( | 973 EXPECT_TRUE(ProcessWithContext( |
| 955 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 974 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
| 956 EXPECT_FALSE(is_idle(*ewh)); | 975 EXPECT_FALSE(is_idle(ewh)); |
| 957 EXPECT_TRUE(is_ui_shown(*ewh)); | 976 EXPECT_TRUE(is_ui_shown(ewh)); |
| 958 SimulateTimer1Expired(*ewh); | 977 SimulateTimer1Expired(ewh); |
| 959 SimulateTimer2Expired(*ewh); | 978 SimulateTimer2Expired(ewh); |
| 960 EXPECT_FALSE(is_ui_shown(*ewh)); | 979 EXPECT_FALSE(is_ui_shown(ewh)); |
| 961 EXPECT_TRUE(is_exiting(*ewh)); | 980 EXPECT_TRUE(is_exiting(ewh)); |
| 981 Reset(ewh); |
| 962 #endif | 982 #endif |
| 963 | 983 |
| 964 // New tab | 984 // New tab |
| 965 EXPECT_TRUE(ProcessWithContext( | 985 EXPECT_TRUE(ProcessWithContext( |
| 966 ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); | 986 ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); |
| 967 | 987 |
| 968 // New incognito window | 988 // New incognito window |
| 969 EXPECT_TRUE(ProcessWithContext( | 989 EXPECT_TRUE(ProcessWithContext( |
| 970 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 990 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
| 971 | 991 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 1373 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| 1354 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 1374 EXPECT_EQ(0, delegate->handle_volume_up_count()); |
| 1355 EXPECT_TRUE(ProcessWithContext(volume_up)); | 1375 EXPECT_TRUE(ProcessWithContext(volume_up)); |
| 1356 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 1376 EXPECT_EQ(1, delegate->handle_volume_up_count()); |
| 1357 EXPECT_EQ(volume_up, delegate->last_accelerator()); | 1377 EXPECT_EQ(volume_up, delegate->last_accelerator()); |
| 1358 } | 1378 } |
| 1359 } | 1379 } |
| 1360 #endif | 1380 #endif |
| 1361 | 1381 |
| 1362 } // namespace ash | 1382 } // namespace ash |
| OLD | NEW |