diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 23:29:39 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 23:29:39 +0000 |
commit | 4feac66ec2fcf5956b644d08940c6452aef42c69 (patch) | |
tree | 907ec6127399e202602221a20eeab69cd1ecb0c1 /chrome/browser/automation | |
parent | 505c7ca6be6b30af4bacd6f975a1241233516dc8 (diff) | |
download | chromium_src-4feac66ec2fcf5956b644d08940c6452aef42c69.zip chromium_src-4feac66ec2fcf5956b644d08940c6452aef42c69.tar.gz chromium_src-4feac66ec2fcf5956b644d08940c6452aef42c69.tar.bz2 |
GTTF: Move more code from AutomationProvider to TestingAutomationProvider
TEST=ui_tests, chrome_frame_tests
BUG=52097
Review URL: http://codereview.chromium.org/3108049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 202 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 84 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_views.cc | 165 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 181 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 72 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider_views.cc | 158 |
6 files changed, 418 insertions, 444 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index bf76d62..3dc91aba 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -132,8 +132,7 @@ class AutomationInterstitialPage : public InterstitialPage { AutomationProvider::AutomationProvider(Profile* profile) : profile_(profile), - reply_message_(NULL), - popup_menu_waiter_(NULL) { + reply_message_(NULL) { TRACE_EVENT_BEGIN("AutomationProvider::AutomationProvider", 0, ""); browser_tracker_.reset(new AutomationBrowserTracker(this)); @@ -313,15 +312,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) #endif // defined(OS_WIN) IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) - IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, - ExecuteJavascript) - IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, - GetConstrainedWindowCount) - IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest) - IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, - HandleInspectElementRequest) IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, @@ -329,8 +319,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, OpenNewBrowserWindowOfType) IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) - IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, - GetAutocompleteEditForBrowser) IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, ShowInterstitialPage) @@ -350,14 +338,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) - IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, - GetAutocompleteEditText) - IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, - SetAutocompleteEditText) - IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, - AutocompleteEditIsQueryInProgress) - IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, - AutocompleteEditGetMatches) IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, HandleOpenFindInPageRequest) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) @@ -459,14 +439,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting) IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme) -#if defined(TOOLKIT_VIEWS) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange, - WaitForFocusedViewIDToChange) - IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus, - StartTrackingPopupMenus) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen, - WaitForPopupMenuToOpen) -#endif // defined(TOOLKIT_VIEWS) #if defined(OS_WIN) // These are for use with external tabs. IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) @@ -582,43 +554,6 @@ Browser* AutomationProvider::FindAndActivateTab( return browser; } -void AutomationProvider::ApplyAccelerator(int handle, int id) { - NOTREACHED() << "This function has been deprecated. " - << "Please use ExecuteBrowserCommandAsync instead."; -} - -void AutomationProvider::ExecuteJavascript(int handle, - const std::wstring& frame_xpath, - const std::wstring& script, - IPC::Message* reply_message) { - bool succeeded = false; - TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); - if (tab_contents) { - // Set the routing id of this message with the controller. - // This routing id needs to be remembered for the reverse - // communication while sending back the response of - // this javascript execution. - std::wstring set_automation_id; - SStringPrintf(&set_automation_id, - L"window.domAutomationController.setAutomationId(%d);", - reply_message->routing_id()); - - DCHECK(reply_message_ == NULL); - reply_message_ = reply_message; - - tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( - frame_xpath, set_automation_id); - tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( - frame_xpath, script); - succeeded = true; - } - - if (!succeeded) { - AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); - Send(reply_message); - } -} - void AutomationProvider::SetShelfVisibility(int handle, bool visible) { if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); @@ -631,26 +566,6 @@ void AutomationProvider::SetShelfVisibility(int handle, bool visible) { } } -void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { - *count = -1; // -1 is the error code - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* nav_controller = tab_tracker_->GetResource(handle); - TabContents* tab_contents = nav_controller->tab_contents(); - if (tab_contents) { - *count = static_cast<int>(tab_contents->child_windows_.size()); - } - } -} - -void AutomationProvider::HandleFindInPageRequest( - int handle, const std::wstring& find_request, - int forward, int match_case, int* active_ordinal, int* matches_found) { - NOTREACHED() << "This function has been deprecated." - << "Please use HandleFindRequest instead."; - *matches_found = -1; - return; -} - void AutomationProvider::HandleFindRequest( int handle, const AutomationMsg_Find_Params& params, @@ -2722,30 +2637,6 @@ void AutomationProvider::SendJSONRequest(int handle, } } -void AutomationProvider::HandleInspectElementRequest( - int handle, int x, int y, IPC::Message* reply_message) { - TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); - if (tab_contents) { - DCHECK(reply_message_ == NULL); - reply_message_ = reply_message; - - DevToolsManager::GetInstance()->InspectElement( - tab_contents->render_view_host(), x, y); - } else { - AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); - Send(reply_message); - } -} - -void AutomationProvider::ReceivedInspectElementResponse(int num_resources) { - if (reply_message_) { - AutomationMsg_InspectElement::WriteReplyParams(reply_message_, - num_resources); - Send(reply_message_); - reply_message_ = NULL; - } -} - class SetProxyConfigTask : public Task { public: SetProxyConfigTask(URLRequestContextGetter* request_context_getter, @@ -2870,23 +2761,6 @@ void AutomationProvider::GetWindowForBrowser(int browser_handle, } } -void AutomationProvider::GetAutocompleteEditForBrowser( - int browser_handle, - bool* success, - int* autocomplete_edit_handle) { - *success = false; - *autocomplete_edit_handle = 0; - - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - LocationBar* loc_bar = browser->window()->GetLocationBar(); - AutocompleteEditView* edit_view = loc_bar->location_entry(); - // Add() returns the existing handle for the resource if any. - *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); - *success = true; - } -} - void AutomationProvider::ShowInterstitialPage(int tab_handle, const std::string& html_text, IPC::Message* reply_message) { @@ -3064,60 +2938,6 @@ void AutomationProvider::SavePage(int tab_handle, *success = true; } -void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, - bool* success, - std::wstring* text) { - *success = false; - if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { - *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> - GetText(); - *success = true; - } -} - -void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle, - const std::wstring& text, - bool* success) { - *success = false; - if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { - autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> - SetUserText(text); - *success = true; - } -} - -void AutomationProvider::AutocompleteEditGetMatches( - int autocomplete_edit_handle, - bool* success, - std::vector<AutocompleteMatchData>* matches) { - *success = false; - if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { - const AutocompleteResult& result = autocomplete_edit_tracker_-> - GetResource(autocomplete_edit_handle)->model()->result(); - for (AutocompleteResult::const_iterator i = result.begin(); - i != result.end(); ++i) - matches->push_back(AutocompleteMatchData(*i)); - *success = true; - } -} - -void AutomationProvider::AutocompleteEditIsQueryInProgress( - int autocomplete_edit_handle, - bool* success, - bool* query_in_progress) { - *success = false; - *query_in_progress = false; - if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { - *query_in_progress = autocomplete_edit_tracker_-> - GetResource(autocomplete_edit_handle)->model()->query_in_progress(); - *success = true; - } -} - -#if !defined(OS_MACOSX) - -#endif // !defined(OS_MACOSX) - TabContents* AutomationProvider::GetTabContentsForHandle( int handle, NavigationController** tab) { if (tab_tracker_->ContainsHandle(handle)) { @@ -3783,26 +3603,6 @@ void AutomationProvider::SetContentSetting( } } -#if !defined(TOOLKIT_VIEWS) -void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { - NOTIMPLEMENTED(); -}; - -void AutomationProvider::WaitForFocusedViewIDToChange( - int handle, int previous_view_id, IPC::Message* reply_message) { - NOTIMPLEMENTED(); -} - -void AutomationProvider::StartTrackingPopupMenus( - int browser_handle, bool* success) { - NOTIMPLEMENTED(); -} - -void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { - NOTIMPLEMENTED(); -} -#endif // !defined(TOOLKIT_VIEWS) - void AutomationProvider::ResetToDefaultTheme() { profile_->ClearTheme(); } diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index d94b149..da8a842 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -132,9 +132,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, virtual void OnMessageReceived(const IPC::Message& msg); virtual void OnChannelError(); - // Received response from inspector controller - void ReceivedInspectElementResponse(int num_resources); - IPC::Message* reply_message_release() { IPC::Message* reply_message = reply_message_; reply_message_ = NULL; @@ -157,7 +154,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, protected: friend class base::RefCounted<AutomationProvider>; - friend class PopupMenuWaiter; virtual ~AutomationProvider(); // Helper function to find the browser window that contains a given @@ -165,6 +161,12 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, // Returns the Browser if found. Browser* FindAndActivateTab(NavigationController* contents); + // Convert a tab handle into a TabContents. If |tab| is non-NULL a pointer + // to the tab is also returned. Returns NULL in case of failure or if the tab + // is not of the TabContents type. + TabContents* GetTabContentsForHandle(int handle, NavigationController** tab); + + scoped_ptr<AutomationAutocompleteEditTracker> autocomplete_edit_tracker_; scoped_ptr<AutomationBrowserTracker> browser_tracker_; scoped_ptr<AutomationTabTracker> tab_tracker_; scoped_ptr<AutomationWindowTracker> window_tracker_; @@ -198,10 +200,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void GetTabHWND(int handle, HWND* tab_hwnd); #endif // defined(OS_WIN) 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 SetShelfVisibility(int handle, bool visible); void SetFilteredInet(const IPC::Message& message, bool enabled); void GetFilteredInetHitCount(int* hit_count); @@ -212,21 +210,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, ContentSetting setting, bool* success); - void GetFocusedViewID(int handle, int* view_id); - - // Deprecated. - void ApplyAccelerator(int handle, int id); - - void GetConstrainedWindowCount(int handle, int* count); - - // This function has been deprecated, please use HandleFindRequest. - void HandleFindInPageRequest(int handle, - const std::wstring& find_request, - int forward, - int match_case, - int* active_ordinal, - int* matches_found); - // Responds to the FindInPage request, retrieves the search query parameters, // launches an observer to listen for results and issues a StartFind request. void HandleFindRequest(int handle, @@ -538,12 +521,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DictionaryValue*, IPC::Message*); - // Responds to InspectElement request - void HandleInspectElementRequest(int handle, - int x, - int y, - IPC::Message* reply_message); - void GetDownloadDirectory(int handle, FilePath* download_directory); // Retrieves a Browser from a Window and vice-versa. @@ -551,9 +528,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void GetBrowserForWindow(int window_handle, bool* success, int* browser_handle); - void GetAutocompleteEditForBrowser(int browser_handle, bool* success, - int* autocomplete_edit_handle); - // If |show| is true, call Show() on the new window after creating it. void OpenNewBrowserWindow(bool show, IPC::Message* reply_message); void OpenNewBrowserWindowOfType(int type, @@ -654,26 +628,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, int type, bool* success); - // Retrieves the visible text from the autocomplete edit. - void GetAutocompleteEditText(int autocomplete_edit_handle, - bool* success, std::wstring* text); - - // Sets the visible text from the autocomplete edit. - void SetAutocompleteEditText(int autocomplete_edit_handle, - const std::wstring& text, - bool* success); - - // Retrieves if a query to an autocomplete provider is in progress. - void AutocompleteEditIsQueryInProgress(int autocomplete_edit_handle, - bool* success, - bool* query_in_progress); - - // Retrieves the individual autocomplete matches displayed by the popup. - void AutocompleteEditGetMatches(int autocomplete_edit_handle, - bool* success, - std::vector<AutocompleteMatchData>* matches); - - // Retrieves the number of info-bars currently showing in |count|. void GetInfoBarCount(int handle, int* count); @@ -766,11 +720,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, int number_of_navigations, IPC::Message* reply_message); - // Convert a tab handle into a TabContents. If |tab| is non-NULL a pointer - // to the tab is also returned. Returns NULL in case of failure or if the tab - // is not of the TabContents type. - TabContents* GetTabContentsForHandle(int handle, NavigationController** tab); - #if defined(OS_CHROMEOS) // Logs in through the Chrome OS Login Wizard with given |username| and // password. Returns true via |reply_message| on success. @@ -795,19 +744,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, // the associated extension is disabled. Returns NULL otherwise. Extension* GetDisabledExtension(int extension_handle); - // Block until the focused view ID changes to something other than - // previous_view_id. - void WaitForFocusedViewIDToChange(int handle, - int previous_view_id, - IPC::Message* reply_message); - - // Start tracking popup menus. Must be called before executing the - // command that might open the popup menu; then call WaitForPopupMenuToOpen. - void StartTrackingPopupMenus(int browser_handle, bool* success); - - // Wait until a popup menu has opened. - void WaitForPopupMenuToOpen(IPC::Message* reply_message); - // Method called by the popup menu tracker when a popup menu is opened. void NotifyPopupMenuOpened(); @@ -881,20 +817,12 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, extension_test_result_observer_; scoped_ptr<MetricEventDurationObserver> metric_event_duration_observer_; scoped_ptr<AutomationExtensionTracker> extension_tracker_; - scoped_ptr<AutomationAutocompleteEditTracker> autocomplete_edit_tracker_; scoped_ptr<NavigationControllerRestoredObserver> restore_tracker_; PortContainerMap port_containers_; NotificationObserverList notification_observer_list_; scoped_refptr<AutomationResourceMessageFilter> automation_resource_message_filter_; - // Keep track of whether a popup menu has been opened since the last time - // that StartTrackingPopupMenus has been called. - bool popup_menu_opened_; - - // A temporary object that receives a notification when a popup menu opens. - PopupMenuWaiter* popup_menu_waiter_; - DISALLOW_COPY_AND_ASSIGN(AutomationProvider); }; diff --git a/chrome/browser/automation/automation_provider_views.cc b/chrome/browser/automation/automation_provider_views.cc deleted file mode 100644 index 76ff3de..0000000 --- a/chrome/browser/automation/automation_provider_views.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) 2009 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/automation_provider.h" - -#include "chrome/browser/automation/automation_browser_tracker.h" -#include "chrome/browser/automation/automation_window_tracker.h" -#include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/toolbar_view.h" -#include "chrome/test/automation/automation_messages.h" -#include "gfx/point.h" -#include "views/controls/menu/menu_wrapper.h" -#include "views/focus/focus_manager.h" -#include "views/view.h" -#include "views/widget/root_view.h" -#include "views/widget/widget.h" - -void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { - *view_id = -1; - if (window_tracker_->ContainsHandle(handle)) { - gfx::NativeWindow window = window_tracker_->GetResource(handle); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeWindow(window); - DCHECK(focus_manager); - views::View* focused_view = focus_manager->GetFocusedView(); - if (focused_view) - *view_id = focused_view->GetID(); - } -} - -// Helper class that waits until the focus has changed to a view other -// than the one with the provided view id. -class ViewFocusChangeWaiter : public views::FocusChangeListener { - public: - ViewFocusChangeWaiter(views::FocusManager* focus_manager, - int previous_view_id, - AutomationProvider* automation, - IPC::Message* reply_message) - : focus_manager_(focus_manager), - previous_view_id_(previous_view_id), - automation_(automation), - reply_message_(reply_message), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { - focus_manager_->AddFocusChangeListener(this); - // Call the focus change notification once in case the focus has - // already changed. - FocusWillChange(NULL, focus_manager_->GetFocusedView()); - } - - ~ViewFocusChangeWaiter() { - focus_manager_->RemoveFocusChangeListener(this); - } - - // Inherited from FocusChangeListener - virtual void FocusWillChange(views::View* focused_before, - views::View* focused_now) { - // This listener is called before focus actually changes. Post a task - // that will get run after focus changes. - MessageLoop::current()->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &ViewFocusChangeWaiter::FocusChanged, - focused_before, - focused_now)); - } - - private: - void FocusChanged(views::View* focused_before, - views::View* focused_now) { - if (focused_now && focused_now->GetID() != previous_view_id_) { - AutomationMsg_WaitForFocusedViewIDToChange::WriteReplyParams( - reply_message_, true, focused_now->GetID()); - - automation_->Send(reply_message_); - delete this; - } - } - - views::FocusManager* focus_manager_; - int previous_view_id_; - AutomationProvider* automation_; - IPC::Message* reply_message_; - ScopedRunnableMethodFactory<ViewFocusChangeWaiter> method_factory_; - - DISALLOW_COPY_AND_ASSIGN(ViewFocusChangeWaiter); -}; - -void AutomationProvider::WaitForFocusedViewIDToChange( - int handle, int previous_view_id, IPC::Message* reply_message) { - if (!window_tracker_->ContainsHandle(handle)) - return; - gfx::NativeWindow window = window_tracker_->GetResource(handle); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeWindow(window); - - // The waiter will respond to the IPC and delete itself when done. - new ViewFocusChangeWaiter(focus_manager, - previous_view_id, - this, - reply_message); -} - -class PopupMenuWaiter : public views::MenuListener { - public: - PopupMenuWaiter(ToolbarView* toolbar_view, - AutomationProvider* automation) - : toolbar_view_(toolbar_view), - automation_(automation), - reply_message_(NULL) { - toolbar_view_->AddMenuListener(this); - } - - // Implementation of views::MenuListener - virtual void OnMenuOpened() { - toolbar_view_->RemoveMenuListener(this); - automation_->popup_menu_opened_ = true; - automation_->popup_menu_waiter_ = NULL; - if (reply_message_) { - AutomationMsg_WaitForPopupMenuToOpen::WriteReplyParams( - reply_message_, true); - automation_->Send(reply_message_); - } - delete this; - } - - void set_reply_message(IPC::Message* reply_message) { - reply_message_ = reply_message; - } - - private: - ToolbarView* toolbar_view_; - AutomationProvider* automation_; - IPC::Message* reply_message_; - - DISALLOW_COPY_AND_ASSIGN(PopupMenuWaiter); -}; - -void AutomationProvider::StartTrackingPopupMenus( - int browser_handle, bool* success) { - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - BrowserView* browser_view = reinterpret_cast<BrowserView*>( - browser->window()); - ToolbarView* toolbar_view = browser_view->GetToolbarView(); - popup_menu_opened_ = false; - popup_menu_waiter_ = new PopupMenuWaiter(toolbar_view, this); - *success = true; - } -} - -void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { - // See if the menu already opened and return true if so. - if (popup_menu_opened_) { - AutomationMsg_WaitForPopupMenuToOpen::WriteReplyParams( - reply_message, true); - Send(reply_message); - return; - } - - // Otherwise, register this reply message with the waiter, - // which will handle responding to this IPC when the popup - // menu opens. - popup_menu_waiter_->set_reply_message(reply_message); -} diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index f6c2b29..a24935f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -7,6 +7,8 @@ #include "base/command_line.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/autocomplete/autocomplete_edit.h" +#include "chrome/browser/automation/automation_autocomplete_edit_tracker.h" #include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_provider_list.h" #include "chrome/browser/automation/automation_provider_observers.h" @@ -15,9 +17,12 @@ #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/debugger/devtools_manager.h" +#include "chrome/browser/location_bar.h" #include "chrome/browser/login_prompt.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/renderer_host/render_process_host.h" +#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_service.h" @@ -163,6 +168,9 @@ class ClickTask : public Task { TestingAutomationProvider::TestingAutomationProvider(Profile* profile) : AutomationProvider(profile), +#if defined(TOOLKIT_VIEWS) + popup_menu_waiter_(NULL), +#endif redirect_query_(0) { BrowserList::AddObserver(this); registrar_.Add(this, NotificationType::SESSION_END, @@ -239,6 +247,33 @@ void TestingAutomationProvider::OnMessageReceived( IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, GetFullscreenBubbleVisibility) + IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, + GetAutocompleteEditForBrowser) + IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, + GetAutocompleteEditText) + IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, + SetAutocompleteEditText) + IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, + AutocompleteEditIsQueryInProgress) + IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, + AutocompleteEditGetMatches) + IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, + ExecuteJavascript) + IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, + GetConstrainedWindowCount) + IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest) +#if defined(TOOLKIT_VIEWS) + IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange, + WaitForFocusedViewIDToChange) + IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus, + StartTrackingPopupMenus) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen, + WaitForPopupMenuToOpen) +#endif // defined(TOOLKIT_VIEWS) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, + HandleInspectElementRequest) IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); IPC_END_MESSAGE_MAP() @@ -874,6 +909,152 @@ void TestingAutomationProvider::GetFullscreenBubbleVisibility(int handle, } } +void TestingAutomationProvider::GetAutocompleteEditText( + int autocomplete_edit_handle, + bool* success, + std::wstring* text) { + *success = false; + if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { + *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> + GetText(); + *success = true; + } +} + +void TestingAutomationProvider::SetAutocompleteEditText( + int autocomplete_edit_handle, + const std::wstring& text, + bool* success) { + *success = false; + if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { + autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> + SetUserText(text); + *success = true; + } +} + +void TestingAutomationProvider::AutocompleteEditGetMatches( + int autocomplete_edit_handle, + bool* success, + std::vector<AutocompleteMatchData>* matches) { + *success = false; + if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { + const AutocompleteResult& result = autocomplete_edit_tracker_-> + GetResource(autocomplete_edit_handle)->model()->result(); + for (AutocompleteResult::const_iterator i = result.begin(); + i != result.end(); ++i) + matches->push_back(AutocompleteMatchData(*i)); + *success = true; + } +} + +void TestingAutomationProvider::GetAutocompleteEditForBrowser( + int browser_handle, + bool* success, + int* autocomplete_edit_handle) { + *success = false; + *autocomplete_edit_handle = 0; + + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + LocationBar* loc_bar = browser->window()->GetLocationBar(); + AutocompleteEditView* edit_view = loc_bar->location_entry(); + // Add() returns the existing handle for the resource if any. + *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); + *success = true; + } +} + +void TestingAutomationProvider::AutocompleteEditIsQueryInProgress( + int autocomplete_edit_handle, + bool* success, + bool* query_in_progress) { + *success = false; + *query_in_progress = false; + if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { + *query_in_progress = autocomplete_edit_tracker_-> + GetResource(autocomplete_edit_handle)->model()->query_in_progress(); + *success = true; + } +} + +void TestingAutomationProvider::ApplyAccelerator(int handle, int id) { + LOG(ERROR) << "ApplyAccelerator has been deprecated. " + << "Please use ExecuteBrowserCommandAsync instead."; +} + +void TestingAutomationProvider::ExecuteJavascript( + int handle, + const std::wstring& frame_xpath, + const std::wstring& script, + IPC::Message* reply_message) { + bool succeeded = false; + TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); + if (tab_contents) { + // Set the routing id of this message with the controller. + // This routing id needs to be remembered for the reverse + // communication while sending back the response of + // this javascript execution. + std::wstring set_automation_id; + SStringPrintf(&set_automation_id, + L"window.domAutomationController.setAutomationId(%d);", + reply_message->routing_id()); + + DCHECK(reply_message_ == NULL); + reply_message_ = reply_message; + + tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( + frame_xpath, set_automation_id); + tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( + frame_xpath, script); + succeeded = true; + } + + if (!succeeded) { + AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); + Send(reply_message); + } +} + +void TestingAutomationProvider::GetConstrainedWindowCount(int handle, + int* count) { + *count = -1; // -1 is the error code + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* nav_controller = tab_tracker_->GetResource(handle); + TabContents* tab_contents = nav_controller->tab_contents(); + if (tab_contents) { + *count = static_cast<int>(tab_contents->child_windows_.size()); + } + } +} + +void TestingAutomationProvider::HandleFindInPageRequest( + int handle, + const std::wstring& find_request, + int forward, + int match_case, + int* active_ordinal, + int* matches_found) { + LOG(ERROR) << "HandleFindInPageRequest has been deprecated." + << "Please use HandleFindRequest instead."; + *matches_found = -1; +} + +void TestingAutomationProvider::HandleInspectElementRequest( + int handle, int x, int y, IPC::Message* reply_message) { + TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); + if (tab_contents) { + DCHECK(reply_message_ == NULL); + reply_message_ = reply_message; + + DevToolsManager::GetInstance()->InspectElement( + tab_contents->render_view_host(), x, y); + } else { + AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); + Send(reply_message); + } +} + // 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 7d75e36..dadd4e6 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -30,6 +30,8 @@ class TestingAutomationProvider : public AutomationProvider, virtual void OnChannelError(); private: + class PopupMenuWaiter; + virtual ~TestingAutomationProvider(); // IPC Message callbacks. @@ -110,6 +112,67 @@ class TestingAutomationProvider : public AutomationProvider, void GetShelfVisibility(int handle, bool* visible); void IsFullscreen(int handle, bool* is_fullscreen); void GetFullscreenBubbleVisibility(int handle, bool* is_visible); + void GetAutocompleteEditForBrowser(int browser_handle, bool* success, + int* autocomplete_edit_handle); + + // Retrieves the visible text from the autocomplete edit. + void GetAutocompleteEditText(int autocomplete_edit_handle, + bool* success, std::wstring* text); + + // Sets the visible text from the autocomplete edit. + void SetAutocompleteEditText(int autocomplete_edit_handle, + const std::wstring& text, + bool* success); + + // Retrieves if a query to an autocomplete provider is in progress. + void AutocompleteEditIsQueryInProgress(int autocomplete_edit_handle, + bool* success, + bool* query_in_progress); + + // Retrieves the individual autocomplete matches displayed by the popup. + void AutocompleteEditGetMatches(int autocomplete_edit_handle, + bool* success, + std::vector<AutocompleteMatchData>* matches); + + // Deprecated. + void ApplyAccelerator(int handle, int id); + + void ExecuteJavascript(int handle, + const std::wstring& frame_xpath, + const std::wstring& script, + IPC::Message* reply_message); + + void GetConstrainedWindowCount(int handle, int* count); + + // This function has been deprecated, please use HandleFindRequest. + void HandleFindInPageRequest(int handle, + const std::wstring& find_request, + int forward, + int match_case, + int* active_ordinal, + int* matches_found); + +#if defined(TOOLKIT_VIEWS) + void GetFocusedViewID(int handle, int* view_id); + + // Block until the focused view ID changes to something other than + // previous_view_id. + void WaitForFocusedViewIDToChange(int handle, + int previous_view_id, + IPC::Message* reply_message); + + // Start tracking popup menus. Must be called before executing the + // command that might open the popup menu; then call WaitForPopupMenuToOpen. + void StartTrackingPopupMenus(int browser_handle, bool* success); + + // Wait until a popup menu has opened. + void WaitForPopupMenuToOpen(IPC::Message* reply_message); +#endif // defined(TOOLKIT_VIEWS) + + void HandleInspectElementRequest(int handle, + int x, + int y, + IPC::Message* reply_message); // Callback for history redirect queries. virtual void OnRedirectQueryComplete( @@ -124,6 +187,15 @@ class TestingAutomationProvider : public AutomationProvider, void OnRemoveProvider(); // Called via PostTask +#if defined(TOOLKIT_VIEWS) + // Keep track of whether a popup menu has been opened since the last time + // that StartTrackingPopupMenus has been called. + bool popup_menu_opened_; + + // A temporary object that receives a notification when a popup menu opens. + PopupMenuWaiter* popup_menu_waiter_; +#endif // defined(TOOLKIT_VIEWS) + // Handle for an in-process redirect query. We expect only one redirect query // at a time (we should have only one caller, and it will block while waiting // for the results) so there is only one handle. When non-0, indicates a diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc index cf6b4d7..6048cd8 100644 --- a/chrome/browser/automation/testing_automation_provider_views.cc +++ b/chrome/browser/automation/testing_automation_provider_views.cc @@ -4,13 +4,114 @@ #include "chrome/browser/automation/testing_automation_provider.h" +#include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/views/frame/browser_view.h" +#include "chrome/browser/views/toolbar_view.h" +#include "chrome/test/automation/automation_messages.h" #include "gfx/point.h" +#include "views/controls/menu/menu_wrapper.h" #include "views/view.h" #include "views/widget/root_view.h" #include "views/widget/widget.h" +namespace { + +// Helper class that waits until the focus has changed to a view other +// than the one with the provided view id. +class ViewFocusChangeWaiter : public views::FocusChangeListener { + public: + ViewFocusChangeWaiter(views::FocusManager* focus_manager, + int previous_view_id, + AutomationProvider* automation, + IPC::Message* reply_message) + : focus_manager_(focus_manager), + previous_view_id_(previous_view_id), + automation_(automation), + reply_message_(reply_message), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + focus_manager_->AddFocusChangeListener(this); + // Call the focus change notification once in case the focus has + // already changed. + FocusWillChange(NULL, focus_manager_->GetFocusedView()); + } + + ~ViewFocusChangeWaiter() { + focus_manager_->RemoveFocusChangeListener(this); + } + + // Inherited from FocusChangeListener + virtual void FocusWillChange(views::View* focused_before, + views::View* focused_now) { + // This listener is called before focus actually changes. Post a task + // that will get run after focus changes. + MessageLoop::current()->PostTask( + FROM_HERE, + method_factory_.NewRunnableMethod( + &ViewFocusChangeWaiter::FocusChanged, + focused_before, + focused_now)); + } + + private: + void FocusChanged(views::View* focused_before, + views::View* focused_now) { + if (focused_now && focused_now->GetID() != previous_view_id_) { + AutomationMsg_WaitForFocusedViewIDToChange::WriteReplyParams( + reply_message_, true, focused_now->GetID()); + + automation_->Send(reply_message_); + delete this; + } + } + + views::FocusManager* focus_manager_; + int previous_view_id_; + AutomationProvider* automation_; + IPC::Message* reply_message_; + ScopedRunnableMethodFactory<ViewFocusChangeWaiter> method_factory_; + + DISALLOW_COPY_AND_ASSIGN(ViewFocusChangeWaiter); +}; + +} // namespace + +class TestingAutomationProvider::PopupMenuWaiter : public views::MenuListener { + public: + PopupMenuWaiter(ToolbarView* toolbar_view, + TestingAutomationProvider* automation) + : toolbar_view_(toolbar_view), + automation_(automation), + reply_message_(NULL) { + toolbar_view_->AddMenuListener(this); + } + + // Implementation of views::MenuListener + virtual void OnMenuOpened() { + toolbar_view_->RemoveMenuListener(this); + automation_->popup_menu_opened_ = true; + automation_->popup_menu_waiter_ = NULL; + if (reply_message_) { + AutomationMsg_WaitForPopupMenuToOpen::WriteReplyParams( + reply_message_, true); + automation_->Send(reply_message_); + } + delete this; + } + + void set_reply_message(IPC::Message* reply_message) { + reply_message_ = reply_message; + } + + private: + ToolbarView* toolbar_view_; + TestingAutomationProvider* automation_; + IPC::Message* reply_message_; + + DISALLOW_COPY_AND_ASSIGN(PopupMenuWaiter); +}; + void TestingAutomationProvider::WindowGetViewBounds(int handle, int view_id, bool screen_coordinates, @@ -36,3 +137,60 @@ void TestingAutomationProvider::WindowGetViewBounds(int handle, } } } + +void TestingAutomationProvider::GetFocusedViewID(int handle, int* view_id) { + *view_id = -1; + if (window_tracker_->ContainsHandle(handle)) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + views::FocusManager* focus_manager = + views::FocusManager::GetFocusManagerForNativeWindow(window); + DCHECK(focus_manager); + views::View* focused_view = focus_manager->GetFocusedView(); + if (focused_view) + *view_id = focused_view->GetID(); + } +} + +void TestingAutomationProvider::WaitForFocusedViewIDToChange( + int handle, int previous_view_id, IPC::Message* reply_message) { + if (!window_tracker_->ContainsHandle(handle)) + return; + gfx::NativeWindow window = window_tracker_->GetResource(handle); + views::FocusManager* focus_manager = + views::FocusManager::GetFocusManagerForNativeWindow(window); + + // The waiter will respond to the IPC and delete itself when done. + new ViewFocusChangeWaiter(focus_manager, + previous_view_id, + this, + reply_message); +} + +void TestingAutomationProvider::StartTrackingPopupMenus( + int browser_handle, bool* success) { + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + BrowserView* browser_view = reinterpret_cast<BrowserView*>( + browser->window()); + ToolbarView* toolbar_view = browser_view->GetToolbarView(); + popup_menu_opened_ = false; + popup_menu_waiter_ = new PopupMenuWaiter(toolbar_view, this); + *success = true; + } +} + +void TestingAutomationProvider::WaitForPopupMenuToOpen( + IPC::Message* reply_message) { + // See if the menu already opened and return true if so. + if (popup_menu_opened_) { + AutomationMsg_WaitForPopupMenuToOpen::WriteReplyParams( + reply_message, true); + Send(reply_message); + return; + } + + // Otherwise, register this reply message with the waiter, + // which will handle responding to this IPC when the popup + // menu opens. + popup_menu_waiter_->set_reply_message(reply_message); +} |