diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 44 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 8 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls.h | 11 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls_linux.cc | 59 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls_win.cc | 6 | ||||
-rw-r--r-- | chrome/browser/blocked_popup_container_interactive_uitest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_win_interactive_uitest.cc | 6 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 17 | ||||
-rw-r--r-- | chrome/test/automation/window_proxy.cc | 4 | ||||
-rw-r--r-- | chrome/test/automation/window_proxy.h | 5 | ||||
-rw-r--r-- | chrome/test/ui/history_uitest.cc | 11 |
12 files changed, 126 insertions, 57 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; diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index b2b3f02..46bb160 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -12,6 +12,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/gfx/point.h" #include "base/gfx/rect.h" #include "base/string16.h" #include "chrome/common/navigation_types.h" @@ -389,16 +390,20 @@ IPC_BEGIN_MESSAGES(Automation) int /* AutocompleteEdit handle */) #if defined(OS_WIN) - // TODO(port): Port this message. + // TODO(estade): This message is defined later on for Mac and Linux. This is + // to avoid adding a new IPC in the middle for those platforms (see comment + // at top). The message is exactly the same, so they should be remerged when + // all messages in this file have been made cross-platform (at which point we + // will need to check in new reference builds). // // This message requests that a mouse click be performed in window coordinate // space. // Request: // int - the handle of the window that's the context for this click - // POINT - the point to click + // gfx::Point - the point to click // int - the flags which identify the mouse button(s) for the click, as // defined in chrome/views/event.h - IPC_MESSAGE_ROUTED3(AutomationMsg_WindowClick, int, POINT, int) + IPC_MESSAGE_ROUTED3(AutomationMsg_WindowClick, int, gfx::Point, int) #endif // defined(OS_WIN) // This message requests that a key press be performed. @@ -988,4 +993,10 @@ IPC_BEGIN_MESSAGES(Automation) IPC_SYNC_MESSAGE_ROUTED0_1(AutomationMsg_GetFilteredInetHitCount, int /* hit_count */) +#if defined(OS_LINUX) || defined(OS_MACOSX) + // See previous definition of this message for explanation of why it is + // defined twice. + IPC_MESSAGE_ROUTED3(AutomationMsg_WindowClick, int, gfx::Point, int) +#endif + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/window_proxy.cc b/chrome/test/automation/window_proxy.cc index eea1ced..cb672d3 100644 --- a/chrome/test/automation/window_proxy.cc +++ b/chrome/test/automation/window_proxy.cc @@ -27,14 +27,14 @@ bool WindowProxy::GetHWND(HWND* handle) const { return sender_->Send(new AutomationMsg_WindowHWND(0, handle_, handle)); } +#endif // defined(OS_WIN) -bool WindowProxy::SimulateOSClick(const POINT& click, int flags) { +bool WindowProxy::SimulateOSClick(const gfx::Point& click, int flags) { if (!is_valid()) return false; return sender_->Send( new AutomationMsg_WindowClick(0, handle_, click, flags)); } -#endif // defined(OS_WIN) bool WindowProxy::GetWindowTitle(string16* text) { if (!is_valid()) return false; diff --git a/chrome/test/automation/window_proxy.h b/chrome/test/automation/window_proxy.h index efbe1ca..0133ff7 100644 --- a/chrome/test/automation/window_proxy.h +++ b/chrome/test/automation/window_proxy.h @@ -21,6 +21,7 @@ class BrowserProxy; class WindowProxy; namespace gfx { + class Point; class Rect; } @@ -41,14 +42,14 @@ class WindowProxy : public AutomationResourceProxy { // Gets the outermost HWND that corresponds to the given window. // Returns true if the call was successful. bool GetHWND(HWND* handle) const; +#endif // defined(OS_WIN) // Simulates a click at the OS level. |click| is in the window's coordinates // and |flags| specifies which buttons are pressed (as defined in // chrome/views/event.h). Note that this is equivalent to the user moving // the mouse and pressing the button. So if there is a window on top of this // window, the top window is clicked. - bool SimulateOSClick(const POINT& click, int flags); -#endif // defined(OS_WIN) + bool SimulateOSClick(const gfx::Point& click, int flags); // Get the title of the top level window. bool GetWindowTitle(string16* text); diff --git a/chrome/test/ui/history_uitest.cc b/chrome/test/ui/history_uitest.cc index e2ba8a4..3a65d4f 100644 --- a/chrome/test/ui/history_uitest.cc +++ b/chrome/test/ui/history_uitest.cc @@ -93,8 +93,7 @@ TEST_F(HistoryTester, DISABLED_VerifyHistoryLength) { kTestCompleteSuccess, action_max_timeout_ms()); } -#if defined(OS_WIN) -// This test requires simulated mouse click, which is possible only for Windows. +#if defined(OS_WIN) || defined(OS_LINUX) TEST_F(HistoryTester, DISABLED_ConsiderRedirectAfterGestureAsUserInitiated) { // Test the history length for the following page transition. // @@ -116,15 +115,15 @@ TEST_F(HistoryTester, DISABLED_ConsiderRedirectAfterGestureAsUserInitiated) { gfx::Rect tab_view_bounds; ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds, true)); - POINT point(tab_view_bounds.CenterPoint().ToPOINT()); ASSERT_TRUE( - window->SimulateOSClick(point, views::Event::EF_LEFT_BUTTON_DOWN)); + window->SimulateOSClick(tab_view_bounds.CenterPoint(), + views::Event::EF_LEFT_BUTTON_DOWN)); - NavigateToURL(GURL("javascript:redirectToPage12()")); + NavigateToURL(GURL("javascript:redirectToPage12()")); WaitForFinish("History_Length_Test_12", "1", url, kTestCompleteCookie, kTestCompleteSuccess, action_max_timeout_ms()); } -#endif // defined(OS_WIN) +#endif // defined(OS_WIN) || defined(OS_LINUX) TEST_F(HistoryTester, DISABLED_ConsiderSlowRedirectAsUserInitiated) { // Test the history length for the following page transition. |