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

Unified 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 side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698