diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-19 15:07:18 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-19 15:07:18 +0000 |
commit | 6aa8dcb15ffc65b650eaa201babf19690fbffd57 (patch) | |
tree | baf46b5c8b0008d39e0c92f26dc63dffacbb72f1 /chrome/browser | |
parent | 63871741d4b48d1a9bf757ffe2a90f85dda711f0 (diff) | |
download | chromium_src-6aa8dcb15ffc65b650eaa201babf19690fbffd57.zip chromium_src-6aa8dcb15ffc65b650eaa201babf19690fbffd57.tar.gz chromium_src-6aa8dcb15ffc65b650eaa201babf19690fbffd57.tar.bz2 |
Add automation call to wait for multiple navigations.
Convert one ErrorPage UI test to use it.
The rest of the tests will require more work.
TEST=Covered by ui_tests.
http://crbug.com/19361, http://crbug.com/19395
Review URL: http://codereview.chromium.org/174015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 49 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 16 | ||||
-rw-r--r-- | chrome/browser/errorpage_uitest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc | 12 |
4 files changed, 46 insertions, 36 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 1784eeac..855b678 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -226,11 +226,14 @@ class NavigationNotificationObserver : public NotificationObserver { public: NavigationNotificationObserver(NavigationController* controller, AutomationProvider* automation, - IPC::Message* reply_message) + IPC::Message* reply_message, + int number_of_navigations) : automation_(automation), reply_message_(reply_message), controller_(controller), + navigations_remaining_(number_of_navigations), navigation_started_(false) { + DCHECK_LT(0, navigations_remaining_); Source<NavigationController> source(controller_); registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source); registrar_.Add(this, NotificationType::LOAD_START, source); @@ -280,7 +283,8 @@ class NavigationNotificationObserver : public NotificationObserver { } else if (type == NotificationType::LOAD_STOP) { if (navigation_started_) { navigation_started_ = false; - ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS); + if (--navigations_remaining_ == 0) + ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS); } } else if (type == NotificationType::AUTH_SUPPLIED) { // The LoginHandler for this tab is no longer valid. @@ -317,6 +321,7 @@ class NavigationNotificationObserver : public NotificationObserver { AutomationProvider* automation_; IPC::Message* reply_message_; NavigationController* controller_; + int navigations_remaining_; bool navigation_started_; }; @@ -372,7 +377,7 @@ class TabAppendedNotificationObserver : public TabStripNotificationObserver { return; } - automation_->AddNavigationStatusListener(controller, reply_message_); + automation_->AddNavigationStatusListener(controller, reply_message_, 1); } protected: @@ -546,7 +551,7 @@ class ExecuteBrowserCommandObserver : public NotificationObserver { case IDC_RELOAD: { automation->AddNavigationStatusListener( &browser->GetSelectedTabContents()->controller(), - reply_message); + reply_message, 1); break; } default: { @@ -834,9 +839,11 @@ void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { } NotificationObserver* AutomationProvider::AddNavigationStatusListener( - NavigationController* tab, IPC::Message* reply_message) { + NavigationController* tab, IPC::Message* reply_message, + int number_of_navigations) { NotificationObserver* observer = - new NavigationNotificationObserver(tab, this, reply_message); + new NavigationNotificationObserver(tab, this, reply_message, + number_of_navigations); notification_observer_list_.AddObserver(observer); return observer; @@ -919,6 +926,9 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) + IPC_MESSAGE_HANDLER_DELAY_REPLY( + AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, + NavigateToURLBlockUntilNavigationsComplete) IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward) @@ -1115,6 +1125,12 @@ void AutomationProvider::AppendTab(int handle, const GURL& url, void AutomationProvider::NavigateToURL(int handle, const GURL& url, IPC::Message* reply_message) { + NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message); +} + +void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete( + int handle, const GURL& url, int number_of_navigations, + IPC::Message* reply_message) { if (tab_tracker_->ContainsHandle(handle)) { NavigationController* tab = tab_tracker_->GetResource(handle); @@ -1123,7 +1139,7 @@ void AutomationProvider::NavigateToURL(int handle, const GURL& url, Browser* browser = FindAndActivateTab(tab); if (browser) { - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, number_of_navigations); // TODO(darin): avoid conversion to GURL browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); @@ -1135,7 +1151,6 @@ void AutomationProvider::NavigateToURL(int handle, const GURL& url, reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); Send(reply_message); } - void AutomationProvider::NavigationAsync(int handle, const GURL& url, bool* status) { *status = false; @@ -1161,7 +1176,7 @@ void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); browser->GoBack(CURRENT_TAB); return; } @@ -1177,7 +1192,7 @@ void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); browser->GoForward(CURRENT_TAB); return; } @@ -1193,7 +1208,7 @@ void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); browser->Reload(); return; } @@ -1217,7 +1232,7 @@ void AutomationProvider::SetAuth(int tab_handle, // not strictly correct, because a navigation can require both proxy and // server auth, but it should be OK for now. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); handler->SetAuth(username, password); return; } @@ -1237,7 +1252,7 @@ void AutomationProvider::CancelAuth(int tab_handle, if (iter != login_handler_map_.end()) { // If auth is needed again after this, something is screwy. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); handler->CancelAuth(); return; } @@ -2274,7 +2289,7 @@ void AutomationProvider::ShowInterstitialPage(int tab_handle, NavigationController* controller = tab_tracker_->GetResource(tab_handle); TabContents* tab_contents = controller->tab_contents(); - AddNavigationStatusListener(controller, reply_message); + AddNavigationStatusListener(controller, reply_message, 1); AutomationInterstitialPage* interstitial = new AutomationInterstitialPage(tab_contents, GURL("about:interstitial"), @@ -2472,7 +2487,7 @@ void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, InterstitialPage::GetInterstitialPage(tab_contents); if (ssl_blocking_page) { if (proceed) { - AddNavigationStatusListener(tab, reply_message); + AddNavigationStatusListener(tab, reply_message, 1); ssl_blocking_page->Proceed(); return; } @@ -2777,7 +2792,7 @@ void AutomationProvider::ClickSSLInfoBarLink(int handle, 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); + AddNavigationStatusListener(nav_controller, reply_message, 1); } InfoBarDelegate* delegate = nav_controller->tab_contents()->GetInfoBarDelegateAt( @@ -2814,7 +2829,7 @@ void AutomationProvider::WaitForNavigation(int handle, return; } - AddNavigationStatusListener(controller, reply_message); + AddNavigationStatusListener(controller, reply_message, 1); } void AutomationProvider::SetIntPreference(int handle, diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 0997653..da47f06 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -69,14 +69,15 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void SetExpectedTabCount(size_t expected_tabs); // Add a listener for navigation status notification. Currently only - // navigation completion is observed; when the navigation completes, the - // completed_response object is sent; if the server requires authentication, - // we instead send the auth_needed_response object. A pointer to the added - // navigation observer is returned. This object should NOT be deleted and - // should be released by calling the corresponding + // navigation completion is observed; when the |number_of_navigations| + // complete, the completed_response object is sent; if the server requires + // authentication, we instead send the auth_needed_response object. A pointer + // to the added navigation observer is returned. This object should NOT be + // deleted and should be released by calling the corresponding // RemoveNavigationStatusListener method. NotificationObserver* AddNavigationStatusListener( - NavigationController* tab, IPC::Message* reply_message); + NavigationController* tab, IPC::Message* reply_message, + int number_of_navigations); void RemoveNavigationStatusListener(NotificationObserver* obs); @@ -198,6 +199,9 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void GetTabURL(int handle, bool* success, GURL* url); void HandleUnused(const IPC::Message& message, int handle); void NavigateToURL(int handle, const GURL& url, IPC::Message* reply_message); + void NavigateToURLBlockUntilNavigationsComplete(int handle, const GURL& url, + int number_of_navigations, + IPC::Message* reply_message); void NavigationAsync(int handle, const GURL& url, bool* status); void GoBack(int handle, IPC::Message* reply_message); void GoForward(int handle, IPC::Message* reply_message); diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc index fda144d..8a4c3a0 100644 --- a/chrome/browser/errorpage_uitest.cc +++ b/chrome/browser/errorpage_uitest.cc @@ -30,11 +30,10 @@ class ErrorPageTest : public UITest { } }; -// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. -TEST_F(ErrorPageTest, DISABLED_DNSError_Basic) { +TEST_F(ErrorPageTest, DNSError_Basic) { GURL test_url(URLRequestFailedDnsJob::kTestUrl); - NavigateToURL(test_url); + NavigateToURLBlockUntilNavigationsComplete(test_url, 2); EXPECT_TRUE(WaitForTitleContaining(test_url.host())); } diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc index d8654fd..5d0f07c 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc @@ -148,11 +148,7 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { // Navigate to a new page, to dispatch unload event and trigger xhr. // (the bug would make this step hang the renderer). - bool timed_out = false; - tab->NavigateToURLWithTimeout(server->TestServerPageW(L"files/title2.html"), - action_max_timeout_ms(), - &timed_out); - EXPECT_FALSE(timed_out); + tab->NavigateToURL(server->TestServerPageW(L"files/title2.html")); // Check that the new page got loaded, and that no download was triggered. EXPECT_TRUE(tab->GetTabTitle(&tab_title)); @@ -248,11 +244,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { // Make sure that the page loads and displays a title, and doesn't get stuck. FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("title2.html"); - bool timed_out = false; - tab->NavigateToURLWithTimeout(net::FilePathToFileURL(test_file), - action_max_timeout_ms(), - &timed_out); - EXPECT_FALSE(timed_out); + tab->NavigateToURL(net::FilePathToFileURL(test_file)); EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); } |