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

Side by Side Diff: views/focus/accelerator_handler_gtk_unittest.cc

Issue 3046041: [Linux Views] Refactor accelerator handler related code. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Prevent ctrl+alt. Created 10 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gdk/gdkkeysyms.h> 5 #include <gdk/gdkkeysyms.h>
6 6
7 #include "gfx/rect.h" 7 #include "gfx/rect.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "views/focus/accelerator_handler.h" 9 #include "views/focus/accelerator_handler.h"
10 #include "views/view.h" 10 #include "views/view.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 // Test that the homepage accelerator (Alt+Home) is activated on key down 93 // Test that the homepage accelerator (Alt+Home) is activated on key down
94 // and that the menu accelerator (Alt) is never activated. 94 // and that the menu accelerator (Alt) is never activated.
95 TEST_F(AcceleratorHandlerGtkTest, TestHomepageAccelerator) { 95 TEST_F(AcceleratorHandlerGtkTest, TestHomepageAccelerator) {
96 AcceleratorHandler handler; 96 AcceleratorHandler handler;
97 GdkEventKey evt; 97 GdkEventKey evt;
98 98
99 ASSERT_FALSE(menu_pressed_); 99 ASSERT_FALSE(menu_pressed_);
100 ASSERT_FALSE(home_pressed_); 100 ASSERT_FALSE(home_pressed_);
101 101
102 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Menu, 0); 102 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Alt_L, 0);
103 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 103 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
104 104
105 ASSERT_FALSE(menu_pressed_); 105 ASSERT_FALSE(menu_pressed_);
106 ASSERT_FALSE(home_pressed_); 106 ASSERT_FALSE(home_pressed_);
107 107
108 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Home, GDK_MOD1_MASK); 108 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Home, GDK_MOD1_MASK);
109 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 109 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
110 110
111 ASSERT_FALSE(menu_pressed_); 111 ASSERT_FALSE(menu_pressed_);
112 ASSERT_TRUE(home_pressed_); 112 ASSERT_TRUE(home_pressed_);
113 113
114 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Home, GDK_MOD1_MASK); 114 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Home, GDK_MOD1_MASK);
115 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 115 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
116 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Menu, 0); 116 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0);
117 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 117 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
118 118
119 ASSERT_FALSE(menu_pressed_); 119 ASSERT_FALSE(menu_pressed_);
120 ASSERT_TRUE(home_pressed_); 120 ASSERT_TRUE(home_pressed_);
121 } 121 }
122 122
123 // Test that the menu accelerator is activated on key up and not key down. 123 // Test that the menu accelerator is activated on key up and not key down.
124 TEST_F(AcceleratorHandlerGtkTest, TestMenuAccelerator) { 124 TEST_F(AcceleratorHandlerGtkTest, TestMenuAccelerator) {
125 AcceleratorHandler handler; 125 AcceleratorHandler handler;
126 GdkEventKey evt; 126 GdkEventKey evt;
127 127
128 ASSERT_FALSE(menu_pressed_); 128 ASSERT_FALSE(menu_pressed_);
129 129
130 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Menu, 0); 130 evt = CreateKeyEvent(GDK_KEY_PRESS, GDK_Alt_L, 0);
131 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 131 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
132 132
133 ASSERT_FALSE(menu_pressed_); 133 ASSERT_FALSE(menu_pressed_);
134 134
135 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Menu, 0); 135 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0);
136 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 136 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
137 137
138 ASSERT_TRUE(menu_pressed_); 138 ASSERT_TRUE(menu_pressed_);
139 } 139 }
140 140
141 // Test that the menu accelerator isn't confused by the interaction of the 141 // Test that the menu accelerator isn't confused by the interaction of the
142 // Alt and Shift keys. Try the following sequence on Linux: 142 // Alt and Shift keys. Try the following sequence on Linux:
143 // Press Alt 143 // Press Alt
144 // Press Shift 144 // Press Shift
145 // Release Alt 145 // Release Alt
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 // Release Alt - now this should trigger the menu shortcut. 185 // Release Alt - now this should trigger the menu shortcut.
186 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0); 186 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0);
187 evt.hardware_keycode = 0x40; 187 evt.hardware_keycode = 0x40;
188 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); 188 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt)));
189 189
190 ASSERT_TRUE(menu_pressed_); 190 ASSERT_TRUE(menu_pressed_);
191 } 191 }
192 192
193 } // namespace views 193 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698