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

Unified Diff: ui/base/accelerators/accelerator_history_unittest.cc

Issue 2792413002: Fix accelerator history tracking (Closed)
Patch Set: Add test Created 3 years, 8 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: ui/base/accelerators/accelerator_history_unittest.cc
diff --git a/ui/base/accelerators/accelerator_history_unittest.cc b/ui/base/accelerators/accelerator_history_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fcf29a4f660003a333f754244b46fdb076ac815
--- /dev/null
+++ b/ui/base/accelerators/accelerator_history_unittest.cc
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/accelerators/accelerator_history.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ui {
+
+TEST(AcceleratorHistoryTest, SimulatePressAndHold) {
+ AcceleratorHistory history;
+ Accelerator alt_press(ui::VKEY_MENU, ui::EF_NONE,
+ ui::Accelerator::KeyState::PRESSED);
+ history.StoreCurrentAccelerator(alt_press);
+ EXPECT_EQ(alt_press, history.current_accelerator());
+
+ // Repeats don't affect previous accelerators.
+ history.StoreCurrentAccelerator(alt_press);
+ EXPECT_EQ(alt_press, history.current_accelerator());
+ EXPECT_NE(alt_press, history.previous_accelerator());
+
+ Accelerator search_alt_press(ui::VKEY_LWIN, ui::EF_ALT_DOWN,
+ ui::Accelerator::KeyState::PRESSED);
+ history.StoreCurrentAccelerator(search_alt_press);
+ EXPECT_EQ(search_alt_press, history.current_accelerator());
+ EXPECT_EQ(alt_press, history.previous_accelerator());
+ history.StoreCurrentAccelerator(search_alt_press);
+ EXPECT_EQ(search_alt_press, history.current_accelerator());
+ EXPECT_EQ(alt_press, history.previous_accelerator());
+
+ Accelerator alt_release_search_down(ui::VKEY_MENU, ui::EF_COMMAND_DOWN,
+ ui::Accelerator::KeyState::RELEASED);
+ history.StoreCurrentAccelerator(alt_release_search_down);
+ EXPECT_EQ(alt_release_search_down, history.current_accelerator());
+ EXPECT_EQ(search_alt_press, history.previous_accelerator());
+
+ // Search is still down and search presses will keep being generated, but from
+ // the perspective of the AcceleratorHistory, this is the same Search press
+ // that hasn't been released yet.
+ Accelerator search_press(ui::VKEY_LWIN, ui::EF_NONE,
+ ui::Accelerator::KeyState::PRESSED);
+ history.StoreCurrentAccelerator(search_press);
+ history.StoreCurrentAccelerator(search_press);
+ history.StoreCurrentAccelerator(search_press);
+ EXPECT_EQ(alt_release_search_down, history.current_accelerator());
+ EXPECT_EQ(search_alt_press, history.previous_accelerator());
+
+ Accelerator search_release(ui::VKEY_LWIN, ui::EF_NONE,
+ ui::Accelerator::KeyState::RELEASED);
+ history.StoreCurrentAccelerator(search_release);
+ EXPECT_EQ(search_release, history.current_accelerator());
+ EXPECT_EQ(alt_release_search_down, history.previous_accelerator());
+}
+
+} // namespace ui
« ui/base/accelerators/accelerator_history.cc ('K') | « ui/base/accelerators/accelerator_history.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698