summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 23:34:24 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 23:34:24 +0000
commitd1a5941efcd68dddd76d411f276353f34bb93f76 (patch)
tree95030e03f2e5dd16b0fab9da3b8fc4bd64d25b96 /chrome/browser
parent874755ab46efe9e3b84b4c6b479e5dc813e93445 (diff)
downloadchromium_src-d1a5941efcd68dddd76d411f276353f34bb93f76.zip
chromium_src-d1a5941efcd68dddd76d411f276353f34bb93f76.tar.gz
chromium_src-d1a5941efcd68dddd76d411f276353f34bb93f76.tar.bz2
linux: More automation porting.
I have verified that this is working on Linux, but still have yet to enable any new automated tests. Baby steps. BUG=19076 Review URL: http://codereview.chromium.org/164446 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/automation_provider.cc44
-rw-r--r--chrome/browser/automation/automation_provider.h8
-rw-r--r--chrome/browser/automation/ui_controls.h11
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc59
-rw-r--r--chrome/browser/automation/ui_controls_win.cc6
-rw-r--r--chrome/browser/blocked_popup_container_interactive_uitest.cc3
-rw-r--r--chrome/browser/browser.cc9
-rw-r--r--chrome/browser/views/find_bar_win_interactive_uitest.cc6
8 files changed, 102 insertions, 44 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 677b96e..c637311 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -973,10 +973,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds)
IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds)
IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible)
-#if defined(OS_WIN)
- IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
-#endif // defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_LINUX)
+ IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
#endif
#if defined(OS_WIN)
@@ -1490,11 +1488,10 @@ void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
gfx::Rect* bounds) {
*success = false;
-#if defined(OS_WIN)
- void* iter = NULL;
- if (window_tracker_->ContainsHandle(handle)) {
- HWND hwnd = window_tracker_->GetResource(handle);
- views::RootView* root_view = views::WidgetWin::FindRootView(hwnd);
+ gfx::NativeWindow window = window_tracker_->GetResource(handle);
+ if (window) {
+#if defined(TOOLKIT_VIEWS)
+ views::RootView* root_view = views::WidgetWin::FindRootView(window);
if (root_view) {
views::View* view = root_view->GetViewByID(view_id);
if (view) {
@@ -1508,11 +1505,10 @@ void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
bounds->set_origin(point);
}
}
- }
#else
- // TODO(port): Enable when window_tracker is ported.
- NOTIMPLEMENTED();
+ NOTIMPLEMENTED();
#endif
+ }
}
#if defined(OS_WIN)
@@ -1620,17 +1616,17 @@ class WindowDragResponseTask : public Task {
DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
};
+#endif // defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
int handle,
- POINT click,
+ const gfx::Point& click,
int flags) {
- HWND hwnd = 0;
-
- if (window_tracker_->ContainsHandle(handle)) {
- hwnd = window_tracker_->GetResource(handle);
+ gfx::NativeWindow window = window_tracker_->GetResource(handle);
- ui_controls::SendMouseMove(click.x, click.y);
+ if (window) {
+ ui_controls::SendMouseMove(click.x(), click.y());
ui_controls::MouseButton button = ui_controls::LEFT;
if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) ==
@@ -1645,17 +1641,20 @@ void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
} else {
NOTREACHED();
}
- ui_controls::SendMouseClick(button);
+ ui_controls::SendMouseClick(window, click, button);
}
}
+#endif
+#if defined(OS_WIN)
void AutomationProvider::WindowSimulateDrag(int handle,
std::vector<POINT> drag_path,
int flags,
bool press_escape_en_route,
IPC::Message* reply_message) {
bool succeeded = false;
- if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) {
+ gfx::NativeWindow window = window_tracker_->GetResource(handle);
+ if (window && (drag_path.size() > 1)) {
succeeded = true;
UINT down_message = 0;
@@ -1703,7 +1702,7 @@ void AutomationProvider::WindowSimulateDrag(int handle,
if (press_escape_en_route) {
// Press Escape.
- ui_controls::SendKeyPress(VK_ESCAPE,
+ ui_controls::SendKeyPress(window, VK_ESCAPE,
((flags & views::Event::EF_CONTROL_DOWN)
== views::Event::EF_CONTROL_DOWN),
((flags & views::Event::EF_SHIFT_DOWN) ==
@@ -1728,11 +1727,12 @@ void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
int handle,
wchar_t key,
int flags) {
- if (!window_tracker_->ContainsHandle(handle))
+ gfx::NativeWindow window = window_tracker_->GetResource(handle);
+ if (!window)
return;
// The key event is sent to whatever window is active.
- ui_controls::SendKeyPress(key,
+ ui_controls::SendKeyPress(window, key,
((flags & views::Event::EF_CONTROL_DOWN) ==
views::Event::EF_CONTROL_DOWN),
((flags & views::Event::EF_SHIFT_DOWN) ==
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 8a48476..55735b6 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -177,11 +177,11 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
int flags,
bool press_escape_en_route,
IPC::Message* reply_message);
- void WindowSimulateClick(const IPC::Message& message,
- int handle,
- POINT click,
- int flags);
#endif // defined(OS_WIN)
+ void WindowSimulateClick(const IPC::Message& message,
+ int handle,
+ const gfx::Point& click,
+ int flags);
void WindowSimulateKeyPress(const IPC::Message& message,
int handle,
wchar_t key,
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 509ee78..b8781e2 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -5,12 +5,17 @@
#ifndef CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
#define CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
+#include "build/build_config.h"
+
#include <string>
#if defined(OS_WIN)
#include <wtypes.h>
#endif
+#include "base/gfx/native_widget_types.h"
+#include "base/gfx/point.h"
+
namespace views {
class View;
}
@@ -24,7 +29,8 @@ namespace ui_controls {
// Once the generated event is processed the Task is Run (and deleted).
// Send a key press with/without modifier keys.
-bool SendKeyPress(wchar_t key, bool control, bool shift, bool alt);
+bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
+ bool shift, bool alt);
bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
bool alt, Task* task);
@@ -55,7 +61,8 @@ bool SendMouseEvents(MouseButton type, int state);
void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task);
// Simulate a single mouse click with given button type.
-bool SendMouseClick(MouseButton type);
+bool SendMouseClick(gfx::NativeWindow window, const gfx::Point& point,
+ MouseButton type);
// A combination of SendMouseMove to the middle of the view followed by
// SendMouseEvents.
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc
index 26f8715..e369ec7 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -4,13 +4,60 @@
#include "chrome/browser/automation/ui_controls.h"
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
#include "base/logging.h"
+#include "chrome/test/automation/automation_constants.h"
+
+namespace {
+
+int GdkKeycodeForWindowsKeycode(wchar_t windows_keyval) {
+ switch (windows_keyval) {
+ case VK_SPACE:
+ return GDK_space;
+ default:
+ NOTREACHED() << "Unsupported keyval: " << windows_keyval;
+ return 0;
+ }
+}
+
+} // namespace
namespace ui_controls {
-bool SendKeyPress(wchar_t key, bool control, bool shift, bool alt) {
- NOTIMPLEMENTED();
- return false;
+bool SendKeyPress(gfx::NativeWindow window,
+ wchar_t key, bool control, bool shift, bool alt) {
+ GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
+
+ event->key.type = GDK_KEY_PRESS;
+ event->key.window = GTK_WIDGET(window)->window;
+ g_object_ref(event->key.window);
+ event->key.send_event = false;
+ // TODO(estade): Put the real time?
+ event->key.time = GDK_CURRENT_TIME;
+ // TODO(estade): handle other state flags besides control, shift, alt?
+ // For example caps lock.
+ event->key.state = (control ? GDK_CONTROL_MASK : 0) |
+ (shift ? GDK_SHIFT_MASK : 0) |
+ (alt ? GDK_MOD1_MASK : 0);
+ event->key.keyval = GdkKeycodeForWindowsKeycode(key);
+ // TODO(estade): fill in the string?
+
+ GdkKeymapKey* keys;
+ gint n_keys;
+ if (!gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
+ event->key.keyval, &keys, &n_keys)) {
+ return false;
+ }
+ event->key.hardware_keycode = keys[0].keycode;
+ event->key.group = keys[0].group;
+ g_free(keys);
+
+ gdk_event_put(event);
+ // gdk_event_put appends a copy of the event.
+ gdk_event_free(event);
+ return true;
}
bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
@@ -19,11 +66,13 @@ bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
return false;
}
+// TODO(estade): this appears to be unused on Windows. Can we remove it?
bool SendKeyDown(wchar_t key) {
NOTIMPLEMENTED();
return false;
}
+// TODO(estade): this appears to be unused on Windows. Can we remove it?
bool SendKeyUp(wchar_t key) {
NOTIMPLEMENTED();
return false;
@@ -38,10 +87,10 @@ void SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
NOTIMPLEMENTED();
}
-bool SendMouseClick(MouseButton type) {
+bool SendMouseClick(gfx::NativeWindow window, const gfx::Point& point,
+ MouseButton type) {
NOTIMPLEMENTED();
return false;
-
}
// TODO(estade): need to figure out a better type for this than View.
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index e15f1d4..c2eecce 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -295,7 +295,8 @@ bool SendMouseEventsImpl(MouseButton type, int state, Task* task) {
// public functions -----------------------------------------------------------
-bool SendKeyPress(wchar_t key, bool control, bool shift, bool alt) {
+bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
+ bool shift, bool alt) {
return SendKeyPressImpl(key, control, shift, alt, NULL);
}
@@ -328,7 +329,8 @@ void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
SendMouseEventsImpl(type, state, task);
}
-bool SendMouseClick(MouseButton type) {
+bool SendMouseClick(gfx::NativeWindow window, const gfx::Point& point,
+ MouseButton type) {
return SendMouseEventsImpl(type, UP | DOWN, NULL);
}
diff --git a/chrome/browser/blocked_popup_container_interactive_uitest.cc b/chrome/browser/blocked_popup_container_interactive_uitest.cc
index a6eb304..ee659c2 100644
--- a/chrome/browser/blocked_popup_container_interactive_uitest.cc
+++ b/chrome/browser/blocked_popup_container_interactive_uitest.cc
@@ -51,8 +51,7 @@ class BlockedPopupContainerInteractiveTest : public UITest {
// Simulate a click of the actual link to force user_gesture to be
// true; if we don't, the resulting popup will be constrained, which
// isn't what we want to test.
- POINT link_point(tab_view_bounds.CenterPoint().ToPOINT());
- ASSERT_TRUE(window->SimulateOSClick(link_point,
+ ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
views::Event::EF_LEFT_BUTTON_DOWN));
}
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index c6c7ce6..8183090 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1015,12 +1015,14 @@ void Browser::OverrideEncoding(int encoding_id) {
void Browser::Cut() {
UserMetrics::RecordAction(L"Cut", profile_);
- ui_controls::SendKeyPress(L'X', true, false, false);
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), L'X', true, false,
+ false);
}
void Browser::Copy() {
UserMetrics::RecordAction(L"Copy", profile_);
- ui_controls::SendKeyPress(L'C', true, false, false);
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), L'C', true, false,
+ false);
}
void Browser::CopyCurrentPageURL() {
@@ -1049,7 +1051,8 @@ void Browser::CopyCurrentPageURL() {
void Browser::Paste() {
UserMetrics::RecordAction(L"Paste", profile_);
- ui_controls::SendKeyPress(L'V', true, false, false);
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), L'V', true, false,
+ false);
}
#endif // #if defined(OS_WIN)
diff --git a/chrome/browser/views/find_bar_win_interactive_uitest.cc b/chrome/browser/views/find_bar_win_interactive_uitest.cc
index 43ad35c..75f10d5 100644
--- a/chrome/browser/views/find_bar_win_interactive_uitest.cc
+++ b/chrome/browser/views/find_bar_win_interactive_uitest.cc
@@ -38,8 +38,7 @@ bool ActivateTabByClick(AutomationProxy* automation,
if (!browser_window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, &bounds, true))
return false;
- POINT click(bounds.CenterPoint().ToPOINT());
- if (!browser_window->SimulateOSClick(click,
+ if (!browser_window->SimulateOSClick(bounds.CenterPoint(),
views::Event::EF_LEFT_BUTTON_DOWN))
return false;
@@ -83,8 +82,7 @@ TEST_F(FindInPageTest, CrashEscHandlers) {
// Click on the location bar so that Find box loses focus.
gfx::Rect bounds;
EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, false));
- POINT click(bounds.CenterPoint().ToPOINT());
- EXPECT_TRUE(window->SimulateOSClick(click,
+ EXPECT_TRUE(window->SimulateOSClick(bounds.CenterPoint(),
views::Event::EF_LEFT_BUTTON_DOWN));
::Sleep(kActionDelayMs);
int focused_view_id;