Chromium Code Reviews| Index: content/public/test/browser_test_utils.cc |
| diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc |
| index 13846dfa88c5e7b9a0f03d0fa0bb23057a2d97d3..f23f6be0612d31a4689211aec7851f965796a4dd 100644 |
| --- a/content/public/test/browser_test_utils.cc |
| +++ b/content/public/test/browser_test_utils.cc |
| @@ -31,6 +31,19 @@ |
| #include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| + |
| +#if defined(OS_WIN) |
| +#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code} |
| +#elif defined(OS_LINUX) |
| +#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code} |
| +#elif defined(OS_MACOSX) |
| +#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code} |
| +#else |
| +#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code} |
| +#endif |
| +#include "ui/base/keycodes/usb_keycode_map.h" |
| +#undef USB_KEYMAP |
| + |
| #include "ui/base/resource/resource_bundle.h" |
| static const int kDefaultWsPort = 8880; |
| @@ -120,14 +133,15 @@ bool ExecuteScriptHelper(RenderViewHost* render_view_host, |
| } |
| void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
| - ui::KeyboardCode key, |
| + ui::KeyboardCode keyCode, |
| + int nativeKeyCode, |
| bool control, |
| bool shift, |
| bool alt, |
| bool command, |
| NativeWebKeyboardEvent* event) { |
| - event->nativeKeyCode = 0; |
| - event->windowsKeyCode = key; |
| + event->nativeKeyCode = nativeKeyCode; |
| + event->windowsKeyCode = keyCode; |
| event->setKeyIdentifierFromWindowsKeyCode(); |
| event->type = type; |
| event->modifiers = 0; |
| @@ -137,8 +151,8 @@ void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
| if (type == WebKit::WebInputEvent::Char || |
| type == WebKit::WebInputEvent::RawKeyDown) { |
| - event->text[0] = key; |
| - event->unmodifiedText[0] = key; |
| + event->text[0] = keyCode; |
| + event->unmodifiedText[0] = keyCode; |
| } |
| if (control) |
| @@ -265,26 +279,62 @@ void SimulateMouseEvent(WebContents* web_contents, |
| } |
| void SimulateKeyPress(WebContents* web_contents, |
| - ui::KeyboardCode key, |
| + ui::KeyboardCode keyCode, |
| bool control, |
| bool shift, |
| bool alt, |
| bool command) { |
| + 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.
|
| + keyCode, |
| + NULL, |
| + control, |
| + shift, |
| + alt, |
| + command); |
| +} |
| + |
| +void SimulateKeyPressWithCode(WebContents* web_contents, |
| + ui::KeyboardCode keyCode, |
| + const char* code, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command) { |
| + int nativeKeyCode = CodeToNativeKeycode(code); |
| + |
| NativeWebKeyboardEvent event_down; |
| BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command, |
| + WebKit::WebInputEvent::RawKeyDown, |
| + keyCode, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| &event_down); |
| web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
| NativeWebKeyboardEvent char_event; |
| BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::Char, key, control, shift, alt, command, |
| + WebKit::WebInputEvent::Char, |
| + keyCode, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| &char_event); |
| web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
| NativeWebKeyboardEvent event_up; |
| BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, |
| + WebKit::WebInputEvent::KeyUp, |
| + keyCode, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| &event_up); |
| web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
| } |