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

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 23542008: Add a CodeToNativeKeycode helper that converts UIEvent code to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing CR feedback. Created 7 years, 3 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
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | remoting/test/remote_desktop_browsertest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "grit/webui_resources.h" 27 #include "grit/webui_resources.h"
28 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
29 #include "net/cookies/cookie_store.h" 29 #include "net/cookies/cookie_store.h"
30 #include "net/test/python_utils.h" 30 #include "net/test/python_utils.h"
31 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34
35 #if defined(OS_WIN)
36 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code}
37 #elif defined(OS_LINUX)
38 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code}
39 #elif defined(OS_MACOSX)
40 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code}
41 #else
42 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code}
43 #endif
44 #include "ui/base/keycodes/usb_keycode_map.h"
45 #undef USB_KEYMAP
46
34 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
35 48
36 static const int kDefaultWsPort = 8880; 49 static const int kDefaultWsPort = 8880;
37 50
38 namespace content { 51 namespace content {
39 namespace { 52 namespace {
40 53
41 class DOMOperationObserver : public NotificationObserver, 54 class DOMOperationObserver : public NotificationObserver,
42 public WebContentsObserver { 55 public WebContentsObserver {
43 public: 56 public:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 result->reset(reader.ReadToValue(json)); 126 result->reset(reader.ReadToValue(json));
114 if (!result->get()) { 127 if (!result->get()) {
115 DLOG(ERROR) << reader.GetErrorMessage(); 128 DLOG(ERROR) << reader.GetErrorMessage();
116 return false; 129 return false;
117 } 130 }
118 131
119 return true; 132 return true;
120 } 133 }
121 134
122 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, 135 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
123 ui::KeyboardCode key, 136 ui::KeyboardCode keyCode,
137 int nativeKeyCode,
124 bool control, 138 bool control,
125 bool shift, 139 bool shift,
126 bool alt, 140 bool alt,
127 bool command, 141 bool command,
128 NativeWebKeyboardEvent* event) { 142 NativeWebKeyboardEvent* event) {
129 event->nativeKeyCode = 0; 143 event->nativeKeyCode = nativeKeyCode;
130 event->windowsKeyCode = key; 144 event->windowsKeyCode = keyCode;
131 event->setKeyIdentifierFromWindowsKeyCode(); 145 event->setKeyIdentifierFromWindowsKeyCode();
132 event->type = type; 146 event->type = type;
133 event->modifiers = 0; 147 event->modifiers = 0;
134 event->isSystemKey = false; 148 event->isSystemKey = false;
135 event->timeStampSeconds = base::Time::Now().ToDoubleT(); 149 event->timeStampSeconds = base::Time::Now().ToDoubleT();
136 event->skip_in_browser = true; 150 event->skip_in_browser = true;
137 151
138 if (type == WebKit::WebInputEvent::Char || 152 if (type == WebKit::WebInputEvent::Char ||
139 type == WebKit::WebInputEvent::RawKeyDown) { 153 type == WebKit::WebInputEvent::RawKeyDown) {
140 event->text[0] = key; 154 event->text[0] = keyCode;
141 event->unmodifiedText[0] = key; 155 event->unmodifiedText[0] = keyCode;
142 } 156 }
143 157
144 if (control) 158 if (control)
145 event->modifiers |= WebKit::WebInputEvent::ControlKey; 159 event->modifiers |= WebKit::WebInputEvent::ControlKey;
146 160
147 if (shift) 161 if (shift)
148 event->modifiers |= WebKit::WebInputEvent::ShiftKey; 162 event->modifiers |= WebKit::WebInputEvent::ShiftKey;
149 163
150 if (alt) 164 if (alt)
151 event->modifiers |= WebKit::WebInputEvent::AltKey; 165 event->modifiers |= WebKit::WebInputEvent::AltKey;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 WebKit::WebInputEvent::Type type, 272 WebKit::WebInputEvent::Type type,
259 const gfx::Point& point) { 273 const gfx::Point& point) {
260 WebKit::WebMouseEvent mouse_event; 274 WebKit::WebMouseEvent mouse_event;
261 mouse_event.type = type; 275 mouse_event.type = type;
262 mouse_event.x = point.x(); 276 mouse_event.x = point.x();
263 mouse_event.y = point.y(); 277 mouse_event.y = point.y();
264 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 278 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
265 } 279 }
266 280
267 void SimulateKeyPress(WebContents* web_contents, 281 void SimulateKeyPress(WebContents* web_contents,
268 ui::KeyboardCode key, 282 ui::KeyboardCode keyCode,
269 bool control, 283 bool control,
270 bool shift, 284 bool shift,
271 bool alt, 285 bool alt,
272 bool command) { 286 bool command) {
287 SimulateKeyPressWithCode(web_contents,
Sergey Ulanov 2013/09/05 16:18:16 nit: there is no need to put each argument to a se
weitao 2013/09/05 16:46:33 Done.
288 keyCode,
289 NULL,
290 control,
291 shift,
292 alt,
293 command);
294 }
295
296 void SimulateKeyPressWithCode(WebContents* web_contents,
297 ui::KeyboardCode keyCode,
298 const char* code,
299 bool control,
300 bool shift,
301 bool alt,
302 bool command) {
303 int nativeKeyCode = CodeToNativeKeycode(code);
304
273 NativeWebKeyboardEvent event_down; 305 NativeWebKeyboardEvent event_down;
274 BuildSimpleWebKeyEvent( 306 BuildSimpleWebKeyEvent(
275 WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command, 307 WebKit::WebInputEvent::RawKeyDown,
308 keyCode,
309 nativeKeyCode,
310 control,
311 shift,
312 alt,
313 command,
276 &event_down); 314 &event_down);
277 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); 315 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
278 316
279 NativeWebKeyboardEvent char_event; 317 NativeWebKeyboardEvent char_event;
280 BuildSimpleWebKeyEvent( 318 BuildSimpleWebKeyEvent(
281 WebKit::WebInputEvent::Char, key, control, shift, alt, command, 319 WebKit::WebInputEvent::Char,
320 keyCode,
321 nativeKeyCode,
322 control,
323 shift,
324 alt,
325 command,
282 &char_event); 326 &char_event);
283 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); 327 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
284 328
285 NativeWebKeyboardEvent event_up; 329 NativeWebKeyboardEvent event_up;
286 BuildSimpleWebKeyEvent( 330 BuildSimpleWebKeyEvent(
287 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, 331 WebKit::WebInputEvent::KeyUp,
332 keyCode,
333 nativeKeyCode,
334 control,
335 shift,
336 alt,
337 command,
288 &event_up); 338 &event_up);
289 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); 339 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
290 } 340 }
291 341
292 namespace internal { 342 namespace internal {
293 343
294 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) 344 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents)
295 : render_view_host_(web_contents->GetRenderViewHost()) { 345 : render_view_host_(web_contents->GetRenderViewHost()) {
296 } 346 }
297 347
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 // The queue should not be empty, unless we were quit because of a timeout. 589 // The queue should not be empty, unless we were quit because of a timeout.
540 if (message_queue_.empty()) 590 if (message_queue_.empty())
541 return false; 591 return false;
542 if (message) 592 if (message)
543 *message = message_queue_.front(); 593 *message = message_queue_.front();
544 message_queue_.pop(); 594 message_queue_.pop();
545 return true; 595 return true;
546 } 596 }
547 597
548 } // namespace content 598 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | remoting/test/remote_desktop_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698