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

Unified Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 1177773002: Deprecating high-conflict accelerators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted whitespace from generated_resources.grd Created 5 years, 6 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 371fcc265021094d6841f2fffa0bdd2a14eaefbe..283be8dcf1a8e262bd85b31d2fdd90e88b0f957a 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,86 @@ TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) {
}
}
+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));
+
+ // Whether the deprecated accelerator is still enabled or not, if
+ // |should_show_notification| is true, then we expect to see a notification
+ // in the message center.
+ if (data.should_show_notification) {
+ EXPECT_TRUE(ContainsDeprecatedAcceleratorNotification());
+ RemoveAllNotifications();
+ } else {
+ 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();
+
+ // New accelerator should always be enabled.
+ ui::Accelerator new_accelerator = CreateAccelerator(data.new_accelerator);
+ EXPECT_TRUE(ProcessInController(new_accelerator));
+
+ ResetStateIfNeeded();
+ }
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698