Index: ui/aura/test/event_generator.cc |
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc |
index c21e1ad83f9f628843fdf62b6f6490672fc3174f..59d2854c1c3477e31dc98b4668381f705b078f85 100644 |
--- a/ui/aura/test/event_generator.cc |
+++ b/ui/aura/test/event_generator.cc |
@@ -4,9 +4,15 @@ |
#include "ui/aura/test/event_generator.h" |
+#include "base/memory/scoped_ptr.h" |
#include "ui/aura/event.h" |
#include "ui/aura/root_window.h" |
+#if defined(USE_X11) |
+#include <X11/Xlib.h> |
+#include "ui/base/x/x11_util.h" |
+#endif |
+ |
namespace { |
gfx::Point CenterOfWindowInRootWindowCoordinate(aura::Window* window) { |
@@ -119,6 +125,14 @@ void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { |
PressMoveAndReleaseTouchTo(CenterOfWindowInRootWindowCoordinate(window)); |
} |
+void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
+ DispatchKeyEvent(true, key_code, flags); |
+} |
+ |
+void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
+ DispatchKeyEvent(false, key_code, flags); |
+} |
+ |
void EventGenerator::Dispatch(Event& event) { |
switch (event.type()) { |
case ui::ET_KEY_PRESSED: |
@@ -150,5 +164,25 @@ void EventGenerator::Dispatch(Event& event) { |
} |
} |
+void EventGenerator::DispatchKeyEvent(bool is_press, |
+ ui::KeyboardCode key_code, |
+ int flags) { |
+#if defined(OS_WIN) |
+ MSG native_event = |
+ { NULL, (is_press ? WM_KEYDOWN : WM_KEYUP), key_code, flags }; |
+ KeyEvent keyev(native_event, false /* is_char */); |
+#else |
+ ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
+#if defined(USE_X11) |
+ scoped_ptr<XEvent> native_event(new XEvent); |
+ ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); |
+ KeyEvent keyev(native_event.get(), false); |
+#else |
+ KeyEvent keyev(type, key_code, flags); |
+#endif // USE_X11 |
+#endif // OS_WIN |
+ Dispatch(keyev); |
+} |
+ |
} // namespace test |
} // namespace aura |