1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
// Copyright (c) 2006-2008 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/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/test/test_server.h"
class ErrorPageTest : public UITest {
protected:
bool WaitForTitleMatching(const std::wstring& title) {
for (int i = 0; i < 10; ++i) {
if (GetActiveTabTitle() == title)
return true;
PlatformThread::Sleep(sleep_timeout_ms());
}
EXPECT_EQ(title, GetActiveTabTitle());
return false;
}
};
TEST_F(ErrorPageTest, DNSError_Basic) {
GURL test_url(URLRequestFailedDnsJob::kTestUrl);
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
}
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(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(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(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("title3.html"))));
// The first navigation should fail, and the second one should be the error
// page.
EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(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(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("title3.html"))));
// The first navigation should fail, and the second one should be the error
// page.
EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(GetActiveTab()->GoBack());
// The first navigation should fail, and the second one should be the error
// page.
EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
}
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(
FilePath(FILE_PATH_LITERAL("title3.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(GetActiveTab()->GoBack());
// The first navigation should fail, and the second one should be the error
// page.
EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(GetActiveTab()->GoForward());
EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
}
TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("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(
FilePath(FILE_PATH_LITERAL("title2.html"))));
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
EXPECT_TRUE(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(
FilePath(FILE_PATH_LITERAL("title2.html"))));
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
EXPECT_TRUE(GetActiveTab()->GoBack());
EXPECT_TRUE(GetActiveTab()->GoForward());
EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
}
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"
// when the iframe loads. If the iframe fails to load (because an alternate
// error page loads instead), then the title will remain as "FAIL".
net::TestServer test_server(net::TestServer::TYPE_HTTP,
FilePath(FILE_PATH_LITERAL("chrome/test/data")));
ASSERT_TRUE(test_server.Start());
NavigateToURL(test_server.GetURL("files/iframe404.html"));
EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS"));
}
TEST_F(ErrorPageTest, Page404) {
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(
URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("page404.html"))), 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
}
TEST_F(ErrorPageTest, Page404_GoBack) {
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("title2.html"))));
// The first navigation should fail, and the second one should be the error
// page.
NavigateToURLBlockUntilNavigationsComplete(
URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("page404.html"))), 2);
EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
EXPECT_TRUE(GetActiveTab()->GoBack());
EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
}
|