diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-15 00:02:40 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-15 00:02:40 +0000 |
commit | b7a20d363af744159a2bb85bfe3db027d2d4819e (patch) | |
tree | 14a363b284d4456d6c0a4888a6b944af3e10b490 | |
parent | 3f58d855ccb7c29abd2fd73cb60e11089abe8dd1 (diff) | |
download | chromium_src-b7a20d363af744159a2bb85bfe3db027d2d4819e.zip chromium_src-b7a20d363af744159a2bb85bfe3db027d2d4819e.tar.gz chromium_src-b7a20d363af744159a2bb85bfe3db027d2d4819e.tar.bz2 |
Convert parts of errorpage_uitest.cc to be not flaky.
TEST=Covered by browser_tests.
http://crbug.com/19361, http://crbug.com/19395
Review URL: http://codereview.chromium.org/169002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23500 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_focus_uitest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/crash_recovery_browsertest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/errorpage_browsertest.cc | 132 | ||||
-rw-r--r-- | chrome/browser/errorpage_uitest.cc | 15 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 5 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.cc | 26 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.h | 13 |
8 files changed, 184 insertions, 23 deletions
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 33f0bfc..853f424 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -651,7 +651,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { // Open the new tab, reload. browser()->NewTab(); - ui_test_utils::ReloadCurrentTab(browser()); + browser()->Reload(); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); // Focus should stay on the location bar. EXPECT_EQ(browser_view->GetLocationBarView(), focus_manager->GetFocusedView()); @@ -661,7 +662,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { browser_view->GetLocationBarView()->FocusLocation(); EXPECT_EQ(browser_view->GetLocationBarView(), focus_manager->GetFocusedView()); - ui_test_utils::ReloadCurrentTab(browser()); + browser()->Reload(); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); // Focus should now be on the tab contents. EXPECT_EQ(browser_view->GetTabContentsContainerView(), focus_manager->GetFocusedView()); @@ -681,7 +683,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReloadCrashedTab) { // Open a regular page, crash, reload. ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); - ui_test_utils::ReloadCurrentTab(browser()); + browser()->Reload(); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); // Focus should now be on the tab contents. EXPECT_EQ(browser_view->GetTabContentsContainerView(), focus_manager->GetFocusedView()); diff --git a/chrome/browser/crash_recovery_browsertest.cc b/chrome/browser/crash_recovery_browsertest.cc index 1a61b15..63ddf11 100644 --- a/chrome/browser/crash_recovery_browsertest.cc +++ b/chrome/browser/crash_recovery_browsertest.cc @@ -70,7 +70,8 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title_before_crash)); SimulateRendererCrash(browser()); - ASSERT_TRUE(ui_test_utils::ReloadCurrentTab(browser())); + browser()->Reload(); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title_after_crash)); EXPECT_NE(title_before_crash, title_after_crash); @@ -90,7 +91,8 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title_before_crash)); SimulateRendererCrash(browser()); - ASSERT_TRUE(ui_test_utils::ReloadCurrentTab(browser())); + browser()->Reload(); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title_after_crash)); EXPECT_EQ(title_before_crash, title_after_crash); diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc new file mode 100644 index 0000000..338c521 --- /dev/null +++ b/chrome/browser/errorpage_browsertest.cc @@ -0,0 +1,132 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/string_util.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/net/url_request_failed_dns_job.h" +#include "chrome/browser/net/url_request_mock_http_job.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/ui_test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webkit/glue/window_open_disposition.h" + +namespace { + +class ErrorPageBrowserTest : public InProcessBrowserTest { + protected: + // We're generally not sure what the title will be exactly (it comes from + // external source, and may be localized etc), but it will alway contain the + // hostname, so we check for that. + // For a proper way to do that http://crbug.com/18365 has been filed. + void AssertCurrentTabTitleContains(const std::string& text) { + string16 title; + EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); + EXPECT_NE(string16::npos, title.find(ASCIIToUTF16(text))) << + "could not find \"" << text << "\" in \"" << title << "\""; + } +}; + +using ui_test_utils::NavigateToURL; + +// We want to wait for two navigations: first will be the failing one, +// and the second will be the error page. +using ui_test_utils::NavigateToURLBlockUntilNavigationsComplete; + +IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_Basic) { + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); + AssertCurrentTabTitleContains(test_url.host()); +} + +// Test that a DNS error occuring in the main frame does not result in an +// additional session history entry. +IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack1) { + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); + AssertCurrentTabTitleContains(test_url.host()); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + string16 title; + ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); + EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); +} + +// Test that a DNS error occuring in the main frame does not result in an +// additional session history entry. +IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack2) { + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); + AssertCurrentTabTitleContains(test_url.host()); + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); + AssertCurrentTabTitleContains(test_url.host()); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + string16 title; + ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); + EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); +} + +// Test that a DNS error occuring in the main frame does not result in an +// additional session history entry. +IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward1) { + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); + AssertCurrentTabTitleContains(test_url.host()); + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); + AssertCurrentTabTitleContains(test_url.host()); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + browser()->GoForward(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); + AssertCurrentTabTitleContains(test_url.host()); +} + +// Test that a DNS error occuring in the main frame does not result in an +// additional session history entry. +IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward2) { + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); + AssertCurrentTabTitleContains(test_url.host()); + NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); + AssertCurrentTabTitleContains(test_url.host()); + + browser()->GoBack(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + browser()->GoForward(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); + AssertCurrentTabTitleContains(test_url.host()); + + browser()->GoForward(CURRENT_TAB); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + string16 title; + ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); + EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); +} + +} // namespace diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc index 4fa2125..fda144d 100644 --- a/chrome/browser/errorpage_uitest.cc +++ b/chrome/browser/errorpage_uitest.cc @@ -30,7 +30,8 @@ class ErrorPageTest : public UITest { } }; -TEST_F(ErrorPageTest, DNSError_Basic) { +// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. +TEST_F(ErrorPageTest, DISABLED_DNSError_Basic) { GURL test_url(URLRequestFailedDnsJob::kTestUrl); NavigateToURL(test_url); @@ -38,7 +39,8 @@ TEST_F(ErrorPageTest, DNSError_Basic) { EXPECT_TRUE(WaitForTitleContaining(test_url.host())); } -TEST_F(ErrorPageTest, DNSError_GoBack1) { +// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. +TEST_F(ErrorPageTest, DISABLED_DNSError_GoBack1) { // Test that a DNS error occuring in the main frame does not result in an // additional session history entry. GURL test_url(URLRequestFailedDnsJob::kTestUrl); @@ -52,7 +54,8 @@ TEST_F(ErrorPageTest, DNSError_GoBack1) { EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); } -TEST_F(ErrorPageTest, DNSError_GoBack2) { +// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. +TEST_F(ErrorPageTest, DISABLED_DNSError_GoBack2) { // Test that a DNS error occuring in the main frame does not result in an // additional session history entry. GURL test_url(URLRequestFailedDnsJob::kTestUrl); @@ -69,7 +72,8 @@ TEST_F(ErrorPageTest, DNSError_GoBack2) { EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); } -TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { +// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. +TEST_F(ErrorPageTest, DISABLED_DNSError_GoBack2AndForward) { // Test that a DNS error occuring in the main frame does not result in an // additional session history entry. @@ -88,7 +92,8 @@ TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { EXPECT_TRUE(WaitForTitleContaining(test_url.host())); } -TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { +// Flaky, see http://crbug.com/19361 and http://crbug.com/19395. +TEST_F(ErrorPageTest, DISABLED_DNSError_GoBack2Forward2) { // Test that a DNS error occuring in the main frame does not result in an // additional session history entry. diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 2f17cf7..462bcb2 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -36,6 +36,7 @@ 'browser/browser_init_browsertest.cc', 'browser/crash_recovery_browsertest.cc', 'browser/download/save_page_browsertest.cc', + 'browser/errorpage_browsertest.cc', 'browser/ssl/ssl_browser_tests.cc', ], 'browser_tests_sources_win_specific': [ diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 6c07e41..0c58c55 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -243,7 +243,12 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { void InProcessBrowserTest::ConfigureHostResolverProc( net::RuleBasedHostResolverProc* host_resolver_proc) { + // TODO(phajdan.jr): remove, http://crbug.com/2635 host_resolver_proc->AllowDirectLookup("*.google.com"); + + // TODO(phajdan.jr): remove, http://crbug.com/18365 + host_resolver_proc->AllowDirectLookup("*.gstatic.com"); + // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol // We don't want the test code to use it. host_resolver_proc->AddSimulatedFailure("wpad"); diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index 928ff87..543828b 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -282,6 +282,23 @@ bool GetCurrentTabTitle(const Browser* browser, string16* title) { return true; } +bool WaitForNavigationInCurrentTab(Browser* browser) { + TabContents* tab_contents = browser->GetSelectedTabContents(); + if (!tab_contents) + return false; + WaitForNavigation(&tab_contents->controller()); + return true; +} + +bool WaitForNavigationsInCurrentTab(Browser* browser, + int number_of_navigations) { + TabContents* tab_contents = browser->GetSelectedTabContents(); + if (!tab_contents) + return false; + WaitForNavigations(&tab_contents->controller(), number_of_navigations); + return true; +} + void WaitForNavigation(NavigationController* controller) { WaitForNavigations(controller, 1); } @@ -304,15 +321,6 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, WaitForNavigations(controller, number_of_navigations); } -bool ReloadCurrentTab(Browser* browser) { - browser->Reload(); - TabContents* tab_contents = browser->GetSelectedTabContents(); - if (!tab_contents) - return false; - WaitForNavigation(&tab_contents->controller()); - return true; -} - Value* ExecuteJavaScript(RenderViewHost* render_view_host, const std::wstring& frame_xpath, const std::wstring& original_script) { diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h index 952cf5f..94e4235 100644 --- a/chrome/test/ui_test_utils.h +++ b/chrome/test/ui_test_utils.h @@ -31,6 +31,15 @@ void RunMessageLoop(); // Puts the current tab title in |title|. Returns true on success. bool GetCurrentTabTitle(const Browser* browser, string16* title); +// Waits for the current tab to complete the navigation. Returns true on +// success. +bool WaitForNavigationInCurrentTab(Browser* browser); + +// Waits for the current tab to complete the specified number of navigations. +// Returns true on success. +bool WaitForNavigationsInCurrentTab(Browser* browser, + int number_of_navigations); + // Waits for |controller| to complete a navigation. This blocks until // the navigation finishes. void WaitForNavigation(NavigationController* controller); @@ -44,10 +53,6 @@ void WaitForNavigations(NavigationController* controller, // navigation finishes. void NavigateToURL(Browser* browser, const GURL& url); -// Reloads current tab contents and waits for navigation to finish. -// Returns true on success. -bool ReloadCurrentTab(Browser* browser); - // Navigates the selected tab of |browser| to |url|, blocking until the // number of navigations specified complete. void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, |