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

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
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 void ExitWarningHandlerTestDoublePress();
325 void ExitWarningHandlerTestLongHold();
326 void ExitWarningHandlerTestEarlyRelease();
327 void ExitWarningHandlerTestQuickRelease();
328
324 private: 329 private:
325 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); 330 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
326 }; 331 };
327 332
328 AcceleratorController* AcceleratorControllerTest::GetController() { 333 AcceleratorController* AcceleratorControllerTest::GetController() {
329 return Shell::GetInstance()->accelerator_controller(); 334 return Shell::GetInstance()->accelerator_controller();
330 } 335 }
331 336
332 bool AcceleratorControllerTest::ProcessWithContext( 337 bool AcceleratorControllerTest::ProcessWithContext(
333 const ui::Accelerator& accelerator) { 338 const ui::Accelerator& accelerator) {
334 AcceleratorController* controller = GetController(); 339 AcceleratorController* controller = GetController();
335 controller->context()->UpdateContext(accelerator); 340 controller->context()->UpdateContext(accelerator);
336 return controller->Process(accelerator); 341 return controller->Process(accelerator);
337 } 342 }
338 343
344 // Quick double press of exit key => exiting
345 void AcceleratorControllerTest::ExitWarningHandlerTestDoublePress() {
346 ExitWarningHandler ewh;
347 ewh.StubTimersForTest();
348 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
349 EXPECT_FALSE(ewh.ui_shown());
350
351 ewh.HandleExitKey(true);
352 EXPECT_TRUE(ewh.ui_shown());
353 ewh.HandleExitKey(false);
354 ewh.HandleExitKey(true); // double press
355 ewh.Timer1Action(); // simulate double press timer expired
356 ewh.Timer2Action(); // simulate long hold timer expired
357 ewh.HandleExitKey(false);
358 EXPECT_FALSE(ewh.ui_shown());
359 EXPECT_EQ(ExitWarningHandler::EXITING, ewh.state());
360 }
361
362 // Long hold of exit key => exiting
363 void AcceleratorControllerTest::ExitWarningHandlerTestLongHold() {
364 ExitWarningHandler ewh;
365 ewh.StubTimersForTest();
366 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
367 EXPECT_FALSE(ewh.ui_shown());
368
369 ewh.HandleExitKey(true);
370 EXPECT_TRUE(ewh.ui_shown());
371 ewh.Timer1Action(); // simulate double press timer expired
372 ewh.Timer2Action(); // simulate long hold timer expired
373 ewh.HandleExitKey(false); // release after long hold
374 EXPECT_FALSE(ewh.ui_shown());
375 EXPECT_EQ(ExitWarningHandler::EXITING, ewh.state());
376 }
377
378 // Release of exit key before hold time limit => cancel
379 void AcceleratorControllerTest::ExitWarningHandlerTestEarlyRelease() {
380 ExitWarningHandler ewh;
381 ewh.StubTimersForTest();
382 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
383 EXPECT_FALSE(ewh.ui_shown());
384
385 ewh.HandleExitKey(true);
386 EXPECT_TRUE(ewh.ui_shown());
387 ewh.Timer1Action(); // simulate double press timer expired
388 ewh.HandleExitKey(false); // release before long hold limit
389 ewh.Timer2Action(); // simulate long hold timer expired
390 EXPECT_FALSE(ewh.ui_shown());
391 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
392 }
393
394 // Release of exit key before double press limit => cancel.
395 void AcceleratorControllerTest::ExitWarningHandlerTestQuickRelease() {
396 ExitWarningHandler ewh;
397 ewh.StubTimersForTest();
398 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
399 EXPECT_FALSE(ewh.ui_shown());
400
401 ewh.HandleExitKey(true);
402 EXPECT_TRUE(ewh.ui_shown());
403 ewh.HandleExitKey(false); // release before double press limit
404 ewh.Timer1Action(); // simulate double press timer expired
405 ewh.Timer2Action(); // simulate long hold timer expired
406 EXPECT_FALSE(ewh.ui_shown());
407 EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state());
408 }
409
410 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) {
411 ExitWarningHandlerTestDoublePress();
sky 2013/05/14 17:10:05 The typical pattern is to put the assertions in yo
sschmitz 2013/05/14 21:36:43 Done. Due to the need of friendship to ExitWarning
412 }
413
414 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) {
415 ExitWarningHandlerTestLongHold();
416 }
417
418 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) {
419 ExitWarningHandlerTestEarlyRelease();
420 }
421
422 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) {
423 ExitWarningHandlerTestQuickRelease();
424 }
425
339 TEST_F(AcceleratorControllerTest, Register) { 426 TEST_F(AcceleratorControllerTest, Register) {
340 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 427 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
341 TestTarget target; 428 TestTarget target;
342 GetController()->Register(accelerator_a, &target); 429 GetController()->Register(accelerator_a, &target);
343 430
344 // The registered accelerator is processed. 431 // The registered accelerator is processed.
345 EXPECT_TRUE(ProcessWithContext(accelerator_a)); 432 EXPECT_TRUE(ProcessWithContext(accelerator_a));
346 EXPECT_EQ(1, target.accelerator_pressed_count()); 433 EXPECT_EQ(1, target.accelerator_pressed_count());
347 } 434 }
348 435
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 EXPECT_EQ(volume_down, delegate->last_accelerator()); 1331 EXPECT_EQ(volume_down, delegate->last_accelerator());
1245 EXPECT_EQ(0, delegate->handle_volume_up_count()); 1332 EXPECT_EQ(0, delegate->handle_volume_up_count());
1246 EXPECT_TRUE(ProcessWithContext(volume_up)); 1333 EXPECT_TRUE(ProcessWithContext(volume_up));
1247 EXPECT_EQ(1, delegate->handle_volume_up_count()); 1334 EXPECT_EQ(1, delegate->handle_volume_up_count());
1248 EXPECT_EQ(volume_up, delegate->last_accelerator()); 1335 EXPECT_EQ(volume_up, delegate->last_accelerator());
1249 } 1336 }
1250 } 1337 }
1251 #endif 1338 #endif
1252 1339
1253 } // namespace ash 1340 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698