Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 686343002: Add MaybeInterceptRedirect/Response to URLRequestInterceptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed build Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // all requests after that, keeping count of failures and successes. 152 // all requests after that, keeping count of failures and successes.
153 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor { 153 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor {
154 public: 154 public:
155 explicit FailFirstNRequestsInterceptor(int requests_to_fail) 155 explicit FailFirstNRequestsInterceptor(int requests_to_fail)
156 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} 156 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {}
157 ~FailFirstNRequestsInterceptor() override {} 157 ~FailFirstNRequestsInterceptor() override {}
158 158
159 // net::URLRequestInterceptor implementation 159 // net::URLRequestInterceptor implementation
160 net::URLRequestJob* MaybeInterceptRequest( 160 net::URLRequestJob* MaybeInterceptRequest(
161 net::URLRequest* request, 161 net::URLRequest* request,
162 net::NetworkDelegate* network_delegate) const override { 162 net::NetworkDelegate* network_delegate) override {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
164 requests_++; 164 requests_++;
165 if (failures_ < requests_to_fail_) { 165 if (failures_ < requests_to_fail_) {
166 failures_++; 166 failures_++;
167 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see 167 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see
168 // NetErrorHelperCore::GetErrorPageURL. 168 // NetErrorHelperCore::GetErrorPageURL.
169 return new URLRequestFailedJob(request, 169 return new URLRequestFailedJob(request,
170 network_delegate, 170 network_delegate,
171 net::ERR_CONNECTION_RESET); 171 net::ERR_CONNECTION_RESET);
172 } else { 172 } else {
173 return new URLRequestTestJob(request, network_delegate, 173 return new URLRequestTestJob(request, network_delegate,
174 URLRequestTestJob::test_headers(), 174 URLRequestTestJob::test_headers(),
175 URLRequestTestJob::test_data_1(), 175 URLRequestTestJob::test_data_1(),
176 true); 176 true);
177 } 177 }
178 } 178 }
179 179
180 net::URLRequestJob* MaybeInterceptRedirect(
181 net::URLRequest* request,
182 net::NetworkDelegate* network_delegate,
183 const GURL& location) override {
184 return NULL;
185 }
186
187 net::URLRequestJob* MaybeInterceptResponse(
188 net::URLRequest* request,
189 net::NetworkDelegate* network_delegate) override {
190 return NULL;
191 }
192
180 int requests() const { return requests_; } 193 int requests() const { return requests_; }
181 int failures() const { return failures_; } 194 int failures() const { return failures_; }
182 195
183 private: 196 private:
184 // These are mutable because MaybeCreateJob is const but we want this state 197 // These are mutable because MaybeCreateJob is const but we want this state
185 // for testing. 198 // for testing.
186 mutable int requests_; 199 mutable int requests_;
187 mutable int failures_; 200 mutable int failures_;
188 int requests_to_fail_; 201 int requests_to_fail_;
189 202
190 DISALLOW_COPY_AND_ASSIGN(FailFirstNRequestsInterceptor); 203 DISALLOW_COPY_AND_ASSIGN(FailFirstNRequestsInterceptor);
191 }; 204 };
192 205
193 // An interceptor that serves LinkDoctor responses. It also allows waiting 206 // An interceptor that serves LinkDoctor responses. It also allows waiting
194 // until a certain number of requests have been sent. 207 // until a certain number of requests have been sent.
195 // TODO(mmenke): Wait until responses have been received instead. 208 // TODO(mmenke): Wait until responses have been received instead.
196 class LinkDoctorInterceptor : public net::URLRequestInterceptor { 209 class LinkDoctorInterceptor : public net::URLRequestInterceptor {
197 public: 210 public:
198 LinkDoctorInterceptor() : num_requests_(0), 211 LinkDoctorInterceptor() : num_requests_(0),
199 requests_to_wait_for_(-1), 212 requests_to_wait_for_(-1),
200 weak_factory_(this) { 213 weak_factory_(this) {
201 } 214 }
202 215
203 ~LinkDoctorInterceptor() override {} 216 ~LinkDoctorInterceptor() override {}
204 217
205 // net::URLRequestInterceptor implementation 218 // net::URLRequestInterceptor implementation
206 net::URLRequestJob* MaybeInterceptRequest( 219 net::URLRequestJob* MaybeInterceptRequest(
207 net::URLRequest* request, 220 net::URLRequest* request,
208 net::NetworkDelegate* network_delegate) const override { 221 net::NetworkDelegate* network_delegate) override {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
210 223
211 BrowserThread::PostTask( 224 BrowserThread::PostTask(
212 BrowserThread::UI, FROM_HERE, 225 BrowserThread::UI, FROM_HERE,
213 base::Bind(&LinkDoctorInterceptor::RequestCreated, 226 base::Bind(&LinkDoctorInterceptor::RequestCreated,
214 weak_factory_.GetWeakPtr())); 227 weak_factory_.GetWeakPtr()));
215 228
216 base::FilePath root_http; 229 base::FilePath root_http;
217 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 230 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
218 return new net::URLRequestMockHTTPJob( 231 return new net::URLRequestMockHTTPJob(
219 request, 232 request,
220 network_delegate, 233 network_delegate,
221 root_http.AppendASCII("mock-link-doctor.json"), 234 root_http.AppendASCII("mock-link-doctor.json"),
222 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 235 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
223 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 236 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
224 } 237 }
225 238
239 net::URLRequestJob* MaybeInterceptRedirect(
240 net::URLRequest* request,
241 net::NetworkDelegate* network_delegate,
242 const GURL& location) override {
243 return NULL;
244 }
245
246 net::URLRequestJob* MaybeInterceptResponse(
247 net::URLRequest* request,
248 net::NetworkDelegate* network_delegate) override {
249 return NULL;
250 }
251
226 void WaitForRequests(int requests_to_wait_for) { 252 void WaitForRequests(int requests_to_wait_for) {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
228 DCHECK_EQ(-1, requests_to_wait_for_); 254 DCHECK_EQ(-1, requests_to_wait_for_);
229 DCHECK(!run_loop_); 255 DCHECK(!run_loop_);
230 256
231 if (requests_to_wait_for >= num_requests_) 257 if (requests_to_wait_for >= num_requests_)
232 return; 258 return;
233 259
234 requests_to_wait_for_ = requests_to_wait_for; 260 requests_to_wait_for_ = requests_to_wait_for;
235 run_loop_.reset(new base::RunLoop()); 261 run_loop_.reset(new base::RunLoop());
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 960
935 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 961 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
936 class AddressUnreachableInterceptor : public net::URLRequestInterceptor { 962 class AddressUnreachableInterceptor : public net::URLRequestInterceptor {
937 public: 963 public:
938 AddressUnreachableInterceptor() {} 964 AddressUnreachableInterceptor() {}
939 ~AddressUnreachableInterceptor() override {} 965 ~AddressUnreachableInterceptor() override {}
940 966
941 // net::URLRequestInterceptor: 967 // net::URLRequestInterceptor:
942 net::URLRequestJob* MaybeInterceptRequest( 968 net::URLRequestJob* MaybeInterceptRequest(
943 net::URLRequest* request, 969 net::URLRequest* request,
944 net::NetworkDelegate* network_delegate) const override { 970 net::NetworkDelegate* network_delegate) override {
945 return new URLRequestFailedJob(request, 971 return new URLRequestFailedJob(request,
946 network_delegate, 972 network_delegate,
947 net::ERR_ADDRESS_UNREACHABLE); 973 net::ERR_ADDRESS_UNREACHABLE);
948 } 974 }
949 975
976 net::URLRequestJob* MaybeInterceptResponse(
977 net::URLRequest* request,
978 net::NetworkDelegate* network_delegate) override {
979 return NULL;
980 }
981
982 net::URLRequestJob* MaybeInterceptRedirect(
983 net::URLRequest* request,
984 net::NetworkDelegate* network_delegate,
985 const GURL& location) override {
986 return NULL;
987 }
988
950 private: 989 private:
951 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableInterceptor); 990 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableInterceptor);
952 }; 991 };
953 992
954 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation 993 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation
955 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use 994 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use
956 // a different error for the correction service and the original page to 995 // a different error for the correction service and the original page to
957 // validate the right page is being displayed. 996 // validate the right page is being displayed.
958 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { 997 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
959 public: 998 public:
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 browser(), 1137 browser(),
1099 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1138 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1100 kHostname), 1139 kHostname),
1101 1); 1140 1);
1102 1141
1103 ToggleHelpBox(browser()); 1142 ToggleHelpBox(browser());
1104 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1143 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1105 } 1144 }
1106 1145
1107 } // namespace 1146 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698