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
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 14504be..be269756 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 @@
   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 @@
         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 @@
                                              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