diff options
author | afakhry <afakhry@chromium.org> | 2015-06-19 18:09:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-20 01:10:23 +0000 |
commit | c2b81c9fca4abc10cafdc75d2e7b4f15314e2e5b (patch) | |
tree | eb356e896584fca3c62720c57a34fe6d84f78acc /ash/accelerators/accelerator_controller_unittest.cc | |
parent | d6fad194e01aeae668c210f460630228943338c2 (diff) | |
download | chromium_src-c2b81c9fca4abc10cafdc75d2e7b4f15314e2e5b.zip chromium_src-c2b81c9fca4abc10cafdc75d2e7b4f15314e2e5b.tar.gz chromium_src-c2b81c9fca4abc10cafdc75d2e7b4f15314e2e5b.tar.bz2 |
Deprecating high-conflict accelerators
This CL designs a framework for deprecated accelerators.
In this CL we deprecate the following accelerators:
- Lock Screen: Ctrl+Shift+L --> Search+L
- Task Manager: Shift+Esc --> Search+Esc
The old accelerators are still enabled, but the user is shown a
notification message telling him about the new accelerator.
UMA stats are recorded for both old and new accelerators.
Keyboard overlay has been updated.
BUG=492454, 486198, 498565, 405317
TEST=manually, ash_unittests --gtest_filter=DeprecatedAcceleratorTester.*,
ash_unittests --gtest_filter=AcceleratorTableTest.CheckDeprecatedAccelerators
Review URL: https://codereview.chromium.org/1177773002
Cr-Commit-Position: refs/heads/master@{#335410}
Diffstat (limited to 'ash/accelerators/accelerator_controller_unittest.cc')
-rw-r--r-- | ash/accelerators/accelerator_controller_unittest.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index 371fcc2..ac4131d 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -37,6 +37,7 @@ #include "ui/events/event_processor.h" #include "ui/events/test/event_generator.h" #include "ui/gfx/screen.h" +#include "ui/message_center/message_center.h" #include "ui/views/widget/widget.h" #if defined(USE_X11) @@ -1408,4 +1409,97 @@ TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) { } } +#if defined(OS_CHROMEOS) +namespace { + +// defines a class to test the behavior of deprecated accelerators. +class DeprecatedAcceleratorTester : public AcceleratorControllerTest { + public: + DeprecatedAcceleratorTester() {} + ~DeprecatedAcceleratorTester() override {} + + ui::Accelerator CreateAccelerator(const AcceleratorData& data) const { + ui::Accelerator result(data.keycode, data.modifiers); + result.set_type(data.trigger_on_press ? ui::ET_KEY_PRESSED + : ui::ET_KEY_RELEASED); + return result; + } + + void ResetStateIfNeeded() { + Shell* shell = Shell::GetInstance(); + if (shell->session_state_delegate()->IsScreenLocked() || + shell->session_state_delegate()->IsUserSessionBlocked()) { + UnblockUserSession(); + } + } + + bool ContainsDeprecatedAcceleratorNotification() const { + return nullptr != + message_center()->FindVisibleNotificationById( + kDeprecatedAcceleratorNotificationId); + } + + bool IsMessageCenterEmpty() const { + return message_center()->GetVisibleNotifications().empty(); + } + + void RemoveAllNotifications() const { + message_center()->RemoveAllNotifications(false); + } + + message_center::MessageCenter* message_center() const { + return message_center::MessageCenter::Get(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); +}; + +} // namespace + +TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) { + for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { + const DeprecatedAcceleratorData& data = kDeprecatedAccelerators[i]; + + EXPECT_TRUE(IsMessageCenterEmpty()); + + ui::Accelerator deprecated_accelerator = + CreateAccelerator(data.deprecated_accelerator); + if (data.deprecated_enabled) + EXPECT_TRUE(ProcessInController(deprecated_accelerator)); + else + EXPECT_FALSE(ProcessInController(deprecated_accelerator)); + + // We expect to see a notification in the message center. + EXPECT_TRUE(ContainsDeprecatedAcceleratorNotification()); + RemoveAllNotifications(); + + // If the action is LOCK_SCREEN, we must reset the state by unlocking the + // screen before we proceed testing the rest of accelerators. + ResetStateIfNeeded(); + } +} + +TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) { + // Add below the new accelerators that replaced the deprecated ones (if any). + const AcceleratorData kNewAccelerators[] = { + { true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN }, + { true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER }, + }; + + EXPECT_TRUE(IsMessageCenterEmpty()); + + for (auto data : kNewAccelerators) { + EXPECT_TRUE(ProcessInController(CreateAccelerator(data))); + + // Expect no notifications from the new accelerators. + EXPECT_TRUE(IsMessageCenterEmpty()); + + // If the action is LOCK_SCREEN, we must reset the state by unlocking the + // screen before we proceed testing the rest of accelerators. + ResetStateIfNeeded(); + } +} +#endif // defined(OS_CHROMEOS) + } // namespace ash |