errorpage_uitest.cc revision 513209b27ff55e2841eac0e4120199c23acce758
1// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/string_util.h"
6#include "chrome/test/automation/tab_proxy.h"
7#include "chrome/test/ui/ui_test.h"
8#include "chrome/browser/net/url_request_failed_dns_job.h"
9#include "chrome/browser/net/url_request_mock_http_job.h"
10#include "net/test/test_server.h"
11
12class ErrorPageTest : public UITest {
13 protected:
14  bool WaitForTitleMatching(const std::wstring& title) {
15    for (int i = 0; i < 10; ++i) {
16      if (GetActiveTabTitle() == title)
17        return true;
18      PlatformThread::Sleep(sleep_timeout_ms());
19    }
20    EXPECT_EQ(title, GetActiveTabTitle());
21    return false;
22  }
23};
24
25TEST_F(ErrorPageTest, DNSError_Basic) {
26  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
27
28  // The first navigation should fail, and the second one should be the error
29  // page.
30  NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
31
32  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
33}
34
35TEST_F(ErrorPageTest, DNSError_GoBack1) {
36  // Test that a DNS error occuring in the main frame does not result in an
37  // additional session history entry.
38  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
39
40  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
41                    FilePath(FILE_PATH_LITERAL("title2.html"))));
42  // The first navigation should fail, and the second one should be the error
43  // page.
44  NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
45  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
46
47  EXPECT_TRUE(GetActiveTab()->GoBack());
48
49  EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
50}
51
52TEST_F(ErrorPageTest, DNSError_GoBack2) {
53  // Test that a DNS error occuring in the main frame does not result in an
54  // additional session history entry.
55  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
56
57  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
58                    FilePath(FILE_PATH_LITERAL("title2.html"))));
59  // The first navigation should fail, and the second one should be the error
60  // page.
61  NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
62  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
63  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
64                    FilePath(FILE_PATH_LITERAL("title3.html"))));
65
66  // The first navigation should fail, and the second one should be the error
67  // page.
68  EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
69  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
70  EXPECT_TRUE(GetActiveTab()->GoBack());
71
72  EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
73}
74
75TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
76  // Test that a DNS error occuring in the main frame does not result in an
77  // additional session history entry.
78
79  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
80
81  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
82                    FilePath(FILE_PATH_LITERAL("title2.html"))));
83  // The first navigation should fail, and the second one should be the error
84  // page.
85  NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
86  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
87  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
88                    FilePath(FILE_PATH_LITERAL("title3.html"))));
89
90  // The first navigation should fail, and the second one should be the error
91  // page.
92  EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
93  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
94  EXPECT_TRUE(GetActiveTab()->GoBack());
95  // The first navigation should fail, and the second one should be the error
96  // page.
97  EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
98
99  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
100}
101
102TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
103  // Test that a DNS error occuring in the main frame does not result in an
104  // additional session history entry.
105
106  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
107
108  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
109                    FilePath(FILE_PATH_LITERAL("title3.html"))));
110  // The first navigation should fail, and the second one should be the error
111  // page.
112  NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
113  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
114  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
115                    FilePath(FILE_PATH_LITERAL("title2.html"))));
116
117  // The first navigation should fail, and the second one should be the error
118  // page.
119  EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
120  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
121  EXPECT_TRUE(GetActiveTab()->GoBack());
122  // The first navigation should fail, and the second one should be the error
123  // page.
124  EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
125  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
126  EXPECT_TRUE(GetActiveTab()->GoForward());
127
128  EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
129}
130
131TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
132  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
133                    FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
134  EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
135}
136
137TEST_F(ErrorPageTest, IFrameDNSError_GoBack) {
138  // Test that a DNS error occuring in an iframe does not result in an
139  // additional session history entry.
140
141  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
142                    FilePath(FILE_PATH_LITERAL("title2.html"))));
143  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
144                    FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
145
146  EXPECT_TRUE(GetActiveTab()->GoBack());
147
148  EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
149}
150
151TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) {
152  // Test that a DNS error occuring in an iframe does not result in an
153  // additional session history entry.
154
155  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
156                    FilePath(FILE_PATH_LITERAL("title2.html"))));
157  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
158                    FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
159
160  EXPECT_TRUE(GetActiveTab()->GoBack());
161  EXPECT_TRUE(GetActiveTab()->GoForward());
162
163  EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
164}
165
166#if defined(OS_WIN)
167// Might be related to http://crbug.com/60937
168#define MAYBE_IFrame404 FLAKY_IFrame404
169#else
170#define MAYBE_IFrame404 IFrame404
171#endif
172
173TEST_F(ErrorPageTest, MAYBE_IFrame404) {
174  // iframes that have 404 pages should not trigger an alternate error page.
175  // In this test, the iframe sets the title of the parent page to "SUCCESS"
176  // when the iframe loads.  If the iframe fails to load (because an alternate
177  // error page loads instead), then the title will remain as "FAIL".
178  net::TestServer test_server(net::TestServer::TYPE_HTTP,
179                              FilePath(FILE_PATH_LITERAL("chrome/test/data")));
180  ASSERT_TRUE(test_server.Start());
181  NavigateToURL(test_server.GetURL("files/iframe404.html"));
182  EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS"));
183}
184
185TEST_F(ErrorPageTest, Page404) {
186  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
187                    FilePath(FILE_PATH_LITERAL("title2.html"))));
188  // The first navigation should fail, and the second one should be the error
189  // page.
190  NavigateToURLBlockUntilNavigationsComplete(
191      URLRequestMockHTTPJob::GetMockUrl(
192          FilePath(FILE_PATH_LITERAL("page404.html"))), 2);
193
194  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
195}
196
197TEST_F(ErrorPageTest, Page404_GoBack) {
198  NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
199                    FilePath(FILE_PATH_LITERAL("title2.html"))));
200  // The first navigation should fail, and the second one should be the error
201  // page.
202  NavigateToURLBlockUntilNavigationsComplete(
203      URLRequestMockHTTPJob::GetMockUrl(
204          FilePath(FILE_PATH_LITERAL("page404.html"))), 2);
205  EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
206
207  EXPECT_TRUE(GetActiveTab()->GoBack());
208
209  EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
210}
211