diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/errorpage_uitest.cc | 161 |
1 files changed, 126 insertions, 35 deletions
diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc index 9b2c489..b72308c 100644 --- a/chrome/browser/errorpage_uitest.cc +++ b/chrome/browser/errorpage_uitest.cc @@ -3,35 +3,141 @@ // found in the LICENSE file. #include "base/string_util.h" +#include "chrome/test/automation/tab_proxy.h" #include "chrome/test/ui/ui_test.h" #include "chrome/browser/net/url_request_failed_dns_job.h" +#include "chrome/browser/net/url_request_mock_http_job.h" #include "net/url_request/url_request_unittest.h" class ErrorPageTest : public UITest { + protected: + bool WaitForTitleMatching(const std::wstring& title) { + for (int i = 0; i < 100; ++i) { + if (GetActiveTabTitle() == title) + return true; + PlatformThread::Sleep(sleep_timeout_ms() / 10); + } + return false; + } + bool WaitForTitleContaining(const std::string& title_substring) { + for (int i = 0; i < 100; ++i) { + std::wstring title = GetActiveTabTitle(); + if (title.find(UTF8ToWide(title_substring)) != std::wstring::npos) + return true; + PlatformThread::Sleep(sleep_timeout_ms() / 10); + } + return false; + } }; -TEST_F(ErrorPageTest, DNSError) { +TEST_F(ErrorPageTest, DNSError_Basic) { GURL test_url(URLRequestFailedDnsJob::kTestUrl); - std::wstring test_host = UTF8ToWide(test_url.host()); + NavigateToURL(test_url); - // Verify that the url is in the title. Since it's set via Javascript, we - // need to give it a chance to run. - int i; - std::wstring title; - for (i = 0; i < 10; ++i) { - PlatformThread::Sleep(sleep_timeout_ms()); - title = GetActiveTabTitle(); - if (title.find(test_host) != std::wstring::npos) { - // Success, bail out. - break; - } - } + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); +} - if (i == 10) { - FAIL() << "failed to get error page title; got " << title; - } -}; +TEST_F(ErrorPageTest, 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); + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURL(test_url); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + + GetActiveTab()->GoBack(); + + EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); +} + +TEST_F(ErrorPageTest, 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); + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURL(test_url); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + + GetActiveTab()->GoBack(); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + GetActiveTab()->GoBack(); + + EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); +} + +TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { + // Test that a DNS error occuring in the main frame does not result in an + // additional session history entry. + + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURL(test_url); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + + GetActiveTab()->GoBack(); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + GetActiveTab()->GoBack(); + GetActiveTab()->GoForward(); + + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); +} + +TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { + // Test that a DNS error occuring in the main frame does not result in an + // additional session history entry. + + GURL test_url(URLRequestFailedDnsJob::kTestUrl); + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); + NavigateToURL(test_url); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + + GetActiveTab()->GoBack(); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + GetActiveTab()->GoBack(); + GetActiveTab()->GoForward(); + EXPECT_TRUE(WaitForTitleContaining(test_url.host())); + GetActiveTab()->GoForward(); + + EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); +} + +TEST_F(ErrorPageTest, IFrameDNSError_Basic) { + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); + EXPECT_TRUE(WaitForTitleMatching(L"Blah")); +} + +TEST_F(ErrorPageTest, IFrameDNSError_GoBack) { + // Test that a DNS error occuring in an iframe does not result in an + // additional session history entry. + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); + + GetActiveTab()->GoBack(); + + EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); +} + +TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) { + // Test that a DNS error occuring in an iframe does not result in an + // additional session history entry. + + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); + + GetActiveTab()->GoBack(); + GetActiveTab()->GoForward(); + + EXPECT_TRUE(WaitForTitleMatching(L"Blah")); +} TEST_F(ErrorPageTest, IFrame404) { // iframes that have 404 pages should not trigger an alternate error page. @@ -44,20 +150,5 @@ TEST_F(ErrorPageTest, IFrame404) { GURL test_url = server->TestServerPage("files/iframe404.html"); NavigateToURL(test_url); - // Verify that the url is in the title. Since it's set via Javascript, we - // need to give it a chance to run. - int i; - std::wstring title; - for (i = 0; i < 10; ++i) { - PlatformThread::Sleep(sleep_timeout_ms()); - title = GetActiveTabTitle(); - if (title == L"SUCCESS") { - // Success, bail out. - break; - } - } - - if (i == 10) { - FAIL() << "iframe 404 didn't load properly"; - } -}; + EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS")); +} |