diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 16:26:05 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 16:26:05 +0000 |
commit | a0eca45b109d89137269cb9b5004e8a51309a6b2 (patch) | |
tree | f41edc2d88c5d944f86021725f4ed87eece0a86b | |
parent | bd1fc4c8a20ca6728df62cb8bf865a294832f07a (diff) | |
download | chromium_src-a0eca45b109d89137269cb9b5004e8a51309a6b2.zip chromium_src-a0eca45b109d89137269cb9b5004e8a51309a6b2.tar.gz chromium_src-a0eca45b109d89137269cb9b5004e8a51309a6b2.tar.bz2 |
GTTF: Continue moving test automation code out of AutomationProvider.
TEST=ui_tests, chrome_frame_tests
BUG=52097
Review URL: http://codereview.chromium.org/3201019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57687 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 396 insertions, 376 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 8a57931..d432550 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -300,49 +300,15 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, SendJSONRequest) - IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickInfoBarAccept, - ClickInfoBarAccept) - IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime, - GetLastNavigationTime) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation, - WaitForNavigation) - IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference) - IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog, - GetShowingAppModalDialog) - IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton, - ClickAppModalDialogButton) - IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference) - IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference, - GetBooleanPreference) - IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference, - SetBooleanPreference) IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, GetPageCurrentEncoding) IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) - IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, - SavePackageShouldPromptUser) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) - IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) - IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) - IPC_MESSAGE_HANDLER_DELAY_REPLY( - AutomationMsg_WaitForBrowserWindowCountToBecome, - WaitForBrowserWindowCountToBecome) - IPC_MESSAGE_HANDLER_DELAY_REPLY( - AutomationMsg_WaitForAppModalDialogToBeShown, - WaitForAppModalDialogToBeShown) - IPC_MESSAGE_HANDLER_DELAY_REPLY( - AutomationMsg_GoBackBlockUntilNavigationsComplete, - GoBackBlockUntilNavigationsComplete) - IPC_MESSAGE_HANDLER_DELAY_REPLY( - AutomationMsg_GoForwardBlockUntilNavigationsComplete, - GoForwardBlockUntilNavigationsComplete) IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, InstallExtension) @@ -403,38 +369,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_END_MESSAGE_MAP() } -void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, - int* dialog_button) { - AppModalDialog* dialog_delegate = - Singleton<AppModalDialogQueue>()->active_dialog(); - *showing_dialog = (dialog_delegate != NULL); - if (*showing_dialog) - *dialog_button = dialog_delegate->GetDialogButtons(); - else - *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; -} - -void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { - *success = false; - - AppModalDialog* dialog_delegate = - Singleton<AppModalDialogQueue>()->active_dialog(); - if (dialog_delegate && - (dialog_delegate->GetDialogButtons() & button) == button) { - if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == - MessageBoxFlags::DIALOGBUTTON_OK) { - dialog_delegate->AcceptWindow(); - *success = true; - } - if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == - MessageBoxFlags::DIALOGBUTTON_CANCEL) { - DCHECK(!*success) << "invalid param, OK and CANCEL specified"; - dialog_delegate->CancelWindow(); - *success = true; - } - } -} - void AutomationProvider::ShutdownSessionService(int handle, bool* result) { if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); @@ -489,18 +423,6 @@ Browser* AutomationProvider::FindAndActivateTab( return browser; } -void AutomationProvider::SetShelfVisibility(int handle, bool visible) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - if (visible) - browser->window()->GetDownloadShelf()->Show(); - else - browser->window()->GetDownloadShelf()->Close(); - } - } -} - void AutomationProvider::HandleFindRequest( int handle, const AutomationMsg_Find_Params& params, @@ -2418,120 +2340,6 @@ TabContents* AutomationProvider::GetTabContentsForHandle( return NULL; } -void AutomationProvider::GetInfoBarCount(int handle, int* count) { - *count = -1; // -1 means error. - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* nav_controller = tab_tracker_->GetResource(handle); - if (nav_controller) - *count = nav_controller->tab_contents()->infobar_delegate_count(); - } -} - -void AutomationProvider::ClickInfoBarAccept(int handle, - int info_bar_index, - bool wait_for_navigation, - IPC::Message* reply_message) { - bool success = false; - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* nav_controller = tab_tracker_->GetResource(handle); - if (nav_controller) { - int count = nav_controller->tab_contents()->infobar_delegate_count(); - if (info_bar_index >= 0 && info_bar_index < count) { - if (wait_for_navigation) { - AddNavigationStatusListener(nav_controller, reply_message, 1, false); - } - InfoBarDelegate* delegate = - nav_controller->tab_contents()->GetInfoBarDelegateAt( - info_bar_index); - if (delegate->AsConfirmInfoBarDelegate()) - delegate->AsConfirmInfoBarDelegate()->Accept(); - success = true; - } - } - } - - // This "!wait_for_navigation || !success condition" logic looks suspicious. - // It will send a failure message when success is true but - // |wait_for_navigation| is false. - // TODO(phajdan.jr): investgate whether the reply param (currently - // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success. - if (!wait_for_navigation || !success) - AutomationMsg_ClickInfoBarAccept::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); -} - -void AutomationProvider::GetLastNavigationTime(int handle, - int64* last_navigation_time) { - Time time = tab_tracker_->GetLastNavigationTime(handle); - *last_navigation_time = time.ToInternalValue(); -} - -void AutomationProvider::WaitForNavigation(int handle, - int64 last_navigation_time, - IPC::Message* reply_message) { - NavigationController* controller = tab_tracker_->GetResource(handle); - Time time = tab_tracker_->GetLastNavigationTime(handle); - - if (time.ToInternalValue() > last_navigation_time || !controller) { - AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, - controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : - AUTOMATION_MSG_NAVIGATION_SUCCESS); - Send(reply_message); - return; - } - - AddNavigationStatusListener(controller, reply_message, 1, true); -} - -void AutomationProvider::SetIntPreference(int handle, - const std::string& name, - int value, - bool* success) { - *success = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); - *success = true; - } -} - -void AutomationProvider::SetStringPreference(int handle, - const std::string& name, - const std::string& value, - bool* success) { - *success = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - browser->profile()->GetPrefs()->SetString(name.c_str(), value); - *success = true; - } -} - -void AutomationProvider::GetBooleanPreference(int handle, - const std::string& name, - bool* success, - bool* value) { - *success = false; - *value = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); - *success = true; - } -} - -void AutomationProvider::SetBooleanPreference(int handle, - const std::string& name, - bool value, - bool* success) { - *success = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); - *success = true; - } -} - // Gets the current used encoding name of the page in the specified tab. void AutomationProvider::GetPageCurrentEncoding( int tab_handle, std::string* current_encoding) { @@ -2581,29 +2389,6 @@ void AutomationProvider::OverrideEncoding(int tab_handle, } } -void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { - SavePackage::SetShouldPromptUser(should_prompt); -} - -void AutomationProvider::GetBlockedPopupCount(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) { - BlockedPopupContainer* container = - tab_contents->blocked_popup_container(); - if (container) { - *count = static_cast<int>(container->GetBlockedPopupCount()); - } else { - // If we don't have a container, we don't have any blocked popups to - // contain! - *count = 0; - } - } - } -} - void AutomationProvider::SelectAll(int tab_handle) { RenderViewHost* view = GetViewForTab(tab_handle); if (!view) { @@ -2701,68 +2486,6 @@ void AutomationProvider::RemoveBrowsingData(int remove_mask) { // BrowsingDataRemover deletes itself. } -void AutomationProvider::WaitForBrowserWindowCountToBecome( - int target_count, IPC::Message* reply_message) { - if (static_cast<int>(BrowserList::size()) == target_count) { - AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( - reply_message, true); - Send(reply_message); - return; - } - - // Set up an observer (it will delete itself). - new BrowserCountChangeNotificationObserver(target_count, this, reply_message); -} - -void AutomationProvider::WaitForAppModalDialogToBeShown( - IPC::Message* reply_message) { - if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { - AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( - reply_message, true); - Send(reply_message); - return; - } - - // Set up an observer (it will delete itself). - new AppModalDialogShownObserver(this, reply_message); -} - -void AutomationProvider::GoBackBlockUntilNavigationsComplete( - int handle, int number_of_navigations, IPC::Message* reply_message) { - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - Browser* browser = FindAndActivateTab(tab); - if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations, - false); - browser->GoBack(CURRENT_TAB); - return; - } - } - - AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); - Send(reply_message); -} - -void AutomationProvider::GoForwardBlockUntilNavigationsComplete( - int handle, int number_of_navigations, IPC::Message* reply_message) { - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - Browser* browser = FindAndActivateTab(tab); - if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations, - false); - browser->GoForward(CURRENT_TAB); - return; - } - } - - AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); - Send(reply_message); -} - RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { if (tab_tracker_->ContainsHandle(tab_handle)) { NavigationController* tab = tab_tracker_->GetResource(tab_handle); diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index e3f653d..5cdae38 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -192,8 +192,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, private: // IPC Message callbacks. - void GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button); - void ClickAppModalDialogButton(int button, bool* success); void ShutdownSessionService(int handle, bool* result); void WindowSimulateDrag(int handle, std::vector<gfx::Point> drag_path, @@ -206,7 +204,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 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); @@ -528,49 +525,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, // Asynchronous request for printing the current tab. void PrintAsync(int tab_handle); - // Retrieves the number of info-bars currently showing in |count|. - void GetInfoBarCount(int handle, int* count); - - // Causes a click on the "accept" button of the info-bar at |info_bar_index|. - // If |wait_for_navigation| is true, it sends the reply after a navigation has - // occurred. - void ClickInfoBarAccept(int handle, int info_bar_index, - bool wait_for_navigation, - IPC::Message* reply_message); - - // Retrieves the last time a navigation occurred for the tab. - void GetLastNavigationTime(int handle, int64* last_navigation_time); - - // Waits for a new navigation in the tab if none has happened since - // |last_navigation_time|. - void WaitForNavigation(int handle, - int64 last_navigation_time, - IPC::Message* reply_message); - - // Sets the int value for preference with name |name|. - void SetIntPreference(int handle, - const std::string& name, - int value, - bool* success); - - // Sets the string value for preference with name |name|. - void SetStringPreference(int handle, - const std::string& name, - const std::string& value, - bool* success); - - // Gets the bool value for preference with name |name|. - void GetBooleanPreference(int handle, - const std::string& name, - bool* success, - bool* value); - - // Sets the bool value for preference with name |name|. - void SetBooleanPreference(int handle, - const std::string& name, - bool value, - bool* success); - // Resets to the default theme. void ResetToDefaultTheme(); @@ -583,18 +537,11 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, const std::string& encoding_name, bool* success); - void SavePackageShouldPromptUser(bool should_prompt); - // Enables extension automation (for e.g. UITests). void SetEnableExtensionAutomation( int tab_handle, const std::vector<std::string>& functions_enabled); - void GetWindowTitle(int handle, string16* text); - - // Returns the number of blocked popups in the tab |handle|. - void GetBlockedPopupCount(int handle, int* count); - // Selects all contents on the page. void SelectAll(int tab_handle); @@ -607,19 +554,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void StopAsync(int tab_handle); void SaveAsAsync(int tab_handle); - void WaitForBrowserWindowCountToBecome(int target_count, - IPC::Message* reply_message); - - void WaitForAppModalDialogToBeShown(IPC::Message* reply_message); - - void GoBackBlockUntilNavigationsComplete(int handle, - int number_of_navigations, - IPC::Message* reply_message); - - void GoForwardBlockUntilNavigationsComplete(int handle, - int number_of_navigations, - IPC::Message* reply_message); - #if defined(OS_CHROMEOS) // Logs in through the Chrome OS Login Wizard with given |username| and // password. Returns true via |reply_message| on success. diff --git a/chrome/browser/automation/automation_provider_gtk.cc b/chrome/browser/automation/automation_provider_gtk.cc index 5438eeb..37c4fb8 100644 --- a/chrome/browser/automation/automation_provider_gtk.cc +++ b/chrome/browser/automation/automation_provider_gtk.cc @@ -139,9 +139,3 @@ void AutomationProvider::WindowSimulateDrag(int handle, Send(reply_message); } } - -void AutomationProvider::GetWindowTitle(int handle, string16* text) { - gfx::NativeWindow window = window_tracker_->GetResource(handle); - const gchar* title = gtk_window_get_title(window); - text->assign(UTF8ToUTF16(title)); -} diff --git a/chrome/browser/automation/automation_provider_mac.mm b/chrome/browser/automation/automation_provider_mac.mm index 29d5af4..99c1bdb 100644 --- a/chrome/browser/automation/automation_provider_mac.mm +++ b/chrome/browser/automation/automation_provider_mac.mm @@ -33,22 +33,3 @@ void AutomationProvider::WindowSimulateDrag(int handle, Send(reply_message); } -void AutomationProvider::GetWindowTitle(int handle, string16* text) { - gfx::NativeWindow window = window_tracker_->GetResource(handle); - NSString* title = nil; - if ([[window delegate] isKindOfClass:[TabWindowController class]]) { - TabWindowController* delegate = - reinterpret_cast<TabWindowController*>([window delegate]); - title = [delegate selectedTabTitle]; - } else { - title = [window title]; - } - // If we don't yet have a title, use "Untitled". - if (![title length]) { - text->assign(l10n_util::GetStringUTF16( - IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); - return; - } - - text->assign(base::SysNSStringToUTF16(title)); -} diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 70312df..23e8e3d 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -422,14 +422,6 @@ void AutomationProvider::OnBrowserMoved(int tab_handle) { } } -void AutomationProvider::GetWindowTitle(int handle, string16* text) { - gfx::NativeWindow window = window_tracker_->GetResource(handle); - std::wstring result; - int length = ::GetWindowTextLength(window) + 1; - ::GetWindowText(window, WriteInto(&result, length), length); - text->assign(WideToUTF16(result)); -} - void AutomationProvider::OnMessageFromExternalHost(int handle, const std::string& message, const std::string& origin, diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 5ec755b..e7abd68 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -4,9 +4,13 @@ #include "chrome/browser/automation/testing_automation_provider.h" +#include "app/message_box_flags.h" #include "base/command_line.h" +#include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/app_modal_dialog.h" +#include "chrome/browser/app_modal_dialog_queue.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" @@ -17,15 +21,19 @@ #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_storage.h" +#include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/debugger/devtools_manager.h" +#include "chrome/browser/download/download_shelf.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/login_prompt.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/interstitial_page.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_request_context_getter.h" @@ -343,6 +351,40 @@ void TestingAutomationProvider::OnMessageReceived( SetBookmarkURL) IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark, RemoveBookmark) + IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickInfoBarAccept, + ClickInfoBarAccept) + IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime, + GetLastNavigationTime) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation, + WaitForNavigation) + IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference) + IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog, + GetShowingAppModalDialog) + IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton, + ClickAppModalDialogButton) + IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference) + IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference, + GetBooleanPreference) + IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference, + SetBooleanPreference) + IPC_MESSAGE_HANDLER_DELAY_REPLY( + AutomationMsg_WaitForBrowserWindowCountToBecome, + WaitForBrowserWindowCountToBecome) + IPC_MESSAGE_HANDLER_DELAY_REPLY( + AutomationMsg_WaitForAppModalDialogToBeShown, + WaitForAppModalDialogToBeShown) + IPC_MESSAGE_HANDLER_DELAY_REPLY( + AutomationMsg_GoBackBlockUntilNavigationsComplete, + GoBackBlockUntilNavigationsComplete) + IPC_MESSAGE_HANDLER_DELAY_REPLY( + AutomationMsg_GoForwardBlockUntilNavigationsComplete, + GoForwardBlockUntilNavigationsComplete) + IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, + SavePackageShouldPromptUser) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) + IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) + IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); IPC_END_MESSAGE_MAP() @@ -1627,6 +1669,253 @@ void TestingAutomationProvider::RemoveBookmark(int handle, *success = false; } +void TestingAutomationProvider::GetInfoBarCount(int handle, int* count) { + *count = -1; // -1 means error. + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* nav_controller = tab_tracker_->GetResource(handle); + if (nav_controller) + *count = nav_controller->tab_contents()->infobar_delegate_count(); + } +} + +void TestingAutomationProvider::ClickInfoBarAccept( + int handle, + int info_bar_index, + bool wait_for_navigation, + IPC::Message* reply_message) { + bool success = false; + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* nav_controller = tab_tracker_->GetResource(handle); + if (nav_controller) { + int count = nav_controller->tab_contents()->infobar_delegate_count(); + if (info_bar_index >= 0 && info_bar_index < count) { + if (wait_for_navigation) { + AddNavigationStatusListener(nav_controller, reply_message, 1, false); + } + InfoBarDelegate* delegate = + nav_controller->tab_contents()->GetInfoBarDelegateAt( + info_bar_index); + if (delegate->AsConfirmInfoBarDelegate()) + delegate->AsConfirmInfoBarDelegate()->Accept(); + success = true; + } + } + } + + // This "!wait_for_navigation || !success condition" logic looks suspicious. + // It will send a failure message when success is true but + // |wait_for_navigation| is false. + // TODO(phajdan.jr): investgate whether the reply param (currently + // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success. + if (!wait_for_navigation || !success) + AutomationMsg_ClickInfoBarAccept::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); +} + +void TestingAutomationProvider::GetLastNavigationTime( + int handle, + int64* last_navigation_time) { + base::Time time(tab_tracker_->GetLastNavigationTime(handle)); + *last_navigation_time = time.ToInternalValue(); +} + +void TestingAutomationProvider::WaitForNavigation(int handle, + int64 last_navigation_time, + IPC::Message* reply_message) { + NavigationController* controller = tab_tracker_->GetResource(handle); + base::Time time(tab_tracker_->GetLastNavigationTime(handle)); + + if (time.ToInternalValue() > last_navigation_time || !controller) { + AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, + controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : + AUTOMATION_MSG_NAVIGATION_SUCCESS); + Send(reply_message); + return; + } + + AddNavigationStatusListener(controller, reply_message, 1, true); +} + +void TestingAutomationProvider::SetIntPreference(int handle, + const std::string& name, + int value, + bool* success) { + *success = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); + *success = true; + } +} + +void TestingAutomationProvider::SetStringPreference(int handle, + const std::string& name, + const std::string& value, + bool* success) { + *success = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + browser->profile()->GetPrefs()->SetString(name.c_str(), value); + *success = true; + } +} + +void TestingAutomationProvider::GetBooleanPreference(int handle, + const std::string& name, + bool* success, + bool* value) { + *success = false; + *value = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); + *success = true; + } +} + +void TestingAutomationProvider::SetBooleanPreference(int handle, + const std::string& name, + bool value, + bool* success) { + *success = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); + *success = true; + } +} + +void TestingAutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, + int* dialog_button) { + AppModalDialog* dialog_delegate = + Singleton<AppModalDialogQueue>()->active_dialog(); + *showing_dialog = (dialog_delegate != NULL); + if (*showing_dialog) + *dialog_button = dialog_delegate->GetDialogButtons(); + else + *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; +} + +void TestingAutomationProvider::ClickAppModalDialogButton(int button, + bool* success) { + *success = false; + + AppModalDialog* dialog_delegate = + Singleton<AppModalDialogQueue>()->active_dialog(); + if (dialog_delegate && + (dialog_delegate->GetDialogButtons() & button) == button) { + if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == + MessageBoxFlags::DIALOGBUTTON_OK) { + dialog_delegate->AcceptWindow(); + *success = true; + } + if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == + MessageBoxFlags::DIALOGBUTTON_CANCEL) { + DCHECK(!*success) << "invalid param, OK and CANCEL specified"; + dialog_delegate->CancelWindow(); + *success = true; + } + } +} + +void TestingAutomationProvider::WaitForBrowserWindowCountToBecome( + int target_count, IPC::Message* reply_message) { + if (static_cast<int>(BrowserList::size()) == target_count) { + AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( + reply_message, true); + Send(reply_message); + return; + } + + // Set up an observer (it will delete itself). + new BrowserCountChangeNotificationObserver(target_count, this, reply_message); +} + +void TestingAutomationProvider::WaitForAppModalDialogToBeShown( + IPC::Message* reply_message) { + if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { + AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( + reply_message, true); + Send(reply_message); + return; + } + + // Set up an observer (it will delete itself). + new AppModalDialogShownObserver(this, reply_message); +} + +void TestingAutomationProvider::GoBackBlockUntilNavigationsComplete( + int handle, int number_of_navigations, IPC::Message* reply_message) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + Browser* browser = FindAndActivateTab(tab); + if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { + AddNavigationStatusListener(tab, reply_message, number_of_navigations, + false); + browser->GoBack(CURRENT_TAB); + return; + } + } + + AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); + Send(reply_message); +} + +void TestingAutomationProvider::GoForwardBlockUntilNavigationsComplete( + int handle, int number_of_navigations, IPC::Message* reply_message) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + Browser* browser = FindAndActivateTab(tab); + if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { + AddNavigationStatusListener(tab, reply_message, number_of_navigations, + false); + browser->GoForward(CURRENT_TAB); + return; + } + } + + AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); + Send(reply_message); +} + +void TestingAutomationProvider::SavePackageShouldPromptUser( + bool should_prompt) { + SavePackage::SetShouldPromptUser(should_prompt); +} + +void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + if (visible) + browser->window()->GetDownloadShelf()->Show(); + else + browser->window()->GetDownloadShelf()->Close(); + } + } +} + +void TestingAutomationProvider::GetBlockedPopupCount(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) { + BlockedPopupContainer* container = + tab_contents->blocked_popup_container(); + if (container) { + *count = static_cast<int>(container->GetBlockedPopupCount()); + } else { + // If we don't have a container, we don't have any blocked popups to + // contain! + *count = 0; + } + } + } +} + // 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 1ea87e2..11be6c9b 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -278,6 +278,74 @@ class TestingAutomationProvider : public AutomationProvider, int64 id, bool* success); + // Retrieves the number of info-bars currently showing in |count|. + void GetInfoBarCount(int handle, int* count); + + // Causes a click on the "accept" button of the info-bar at |info_bar_index|. + // If |wait_for_navigation| is true, it sends the reply after a navigation has + // occurred. + void ClickInfoBarAccept(int handle, int info_bar_index, + bool wait_for_navigation, + IPC::Message* reply_message); + + // Retrieves the last time a navigation occurred for the tab. + void GetLastNavigationTime(int handle, int64* last_navigation_time); + + // Waits for a new navigation in the tab if none has happened since + // |last_navigation_time|. + void WaitForNavigation(int handle, + int64 last_navigation_time, + IPC::Message* reply_message); + + // Sets the int value for preference with name |name|. + void SetIntPreference(int handle, + const std::string& name, + int value, + bool* success); + + // Sets the string value for preference with name |name|. + void SetStringPreference(int handle, + const std::string& name, + const std::string& value, + bool* success); + + // Gets the bool value for preference with name |name|. + void GetBooleanPreference(int handle, + const std::string& name, + bool* success, + bool* value); + + // Sets the bool value for preference with name |name|. + void SetBooleanPreference(int handle, + const std::string& name, + bool value, + bool* success); + + void GetShowingAppModalDialog(bool* showing_dialog, int* dialog_button); + void ClickAppModalDialogButton(int button, bool* success); + + void WaitForBrowserWindowCountToBecome(int target_count, + IPC::Message* reply_message); + + void WaitForAppModalDialogToBeShown(IPC::Message* reply_message); + + void GoBackBlockUntilNavigationsComplete(int handle, + int number_of_navigations, + IPC::Message* reply_message); + + void GoForwardBlockUntilNavigationsComplete(int handle, + int number_of_navigations, + IPC::Message* reply_message); + + void SavePackageShouldPromptUser(bool should_prompt); + + void GetWindowTitle(int handle, string16* text); + + void SetShelfVisibility(int handle, bool visible); + + // Returns the number of blocked popups in the tab |handle|. + void GetBlockedPopupCount(int handle, int* count); + // Callback for history redirect queries. virtual void OnRedirectQueryComplete( HistoryService::Handle request_handle, diff --git a/chrome/browser/automation/testing_automation_provider_gtk.cc b/chrome/browser/automation/testing_automation_provider_gtk.cc index 93959fd..b57d1b9 100644 --- a/chrome/browser/automation/testing_automation_provider_gtk.cc +++ b/chrome/browser/automation/testing_automation_provider_gtk.cc @@ -7,6 +7,7 @@ #include <gtk/gtk.h> #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/automation/automation_window_tracker.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/view_id_util.h" @@ -91,3 +92,8 @@ void TestingAutomationProvider::SetWindowVisible(int handle, } } +void TestingAutomationProvider::GetWindowTitle(int handle, string16* text) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + const gchar* title = gtk_window_get_title(window); + text->assign(UTF8ToUTF16(title)); +} diff --git a/chrome/browser/automation/testing_automation_provider_mac.mm b/chrome/browser/automation/testing_automation_provider_mac.mm index 4d4084f..4d368b1 100644 --- a/chrome/browser/automation/testing_automation_provider_mac.mm +++ b/chrome/browser/automation/testing_automation_provider_mac.mm @@ -6,12 +6,16 @@ #import <Cocoa/Cocoa.h> +#include "app/l10n_util.h" +#include "app/l10n_util_mac.h" #include "base/logging.h" +#include "base/sys_string_conversions.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" +#include "grit/generated_resources.h" void TestingAutomationProvider::ActivateWindow(int handle) { NOTIMPLEMENTED(); @@ -109,3 +113,22 @@ void TestingAutomationProvider::SetWindowVisible(int handle, } } +void TestingAutomationProvider::GetWindowTitle(int handle, string16* text) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + NSString* title = nil; + if ([[window delegate] isKindOfClass:[TabWindowController class]]) { + TabWindowController* delegate = + reinterpret_cast<TabWindowController*>([window delegate]); + title = [delegate selectedTabTitle]; + } else { + title = [window title]; + } + // If we don't yet have a title, use "Untitled". + if (![title length]) { + text->assign(l10n_util::GetStringUTF16( + IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); + return; + } + + text->assign(base::SysNSStringToUTF16(title)); +} diff --git a/chrome/browser/automation/testing_automation_provider_win.cc b/chrome/browser/automation/testing_automation_provider_win.cc index c48b372..8cd2a72 100644 --- a/chrome/browser/automation/testing_automation_provider_win.cc +++ b/chrome/browser/automation/testing_automation_provider_win.cc @@ -6,6 +6,8 @@ #include <windows.h> +#include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" #include "chrome/browser/browser_window.h" @@ -78,3 +80,11 @@ void TestingAutomationProvider::SetWindowVisible(int handle, } } +void TestingAutomationProvider::GetWindowTitle(int handle, string16* text) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + std::wstring result; + int length = ::GetWindowTextLength(window) + 1; + ::GetWindowText(window, WriteInto(&result, length), length); + text->assign(WideToUTF16(result)); +} + |