diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 18:13:10 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 18:13:10 +0000 |
commit | e6022ca66a35f529dd4f206ba8c882401619c9b9 (patch) | |
tree | 94c8432617d844648740470042caaf3bfacb8fbd /chrome/browser/automation | |
parent | 9cae6a30cd835001be45b411f8ace91005ceb988 (diff) | |
download | chromium_src-e6022ca66a35f529dd4f206ba8c882401619c9b9.zip chromium_src-e6022ca66a35f529dd4f206ba8c882401619c9b9.tar.gz chromium_src-e6022ca66a35f529dd4f206ba8c882401619c9b9.tar.bz2 |
GTTF: Move more and more automation bits to TestingAutomationProvider
And now it seems to handle more automation messages than the original one.
TEST=ui_tests, chrome_frame_tests
BUG=52097
Review URL: http://codereview.chromium.org/3185030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 553 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 115 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 572 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 104 |
4 files changed, 681 insertions, 663 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index eee8fbb..8a57931 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -113,23 +113,6 @@ using base::Time; -class AutomationInterstitialPage : public InterstitialPage { - public: - AutomationInterstitialPage(TabContents* tab, - const GURL& url, - const std::string& contents) - : InterstitialPage(tab, true, url), - contents_(contents) { - } - - virtual std::string GetHTMLContents() { return contents_; } - - private: - std::string contents_; - - DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); -}; - AutomationProvider::AutomationProvider(Profile* profile) : profile_(profile), reply_message_(NULL) { @@ -312,57 +295,9 @@ 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_DownloadDirectory, GetDownloadDirectory) IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, - OpenNewBrowserWindow) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, - OpenNewBrowserWindowOfType) - IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) - IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, - ShowInterstitialPage) - IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, - HideInterstitialPage) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, - WaitForTabToBeRestored) - IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) - IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) - IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, - GetMetricEventDuration) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, - ActionOnSSLBlockingPage) - IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) - IPC_MESSAGE_HANDLER(AutomationMsg_IsMenuCommandEnabled, - IsMenuCommandEnabled) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) - IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) - IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, - HandleOpenFindInPageRequest) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) - IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, - GetFindWindowVisibility) - IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation, - HandleFindWindowLocationRequest) - IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, - GetBookmarkBarVisibility) - IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON, - GetBookmarksAsJSON) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad, - WaitForBookmarkModelToLoad) - IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkGroup, - AddBookmarkGroup) - IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkURL, - AddBookmarkURL) - IPC_MESSAGE_HANDLER(AutomationMsg_ReparentBookmark, - ReparentBookmark) - IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkTitle, - SetBookmarkTitle) - IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkURL, - SetBookmarkURL) - IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark, - RemoveBookmark) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, SendJSONRequest) IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount) @@ -590,251 +525,6 @@ void AutomationProvider::HandleFindRequest( params.find_next); } -void AutomationProvider::HandleOpenFindInPageRequest( - const IPC::Message& message, int handle) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - browser->FindInPage(false, false); - } -} - -void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) { - *visible = false; - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - FindBarTesting* find_bar = - browser->GetFindBarController()->find_bar()->GetFindBarTesting(); - find_bar->GetFindBarWindowInfo(NULL, visible); - } -} - -void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x, - int* y) { - gfx::Point position(0, 0); - bool visible = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - FindBarTesting* find_bar = - browser->GetFindBarController()->find_bar()->GetFindBarTesting(); - find_bar->GetFindBarWindowInfo(&position, &visible); - } - - *x = position.x(); - *y = position.y(); -} - -// Bookmark bar visibility is based on the pref (e.g. is it in the toolbar). -// Presence in the NTP is NOT considered visible by this call. -void AutomationProvider::GetBookmarkBarVisibility(int handle, - bool* visible, - bool* animating) { - *visible = false; - *animating = false; - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { -#if 0 // defined(TOOLKIT_VIEWS) && defined(OS_LINUX) - // TODO(jrg): Was removed in rev43789 for perf. Need to investigate. - - // IsBookmarkBarVisible() line looks correct but is not - // consistent across platforms. Specifically, on Mac/Linux, it - // returns false if the bar is hidden in a pref (even if visible - // on the NTP). On ChromeOS, it returned true if on NTP - // independent of the pref. Making the code more consistent - // caused a perf bot regression on Windows (which shares views). - // See http://crbug.com/40225 - *visible = browser->profile()->GetPrefs()->GetBoolean( - prefs::kShowBookmarkBar); -#else - *visible = browser->window()->IsBookmarkBarVisible(); -#endif - *animating = browser->window()->IsBookmarkBarAnimating(); - } - } -} - -void AutomationProvider::GetBookmarksAsJSON(int handle, - std::string* bookmarks_as_json, - bool *success) { - *success = false; - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - if (!browser->profile()->GetBookmarkModel()->IsLoaded()) { - return; - } - scoped_refptr<BookmarkStorage> storage = new BookmarkStorage( - browser->profile(), - browser->profile()->GetBookmarkModel()); - *success = storage->SerializeData(bookmarks_as_json); - } - } -} - -void AutomationProvider::WaitForBookmarkModelToLoad( - int handle, - IPC::Message* reply_message) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (model->IsLoaded()) { - AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( - reply_message, true); - Send(reply_message); - } else { - // The observer will delete itself when done. - new AutomationProviderBookmarkModelObserver(this, reply_message, - model); - } - } -} - -void AutomationProvider::AddBookmarkGroup(int handle, - int64 parent_id, int index, - std::wstring title, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* parent = model->GetNodeByID(parent_id); - DCHECK(parent); - if (parent) { - const BookmarkNode* child = model->AddGroup(parent, index, - WideToUTF16Hack(title)); - DCHECK(child); - if (child) - *success = true; - } - } - } - *success = false; -} - -void AutomationProvider::AddBookmarkURL(int handle, - int64 parent_id, int index, - std::wstring title, const GURL& url, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* parent = model->GetNodeByID(parent_id); - DCHECK(parent); - if (parent) { - const BookmarkNode* child = model->AddURL(parent, index, - WideToUTF16Hack(title), url); - DCHECK(child); - if (child) - *success = true; - } - } - } - *success = false; -} - -void AutomationProvider::ReparentBookmark(int handle, - int64 id, int64 new_parent_id, - int index, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* node = model->GetNodeByID(id); - DCHECK(node); - const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id); - DCHECK(new_parent); - if (node && new_parent) { - model->Move(node, new_parent, index); - *success = true; - } - } - } - *success = false; -} - -void AutomationProvider::SetBookmarkTitle(int handle, - int64 id, std::wstring title, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* node = model->GetNodeByID(id); - DCHECK(node); - if (node) { - model->SetTitle(node, WideToUTF16Hack(title)); - *success = true; - } - } - } - *success = false; -} - -void AutomationProvider::SetBookmarkURL(int handle, - int64 id, const GURL& url, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* node = model->GetNodeByID(id); - DCHECK(node); - if (node) { - model->SetURL(node, url); - *success = true; - } - } - } - *success = false; -} - -void AutomationProvider::RemoveBookmark(int handle, - int64 id, - bool* success) { - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - if (browser) { - BookmarkModel* model = browser->profile()->GetBookmarkModel(); - if (!model->IsLoaded()) { - *success = false; - return; - } - const BookmarkNode* node = model->GetNodeByID(id); - DCHECK(node); - if (node) { - const BookmarkNode* parent = node->GetParent(); - DCHECK(parent); - model->Remove(parent, parent->IndexOfChild(node)); - *success = true; - } - } - } - *success = false; -} - // Sample json input: { "command": "SetWindowDimensions", // "x": 20, # optional // "y": 20, # optional @@ -2717,227 +2407,6 @@ void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { new SetProxyConfigTask(context_getter, new_proxy_config)); } -void AutomationProvider::GetDownloadDirectory( - int handle, FilePath* download_directory) { - DLOG(INFO) << "Handling download directory request"; - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - DownloadManager* dlm = tab->profile()->GetDownloadManager(); - DCHECK(dlm); - *download_directory = dlm->download_path(); - } -} - -void AutomationProvider::OpenNewBrowserWindow(bool show, - IPC::Message* reply_message) { - OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show, - reply_message); -} - -void AutomationProvider::OpenNewBrowserWindowOfType( - int type, bool show, IPC::Message* reply_message) { - new BrowserOpenedNotificationObserver(this, reply_message); - // We may have no current browser windows open so don't rely on - // asking an existing browser to execute the IDC_NEWWINDOW command - Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); - browser->CreateBrowserWindow(); - browser->AddBlankTab(true); - if (show) - browser->window()->Show(); -} - -void AutomationProvider::GetWindowForBrowser(int browser_handle, - bool* success, - int* handle) { - *success = false; - *handle = 0; - - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - gfx::NativeWindow win = browser->window()->GetNativeHandle(); - // Add() returns the existing handle for the resource if any. - *handle = window_tracker_->Add(win); - *success = true; - } -} - -void AutomationProvider::ShowInterstitialPage(int tab_handle, - const std::string& html_text, - IPC::Message* reply_message) { - if (tab_tracker_->ContainsHandle(tab_handle)) { - NavigationController* controller = tab_tracker_->GetResource(tab_handle); - TabContents* tab_contents = controller->tab_contents(); - - AddNavigationStatusListener(controller, reply_message, 1, false); - AutomationInterstitialPage* interstitial = - new AutomationInterstitialPage(tab_contents, - GURL("about:interstitial"), - html_text); - interstitial->Show(); - return; - } - - AutomationMsg_ShowInterstitialPage::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); - Send(reply_message); -} - -void AutomationProvider::HideInterstitialPage(int tab_handle, - bool* success) { - *success = false; - TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); - if (tab_contents && tab_contents->interstitial_page()) { - tab_contents->interstitial_page()->DontProceed(); - *success = true; - } -} - -void AutomationProvider::WaitForTabToBeRestored(int tab_handle, - IPC::Message* reply_message) { - if (tab_tracker_->ContainsHandle(tab_handle)) { - NavigationController* tab = tab_tracker_->GetResource(tab_handle); - restore_tracker_.reset( - new NavigationControllerRestoredObserver(this, tab, reply_message)); - } -} - -void AutomationProvider::GetSecurityState(int handle, bool* success, - SecurityStyle* security_style, - int* ssl_cert_status, - int* insecure_content_status) { - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - NavigationEntry* entry = tab->GetActiveEntry(); - *success = true; - *security_style = entry->ssl().security_style(); - *ssl_cert_status = entry->ssl().cert_status(); - *insecure_content_status = entry->ssl().content_status(); - } else { - *success = false; - *security_style = SECURITY_STYLE_UNKNOWN; - *ssl_cert_status = 0; - *insecure_content_status = 0; - } -} - -void AutomationProvider::GetPageType(int handle, bool* success, - NavigationEntry::PageType* page_type) { - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - NavigationEntry* entry = tab->GetActiveEntry(); - *page_type = entry->page_type(); - *success = true; - // In order to return the proper result when an interstitial is shown and - // no navigation entry were created for it we need to ask the TabContents. - if (*page_type == NavigationEntry::NORMAL_PAGE && - tab->tab_contents()->showing_interstitial_page()) - *page_type = NavigationEntry::INTERSTITIAL_PAGE; - } else { - *success = false; - *page_type = NavigationEntry::NORMAL_PAGE; - } -} - -void AutomationProvider::GetMetricEventDuration(const std::string& event_name, - int* duration_ms) { - *duration_ms = metric_event_duration_observer_->GetEventDurationMs( - event_name); -} - -void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, - IPC::Message* reply_message) { - if (tab_tracker_->ContainsHandle(handle)) { - NavigationController* tab = tab_tracker_->GetResource(handle); - NavigationEntry* entry = tab->GetActiveEntry(); - if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { - TabContents* tab_contents = tab->tab_contents(); - InterstitialPage* ssl_blocking_page = - InterstitialPage::GetInterstitialPage(tab_contents); - if (ssl_blocking_page) { - if (proceed) { - AddNavigationStatusListener(tab, reply_message, 1, false); - ssl_blocking_page->Proceed(); - return; - } - ssl_blocking_page->DontProceed(); - AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); - Send(reply_message); - return; - } - } - } - // We failed. - AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); - Send(reply_message); -} - -void AutomationProvider::BringBrowserToFront(int browser_handle, - bool* success) { - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - browser->window()->Activate(); - *success = true; - } else { - *success = false; - } -} - -void AutomationProvider::IsMenuCommandEnabled(int browser_handle, - int message_num, - bool* menu_item_enabled) { - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - *menu_item_enabled = - browser->command_updater()->IsCommandEnabled(message_num); - } else { - *menu_item_enabled = false; - } -} - -void AutomationProvider::PrintNow(int tab_handle, - IPC::Message* reply_message) { - NavigationController* tab = NULL; - TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); - if (tab_contents) { - FindAndActivateTab(tab); - notification_observer_list_.AddObserver( - new DocumentPrintedNotificationObserver(this, reply_message)); - if (tab_contents->PrintNow()) - return; - } - AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); - Send(reply_message); -} - -void AutomationProvider::SavePage(int tab_handle, - const FilePath& file_name, - const FilePath& dir_path, - int type, - bool* success) { - if (!tab_tracker_->ContainsHandle(tab_handle)) { - *success = false; - return; - } - - NavigationController* nav = tab_tracker_->GetResource(tab_handle); - Browser* browser = FindAndActivateTab(nav); - DCHECK(browser); - if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { - *success = false; - return; - } - - SavePackage::SavePackageType save_type = - static_cast<SavePackage::SavePackageType>(type); - DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && - save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); - nav->tab_contents()->SavePage(file_name, dir_path, save_type); - - *success = true; -} - TabContents* AutomationProvider::GetTabContentsForHandle( int handle, NavigationController** tab) { if (tab_tracker_->ContainsHandle(handle)) { @@ -3315,28 +2784,6 @@ RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { return NULL; } -void AutomationProvider::GetBrowserForWindow(int window_handle, - bool* success, - int* browser_handle) { - *success = false; - *browser_handle = 0; - - gfx::NativeWindow window = window_tracker_->GetResource(window_handle); - if (!window) - return; - - BrowserList::const_iterator iter = BrowserList::begin(); - for (;iter != BrowserList::end(); ++iter) { - gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); - if (window == this_window) { - // Add() returns the existing handle for the resource if any. - *browser_handle = browser_tracker_->Add(*iter); - *success = true; - return; - } - } -} - void AutomationProvider::InstallExtension(const FilePath& crx_path, IPC::Message* reply_message) { ExtensionsService* service = profile_->GetExtensionsService(); diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 5bb8e0f..e3f653d 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -169,9 +169,14 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, scoped_ptr<AutomationAutocompleteEditTracker> autocomplete_edit_tracker_; scoped_ptr<AutomationBrowserTracker> browser_tracker_; + scoped_ptr<MetricEventDurationObserver> metric_event_duration_observer_; + scoped_ptr<NavigationControllerRestoredObserver> restore_tracker_; scoped_ptr<AutomationTabTracker> tab_tracker_; scoped_ptr<AutomationWindowTracker> window_tracker_; + typedef ObserverList<NotificationObserver> NotificationObserverList; + NotificationObserverList notification_observer_list_; + typedef std::map<NavigationController*, LoginHandler*> LoginHandlerMap; LoginHandlerMap login_handler_map_; @@ -217,51 +222,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, const AutomationMsg_Find_Params& params, IPC::Message* reply_message); - // Responds to requests to open the FindInPage window. - void HandleOpenFindInPageRequest(const IPC::Message& message, - int handle); - - // Get the visibility state of the Find window. - void GetFindWindowVisibility(int handle, bool* visible); - - // Responds to requests to find the location of the Find window. - void HandleFindWindowLocationRequest(int handle, int* x, int* y); - - // Get the visibility state of the Bookmark bar. - void GetBookmarkBarVisibility(int handle, bool* visible, bool* animating); - - // Get the bookmarks as a JSON string. - void GetBookmarksAsJSON(int handle, std::string* bookmarks_as_json, - bool *success); - - // Wait for the bookmark model to load. - void WaitForBookmarkModelToLoad(int handle, IPC::Message* reply_message); - - // Set |loaded| to true if the bookmark model has loaded, else false. - void BookmarkModelHasLoaded(int handle, bool* loaded); - - // Editing, modification, and removal of bookmarks. - // Bookmarks are referenced by id. - void AddBookmarkGroup(int handle, - int64 parent_id, int index, std::wstring title, - bool* success); - void AddBookmarkURL(int handle, - int64 parent_id, int index, - std::wstring title, const GURL& url, - bool* success); - void ReparentBookmark(int handle, - int64 id, int64 new_parent_id, int index, - bool* success); - void SetBookmarkTitle(int handle, - int64 id, std::wstring title, - bool* success); - void SetBookmarkURL(int handle, - int64 id, const GURL& url, - bool* success); - void RemoveBookmark(int handle, - int64 id, - bool* success); - // Set window dimensions. // Uses the JSON interface for input/output. void SetWindowDimensions(Browser* browser, @@ -522,24 +482,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DictionaryValue*, IPC::Message*); - void GetDownloadDirectory(int handle, FilePath* download_directory); - - // Retrieves a Browser from a Window and vice-versa. - void GetWindowForBrowser(int window_handle, bool* success, int* handle); - void GetBrowserForWindow(int window_handle, bool* success, - int* browser_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, - bool show, - IPC::Message* reply_message); - - void ShowInterstitialPage(int tab_handle, - const std::string& html_text, - IPC::Message* reply_message); - void HideInterstitialPage(int tab_handle, bool* success); - void OnSetPageFontSize(int tab_handle, int font_size); // See browsing_data_remover.h for explanation of bitmap fields. @@ -583,52 +525,9 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, bool* success, std::string* value); - - // See comment in AutomationMsg_WaitForTabToBeRestored. - void WaitForTabToBeRestored(int tab_handle, IPC::Message* reply_message); - - // Gets the security state for the tab associated to the specified |handle|. - void GetSecurityState(int handle, bool* success, - SecurityStyle* security_style, int* ssl_cert_status, - int* insecure_content_status); - - // Gets the page type for the tab associated to the specified |handle|. - void GetPageType(int handle, bool* success, - NavigationEntry::PageType* page_type); - - // Gets the duration in ms of the last event matching |event_name|. - // |duration_ms| is -1 if the event hasn't occurred yet. - void GetMetricEventDuration(const std::string& event_name, int* duration_ms); - - // Simulates an action on the SSL blocking page at the tab specified by - // |handle|. If |proceed| is true, it is equivalent to the user pressing the - // 'Proceed' button, if false the 'Get me out of there button'. - // Not that this fails if the tab is not displaying a SSL blocking page. - void ActionOnSSLBlockingPage(int handle, - bool proceed, - IPC::Message* reply_message); - - // Brings the browser window to the front and activates it. - void BringBrowserToFront(int browser_handle, bool* success); - - // Checks to see if a command on the browser's CommandController is enabled. - void IsMenuCommandEnabled(int browser_handle, - int message_num, - bool* menu_item_enabled); - - // Prints the current tab immediately. - void PrintNow(int tab_handle, IPC::Message* reply_message); - // Asynchronous request for printing the current tab. void PrintAsync(int tab_handle); - // Save the current web page. - void SavePage(int tab_handle, - const FilePath& file_name, - const FilePath& dir_path, - int type, - bool* success); - // Retrieves the number of info-bars currently showing in |count|. void GetInfoBarCount(int handle, int* count); @@ -805,7 +704,6 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, ExternalTabContainer* GetExternalTabForHandle(int handle); #endif // defined(OS_WIN) - typedef ObserverList<NotificationObserver> NotificationObserverList; typedef std::map<int, ExtensionPortContainer*> PortContainerMap; scoped_ptr<IPC::ChannelProxy> channel_; @@ -816,11 +714,8 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, scoped_ptr<NotificationObserver> dom_inspector_observer_; scoped_ptr<ExtensionTestResultNotificationObserver> extension_test_result_observer_; - scoped_ptr<MetricEventDurationObserver> metric_event_duration_observer_; scoped_ptr<AutomationExtensionTracker> extension_tracker_; - scoped_ptr<NavigationControllerRestoredObserver> restore_tracker_; PortContainerMap port_containers_; - NotificationObserverList notification_observer_list_; scoped_refptr<AutomationResourceMessageFilter> automation_resource_message_filter_; diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index a24935f..5ec755b 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -15,14 +15,18 @@ #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/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_storage.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/debugger/devtools_manager.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/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/tab_contents/interstitial_page.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_service.h" @@ -164,6 +168,23 @@ class ClickTask : public Task { DISALLOW_COPY_AND_ASSIGN(ClickTask); }; +class AutomationInterstitialPage : public InterstitialPage { + public: + AutomationInterstitialPage(TabContents* tab, + const GURL& url, + const std::string& contents) + : InterstitialPage(tab, true, url), + contents_(contents) { + } + + virtual std::string GetHTMLContents() { return contents_; } + + private: + std::string contents_; + + DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); +}; + } // namespace TestingAutomationProvider::TestingAutomationProvider(Profile* profile) @@ -274,6 +295,54 @@ void TestingAutomationProvider::OnMessageReceived( #endif // defined(TOOLKIT_VIEWS) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, HandleInspectElementRequest) + IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, + OpenNewBrowserWindow) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, + OpenNewBrowserWindowOfType) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) + IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, + ShowInterstitialPage) + IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, + HideInterstitialPage) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, + WaitForTabToBeRestored) + IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) + IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) + IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, + GetMetricEventDuration) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, + ActionOnSSLBlockingPage) + IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) + IPC_MESSAGE_HANDLER(AutomationMsg_IsMenuCommandEnabled, + IsMenuCommandEnabled) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) + IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) + IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, + HandleOpenFindInPageRequest) + IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, + GetFindWindowVisibility) + IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation, + HandleFindWindowLocationRequest) + IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, + GetBookmarkBarVisibility) + IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON, + GetBookmarksAsJSON) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad, + WaitForBookmarkModelToLoad) + IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkGroup, + AddBookmarkGroup) + IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkURL, + AddBookmarkURL) + IPC_MESSAGE_HANDLER(AutomationMsg_ReparentBookmark, + ReparentBookmark) + IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkTitle, + SetBookmarkTitle) + IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkURL, + SetBookmarkURL) + IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark, + RemoveBookmark) IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); IPC_END_MESSAGE_MAP() @@ -1055,6 +1124,509 @@ void TestingAutomationProvider::HandleInspectElementRequest( } } +void TestingAutomationProvider::GetDownloadDirectory( + int handle, FilePath* download_directory) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + DownloadManager* dlm = tab->profile()->GetDownloadManager(); + *download_directory = dlm->download_path(); + } +} + +void TestingAutomationProvider::OpenNewBrowserWindow( + bool show, IPC::Message* reply_message) { + OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show, + reply_message); +} + +void TestingAutomationProvider::OpenNewBrowserWindowOfType( + int type, bool show, IPC::Message* reply_message) { + new BrowserOpenedNotificationObserver(this, reply_message); + // We may have no current browser windows open so don't rely on + // asking an existing browser to execute the IDC_NEWWINDOW command + Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); + browser->CreateBrowserWindow(); + browser->AddBlankTab(true); + if (show) + browser->window()->Show(); +} + +void TestingAutomationProvider::GetWindowForBrowser(int browser_handle, + bool* success, + int* handle) { + *success = false; + *handle = 0; + + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + gfx::NativeWindow win = browser->window()->GetNativeHandle(); + // Add() returns the existing handle for the resource if any. + *handle = window_tracker_->Add(win); + *success = true; + } +} + +void TestingAutomationProvider::GetBrowserForWindow(int window_handle, + bool* success, + int* browser_handle) { + *success = false; + *browser_handle = 0; + + gfx::NativeWindow window = window_tracker_->GetResource(window_handle); + if (!window) + return; + + BrowserList::const_iterator iter = BrowserList::begin(); + for (;iter != BrowserList::end(); ++iter) { + gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); + if (window == this_window) { + // Add() returns the existing handle for the resource if any. + *browser_handle = browser_tracker_->Add(*iter); + *success = true; + return; + } + } +} + +void TestingAutomationProvider::ShowInterstitialPage( + int tab_handle, + const std::string& html_text, + IPC::Message* reply_message) { + if (tab_tracker_->ContainsHandle(tab_handle)) { + NavigationController* controller = tab_tracker_->GetResource(tab_handle); + TabContents* tab_contents = controller->tab_contents(); + + AddNavigationStatusListener(controller, reply_message, 1, false); + AutomationInterstitialPage* interstitial = + new AutomationInterstitialPage(tab_contents, + GURL("about:interstitial"), + html_text); + interstitial->Show(); + return; + } + + AutomationMsg_ShowInterstitialPage::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); + Send(reply_message); +} + +void TestingAutomationProvider::HideInterstitialPage(int tab_handle, + bool* success) { + *success = false; + TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); + if (tab_contents && tab_contents->interstitial_page()) { + tab_contents->interstitial_page()->DontProceed(); + *success = true; + } +} + +void TestingAutomationProvider::WaitForTabToBeRestored( + int tab_handle, + IPC::Message* reply_message) { + if (tab_tracker_->ContainsHandle(tab_handle)) { + NavigationController* tab = tab_tracker_->GetResource(tab_handle); + restore_tracker_.reset( + new NavigationControllerRestoredObserver(this, tab, reply_message)); + } +} + +void TestingAutomationProvider::GetSecurityState(int handle, + bool* success, + SecurityStyle* security_style, + int* ssl_cert_status, + int* insecure_content_status) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + NavigationEntry* entry = tab->GetActiveEntry(); + *success = true; + *security_style = entry->ssl().security_style(); + *ssl_cert_status = entry->ssl().cert_status(); + *insecure_content_status = entry->ssl().content_status(); + } else { + *success = false; + *security_style = SECURITY_STYLE_UNKNOWN; + *ssl_cert_status = 0; + *insecure_content_status = 0; + } +} + +void TestingAutomationProvider::GetPageType( + int handle, + bool* success, + NavigationEntry::PageType* page_type) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + NavigationEntry* entry = tab->GetActiveEntry(); + *page_type = entry->page_type(); + *success = true; + // In order to return the proper result when an interstitial is shown and + // no navigation entry were created for it we need to ask the TabContents. + if (*page_type == NavigationEntry::NORMAL_PAGE && + tab->tab_contents()->showing_interstitial_page()) + *page_type = NavigationEntry::INTERSTITIAL_PAGE; + } else { + *success = false; + *page_type = NavigationEntry::NORMAL_PAGE; + } +} + +void TestingAutomationProvider::GetMetricEventDuration( + const std::string& event_name, + int* duration_ms) { + *duration_ms = metric_event_duration_observer_->GetEventDurationMs( + event_name); +} + +void TestingAutomationProvider::ActionOnSSLBlockingPage( + int handle, + bool proceed, + IPC::Message* reply_message) { + if (tab_tracker_->ContainsHandle(handle)) { + NavigationController* tab = tab_tracker_->GetResource(handle); + NavigationEntry* entry = tab->GetActiveEntry(); + if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { + TabContents* tab_contents = tab->tab_contents(); + InterstitialPage* ssl_blocking_page = + InterstitialPage::GetInterstitialPage(tab_contents); + if (ssl_blocking_page) { + if (proceed) { + AddNavigationStatusListener(tab, reply_message, 1, false); + ssl_blocking_page->Proceed(); + return; + } + ssl_blocking_page->DontProceed(); + AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); + Send(reply_message); + return; + } + } + } + // We failed. + AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( + reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); + Send(reply_message); +} + +void TestingAutomationProvider::BringBrowserToFront(int browser_handle, + bool* success) { + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + browser->window()->Activate(); + *success = true; + } else { + *success = false; + } +} + +void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle, + int message_num, + bool* menu_item_enabled) { + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + *menu_item_enabled = + browser->command_updater()->IsCommandEnabled(message_num); + } else { + *menu_item_enabled = false; + } +} + +void TestingAutomationProvider::PrintNow(int tab_handle, + IPC::Message* reply_message) { + NavigationController* tab = NULL; + TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); + if (tab_contents) { + FindAndActivateTab(tab); + notification_observer_list_.AddObserver( + new DocumentPrintedNotificationObserver(this, reply_message)); + if (tab_contents->PrintNow()) + return; + } + AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); + Send(reply_message); +} + +void TestingAutomationProvider::SavePage(int tab_handle, + const FilePath& file_name, + const FilePath& dir_path, + int type, + bool* success) { + if (!tab_tracker_->ContainsHandle(tab_handle)) { + *success = false; + return; + } + + NavigationController* nav = tab_tracker_->GetResource(tab_handle); + Browser* browser = FindAndActivateTab(nav); + DCHECK(browser); + if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { + *success = false; + return; + } + + SavePackage::SavePackageType save_type = + static_cast<SavePackage::SavePackageType>(type); + DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && + save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); + nav->tab_contents()->SavePage(file_name, dir_path, save_type); + + *success = true; +} + +void TestingAutomationProvider::HandleOpenFindInPageRequest( + const IPC::Message& message, int handle) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + browser->FindInPage(false, false); + } +} + +void TestingAutomationProvider::GetFindWindowVisibility(int handle, + bool* visible) { + *visible = false; + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + FindBarTesting* find_bar = + browser->GetFindBarController()->find_bar()->GetFindBarTesting(); + find_bar->GetFindBarWindowInfo(NULL, visible); + } +} + +void TestingAutomationProvider::HandleFindWindowLocationRequest(int handle, + int* x, + int* y) { + gfx::Point position(0, 0); + bool visible = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + FindBarTesting* find_bar = + browser->GetFindBarController()->find_bar()->GetFindBarTesting(); + find_bar->GetFindBarWindowInfo(&position, &visible); + } + + *x = position.x(); + *y = position.y(); +} + +// Bookmark bar visibility is based on the pref (e.g. is it in the toolbar). +// Presence in the NTP is NOT considered visible by this call. +void TestingAutomationProvider::GetBookmarkBarVisibility(int handle, + bool* visible, + bool* animating) { + *visible = false; + *animating = false; + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { +#if 0 // defined(TOOLKIT_VIEWS) && defined(OS_LINUX) + // TODO(jrg): Was removed in rev43789 for perf. Need to investigate. + + // IsBookmarkBarVisible() line looks correct but is not + // consistent across platforms. Specifically, on Mac/Linux, it + // returns false if the bar is hidden in a pref (even if visible + // on the NTP). On ChromeOS, it returned true if on NTP + // independent of the pref. Making the code more consistent + // caused a perf bot regression on Windows (which shares views). + // See http://crbug.com/40225 + *visible = browser->profile()->GetPrefs()->GetBoolean( + prefs::kShowBookmarkBar); +#else + *visible = browser->window()->IsBookmarkBarVisible(); +#endif + *animating = browser->window()->IsBookmarkBarAnimating(); + } + } +} + +void TestingAutomationProvider::GetBookmarksAsJSON( + int handle, + std::string* bookmarks_as_json, + bool *success) { + *success = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + if (!browser->profile()->GetBookmarkModel()->IsLoaded()) { + return; + } + scoped_refptr<BookmarkStorage> storage = new BookmarkStorage( + browser->profile(), + browser->profile()->GetBookmarkModel()); + *success = storage->SerializeData(bookmarks_as_json); + } + } +} + +void TestingAutomationProvider::WaitForBookmarkModelToLoad( + int handle, + IPC::Message* reply_message) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (model->IsLoaded()) { + AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( + reply_message, true); + Send(reply_message); + } else { + // The observer will delete itself when done. + new AutomationProviderBookmarkModelObserver(this, reply_message, + model); + } + } +} + +void TestingAutomationProvider::AddBookmarkGroup(int handle, + int64 parent_id, + int index, + std::wstring title, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* parent = model->GetNodeByID(parent_id); + DCHECK(parent); + if (parent) { + const BookmarkNode* child = model->AddGroup(parent, index, + WideToUTF16Hack(title)); + DCHECK(child); + if (child) + *success = true; + } + } + } + *success = false; +} + +void TestingAutomationProvider::AddBookmarkURL(int handle, + int64 parent_id, + int index, + std::wstring title, + const GURL& url, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* parent = model->GetNodeByID(parent_id); + DCHECK(parent); + if (parent) { + const BookmarkNode* child = model->AddURL(parent, index, + WideToUTF16Hack(title), url); + DCHECK(child); + if (child) + *success = true; + } + } + } + *success = false; +} + +void TestingAutomationProvider::ReparentBookmark(int handle, + int64 id, + int64 new_parent_id, + int index, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* node = model->GetNodeByID(id); + DCHECK(node); + const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id); + DCHECK(new_parent); + if (node && new_parent) { + model->Move(node, new_parent, index); + *success = true; + } + } + } + *success = false; +} + +void TestingAutomationProvider::SetBookmarkTitle(int handle, + int64 id, + std::wstring title, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* node = model->GetNodeByID(id); + DCHECK(node); + if (node) { + model->SetTitle(node, WideToUTF16Hack(title)); + *success = true; + } + } + } + *success = false; +} + +void TestingAutomationProvider::SetBookmarkURL(int handle, + int64 id, + const GURL& url, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* node = model->GetNodeByID(id); + DCHECK(node); + if (node) { + model->SetURL(node, url); + *success = true; + } + } + } + *success = false; +} + +void TestingAutomationProvider::RemoveBookmark(int handle, + int64 id, + bool* success) { + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + if (browser) { + BookmarkModel* model = browser->profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + *success = false; + return; + } + const BookmarkNode* node = model->GetNodeByID(id); + DCHECK(node); + if (node) { + const BookmarkNode* parent = node->GetParent(); + DCHECK(parent); + model->Remove(parent, parent->IndexOfChild(node)); + *success = true; + } + } + } + *success = false; +} + // 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 dadd4e6..1ea87e2 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -174,6 +174,110 @@ class TestingAutomationProvider : public AutomationProvider, int y, IPC::Message* reply_message); + void GetDownloadDirectory(int handle, FilePath* download_directory); + + // 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, + bool show, + IPC::Message* reply_message); + + // Retrieves a Browser from a Window and vice-versa. + void GetWindowForBrowser(int window_handle, bool* success, int* handle); + void GetBrowserForWindow(int window_handle, bool* success, + int* browser_handle); + + void ShowInterstitialPage(int tab_handle, + const std::string& html_text, + IPC::Message* reply_message); + void HideInterstitialPage(int tab_handle, bool* success); + + void WaitForTabToBeRestored(int tab_handle, IPC::Message* reply_message); + + // Gets the security state for the tab associated to the specified |handle|. + void GetSecurityState(int handle, bool* success, + SecurityStyle* security_style, int* ssl_cert_status, + int* insecure_content_status); + + // Gets the page type for the tab associated to the specified |handle|. + void GetPageType(int handle, bool* success, + NavigationEntry::PageType* page_type); + + // Gets the duration in ms of the last event matching |event_name|. + // |duration_ms| is -1 if the event hasn't occurred yet. + void GetMetricEventDuration(const std::string& event_name, int* duration_ms); + + // Simulates an action on the SSL blocking page at the tab specified by + // |handle|. If |proceed| is true, it is equivalent to the user pressing the + // 'Proceed' button, if false the 'Get me out of there button'. + // Not that this fails if the tab is not displaying a SSL blocking page. + void ActionOnSSLBlockingPage(int handle, + bool proceed, + IPC::Message* reply_message); + + // Brings the browser window to the front and activates it. + void BringBrowserToFront(int browser_handle, bool* success); + + // Checks to see if a command on the browser's CommandController is enabled. + void IsMenuCommandEnabled(int browser_handle, + int message_num, + bool* menu_item_enabled); + + // Prints the current tab immediately. + void PrintNow(int tab_handle, IPC::Message* reply_message); + + // Save the current web page. + void SavePage(int tab_handle, + const FilePath& file_name, + const FilePath& dir_path, + int type, + bool* success); + + // Responds to requests to open the FindInPage window. + void HandleOpenFindInPageRequest(const IPC::Message& message, + int handle); + + // Get the visibility state of the Find window. + void GetFindWindowVisibility(int handle, bool* visible); + + // Responds to requests to find the location of the Find window. + void HandleFindWindowLocationRequest(int handle, int* x, int* y); + + // Get the visibility state of the Bookmark bar. + void GetBookmarkBarVisibility(int handle, bool* visible, bool* animating); + + // Get the bookmarks as a JSON string. + void GetBookmarksAsJSON(int handle, std::string* bookmarks_as_json, + bool *success); + + // Wait for the bookmark model to load. + void WaitForBookmarkModelToLoad(int handle, IPC::Message* reply_message); + + // Set |loaded| to true if the bookmark model has loaded, else false. + void BookmarkModelHasLoaded(int handle, bool* loaded); + + // Editing, modification, and removal of bookmarks. + // Bookmarks are referenced by id. + void AddBookmarkGroup(int handle, + int64 parent_id, int index, std::wstring title, + bool* success); + void AddBookmarkURL(int handle, + int64 parent_id, int index, + std::wstring title, const GURL& url, + bool* success); + void ReparentBookmark(int handle, + int64 id, int64 new_parent_id, int index, + bool* success); + void SetBookmarkTitle(int handle, + int64 id, std::wstring title, + bool* success); + void SetBookmarkURL(int handle, + int64 id, const GURL& url, + bool* success); + void RemoveBookmark(int handle, + int64 id, + bool* success); + // Callback for history redirect queries. virtual void OnRedirectQueryComplete( HistoryService::Handle request_handle, |