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..b1afec887f1bf2521832d84cf5b39937491be3ee 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; |
| @@ -121,12 +134,13 @@ bool ExecuteScriptHelper(RenderViewHost* render_view_host, |
| void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
| ui::KeyboardCode key, |
| + int nativeKeyCode, |
| bool control, |
| bool shift, |
| bool alt, |
| bool command, |
| NativeWebKeyboardEvent* event) { |
| - event->nativeKeyCode = 0; |
| + event->nativeKeyCode = nativeKeyCode; |
| event->windowsKeyCode = key; |
| event->setKeyIdentifierFromWindowsKeyCode(); |
| event->type = type; |
| @@ -154,6 +168,50 @@ void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
| event->modifiers |= WebKit::WebInputEvent::MetaKey; |
| } |
| +void SimulateKeyPress(WebContents* web_contents, |
| + ui::KeyboardCode key, |
| + int nativeKeyCode, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command) { |
|
Wez
2013/09/05 00:16:33
Why do you need this extra SimulateKeyPress overri
weitao
2013/09/05 07:49:17
Done.
|
| + NativeWebKeyboardEvent event_down; |
| + BuildSimpleWebKeyEvent( |
| + WebKit::WebInputEvent::RawKeyDown, |
| + key, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| + &event_down); |
| + web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
| + |
| + NativeWebKeyboardEvent char_event; |
| + BuildSimpleWebKeyEvent( |
| + WebKit::WebInputEvent::RawKeyDown, |
|
Wez
2013/09/05 00:16:33
This should be Char.
weitao
2013/09/05 07:49:17
Done.
|
| + key, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| + &char_event); |
| + web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
| + |
| + NativeWebKeyboardEvent event_up; |
| + BuildSimpleWebKeyEvent( |
| + WebKit::WebInputEvent::RawKeyDown, |
|
Wez
2013/09/05 00:16:33
This should be KeyUp.
weitao
2013/09/05 07:49:17
Done.
|
| + key, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command, |
| + &event_up); |
| + web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
| +} |
| + |
| void GetCookiesCallback(std::string* cookies_out, |
| base::WaitableEvent* event, |
| const std::string& cookies) { |
| @@ -270,23 +328,24 @@ void SimulateKeyPress(WebContents* web_contents, |
| bool shift, |
| bool alt, |
| bool command) { |
| - NativeWebKeyboardEvent event_down; |
| - BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command, |
| - &event_down); |
| - web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
| - |
| - NativeWebKeyboardEvent char_event; |
| - BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::Char, key, control, shift, alt, command, |
| - &char_event); |
| - web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
| + SimulateKeyPress(web_contents, key, 0, control, shift, alt, command); |
|
Wez
2013/09/05 00:16:33
0 -> NULL, or better still, InvalidKeyboardEventCo
weitao
2013/09/05 07:49:17
Done.
|
| +} |
| - NativeWebKeyboardEvent event_up; |
| - BuildSimpleWebKeyEvent( |
| - WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, |
| - &event_up); |
| - web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
| +void SimulateKeyPress(WebContents* web_contents, |
| + ui::KeyboardCode key, |
| + const char* code, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command) { |
| + int nativeKeyCode = CodeToNativeKeycode(code); |
| + SimulateKeyPress(web_contents, |
| + key, |
| + nativeKeyCode, |
| + control, |
| + shift, |
| + alt, |
| + command); |
| } |
| namespace internal { |