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

Unified Diff: ui/views/focus/focus_manager_unittest.cc

Issue 838253004: MacViews: Fix duplicate definition of ExtensionKeyBindingRegistry::SetShortcutHandlingSuspended (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DragBookmarks2
Patch Set: Use callback Created 5 years, 11 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
« ui/views/focus/focus_manager.cc ('K') | « ui/views/focus/focus_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/focus/focus_manager_unittest.cc
diff --git a/ui/views/focus/focus_manager_unittest.cc b/ui/views/focus/focus_manager_unittest.cc
index 32b8665925646f3f949002e19ba1fa159a7c6548..5ff900e106f3ccd307e6d397becb05377d8f1212 100644
--- a/ui/views/focus/focus_manager_unittest.cc
+++ b/ui/views/focus/focus_manager_unittest.cc
@@ -469,6 +469,38 @@ TEST_F(FocusManagerTest, CallsSelfDeletingAcceleratorTarget) {
EXPECT_EQ(target.accelerator_count(), 1);
}
+static bool SuspendAcceleratorsCallback(bool input) {
+ return input;
+}
+
+TEST_F(FocusManagerTest, SuspendAccelerators) {
+ const ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE);
+ ui::Accelerator accelerator(event.key_code(), event.flags());
+ TestAcceleratorTarget target(true);
+ FocusManager* focus_manager = GetFocusManager();
+ focus_manager->RegisterAccelerator(accelerator,
+ ui::AcceleratorManager::kNormalPriority,
+ &target);
+
+ // Callback returns true, should not process accelerators.
+ base::Callback<bool()> callback =
+ base::Bind(&SuspendAcceleratorsCallback, true);
+ focus_manager->set_shortcut_handling_suspended_callback(&callback);
+ EXPECT_TRUE(focus_manager->OnKeyEvent(event));
+ EXPECT_EQ(0, target.accelerator_count());
+
+ // Callback returns false, should process accelerators.
+ callback = base::Bind(&SuspendAcceleratorsCallback, false);
+ focus_manager->set_shortcut_handling_suspended_callback(&callback);
+ EXPECT_FALSE(focus_manager->OnKeyEvent(event));
+ EXPECT_EQ(1, target.accelerator_count());
+
+ // Uninstall callback, should process accelerators.
+ focus_manager->set_shortcut_handling_suspended_callback(nullptr);
+ EXPECT_FALSE(focus_manager->OnKeyEvent(event));
+ EXPECT_EQ(2, target.accelerator_count());
+}
+
class FocusManagerDtorTest : public FocusManagerTest {
protected:
typedef std::vector<std::string> DtorTrackVector;
« ui/views/focus/focus_manager.cc ('K') | « ui/views/focus/focus_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698