Chromium Code Reviews| Index: ash/accelerators/accelerator_controller_unittest.cc |
| diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc |
| index 7ef53ff0d71377354a82e9161f8eb2c60918acc7..f21326072baec3cd41248b4a898f3de79e65c1bd 100644 |
| --- a/ash/accelerators/accelerator_controller_unittest.cc |
| +++ b/ash/accelerators/accelerator_controller_unittest.cc |
| @@ -321,6 +321,11 @@ class AcceleratorControllerTest : public test::AshTestBase { |
| static AcceleratorController* GetController(); |
| static bool ProcessWithContext(const ui::Accelerator& accelerator); |
| + void ExitWarningHandlerTestDoublePress(); |
| + void ExitWarningHandlerTestLongHold(); |
| + void ExitWarningHandlerTestEarlyRelease(); |
| + void ExitWarningHandlerTestQuickRelease(); |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); |
| }; |
| @@ -336,6 +341,88 @@ bool AcceleratorControllerTest::ProcessWithContext( |
| return controller->Process(accelerator); |
| } |
| +// Quick double press of exit key => exiting |
| +void AcceleratorControllerTest::ExitWarningHandlerTestDoublePress() { |
| + ExitWarningHandler ewh; |
| + ewh.StubTimersForTest(); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + |
| + ewh.HandleExitKey(true); |
| + EXPECT_TRUE(ewh.ui_shown()); |
| + ewh.HandleExitKey(false); |
| + ewh.HandleExitKey(true); // double press |
| + ewh.Timer1Action(); // simulate double press timer expired |
| + ewh.Timer2Action(); // simulate long hold timer expired |
| + ewh.HandleExitKey(false); |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + EXPECT_EQ(ExitWarningHandler::EXITING, ewh.state()); |
| +} |
| + |
| +// Long hold of exit key => exiting |
| +void AcceleratorControllerTest::ExitWarningHandlerTestLongHold() { |
| + ExitWarningHandler ewh; |
| + ewh.StubTimersForTest(); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + |
| + ewh.HandleExitKey(true); |
| + EXPECT_TRUE(ewh.ui_shown()); |
| + ewh.Timer1Action(); // simulate double press timer expired |
| + ewh.Timer2Action(); // simulate long hold timer expired |
| + ewh.HandleExitKey(false); // release after long hold |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + EXPECT_EQ(ExitWarningHandler::EXITING, ewh.state()); |
| +} |
| + |
| +// Release of exit key before hold time limit => cancel |
| +void AcceleratorControllerTest::ExitWarningHandlerTestEarlyRelease() { |
| + ExitWarningHandler ewh; |
| + ewh.StubTimersForTest(); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + |
| + ewh.HandleExitKey(true); |
| + EXPECT_TRUE(ewh.ui_shown()); |
| + ewh.Timer1Action(); // simulate double press timer expired |
| + ewh.HandleExitKey(false); // release before long hold limit |
| + ewh.Timer2Action(); // simulate long hold timer expired |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| +} |
| + |
| +// Release of exit key before double press limit => cancel. |
| +void AcceleratorControllerTest::ExitWarningHandlerTestQuickRelease() { |
| + ExitWarningHandler ewh; |
| + ewh.StubTimersForTest(); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + |
| + ewh.HandleExitKey(true); |
| + EXPECT_TRUE(ewh.ui_shown()); |
| + ewh.HandleExitKey(false); // release before double press limit |
| + ewh.Timer1Action(); // simulate double press timer expired |
| + ewh.Timer2Action(); // simulate long hold timer expired |
| + EXPECT_FALSE(ewh.ui_shown()); |
| + EXPECT_EQ(ExitWarningHandler::IDLE, ewh.state()); |
| +} |
| + |
| +TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { |
| + 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
|
| +} |
| + |
| +TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) { |
| + ExitWarningHandlerTestLongHold(); |
| +} |
| + |
| +TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) { |
| + ExitWarningHandlerTestEarlyRelease(); |
| +} |
| + |
| +TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) { |
| + ExitWarningHandlerTestQuickRelease(); |
| +} |
| + |
| TEST_F(AcceleratorControllerTest, Register) { |
| const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| TestTarget target; |