| Index: chrome/browser/errorpage_uitest.cc
|
| ===================================================================
|
| --- chrome/browser/errorpage_uitest.cc (revision 22154)
|
| +++ chrome/browser/errorpage_uitest.cc (working copy)
|
| @@ -3,36 +3,132 @@
|
| // 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:
|
| + std::wstring WaitForTitle() {
|
| + std::wstring title;
|
| + for (int i = 0; i < 10; ++i) {
|
| + PlatformThread::Sleep(sleep_timeout_ms());
|
| + title = GetActiveTabTitle();
|
| + if (!title.empty())
|
| + break;
|
| + }
|
| + return title;
|
| + }
|
| };
|
|
|
| -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;
|
| - }
|
| - }
|
| + // Verify that the title contains test_host.
|
| + std::wstring title = WaitForTitle();
|
| + EXPECT_NE(std::wstring(), title);
|
| + EXPECT_TRUE(title.find(test_host) != std::wstring::npos) <<
|
| + "Title was: " << title;
|
| +}
|
|
|
| - 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.
|
|
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
|
| + NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
|
| +
|
| + GetActiveTab()->GoBack();
|
| +
|
| + EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
|
| +}
|
| +
|
| +TEST_F(ErrorPageTest, DNSError_GoBack2) {
|
| + // Test that a DNS error occuring in the main frame does not result in an
|
| + // additional session history entry.
|
| +
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
|
| + NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
|
| +
|
| + GetActiveTab()->GoBack();
|
| + GetActiveTab()->GoBack();
|
| +
|
| + EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
|
| +}
|
| +
|
| +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);
|
| + std::wstring test_host = UTF8ToWide(test_url.host());
|
| +
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
|
| + NavigateToURL(test_url);
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
|
| +
|
| + GetActiveTab()->GoBack();
|
| + GetActiveTab()->GoBack();
|
| + GetActiveTab()->GoForward();
|
| +
|
| + // Verify that the title contains test_host.
|
| + std::wstring title = WaitForTitle();
|
| + EXPECT_NE(std::wstring(), title);
|
| + EXPECT_TRUE(title.find(test_host) != std::wstring::npos) <<
|
| + "Title was: " << title;
|
| +}
|
| +
|
| +TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
|
| + // Test that a DNS error occuring in the main frame does not result in an
|
| + // additional session history entry.
|
| +
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
|
| + NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
|
| +
|
| + GetActiveTab()->GoBack();
|
| + GetActiveTab()->GoBack();
|
| + GetActiveTab()->GoForward();
|
| + GetActiveTab()->GoForward();
|
| +
|
| + EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
|
| +}
|
| +
|
| +TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
|
| + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html"));
|
| + EXPECT_EQ(L"Blah", WaitForTitle());
|
| +}
|
| +
|
| +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_EQ(L"Title Of Awesomeness", WaitForTitle());
|
| +}
|
| +
|
| +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_EQ(L"Blah", WaitForTitle());
|
| +}
|
| +
|
| TEST_F(ErrorPageTest, IFrame404) {
|
| // iframes that have 404 pages should not trigger an alternate error page.
|
| // In this test, the iframe sets the title of the parent page to "SUCCESS"
|
| @@ -44,20 +140,5 @@
|
| 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_EQ(L"SUCCESS", WaitForTitle());
|
| +}
|
|
|