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

Side by Side Diff: ui/views/widget/root_view_unittest.cc

Issue 404203003: Distinguish between keystroke and character events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsCharFromNative() for Mac build Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include "ui/views/context_menu_controller.h" 7 #include "ui/views/context_menu_controller.h"
8 #include "ui/views/test/views_test_base.h" 8 #include "ui/views/test/views_test_base.h"
9 #include "ui/views/view_targeter.h" 9 #include "ui/views/view_targeter.h"
10 #include "ui/views/widget/root_view.h" 10 #include "ui/views/widget/root_view.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Give focus to |child| so that it will be the target of the key event. 52 // Give focus to |child| so that it will be the target of the key event.
53 child->SetFocusable(true); 53 child->SetFocusable(true);
54 child->RequestFocus(); 54 child->RequestFocus();
55 55
56 internal::RootView* root_view = 56 internal::RootView* root_view =
57 static_cast<internal::RootView*>(widget.GetRootView()); 57 static_cast<internal::RootView*>(widget.GetRootView());
58 ViewTargeter* view_targeter = new ViewTargeter(root_view); 58 ViewTargeter* view_targeter = new ViewTargeter(root_view);
59 root_view->SetEventTargeter(make_scoped_ptr(view_targeter)); 59 root_view->SetEventTargeter(make_scoped_ptr(view_targeter));
60 60
61 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0, false); 61 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE);
62 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event); 62 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event);
63 EXPECT_TRUE(details.target_destroyed); 63 EXPECT_TRUE(details.target_destroyed);
64 EXPECT_FALSE(details.dispatcher_destroyed); 64 EXPECT_FALSE(details.dispatcher_destroyed);
65 EXPECT_TRUE(got_key_event); 65 EXPECT_TRUE(got_key_event);
66 } 66 }
67 67
68 // Tracks whether a context menu is shown. 68 // Tracks whether a context menu is shown.
69 class TestContextMenuController : public ContextMenuController { 69 class TestContextMenuController : public ContextMenuController {
70 public: 70 public:
71 TestContextMenuController() 71 TestContextMenuController()
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 static_cast<internal::RootView*>(widget.GetRootView()); 115 static_cast<internal::RootView*>(widget.GetRootView());
116 116
117 TestContextMenuController controller; 117 TestContextMenuController controller;
118 View* focused_view = new View; 118 View* focused_view = new View;
119 focused_view->set_context_menu_controller(&controller); 119 focused_view->set_context_menu_controller(&controller);
120 widget.SetContentsView(focused_view); 120 widget.SetContentsView(focused_view);
121 focused_view->SetFocusable(true); 121 focused_view->SetFocusable(true);
122 focused_view->RequestFocus(); 122 focused_view->RequestFocus();
123 123
124 // No context menu should be shown for a keypress of 'A'. 124 // No context menu should be shown for a keypress of 'A'.
125 ui::KeyEvent nomenu_key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, true); 125 ui::KeyEvent nomenu_key_event('a', ui::VKEY_A, ui::EF_NONE);
126 ui::EventDispatchDetails details = 126 ui::EventDispatchDetails details =
127 root_view->OnEventFromSource(&nomenu_key_event); 127 root_view->OnEventFromSource(&nomenu_key_event);
128 EXPECT_FALSE(details.target_destroyed); 128 EXPECT_FALSE(details.target_destroyed);
129 EXPECT_FALSE(details.dispatcher_destroyed); 129 EXPECT_FALSE(details.dispatcher_destroyed);
130 EXPECT_EQ(0, controller.show_context_menu_calls()); 130 EXPECT_EQ(0, controller.show_context_menu_calls());
131 EXPECT_EQ(NULL, controller.menu_source_view()); 131 EXPECT_EQ(NULL, controller.menu_source_view());
132 EXPECT_EQ(ui::MENU_SOURCE_NONE, controller.menu_source_type()); 132 EXPECT_EQ(ui::MENU_SOURCE_NONE, controller.menu_source_type());
133 controller.Reset(); 133 controller.Reset();
134 134
135 // A context menu should be shown for a keypress of Shift+F10. 135 // A context menu should be shown for a keypress of Shift+F10.
136 ui::KeyEvent menu_key_event( 136 ui::KeyEvent menu_key_event(
137 ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::EF_SHIFT_DOWN, false); 137 ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::EF_SHIFT_DOWN);
138 details = root_view->OnEventFromSource(&menu_key_event); 138 details = root_view->OnEventFromSource(&menu_key_event);
139 EXPECT_FALSE(details.target_destroyed); 139 EXPECT_FALSE(details.target_destroyed);
140 EXPECT_FALSE(details.dispatcher_destroyed); 140 EXPECT_FALSE(details.dispatcher_destroyed);
141 EXPECT_EQ(1, controller.show_context_menu_calls()); 141 EXPECT_EQ(1, controller.show_context_menu_calls());
142 EXPECT_EQ(focused_view, controller.menu_source_view()); 142 EXPECT_EQ(focused_view, controller.menu_source_view());
143 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type()); 143 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type());
144 controller.Reset(); 144 controller.Reset();
145 145
146 // A context menu should be shown for a keypress of VKEY_APPS. 146 // A context menu should be shown for a keypress of VKEY_APPS.
147 ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, 0, false); 147 ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, ui::EF_NONE);
148 details = root_view->OnEventFromSource(&menu_key_event2); 148 details = root_view->OnEventFromSource(&menu_key_event2);
149 EXPECT_FALSE(details.target_destroyed); 149 EXPECT_FALSE(details.target_destroyed);
150 EXPECT_FALSE(details.dispatcher_destroyed); 150 EXPECT_FALSE(details.dispatcher_destroyed);
151 EXPECT_EQ(1, controller.show_context_menu_calls()); 151 EXPECT_EQ(1, controller.show_context_menu_calls());
152 EXPECT_EQ(focused_view, controller.menu_source_view()); 152 EXPECT_EQ(focused_view, controller.menu_source_view());
153 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type()); 153 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type());
154 controller.Reset(); 154 controller.Reset();
155 } 155 }
156 156
157 // View which handles all gesture events. 157 // View which handles all gesture events.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); 245 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0));
246 details = root_view->OnEventFromSource(&end2); 246 details = root_view->OnEventFromSource(&end2);
247 247
248 EXPECT_FALSE(details.target_destroyed); 248 EXPECT_FALSE(details.target_destroyed);
249 EXPECT_FALSE(details.dispatcher_destroyed); 249 EXPECT_FALSE(details.dispatcher_destroyed);
250 EXPECT_EQ(1, controller.show_context_menu_calls()); 250 EXPECT_EQ(1, controller.show_context_menu_calls());
251 } 251 }
252 252
253 } // namespace test 253 } // namespace test
254 } // namespace views 254 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698