Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 14587007: Unify and change logout/sleep/lock shortcuts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: review Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/accelerators/accelerator_table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
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).
325 static void StubForTest(ExitWarningHandler& ewh) {
326 ewh.stub_timers_for_test_ = true;
327 }
328 static void SimulateTimer1Expired(ExitWarningHandler& ewh) {
329 ewh.Timer1Action();
330 }
331 static void SimulateTimer2Expired(ExitWarningHandler& ewh) {
332 ewh.Timer2Action();
333 }
334 static bool is_ui_shown(ExitWarningHandler& ewh) {
335 return !!ewh.widget_;
336 }
337 static bool is_idle(ExitWarningHandler& ewh) {
338 return ewh.state_ == ExitWarningHandler::IDLE;
339 }
340 static bool is_exiting(ExitWarningHandler& ewh) {
341 return ewh.state_ == ExitWarningHandler::EXITING;
342 }
343
324 private: 344 private:
325 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); 345 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
326 }; 346 };
327 347
328 AcceleratorController* AcceleratorControllerTest::GetController() { 348 AcceleratorController* AcceleratorControllerTest::GetController() {
329 return Shell::GetInstance()->accelerator_controller(); 349 return Shell::GetInstance()->accelerator_controller();
330 } 350 }
331 351
332 bool AcceleratorControllerTest::ProcessWithContext( 352 bool AcceleratorControllerTest::ProcessWithContext(
333 const ui::Accelerator& accelerator) { 353 const ui::Accelerator& accelerator) {
334 AcceleratorController* controller = GetController(); 354 AcceleratorController* controller = GetController();
335 controller->context()->UpdateContext(accelerator); 355 controller->context()->UpdateContext(accelerator);
336 return controller->Process(accelerator); 356 return controller->Process(accelerator);
337 } 357 }
338 358
359 // Quick double press of exit key => exiting
360 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) {
361 ExitWarningHandler ewh;
362 StubForTest(ewh);
363 EXPECT_TRUE(is_idle(ewh));
364 EXPECT_FALSE(is_ui_shown(ewh));
365
366 ewh.HandleExitKey(true);
367 EXPECT_TRUE(is_ui_shown(ewh));
368 ewh.HandleExitKey(false);
369 ewh.HandleExitKey(true); // double press
370 SimulateTimer1Expired(ewh); // simulate double press timer expired
371 SimulateTimer2Expired(ewh); // simulate long hold timer expired
372 ewh.HandleExitKey(false);
373 EXPECT_FALSE(is_ui_shown(ewh));
374 EXPECT_TRUE(is_exiting(ewh));
375 }
376
377 // Long hold of exit key => exiting
378 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) {
379 ExitWarningHandler ewh;
380 StubForTest(ewh);
381 EXPECT_TRUE(is_idle(ewh));
382 EXPECT_FALSE(is_ui_shown(ewh));
383
384 ewh.HandleExitKey(true);
385 EXPECT_TRUE(is_ui_shown(ewh));
386 SimulateTimer1Expired(ewh); // simulate double press timer expired
387 SimulateTimer2Expired(ewh); // simulate long hold timer expired
388 ewh.HandleExitKey(false); // release after long hold
389 EXPECT_FALSE(is_ui_shown(ewh));
390 EXPECT_TRUE(is_exiting(ewh));
391 }
392
393 // Release of exit key before hold time limit => cancel
394 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) {
395 ExitWarningHandler ewh;
396 StubForTest(ewh);
397 EXPECT_TRUE(is_idle(ewh));
398 EXPECT_FALSE(is_ui_shown(ewh));
399
400 ewh.HandleExitKey(true);
401 EXPECT_TRUE(is_ui_shown(ewh));
402 SimulateTimer1Expired(ewh); // simulate double press timer expired
403 ewh.HandleExitKey(false); // release before long hold limit
404 SimulateTimer2Expired(ewh); // simulate long hold timer expired
405 EXPECT_FALSE(is_ui_shown(ewh));
406 EXPECT_TRUE(is_idle(ewh));
407 }
408
409 // Release of exit key before double press limit => cancel.
410 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) {
411 ExitWarningHandler ewh;
412 StubForTest(ewh);
413 EXPECT_TRUE(is_idle(ewh));
414 EXPECT_FALSE(is_ui_shown(ewh));
415
416 ewh.HandleExitKey(true);
417 EXPECT_TRUE(is_ui_shown(ewh));
418 ewh.HandleExitKey(false); // release before double press limit
419 SimulateTimer1Expired(ewh); // simulate double press timer expired
420 SimulateTimer2Expired(ewh); // simulate long hold timer expired
421 EXPECT_FALSE(is_ui_shown(ewh));
422 EXPECT_TRUE(is_idle(ewh));
423 }
424
339 TEST_F(AcceleratorControllerTest, Register) { 425 TEST_F(AcceleratorControllerTest, Register) {
340 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
341 TestTarget target; 427 TestTarget target;
342 GetController()->Register(accelerator_a, &target); 428 GetController()->Register(accelerator_a, &target);
343 429
344 // The registered accelerator is processed. 430 // The registered accelerator is processed.
345 EXPECT_TRUE(ProcessWithContext(accelerator_a)); 431 EXPECT_TRUE(ProcessWithContext(accelerator_a));
346 EXPECT_EQ(1, target.accelerator_pressed_count()); 432 EXPECT_EQ(1, target.accelerator_pressed_count());
347 } 433 }
348 434
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))); 939 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)));
854 #if !defined(OS_LINUX) 940 #if !defined(OS_LINUX)
855 // ToggleDesktopFullScreen (not implemented yet on Linux) 941 // ToggleDesktopFullScreen (not implemented yet on Linux)
856 EXPECT_TRUE(ProcessWithContext( 942 EXPECT_TRUE(ProcessWithContext(
857 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN))); 943 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN)));
858 #endif // OS_LINUX 944 #endif // OS_LINUX
859 #endif // !NDEBUG 945 #endif // !NDEBUG
860 946
861 #if !defined(OS_WIN) 947 #if !defined(OS_WIN)
862 // Exit 948 // Exit
949 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
950 ASSERT_TRUE(!!ewh);
951 StubForTest(*ewh);
952 EXPECT_TRUE(is_idle(*ewh));
953 EXPECT_FALSE(is_ui_shown(*ewh));
863 EXPECT_TRUE(ProcessWithContext( 954 EXPECT_TRUE(ProcessWithContext(
864 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 955 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
956 EXPECT_FALSE(is_idle(*ewh));
957 EXPECT_TRUE(is_ui_shown(*ewh));
958 SimulateTimer1Expired(*ewh);
959 SimulateTimer2Expired(*ewh);
960 EXPECT_FALSE(is_ui_shown(*ewh));
961 EXPECT_TRUE(is_exiting(*ewh));
865 #endif 962 #endif
866 963
867 // New tab 964 // New tab
868 EXPECT_TRUE(ProcessWithContext( 965 EXPECT_TRUE(ProcessWithContext(
869 ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); 966 ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN)));
870 967
871 // New incognito window 968 // New incognito window
872 EXPECT_TRUE(ProcessWithContext( 969 EXPECT_TRUE(ProcessWithContext(
873 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 970 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
874 971
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 EXPECT_EQ(volume_down, delegate->last_accelerator()); 1341 EXPECT_EQ(volume_down, delegate->last_accelerator());
1245 EXPECT_EQ(0, delegate->handle_volume_up_count()); 1342 EXPECT_EQ(0, delegate->handle_volume_up_count());
1246 EXPECT_TRUE(ProcessWithContext(volume_up)); 1343 EXPECT_TRUE(ProcessWithContext(volume_up));
1247 EXPECT_EQ(1, delegate->handle_volume_up_count()); 1344 EXPECT_EQ(1, delegate->handle_volume_up_count());
1248 EXPECT_EQ(volume_up, delegate->last_accelerator()); 1345 EXPECT_EQ(volume_up, delegate->last_accelerator());
1249 } 1346 }
1250 } 1347 }
1251 #endif 1348 #endif
1252 1349
1253 } // namespace ash 1350 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/accelerators/accelerator_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698