Index: trunk/src/remoting/test/remote_desktop_browsertest.cc |
=================================================================== |
--- trunk/src/remoting/test/remote_desktop_browsertest.cc (revision 222198) |
+++ trunk/src/remoting/test/remote_desktop_browsertest.cc (working copy) |
@@ -17,6 +17,88 @@ |
namespace remoting { |
+// BuildSimpleWebKeyEvent and SimulateKeyPress below are adapted from |
+// content/public/test/browser_test_utils.cc. |
+// TODO: Move this to browser_test_utils.cc after the support is added for |
+// the UIEvent key |code|. |
+void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
+ ui::KeyboardCode key, |
+ int nativeKeyCode, |
+ bool control, |
+ bool shift, |
+ bool alt, |
+ bool command, |
+ content::NativeWebKeyboardEvent* event) { |
+ event->nativeKeyCode = nativeKeyCode; |
+ event->windowsKeyCode = key; |
+ event->setKeyIdentifierFromWindowsKeyCode(); |
+ event->type = type; |
+ event->modifiers = 0; |
+ event->isSystemKey = false; |
+ event->timeStampSeconds = base::Time::Now().ToDoubleT(); |
+ event->skip_in_browser = true; |
+ |
+ if (type == WebKit::WebInputEvent::Char || |
+ type == WebKit::WebInputEvent::RawKeyDown) { |
+ event->text[0] = key; |
+ event->unmodifiedText[0] = key; |
+ } |
+ |
+ if (control) |
+ event->modifiers |= WebKit::WebInputEvent::ControlKey; |
+ |
+ if (shift) |
+ event->modifiers |= WebKit::WebInputEvent::ShiftKey; |
+ |
+ if (alt) |
+ event->modifiers |= WebKit::WebInputEvent::AltKey; |
+ |
+ if (command) |
+ event->modifiers |= WebKit::WebInputEvent::MetaKey; |
+} |
+ |
+void SimulateKeyPress(content::WebContents* web_contents, |
+ ui::KeyboardCode key, |
+ int nativeKeyCode, |
+ bool control, |
+ bool shift, |
+ bool alt, |
+ bool command) { |
+ content::NativeWebKeyboardEvent event_down; |
+ BuildSimpleWebKeyEvent( |
+ WebKit::WebInputEvent::RawKeyDown, |
+ key, nativeKeyCode, |
+ control, |
+ shift, |
+ alt, |
+ command, |
+ &event_down); |
+ web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
+ |
+ content::NativeWebKeyboardEvent char_event; |
+ BuildSimpleWebKeyEvent( |
+ WebKit::WebInputEvent::Char, |
+ key, nativeKeyCode, |
+ control, |
+ shift, |
+ alt, |
+ command, |
+ &char_event); |
+ web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
+ |
+ content::NativeWebKeyboardEvent event_up; |
+ BuildSimpleWebKeyEvent( |
+ WebKit::WebInputEvent::KeyUp, |
+ key, |
+ nativeKeyCode, |
+ control, |
+ shift, |
+ alt, |
+ command, |
+ &event_up); |
+ web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
+} |
+ |
RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {} |
RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} |
@@ -200,23 +282,25 @@ |
EXPECT_FALSE(HtmlElementVisible("me2me-first-run")); |
} |
-void RemoteDesktopBrowserTest::SimulateKeyPressWithCode( |
- ui::KeyboardCode keyCode, |
- const char* code) { |
- SimulateKeyPressWithCode(keyCode, code, false, false, false, false); |
+void RemoteDesktopBrowserTest::SimulateKeyPress( |
+ ui::KeyboardCode key, |
+ int nativeKeyCode) { |
+ SimulateKeyPress(key, nativeKeyCode, false, false, false, false); |
} |
-void RemoteDesktopBrowserTest::SimulateKeyPressWithCode( |
- ui::KeyboardCode keyCode, |
- const char* code, |
+void RemoteDesktopBrowserTest::SimulateKeyPress( |
+ ui::KeyboardCode key, |
+ int nativeKeyCode, |
bool control, |
bool shift, |
bool alt, |
bool command) { |
- content::SimulateKeyPressWithCode( |
+ // TODO: Switch to content::SimulateKeyPress when an overload of it is |
+ // added to take the UIEvent key |code| string. |
+ remoting::SimulateKeyPress( |
browser()->tab_strip_model()->GetActiveWebContents(), |
- keyCode, |
- code, |
+ key, |
+ nativeKeyCode, |
control, |
shift, |
alt, |