diff options
13 files changed, 507 insertions, 460 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 851adc8..bf76d62 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -130,35 +130,6 @@ class AutomationInterstitialPage : public InterstitialPage { DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); }; -class ClickTask : public Task { - public: - explicit ClickTask(int flags) : 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(button); - } - - private: - int flags_; - - DISALLOW_COPY_AND_ASSIGN(ClickTask); -}; - AutomationProvider::AutomationProvider(Profile* profile) : profile_(profile), reply_message_(NULL), @@ -334,32 +305,13 @@ Extension* AutomationProvider::GetDisabledExtension(int extension_handle) { void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) - IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) - IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) - IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) - IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) #if !defined(OS_MACOSX) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, WindowSimulateDrag) #endif // !defined(OS_MACOSX) - IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) - IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) - IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) #if defined(OS_WIN) IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) #endif // defined(OS_WIN) - IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) - IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) - IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) - IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) - IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) - IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) - IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, - GetFullscreenBubbleVisibility) IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, @@ -604,99 +556,6 @@ class InvokeTaskLaterTask : public Task { DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); }; -void AutomationProvider::WindowSimulateClick(const IPC::Message& message, - int handle, - const gfx::Point& click, - int flags) { - if (window_tracker_->ContainsHandle(handle)) { - ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), - new ClickTask(flags)); - } -} - -void AutomationProvider::WindowSimulateMouseMove(const IPC::Message& message, - int handle, - const gfx::Point& location) { - if (window_tracker_->ContainsHandle(handle)) - ui_controls::SendMouseMove(location.x(), location.y()); -} - -void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, - int handle, - int key, - int flags) { - if (!window_tracker_->ContainsHandle(handle)) - return; - - gfx::NativeWindow window = window_tracker_->GetResource(handle); - // The key event is sent to whatever window is active. - ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), - ((flags & views::Event::EF_CONTROL_DOWN) == - views::Event::EF_CONTROL_DOWN), - ((flags & views::Event::EF_SHIFT_DOWN) == - views::Event::EF_SHIFT_DOWN), - ((flags & views::Event::EF_ALT_DOWN) == - views::Event::EF_ALT_DOWN), - ((flags & views::Event::EF_COMMAND_DOWN) == - views::Event::EF_COMMAND_DOWN)); -} - -void AutomationProvider::GetTabCount(int handle, int* tab_count) { - *tab_count = -1; // -1 is the error code - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - *tab_count = browser->tab_count(); - } -} - -void AutomationProvider::GetType(int handle, int* type_as_int) { - *type_as_int = -1; // -1 is the error code - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - *type_as_int = static_cast<int>(browser->type()); - } -} - -void AutomationProvider::GetTab(int win_handle, int tab_index, - int* tab_handle) { - *tab_handle = 0; - if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { - Browser* browser = browser_tracker_->GetResource(win_handle); - if (tab_index < browser->tab_count()) { - TabContents* tab_contents = - browser->GetTabContentsAt(tab_index); - *tab_handle = tab_tracker_->Add(&tab_contents->controller()); - } - } -} - -void AutomationProvider::GetTabTitle(int handle, int* title_string_size, - std::wstring* title) { - *title_string_size = -1; // -1 is the error code - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - NavigationEntry* entry = tab->GetActiveEntry(); - if (entry != NULL) { - *title = UTF16ToWideHack(entry->title()); - } else { - *title = std::wstring(); - } - *title_string_size = static_cast<int>(title->size()); - } -} - -void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { - *tabstrip_index = -1; // -1 is the error code - - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - Browser* browser = Browser::GetBrowserForController(tab, NULL); - *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab); - } -} - void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { if (window_tracker_->ContainsHandle(handle)) { window_tracker_->Remove(window_tracker_->GetResource(handle)); @@ -723,29 +582,6 @@ Browser* AutomationProvider::FindAndActivateTab( return browser; } -void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { - *success = false; - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - // Return what the user would see in the location bar. - *url = tab->GetActiveEntry()->virtual_url(); - *success = true; - } -} - -void AutomationProvider::GetTabProcessID(int handle, int* process_id) { - *process_id = -1; - - if (tab_tracker_->ContainsHandle(handle)) { - *process_id = 0; - TabContents* tab_contents = - tab_tracker_->GetResource(handle)->tab_contents(); - RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); - if (rph) - *process_id = base::GetProcId(rph->GetHandle()); - } -} - void AutomationProvider::ApplyAccelerator(int handle, int id) { NOTREACHED() << "This function has been deprecated. " << "Please use ExecuteBrowserCommandAsync instead."; @@ -783,35 +619,6 @@ void AutomationProvider::ExecuteJavascript(int handle, } } -void AutomationProvider::GetShelfVisibility(int handle, bool* visible) { - *visible = false; - - if (browser_tracker_->ContainsHandle(handle)) { -#if defined(OS_CHROMEOS) - // Chromium OS shows FileBrowse ui rather than download shelf. So we - // enumerate all browsers and look for a chrome://filebrowse... pop up. - for (BrowserList::const_iterator it = BrowserList::begin(); - it != BrowserList::end(); ++it) { - if ((*it)->type() == Browser::TYPE_POPUP) { - const GURL& url = - (*it)->GetTabContentsAt((*it)->selected_index())->GetURL(); - - if (url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIFileBrowseHost) { - *visible = true; - break; - } - } - } -#else - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - *visible = browser->window()->IsDownloadShelfVisible(); - } -#endif - } -} - void AutomationProvider::SetShelfVisibility(int handle, bool visible) { if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); @@ -824,27 +631,6 @@ void AutomationProvider::SetShelfVisibility(int handle, bool visible) { } } -void AutomationProvider::IsFullscreen(int handle, bool* visible) { - *visible = false; - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) - *visible = browser->window()->IsFullscreen(); - } -} - -void AutomationProvider::GetFullscreenBubbleVisibility(int handle, - bool* visible) { - *visible = false; - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) - *visible = browser->window()->IsFullscreenBubbleVisible(); - } -} - void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { *count = -1; // -1 is the error code if (tab_tracker_->ContainsHandle(handle)) { diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index adc36d8..d94b149 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -187,52 +187,25 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button); void ClickAppModalDialogButton(int button, bool* success); void ShutdownSessionService(int handle, bool* result); - void TerminateSession(int handle, bool* success); - void WindowGetViewBounds(int handle, int view_id, bool screen_coordinates, - bool* success, gfx::Rect* bounds); void WindowSimulateDrag(int handle, std::vector<gfx::Point> drag_path, int flags, bool press_escape_en_route, IPC::Message* reply_message); - void WindowSimulateClick(const IPC::Message& message, - int handle, - const gfx::Point& click, - int flags); - void WindowSimulateMouseMove(const IPC::Message& message, - int handle, - const gfx::Point& location); - void WindowSimulateKeyPress(const IPC::Message& message, - int handle, - int key, - int flags); - void GetWindowBounds(int handle, gfx::Rect* bounds, bool* result); - void SetWindowBounds(int handle, const gfx::Rect& bounds, bool* result); - void SetWindowVisible(int handle, bool visible, bool* result); - - void GetTabCount(int handle, int* tab_count); - void GetType(int handle, int* type_as_int); - void GetTab(int win_handle, int tab_index, int* tab_handle); + #if defined(OS_WIN) // TODO(port): Replace HWND. void GetTabHWND(int handle, HWND* tab_hwnd); #endif // defined(OS_WIN) - void GetTabProcessID(int handle, int* process_id); - void GetTabTitle(int handle, int* title_string_size, std::wstring* title); - void GetTabIndex(int handle, int* tabstrip_index); - void GetTabURL(int handle, bool* success, GURL* url); void HandleUnused(const IPC::Message& message, int handle); void ExecuteJavascript(int handle, const std::wstring& frame_xpath, const std::wstring& script, IPC::Message* reply_message); - void GetShelfVisibility(int handle, bool* visible); void SetShelfVisibility(int handle, bool visible); void SetFilteredInet(const IPC::Message& message, bool enabled); void GetFilteredInetHitCount(int* hit_count); void SetProxyConfig(const std::string& new_proxy_config); - void IsFullscreen(int handle, bool* is_fullscreen); - void GetFullscreenBubbleVisibility(int handle, bool* is_visible); void SetContentSetting(int handle, const std::string& host, ContentSettingsType content_type, diff --git a/chrome/browser/automation/automation_provider_gtk.cc b/chrome/browser/automation/automation_provider_gtk.cc index 097eeb1..5438eeb 100644 --- a/chrome/browser/automation/automation_provider_gtk.cc +++ b/chrome/browser/automation/automation_provider_gtk.cc @@ -17,60 +17,6 @@ #include "gfx/point.h" #include "gfx/rect.h" -void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, - bool* success) { - *success = false; - GtkWindow* window = window_tracker_->GetResource(handle); - if (window) { - gtk_window_move(window, bounds.x(), bounds.height()); - gtk_window_resize(window, bounds.width(), bounds.height()); - *success = true; - } -} - -void AutomationProvider::SetWindowVisible(int handle, bool visible, - bool* result) { - *result = false; - GtkWindow* window = window_tracker_->GetResource(handle); - if (window) { - if (visible) { - gtk_window_present(window); - } else { - gtk_widget_hide(GTK_WIDGET(window)); - } - *result = true; - } -} - -#if !defined(TOOLKIT_VIEWS) -void AutomationProvider::WindowGetViewBounds(int handle, int view_id, - bool screen_coordinates, - bool* success, - gfx::Rect* bounds) { - *success = false; - - GtkWindow* window = window_tracker_->GetResource(handle); - if (window) { - GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), - static_cast<ViewID>(view_id)); - if (!widget) - return; - *success = true; - *bounds = gfx::Rect(widget->allocation.width, widget->allocation.height); - gint x, y; - if (screen_coordinates) { - gfx::Point point = gtk_util::GetWidgetScreenPosition(widget); - x = point.x(); - y = point.y(); - } else { - gtk_widget_translate_coordinates(widget, GTK_WIDGET(window), - 0, 0, &x, &y); - } - bounds->set_origin(gfx::Point(x, y)); - } -} -#endif - void AutomationProvider::PrintAsync(int tab_handle) { NOTIMPLEMENTED(); } @@ -194,17 +140,6 @@ void AutomationProvider::WindowSimulateDrag(int handle, } } -void AutomationProvider::TerminateSession(int handle, bool* success) { - *success = false; - NOTIMPLEMENTED(); -} - -void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds, - bool* result) { - *result = false; - NOTIMPLEMENTED(); -} - void AutomationProvider::GetWindowTitle(int handle, string16* text) { gfx::NativeWindow window = window_tracker_->GetResource(handle); const gchar* title = gtk_window_get_title(window); diff --git a/chrome/browser/automation/automation_provider_mac.mm b/chrome/browser/automation/automation_provider_mac.mm index 74d98e5..29d5af4 100644 --- a/chrome/browser/automation/automation_provider_mac.mm +++ b/chrome/browser/automation/automation_provider_mac.mm @@ -19,76 +19,6 @@ #include "gfx/rect.h" #include "grit/generated_resources.h" -void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, - bool* success) { - *success = false; - NSWindow* window = window_tracker_->GetResource(handle); - if (window) { - NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect()); - - if ([[NSScreen screens] count] > 0) { - new_bounds.origin.y = - [[[NSScreen screens] objectAtIndex:0] frame].size.height - - new_bounds.origin.y - new_bounds.size.height; - } - - [window setFrame:new_bounds display:NO]; - *success = true; - } -} - -void AutomationProvider::SetWindowVisible(int handle, bool visible, - bool* result) { - *result = false; - NSWindow* window = window_tracker_->GetResource(handle); - if (window) { - if (visible) { - [window orderFront:nil]; - } else { - [window orderOut:nil]; - } - *result = true; - } -} - -void AutomationProvider::WindowGetViewBounds(int handle, int view_id, - bool screen_coordinates, - bool* success, - gfx::Rect* bounds) { - *success = false; - - // At the moment we hard code the view ID used by WebDriver and do - // not support arbitrary view IDs. suzhe is working on general view - // ID support for the Mac. - if (view_id != VIEW_ID_TAB_CONTAINER) { - NOTIMPLEMENTED(); - return; - } - - NSWindow* window = window_tracker_->GetResource(handle); - if (!window) - return; - - BrowserWindowController* controller = [window windowController]; - DCHECK([controller isKindOfClass:[BrowserWindowController class]]); - if (![controller isKindOfClass:[BrowserWindowController class]]) - return; - NSView* tab = [controller selectedTabView]; - if (!tab) - return; - - NSPoint coords = NSZeroPoint; - if (screen_coordinates) { - coords = [window convertBaseToScreen:[tab convertPoint:NSZeroPoint - toView:nil]]; - } else { - coords = [tab convertPoint:NSZeroPoint toView:[window contentView]]; - } - // Flip coordinate system - coords.y = [[window screen] frame].size.height - coords.y; - *success = true; -} - void AutomationProvider::PrintAsync(int tab_handle) { NOTIMPLEMENTED(); } @@ -103,17 +33,6 @@ void AutomationProvider::WindowSimulateDrag(int handle, Send(reply_message); } -void AutomationProvider::TerminateSession(int handle, bool* success) { - *success = false; - NOTIMPLEMENTED(); -} - -void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds, - bool* result) { - *result = false; - NOTIMPLEMENTED(); -} - void AutomationProvider::GetWindowTitle(int handle, string16* text) { gfx::NativeWindow window = window_tracker_->GetResource(handle); NSString* title = nil; diff --git a/chrome/browser/automation/automation_provider_views.cc b/chrome/browser/automation/automation_provider_views.cc index f130079..76ff3de 100644 --- a/chrome/browser/automation/automation_provider_views.cc +++ b/chrome/browser/automation/automation_provider_views.cc @@ -16,31 +16,6 @@ #include "views/widget/root_view.h" #include "views/widget/widget.h" -void AutomationProvider::WindowGetViewBounds(int handle, int view_id, - bool screen_coordinates, - bool* success, - gfx::Rect* bounds) { - *success = false; - - if (window_tracker_->ContainsHandle(handle)) { - gfx::NativeWindow window = window_tracker_->GetResource(handle); - views::RootView* root_view = views::Widget::FindRootView(window); - if (root_view) { - views::View* view = root_view->GetViewByID(view_id); - if (view) { - *success = true; - gfx::Point point; - if (screen_coordinates) - views::View::ConvertPointToScreen(view, &point); - else - views::View::ConvertPointToView(view, root_view, &point); - *bounds = view->GetLocalBounds(false); - bounds->set_origin(point); - } - } - } -} - void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { *view_id = -1; if (window_tracker_->ContainsHandle(handle)) { diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 70a8049..70312df 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -220,41 +220,6 @@ void AutomationProvider::WindowSimulateDrag(int handle, } } -void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds, - bool* success) { - *success = false; - HWND hwnd = window_tracker_->GetResource(handle); - if (hwnd) { - *success = true; - WINDOWPLACEMENT window_placement; - GetWindowPlacement(hwnd, &window_placement); - *bounds = window_placement.rcNormalPosition; - } -} - -void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, - bool* success) { - *success = false; - if (window_tracker_->ContainsHandle(handle)) { - HWND hwnd = window_tracker_->GetResource(handle); - if (::MoveWindow(hwnd, bounds.x(), bounds.y(), bounds.width(), - bounds.height(), true)) { - *success = true; - } - } -} - -void AutomationProvider::SetWindowVisible(int handle, bool visible, - bool* result) { - if (window_tracker_->ContainsHandle(handle)) { - HWND hwnd = window_tracker_->GetResource(handle); - ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE); - *result = true; - } else { - *result = false; - } -} - void AutomationProvider::GetTabHWND(int handle, HWND* tab_hwnd) { *tab_hwnd = NULL; @@ -432,16 +397,6 @@ void AutomationProvider::ConnectExternalTab( TRACE_EVENT_END("AutomationProvider::ConnectExternalTab", 0, ""); } -void AutomationProvider::TerminateSession(int handle, bool* success) { - *success = false; - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - HWND window = browser->window()->GetNativeHandle(); - *success = (::PostMessageW(window, WM_ENDSESSION, 0, 0) == TRUE); - } -} - void AutomationProvider::SetEnableExtensionAutomation( int tab_handle, const std::vector<std::string>& functions_enabled) { diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index ac30470..d1fecab 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -12,15 +12,18 @@ #include "chrome/browser/automation/automation_provider_observers.h" #include "chrome/browser/automation/automation_tab_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" +#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/login_prompt.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_service.h" #include "chrome/test/automation/automation_messages.h" #include "net/url_request/url_request_context.h" +#include "views/event.h" namespace { @@ -126,8 +129,36 @@ class DeleteCookieTask : public Task { DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); }; -} // namespace +class ClickTask : public Task { + public: + explicit ClickTask(int flags) : 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(button); + } + + private: + int flags_; + DISALLOW_COPY_AND_ASSIGN(ClickTask); +}; + +} // namespace TestingAutomationProvider::TestingAutomationProvider(Profile* profile) : AutomationProvider(profile), @@ -188,6 +219,25 @@ void TestingAutomationProvider::OnMessageReceived( ExecuteBrowserCommandAsync) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, ExecuteBrowserCommand) + IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) + IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) + IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) + IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) + IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) + IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) + IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) + IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) + IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) + IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) + IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) + IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) + IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) + IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, + GetFullscreenBubbleVisibility) IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); IPC_END_MESSAGE_MAP() @@ -651,6 +701,178 @@ void TestingAutomationProvider::IsWindowActive(int handle, } } +void TestingAutomationProvider::WindowSimulateClick(const IPC::Message& message, + int handle, + const gfx::Point& click, + int flags) { + if (window_tracker_->ContainsHandle(handle)) { + ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), + new ClickTask(flags)); + } +} + +void TestingAutomationProvider::WindowSimulateMouseMove( + const IPC::Message& message, + int handle, + const gfx::Point& location) { + if (window_tracker_->ContainsHandle(handle)) + ui_controls::SendMouseMove(location.x(), location.y()); +} + +void TestingAutomationProvider::WindowSimulateKeyPress( + const IPC::Message& message, + int handle, + int key, + int flags) { + if (!window_tracker_->ContainsHandle(handle)) + return; + + gfx::NativeWindow window = window_tracker_->GetResource(handle); + // The key event is sent to whatever window is active. + ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), + ((flags & views::Event::EF_CONTROL_DOWN) == + views::Event::EF_CONTROL_DOWN), + ((flags & views::Event::EF_SHIFT_DOWN) == + views::Event::EF_SHIFT_DOWN), + ((flags & views::Event::EF_ALT_DOWN) == + views::Event::EF_ALT_DOWN), + ((flags & views::Event::EF_COMMAND_DOWN) == + views::Event::EF_COMMAND_DOWN)); +} + +void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { + *tab_count = -1; // -1 is the error code + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + *tab_count = browser->tab_count(); + } +} + +void TestingAutomationProvider::GetType(int handle, int* type_as_int) { + *type_as_int = -1; // -1 is the error code + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + *type_as_int = static_cast<int>(browser->type()); + } +} + +void TestingAutomationProvider::GetTab(int win_handle, + int tab_index, + int* tab_handle) { + *tab_handle = 0; + if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { + Browser* browser = browser_tracker_->GetResource(win_handle); + if (tab_index < browser->tab_count()) { + TabContents* tab_contents = + browser->GetTabContentsAt(tab_index); + *tab_handle = tab_tracker_->Add(&tab_contents->controller()); + } + } +} + +void TestingAutomationProvider::GetTabProcessID(int handle, int* process_id) { + *process_id = -1; + + if (tab_tracker_->ContainsHandle(handle)) { + *process_id = 0; + TabContents* tab_contents = + tab_tracker_->GetResource(handle)->tab_contents(); + RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); + if (rph) + *process_id = base::GetProcId(rph->GetHandle()); + } +} + +void TestingAutomationProvider::GetTabTitle(int handle, + int* title_string_size, + std::wstring* title) { + *title_string_size = -1; // -1 is the error code + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + NavigationEntry* entry = tab->GetActiveEntry(); + if (entry != NULL) { + *title = UTF16ToWideHack(entry->title()); + } else { + *title = std::wstring(); + } + *title_string_size = static_cast<int>(title->size()); + } +} + +void TestingAutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { + *tabstrip_index = -1; // -1 is the error code + + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + Browser* browser = Browser::GetBrowserForController(tab, NULL); + *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab); + } +} + +void TestingAutomationProvider::GetTabURL(int handle, + bool* success, + GURL* url) { + *success = false; + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + // Return what the user would see in the location bar. + *url = tab->GetActiveEntry()->virtual_url(); + *success = true; + } +} + +void TestingAutomationProvider::GetShelfVisibility(int handle, bool* visible) { + *visible = false; + + if (browser_tracker_->ContainsHandle(handle)) { +#if defined(OS_CHROMEOS) + // Chromium OS shows FileBrowse ui rather than download shelf. So we + // enumerate all browsers and look for a chrome://filebrowse... pop up. + for (BrowserList::const_iterator it = BrowserList::begin(); + it != BrowserList::end(); ++it) { + if ((*it)->type() == Browser::TYPE_POPUP) { + const GURL& url = + (*it)->GetTabContentsAt((*it)->selected_index())->GetURL(); + + if (url.SchemeIs(chrome::kChromeUIScheme) && + url.host() == chrome::kChromeUIFileBrowseHost) { + *visible = true; + break; + } + } + } +#else + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + *visible = browser->window()->IsDownloadShelfVisible(); + } +#endif + } +} + +void TestingAutomationProvider::IsFullscreen(int handle, bool* visible) { + *visible = false; + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) + *visible = browser->window()->IsFullscreen(); + } +} + +void TestingAutomationProvider::GetFullscreenBubbleVisibility(int handle, + bool* visible) { + *visible = false; + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) + *visible = browser->window()->IsFullscreenBubbleVisible(); + } +} + // TODO(brettw) change this to accept GURLs when history supports it void TestingAutomationProvider::OnRedirectQueryComplete( HistoryService::Handle request_handle, diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index 8b6da28..7d75e36 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -83,6 +83,33 @@ class TestingAutomationProvider : public AutomationProvider, void IsWindowActive(int handle, bool* success, bool* is_active); void ActivateWindow(int handle); void IsWindowMaximized(int handle, bool* is_maximized, bool* success); + void TerminateSession(int handle, bool* success); + void WindowGetViewBounds(int handle, int view_id, bool screen_coordinates, + bool* success, gfx::Rect* bounds); + void GetWindowBounds(int handle, gfx::Rect* bounds, bool* result); + void SetWindowBounds(int handle, const gfx::Rect& bounds, bool* result); + void SetWindowVisible(int handle, bool visible, bool* result); + void WindowSimulateClick(const IPC::Message& message, + int handle, + const gfx::Point& click, + int flags); + void WindowSimulateMouseMove(const IPC::Message& message, + int handle, + const gfx::Point& location); + void WindowSimulateKeyPress(const IPC::Message& message, + int handle, + int key, + int flags); + void GetTabCount(int handle, int* tab_count); + void GetType(int handle, int* type_as_int); + void GetTab(int win_handle, int tab_index, int* tab_handle); + void GetTabProcessID(int handle, int* process_id); + void GetTabTitle(int handle, int* title_string_size, std::wstring* title); + void GetTabIndex(int handle, int* tabstrip_index); + void GetTabURL(int handle, bool* success, GURL* url); + void GetShelfVisibility(int handle, bool* visible); + void IsFullscreen(int handle, bool* is_fullscreen); + void GetFullscreenBubbleVisibility(int handle, bool* is_visible); // Callback for history redirect queries. virtual void OnRedirectQueryComplete( diff --git a/chrome/browser/automation/testing_automation_provider_gtk.cc b/chrome/browser/automation/testing_automation_provider_gtk.cc index ce61658..93959fd 100644 --- a/chrome/browser/automation/testing_automation_provider_gtk.cc +++ b/chrome/browser/automation/testing_automation_provider_gtk.cc @@ -4,7 +4,12 @@ #include "chrome/browser/automation/testing_automation_provider.h" +#include <gtk/gtk.h> + #include "base/logging.h" +#include "chrome/browser/automation/automation_window_tracker.h" +#include "chrome/browser/gtk/gtk_util.h" +#include "chrome/browser/gtk/view_id_util.h" void TestingAutomationProvider::ActivateWindow(int handle) { NOTIMPLEMENTED(); @@ -17,3 +22,72 @@ void TestingAutomationProvider::IsWindowMaximized(int handle, NOTIMPLEMENTED(); } +void TestingAutomationProvider::TerminateSession(int handle, bool* success) { + *success = false; + NOTIMPLEMENTED(); +} + +#if !defined(TOOLKIT_VIEWS) +void TestingAutomationProvider::WindowGetViewBounds(int handle, + int view_id, + bool screen_coordinates, + bool* success, + gfx::Rect* bounds) { + *success = false; + + GtkWindow* window = window_tracker_->GetResource(handle); + if (window) { + GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), + static_cast<ViewID>(view_id)); + if (!widget) + return; + *success = true; + *bounds = gfx::Rect(widget->allocation.width, widget->allocation.height); + gint x, y; + if (screen_coordinates) { + gfx::Point point = gtk_util::GetWidgetScreenPosition(widget); + x = point.x(); + y = point.y(); + } else { + gtk_widget_translate_coordinates(widget, GTK_WIDGET(window), + 0, 0, &x, &y); + } + bounds->set_origin(gfx::Point(x, y)); + } +} +#endif + +void TestingAutomationProvider::GetWindowBounds(int handle, + gfx::Rect* bounds, + bool* result) { + *result = false; + NOTIMPLEMENTED(); +} + +void TestingAutomationProvider::SetWindowBounds(int handle, + const gfx::Rect& bounds, + bool* success) { + *success = false; + GtkWindow* window = window_tracker_->GetResource(handle); + if (window) { + gtk_window_move(window, bounds.x(), bounds.height()); + gtk_window_resize(window, bounds.width(), bounds.height()); + *success = true; + } +} + +void TestingAutomationProvider::SetWindowVisible(int handle, + bool visible, + bool* result) { + *result = false; + GtkWindow* window = window_tracker_->GetResource(handle); + if (window) { + if (visible) { + gtk_window_present(window); + } else { + gtk_widget_hide(GTK_WIDGET(window)); + } + *result = true; + } +} + diff --git a/chrome/browser/automation/testing_automation_provider_mac.mm b/chrome/browser/automation/testing_automation_provider_mac.mm index ce61658..4d4084f 100644 --- a/chrome/browser/automation/testing_automation_provider_mac.mm +++ b/chrome/browser/automation/testing_automation_provider_mac.mm @@ -4,7 +4,14 @@ #include "chrome/browser/automation/testing_automation_provider.h" +#import <Cocoa/Cocoa.h> + #include "base/logging.h" +#include "chrome/browser/automation/automation_browser_tracker.h" +#include "chrome/browser/automation/automation_window_tracker.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#include "chrome/browser/cocoa/tab_window_controller.h" +#include "chrome/browser/view_ids.h" void TestingAutomationProvider::ActivateWindow(int handle) { NOTIMPLEMENTED(); @@ -17,3 +24,88 @@ void TestingAutomationProvider::IsWindowMaximized(int handle, NOTIMPLEMENTED(); } +void TestingAutomationProvider::TerminateSession(int handle, bool* success) { + *success = false; + NOTIMPLEMENTED(); +} + +void TestingAutomationProvider::WindowGetViewBounds(int handle, + int view_id, + bool screen_coordinates, + bool* success, + gfx::Rect* bounds) { + *success = false; + + // At the moment we hard code the view ID used by WebDriver and do + // not support arbitrary view IDs. suzhe is working on general view + // ID support for the Mac. + if (view_id != VIEW_ID_TAB_CONTAINER) { + NOTIMPLEMENTED(); + return; + } + + NSWindow* window = window_tracker_->GetResource(handle); + if (!window) + return; + + BrowserWindowController* controller = [window windowController]; + DCHECK([controller isKindOfClass:[BrowserWindowController class]]); + if (![controller isKindOfClass:[BrowserWindowController class]]) + return; + NSView* tab = [controller selectedTabView]; + if (!tab) + return; + + NSPoint coords = NSZeroPoint; + if (screen_coordinates) { + coords = [window convertBaseToScreen:[tab convertPoint:NSZeroPoint + toView:nil]]; + } else { + coords = [tab convertPoint:NSZeroPoint toView:[window contentView]]; + } + // Flip coordinate system + coords.y = [[window screen] frame].size.height - coords.y; + *success = true; +} + +void TestingAutomationProvider::GetWindowBounds(int handle, + gfx::Rect* bounds, + bool* result) { + *result = false; + NOTIMPLEMENTED(); +} + +void TestingAutomationProvider::SetWindowBounds(int handle, + const gfx::Rect& bounds, + bool* success) { + *success = false; + NSWindow* window = window_tracker_->GetResource(handle); + if (window) { + NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect()); + + if ([[NSScreen screens] count] > 0) { + new_bounds.origin.y = + [[[NSScreen screens] objectAtIndex:0] frame].size.height - + new_bounds.origin.y - new_bounds.size.height; + } + + [window setFrame:new_bounds display:NO]; + *success = true; + } +} + +void TestingAutomationProvider::SetWindowVisible(int handle, + bool visible, + bool* result) { + *result = false; + NSWindow* window = window_tracker_->GetResource(handle); + if (window) { + if (visible) { + [window orderFront:nil]; + } else { + [window orderOut:nil]; + } + *result = true; + } +} + diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc new file mode 100644 index 0000000..cf6b4d7 --- /dev/null +++ b/chrome/browser/automation/testing_automation_provider_views.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/automation/testing_automation_provider.h" + +#include "chrome/browser/automation/automation_window_tracker.h" +#include "chrome/browser/browser_window.h" +#include "gfx/point.h" +#include "views/view.h" +#include "views/widget/root_view.h" +#include "views/widget/widget.h" + +void TestingAutomationProvider::WindowGetViewBounds(int handle, + int view_id, + bool screen_coordinates, + bool* success, + gfx::Rect* bounds) { + *success = false; + + if (window_tracker_->ContainsHandle(handle)) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + views::RootView* root_view = views::Widget::FindRootView(window); + if (root_view) { + views::View* view = root_view->GetViewByID(view_id); + if (view) { + *success = true; + gfx::Point point; + if (screen_coordinates) + views::View::ConvertPointToScreen(view, &point); + else + views::View::ConvertPointToView(view, root_view, &point); + *bounds = view->GetLocalBounds(false); + bounds->set_origin(point); + } + } + } +} diff --git a/chrome/browser/automation/testing_automation_provider_win.cc b/chrome/browser/automation/testing_automation_provider_win.cc index dcb8b1c..c48b372 100644 --- a/chrome/browser/automation/testing_automation_provider_win.cc +++ b/chrome/browser/automation/testing_automation_provider_win.cc @@ -6,7 +6,9 @@ #include <windows.h> +#include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" +#include "chrome/browser/browser_window.h" void TestingAutomationProvider::ActivateWindow(int handle) { if (window_tracker_->ContainsHandle(handle)) { @@ -28,3 +30,51 @@ void TestingAutomationProvider::IsWindowMaximized(int handle, } } +void TestingAutomationProvider::TerminateSession(int handle, bool* success) { + *success = false; + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + HWND window = browser->window()->GetNativeHandle(); + *success = (::PostMessageW(window, WM_ENDSESSION, 0, 0) == TRUE); + } +} + +void TestingAutomationProvider::GetWindowBounds(int handle, + gfx::Rect* bounds, + bool* success) { + *success = false; + HWND hwnd = window_tracker_->GetResource(handle); + if (hwnd) { + *success = true; + WINDOWPLACEMENT window_placement; + GetWindowPlacement(hwnd, &window_placement); + *bounds = window_placement.rcNormalPosition; + } +} + +void TestingAutomationProvider::SetWindowBounds(int handle, + const gfx::Rect& bounds, + bool* success) { + *success = false; + if (window_tracker_->ContainsHandle(handle)) { + HWND hwnd = window_tracker_->GetResource(handle); + if (::MoveWindow(hwnd, bounds.x(), bounds.y(), bounds.width(), + bounds.height(), true)) { + *success = true; + } + } +} + +void TestingAutomationProvider::SetWindowVisible(int handle, + bool visible, + bool* result) { + if (window_tracker_->ContainsHandle(handle)) { + HWND hwnd = window_tracker_->GetResource(handle); + ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE); + *result = true; + } else { + *result = false; + } +} + diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index afb1f7b..2158c27 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1,6 +1,6 @@ # Copyright (c) 2010 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. +# found in the LICENSE file. { 'targets': [ @@ -224,6 +224,7 @@ 'browser/automation/extension_port_container.h', 'browser/automation/testing_automation_provider_gtk.cc', 'browser/automation/testing_automation_provider_mac.mm', + 'browser/automation/testing_automation_provider_views.cc', 'browser/automation/testing_automation_provider_win.cc', 'browser/automation/testing_automation_provider.cc', 'browser/automation/testing_automation_provider.h', |