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

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
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/accelerators/accelerator_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..292cc3eafdc1800de765cc20cef1369f93316834 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -321,6 +321,26 @@ class AcceleratorControllerTest : public test::AshTestBase {
static AcceleratorController* GetController();
static bool ProcessWithContext(const ui::Accelerator& accelerator);
+ // Several functions to access ExitWarningHandler (as friend).
+ static void StubForTest(ExitWarningHandler& ewh) {
+ ewh.stub_timers_for_test_ = true;
+ }
+ static void SimulateTimer1Expired(ExitWarningHandler& ewh) {
+ ewh.Timer1Action();
+ }
+ static void SimulateTimer2Expired(ExitWarningHandler& ewh) {
+ ewh.Timer2Action();
+ }
+ static bool is_ui_shown(ExitWarningHandler& ewh) {
+ return !!ewh.widget_;
+ }
+ static bool is_idle(ExitWarningHandler& ewh) {
+ return ewh.state_ == ExitWarningHandler::IDLE;
+ }
+ static bool is_exiting(ExitWarningHandler& ewh) {
+ return ewh.state_ == ExitWarningHandler::EXITING;
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
};
@@ -336,6 +356,72 @@ bool AcceleratorControllerTest::ProcessWithContext(
return controller->Process(accelerator);
}
+// Quick double press of exit key => exiting
+TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) {
+ ExitWarningHandler ewh;
+ StubForTest(ewh);
+ EXPECT_TRUE(is_idle(ewh));
+ EXPECT_FALSE(is_ui_shown(ewh));
+
+ ewh.HandleExitKey(true);
+ EXPECT_TRUE(is_ui_shown(ewh));
+ ewh.HandleExitKey(false);
+ ewh.HandleExitKey(true); // double press
+ SimulateTimer1Expired(ewh); // simulate double press timer expired
+ SimulateTimer2Expired(ewh); // simulate long hold timer expired
+ ewh.HandleExitKey(false);
+ EXPECT_FALSE(is_ui_shown(ewh));
+ EXPECT_TRUE(is_exiting(ewh));
+}
+
+// Long hold of exit key => exiting
+TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestLongHold) {
+ ExitWarningHandler ewh;
+ StubForTest(ewh);
+ EXPECT_TRUE(is_idle(ewh));
+ EXPECT_FALSE(is_ui_shown(ewh));
+
+ ewh.HandleExitKey(true);
+ EXPECT_TRUE(is_ui_shown(ewh));
+ SimulateTimer1Expired(ewh); // simulate double press timer expired
+ SimulateTimer2Expired(ewh); // simulate long hold timer expired
+ ewh.HandleExitKey(false); // release after long hold
+ EXPECT_FALSE(is_ui_shown(ewh));
+ EXPECT_TRUE(is_exiting(ewh));
+}
+
+// Release of exit key before hold time limit => cancel
+TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestEarlyRelease) {
+ ExitWarningHandler ewh;
+ StubForTest(ewh);
+ EXPECT_TRUE(is_idle(ewh));
+ EXPECT_FALSE(is_ui_shown(ewh));
+
+ ewh.HandleExitKey(true);
+ EXPECT_TRUE(is_ui_shown(ewh));
+ SimulateTimer1Expired(ewh); // simulate double press timer expired
+ ewh.HandleExitKey(false); // release before long hold limit
+ SimulateTimer2Expired(ewh); // simulate long hold timer expired
+ EXPECT_FALSE(is_ui_shown(ewh));
+ EXPECT_TRUE(is_idle(ewh));
+}
+
+// Release of exit key before double press limit => cancel.
+TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestQuickRelease) {
+ ExitWarningHandler ewh;
+ StubForTest(ewh);
+ EXPECT_TRUE(is_idle(ewh));
+ EXPECT_FALSE(is_ui_shown(ewh));
+
+ ewh.HandleExitKey(true);
+ EXPECT_TRUE(is_ui_shown(ewh));
+ ewh.HandleExitKey(false); // release before double press limit
+ SimulateTimer1Expired(ewh); // simulate double press timer expired
+ SimulateTimer2Expired(ewh); // simulate long hold timer expired
+ EXPECT_FALSE(is_ui_shown(ewh));
+ EXPECT_TRUE(is_idle(ewh));
+}
+
TEST_F(AcceleratorControllerTest, Register) {
const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
TestTarget target;
@@ -860,8 +946,19 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
#if !defined(OS_WIN)
// Exit
+ ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
+ ASSERT_TRUE(!!ewh);
+ StubForTest(*ewh);
+ EXPECT_TRUE(is_idle(*ewh));
+ EXPECT_FALSE(is_ui_shown(*ewh));
EXPECT_TRUE(ProcessWithContext(
ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
+ EXPECT_FALSE(is_idle(*ewh));
+ EXPECT_TRUE(is_ui_shown(*ewh));
+ SimulateTimer1Expired(*ewh);
+ SimulateTimer2Expired(*ewh);
+ EXPECT_FALSE(is_ui_shown(*ewh));
+ EXPECT_TRUE(is_exiting(*ewh));
#endif
// New tab
« 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