summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 21:16:51 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 21:16:51 +0000
commitc2cb8549159ac80ce1d587445513fae5942e568d (patch)
tree2376250eadf7133a3b3bd8b622c037ccfb88d848 /chrome
parent5be7a2069980722b87e8288b3e59a574a80620cc (diff)
downloadchromium_src-c2cb8549159ac80ce1d587445513fae5942e568d.zip
chromium_src-c2cb8549159ac80ce1d587445513fae5942e568d.tar.gz
chromium_src-c2cb8549159ac80ce1d587445513fae5942e568d.tar.bz2
Linux: more interactive tests porting.
The most noteworthy change here is the implementation of SendMouseMove() and SendMouseClick() in ui_controls. I've combed the interwebs and I don't think it's possible to figure out the GdkWindow that is showing for a given (x,y) coordinate pair (except perhaps by delving into X), so we have to just send clicks to wherever the pointer lies. This is unfortunate in that it means we have to move the pointer, wait for it to get where it's going, and only then make the click. But on the bright side there's this super helpful function called gdk_display_warp_pointer() which makes moving the mouse a breeze. BUG=19076 Review URL: http://codereview.chromium.org/174113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc74
-rw-r--r--chrome/browser/automation/ui_controls.h13
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc74
-rw-r--r--chrome/browser/automation/ui_controls_win.cc15
-rw-r--r--chrome/browser/blocked_popup_container_interactive_uitest.cc21
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc14
-rw-r--r--chrome/chrome.gyp2
7 files changed, 142 insertions, 71 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 14504be..be26975 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -71,6 +71,8 @@
#include "views/widget/root_view.h"
#include "views/widget/widget_win.h"
#include "views/window/window.h"
+#elif defined(OS_LINUX)
+#include "chrome/browser/gtk/view_id_util.h"
#endif
using base::Time;
@@ -787,6 +789,38 @@ class AutomationInterstitialPage : public InterstitialPage {
DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage);
};
+#if !defined(OS_MACOSX)
+class ClickTask : public Task {
+ public:
+ ClickTask(gfx::Point point, int flags) : point_(point), flags_(flags) {}
+ virtual ~ClickTask() {}
+
+ virtual void Run() {
+ ui_controls::MouseButton button = ui_controls::LEFT;
+ if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) ==
+ views::Event::EF_LEFT_BUTTON_DOWN) {
+ button = ui_controls::LEFT;
+ } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) ==
+ views::Event::EF_RIGHT_BUTTON_DOWN) {
+ button = ui_controls::RIGHT;
+ } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) ==
+ views::Event::EF_MIDDLE_BUTTON_DOWN) {
+ button = ui_controls::MIDDLE;
+ } else {
+ NOTREACHED();
+ }
+
+ ui_controls::SendMouseClick(point_, button);
+ }
+
+ private:
+ gfx::Point point_;
+ int flags_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClickTask);
+};
+#endif
+
AutomationProvider::AutomationProvider(Profile* profile)
: redirect_query_(0),
profile_(profile),
@@ -1481,6 +1515,27 @@ void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
bounds->set_origin(point);
}
}
+#elif defined(OS_LINUX)
+ gfx::NativeWindow window = window_tracker_->GetResource(handle);
+ GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window),
+ static_cast<ViewID>(view_id));
+ if (!widget)
+ return;
+ *success = true;
+ *bounds = gfx::Rect(0, 0,
+ widget->allocation.width, widget->allocation.height);
+ gint x, y;
+ if (screen_coordinates) {
+ gdk_window_get_origin(widget->window, &x, &y);
+ if (GTK_WIDGET_NO_WINDOW(widget)) {
+ x += widget->allocation.x;
+ y += widget->allocation.y;
+ }
+ } else {
+ gtk_widget_translate_coordinates(widget, GTK_WIDGET(window),
+ 0, 0, &x, &y);
+ }
+ bounds->set_origin(gfx::Point(x, y));
#else
NOTIMPLEMENTED();
#endif
@@ -1600,23 +1655,8 @@ void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
int flags) {
if (window_tracker_->ContainsHandle(handle)) {
- gfx::NativeWindow window = window_tracker_->GetResource(handle);
- ui_controls::SendMouseMove(click.x(), click.y());
-
- ui_controls::MouseButton button = ui_controls::LEFT;
- if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) ==
- views::Event::EF_LEFT_BUTTON_DOWN) {
- button = ui_controls::LEFT;
- } else if ((flags & views::Event::EF_RIGHT_BUTTON_DOWN) ==
- views::Event::EF_RIGHT_BUTTON_DOWN) {
- button = ui_controls::RIGHT;
- } else if ((flags & views::Event::EF_MIDDLE_BUTTON_DOWN) ==
- views::Event::EF_MIDDLE_BUTTON_DOWN) {
- button = ui_controls::MIDDLE;
- } else {
- NOTREACHED();
- }
- ui_controls::SendMouseClick(window, click, button);
+ ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(),
+ new ClickTask(click, flags));
}
}
#endif
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 3460ec3..0df639f 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -46,15 +46,9 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
bool control, bool shift,
bool alt, Task* task);
-// Send a key down event. Use VK_CONTROL for ctrl key,
-// VK_MENU for alt key and VK_SHIFT for shift key.
-// Refer MSDN for more virtual key codes.
-bool SendKeyDown(wchar_t key);
-bool SendKeyUp(wchar_t key);
-
// Simulate a mouse move. (x,y) are absolute screen coordinates.
bool SendMouseMove(long x, long y);
-void SendMouseMoveNotifyWhenDone(long x, long y, Task* task);
+bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task);
enum MouseButton {
LEFT = 0,
@@ -73,8 +67,9 @@ 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(gfx::NativeWindow window, const gfx::Point& point,
- MouseButton type);
+// The click will be sent to whichever window is under the cursor, so make sure
+// the cursor is where you want it before calling this.
+bool SendMouseClick(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 22902a6..c79dc68 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -13,6 +13,12 @@
namespace {
+guint32 EventTimeNow() {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+}
+
class EventWaiter : public MessageLoopForUI::Observer {
public:
EventWaiter(Task* task, GdkEventType type) : task_(task), type_(type) {
@@ -36,7 +42,7 @@ class EventWaiter : public MessageLoopForUI::Observer {
}
private:
- Task* task_;
+ scoped_ptr<Task> task_;
GdkEventType type_;
};
@@ -53,10 +59,7 @@ bool SendKeyPress(gfx::NativeWindow window,
event->key.window = GTK_WIDGET(window)->window;
g_object_ref(event->key.window);
event->key.send_event = false;
-
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- event->key.time = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+ event->key.time = EventTimeNow();
// TODO(estade): handle other state flags besides control, shift, alt?
// For example caps lock.
@@ -90,30 +93,55 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
return SendKeyPress(window, key, control, shift, alt);
}
-// TODO(estade): this appears to be unused on Windows. Can we remove it?
-bool SendKeyDown(wchar_t key) {
- NOTIMPLEMENTED();
- return false;
+bool SendMouseMove(long x, long y) {
+ gdk_display_warp_pointer(gdk_display_get_default(), gdk_screen_get_default(),
+ x, y);
+ return true;
}
-// TODO(estade): this appears to be unused on Windows. Can we remove it?
-bool SendKeyUp(wchar_t key) {
- NOTIMPLEMENTED();
- return false;
+bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
+ bool rv = SendMouseMove(x, y);
+ // We can't rely on any particular event signalling the completion of the
+ // mouse move. Posting the task to the message loop should gaurantee
+ // the pointer has moved before task is run (although it may not run it as
+ // soon as it could).
+ MessageLoop::current()->PostTask(FROM_HERE, task);
+ return rv;
}
-bool SendMouseMove(long x, long y) {
- NOTIMPLEMENTED();
- return false;
-}
+bool SendMouseClick(const gfx::Point& point, MouseButton type) {
+ GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
-void SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
- NOTIMPLEMENTED();
-}
+ event->button.window = gdk_window_at_pointer(NULL, NULL);
+ g_object_ref(event->button.window);
+ event->button.send_event = false;
+ event->button.time = EventTimeNow();
+
+ event->motion.x_root = point.x();
+ event->motion.y_root = point.x();
+ gint origin_x, origin_y;
+ gdk_window_get_origin(event->button.window, &origin_x, &origin_y);
+ event->button.x = point.x() - origin_x;
+ event->button.y = point.y() - origin_y;
+
+ event->button.axes = NULL;
+ // TODO(estade): as above, we may want to pack this with the actual state.
+ event->button.state = 0;
+ event->button.button = type == LEFT ? 1 : (type == MIDDLE ? 2 : 3);
+ event->button.device = gdk_device_get_core_pointer();
+
+ event->button.type = GDK_BUTTON_PRESS;
+ gdk_event_put(event);
+
+ // Also send a release event.
+ GdkEvent* release_event = gdk_event_copy(event);
+ release_event->button.type = GDK_BUTTON_RELEASE;
+ release_event->button.time++;
+ gdk_event_put(release_event);
+
+ gdk_event_free(event);
+ gdk_event_free(release_event);
-bool SendMouseClick(gfx::NativeWindow window, const gfx::Point& point,
- MouseButton type) {
- NOTIMPLEMENTED();
return false;
}
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index 8e971fa..d1b59ee 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -306,20 +306,12 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
return SendKeyPressImpl(key, control, shift, alt, task);
}
-bool SendKeyDown(wchar_t key) {
- return SendKeyEvent(key, false);
-}
-
-bool SendKeyUp(wchar_t key) {
- return SendKeyEvent(key, true);
-}
-
bool SendMouseMove(long x, long y) {
return SendMouseMoveImpl(x, y, NULL);
}
-void SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
- SendMouseMoveImpl(x, y, task);
+bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
+ return SendMouseMoveImpl(x, y, task);
}
bool SendMouseEvents(MouseButton type, int state) {
@@ -330,8 +322,7 @@ void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
SendMouseEventsImpl(type, state, task);
}
-bool SendMouseClick(gfx::NativeWindow window, const gfx::Point& point,
- MouseButton type) {
+bool SendMouseClick(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 ee659c2..cfa3071 100644
--- a/chrome/browser/blocked_popup_container_interactive_uitest.cc
+++ b/chrome/browser/blocked_popup_container_interactive_uitest.cc
@@ -77,8 +77,14 @@ TEST_F(BlockedPopupContainerInteractiveTest, TestOpenAndResizeTo) {
ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout(
VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
ASSERT_FALSE(is_timeout);
- ASSERT_EQ(300, rect.width());
- ASSERT_EQ(320, rect.height());
+
+#if !defined(OS_LINUX)
+ // TODO(estade): This is a real failure; we create popups with the wrong size.
+ // Fix it. Note: it appears that we are setting the window's bounds to 300,320
+ // instead of setting the content's bounds to 300,320.
+ EXPECT_EQ(300, rect.width());
+ EXPECT_EQ(320, rect.height());
+#endif
SimulateClickInCenterOf(popup_window);
@@ -91,12 +97,14 @@ TEST_F(BlockedPopupContainerInteractiveTest, TestOpenAndResizeTo) {
// inner{Width,Height}.
is_timeout = false;
ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout(
- VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
+ VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
ASSERT_FALSE(is_timeout);
- ASSERT_LT(rect.width(), 200);
- ASSERT_LT(rect.height(), 200);
+ EXPECT_LT(rect.width(), 200);
+ EXPECT_LT(rect.height(), 200);
}
+// TODO(estade): port.
+#if !defined(OS_LINUX)
// Helper function used to get the number of blocked popups out of the window
// title.
bool ParseCountOutOfTitle(const std::wstring& title, int* output) {
@@ -114,7 +122,7 @@ bool ParseCountOutOfTitle(const std::wstring& title, int* output) {
offset++;
}
- return StringToInt(number, output);
+ return StringToInt(WideToUTF16(number), output);
}
// Tests that in the window.open() equivalent of a fork bomb, we stop building
@@ -229,3 +237,4 @@ TEST_F(BlockedPopupContainerInteractiveTest, DontBreakOnBlur) {
// We popup shouldn't be closed by the onblur handler.
ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 1500));
}
+#endif
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
index 42dce95..15b0a7d 100644
--- a/chrome/browser/debugger/devtools_sanity_unittest.cc
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -15,6 +15,16 @@
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
+
+#if defined(OS_WIN)
+#define MAYBE_TestShowScriptsTab TestShowScriptsTab
+#define MAYBE_TestSetBreakpoint TestSetBreakpoint
+#elif defined(OS_LINUX)
+// http://crbug.com/19748
+#define MAYBE_TestShowScriptsTab DISABLED_TestShowScriptsTab
+#define MAYBE_TestSetBreakpoint DISABLED_TestSetBreakpoint
+#endif
+
namespace {
// Used to block until a dev tools client window's browser is closed.
@@ -152,13 +162,13 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestProfilerTab) {
// Tests scripts panel showing.
// http://crbug.com/16767
-IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) {
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestShowScriptsTab) {
RunTest("testShowScriptsTab", kDebuggerTestPage);
}
// Tests set breakpoint.
// http://crbug.com/16767
-IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestSetBreakpoint) {
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestSetBreakpoint) {
RunTest("testSetBreakpoint", kDebuggerTestPage);
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index af80925..e68faae 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -4951,9 +4951,7 @@
],
'sources!': [
# TODO(port)
- 'browser/debugger/devtools_sanity_unittest.cc',
'browser/views/bookmark_bar_view_test.cc',
- 'browser/blocked_popup_container_interactive_uitest.cc',
'browser/views/find_bar_win_interactive_uitest.cc',
'browser/views/tabs/tab_dragging_test.cc',
'test/interactive_ui/npapi_interactive_test.cc',