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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 EXPECT_EQ(USER_CALLBACK, block_mode_); 360 EXPECT_EQ(USER_CALLBACK, block_mode_);
361 return stage_blocked_for_callback_; 361 return stage_blocked_for_callback_;
362 } 362 }
363 363
364 private: 364 private:
365 void RunCallback(int response, const CompletionCallback& callback); 365 void RunCallback(int response, const CompletionCallback& callback);
366 void RunAuthCallback(AuthRequiredResponse response, 366 void RunAuthCallback(AuthRequiredResponse response,
367 const AuthCallback& callback); 367 const AuthCallback& callback);
368 368
369 // TestNetworkDelegate implementation. 369 // TestNetworkDelegate implementation.
370 virtual int OnBeforeURLRequest(URLRequest* request, 370 int OnBeforeURLRequest(URLRequest* request,
371 const CompletionCallback& callback, 371 const CompletionCallback& callback,
372 GURL* new_url) override; 372 GURL* new_url) override;
373 373
374 virtual int OnBeforeSendHeaders(URLRequest* request, 374 int OnBeforeSendHeaders(URLRequest* request,
375 const CompletionCallback& callback, 375 const CompletionCallback& callback,
376 HttpRequestHeaders* headers) override; 376 HttpRequestHeaders* headers) override;
377 377
378 virtual int OnHeadersReceived( 378 int OnHeadersReceived(
379 URLRequest* request, 379 URLRequest* request,
380 const CompletionCallback& callback, 380 const CompletionCallback& callback,
381 const HttpResponseHeaders* original_response_headers, 381 const HttpResponseHeaders* original_response_headers,
382 scoped_refptr<HttpResponseHeaders>* override_response_headers, 382 scoped_refptr<HttpResponseHeaders>* override_response_headers,
383 GURL* allowed_unsafe_redirect_url) override; 383 GURL* allowed_unsafe_redirect_url) override;
384 384
385 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( 385 NetworkDelegate::AuthRequiredResponse OnAuthRequired(
386 URLRequest* request, 386 URLRequest* request,
387 const AuthChallengeInfo& auth_info, 387 const AuthChallengeInfo& auth_info,
388 const AuthCallback& callback, 388 const AuthCallback& callback,
389 AuthCredentials* credentials) override; 389 AuthCredentials* credentials) override;
390 390
391 // Resets the callbacks and |stage_blocked_for_callback_|. 391 // Resets the callbacks and |stage_blocked_for_callback_|.
392 void Reset(); 392 void Reset();
393 393
394 // Checks whether we should block in |stage|. If yes, returns an error code 394 // Checks whether we should block in |stage|. If yes, returns an error code
395 // and optionally sets up callback based on |block_mode_|. If no, returns OK. 395 // and optionally sets up callback based on |block_mode_|. If no, returns OK.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 class TestURLRequestContextWithProxy : public TestURLRequestContext { 589 class TestURLRequestContextWithProxy : public TestURLRequestContext {
590 public: 590 public:
591 // Does not own |delegate|. 591 // Does not own |delegate|.
592 TestURLRequestContextWithProxy(const std::string& proxy, 592 TestURLRequestContextWithProxy(const std::string& proxy,
593 NetworkDelegate* delegate) 593 NetworkDelegate* delegate)
594 : TestURLRequestContext(true) { 594 : TestURLRequestContext(true) {
595 context_storage_.set_proxy_service(ProxyService::CreateFixed(proxy)); 595 context_storage_.set_proxy_service(ProxyService::CreateFixed(proxy));
596 set_network_delegate(delegate); 596 set_network_delegate(delegate);
597 Init(); 597 Init();
598 } 598 }
599 virtual ~TestURLRequestContextWithProxy() {} 599 ~TestURLRequestContextWithProxy() override {}
600 }; 600 };
601 601
602 } // namespace 602 } // namespace
603 603
604 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 604 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
605 class URLRequestTest : public PlatformTest { 605 class URLRequestTest : public PlatformTest {
606 public: 606 public:
607 URLRequestTest() : default_context_(true) { 607 URLRequestTest() : default_context_(true) {
608 default_context_.set_network_delegate(&default_network_delegate_); 608 default_context_.set_network_delegate(&default_network_delegate_);
609 default_context_.set_net_log(&net_log_); 609 default_context_.set_net_log(&net_log_);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 DeleteFile(lnk_path.c_str()); 1098 DeleteFile(lnk_path.c_str());
1099 } 1099 }
1100 #endif // defined(OS_WIN) 1100 #endif // defined(OS_WIN)
1101 1101
1102 // Custom URLRequestJobs for use with interceptor tests 1102 // Custom URLRequestJobs for use with interceptor tests
1103 class RestartTestJob : public URLRequestTestJob { 1103 class RestartTestJob : public URLRequestTestJob {
1104 public: 1104 public:
1105 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate) 1105 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate)
1106 : URLRequestTestJob(request, network_delegate, true) {} 1106 : URLRequestTestJob(request, network_delegate, true) {}
1107 protected: 1107 protected:
1108 virtual void StartAsync() override { 1108 void StartAsync() override { this->NotifyRestartRequired(); }
1109 this->NotifyRestartRequired();
1110 }
1111 private: 1109 private:
1112 virtual ~RestartTestJob() {} 1110 ~RestartTestJob() override {}
1113 }; 1111 };
1114 1112
1115 class CancelTestJob : public URLRequestTestJob { 1113 class CancelTestJob : public URLRequestTestJob {
1116 public: 1114 public:
1117 explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate) 1115 explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate)
1118 : URLRequestTestJob(request, network_delegate, true) {} 1116 : URLRequestTestJob(request, network_delegate, true) {}
1119 protected: 1117 protected:
1120 virtual void StartAsync() override { 1118 void StartAsync() override { request_->Cancel(); }
1121 request_->Cancel();
1122 }
1123 private: 1119 private:
1124 virtual ~CancelTestJob() {} 1120 ~CancelTestJob() override {}
1125 }; 1121 };
1126 1122
1127 class CancelThenRestartTestJob : public URLRequestTestJob { 1123 class CancelThenRestartTestJob : public URLRequestTestJob {
1128 public: 1124 public:
1129 explicit CancelThenRestartTestJob(URLRequest* request, 1125 explicit CancelThenRestartTestJob(URLRequest* request,
1130 NetworkDelegate* network_delegate) 1126 NetworkDelegate* network_delegate)
1131 : URLRequestTestJob(request, network_delegate, true) { 1127 : URLRequestTestJob(request, network_delegate, true) {
1132 } 1128 }
1133 protected: 1129 protected:
1134 virtual void StartAsync() override { 1130 void StartAsync() override {
1135 request_->Cancel(); 1131 request_->Cancel();
1136 this->NotifyRestartRequired(); 1132 this->NotifyRestartRequired();
1137 } 1133 }
1138 private: 1134 private:
1139 virtual ~CancelThenRestartTestJob() {} 1135 ~CancelThenRestartTestJob() override {}
1140 }; 1136 };
1141 1137
1142 // An Interceptor for use with interceptor tests 1138 // An Interceptor for use with interceptor tests
1143 class TestInterceptor : URLRequest::Interceptor { 1139 class TestInterceptor : URLRequest::Interceptor {
1144 public: 1140 public:
1145 TestInterceptor() 1141 TestInterceptor()
1146 : intercept_main_request_(false), restart_main_request_(false), 1142 : intercept_main_request_(false), restart_main_request_(false),
1147 cancel_main_request_(false), cancel_then_restart_main_request_(false), 1143 cancel_main_request_(false), cancel_then_restart_main_request_(false),
1148 simulate_main_network_error_(false), 1144 simulate_main_network_error_(false),
1149 intercept_redirect_(false), cancel_redirect_request_(false), 1145 intercept_redirect_(false), cancel_redirect_request_(false),
1150 intercept_final_response_(false), cancel_final_request_(false), 1146 intercept_final_response_(false), cancel_final_request_(false),
1151 did_intercept_main_(false), did_restart_main_(false), 1147 did_intercept_main_(false), did_restart_main_(false),
1152 did_cancel_main_(false), did_cancel_then_restart_main_(false), 1148 did_cancel_main_(false), did_cancel_then_restart_main_(false),
1153 did_simulate_error_main_(false), 1149 did_simulate_error_main_(false),
1154 did_intercept_redirect_(false), did_cancel_redirect_(false), 1150 did_intercept_redirect_(false), did_cancel_redirect_(false),
1155 did_intercept_final_(false), did_cancel_final_(false) { 1151 did_intercept_final_(false), did_cancel_final_(false) {
1156 URLRequest::Deprecated::RegisterRequestInterceptor(this); 1152 URLRequest::Deprecated::RegisterRequestInterceptor(this);
1157 } 1153 }
1158 1154
1159 virtual ~TestInterceptor() { 1155 ~TestInterceptor() override {
1160 URLRequest::Deprecated::UnregisterRequestInterceptor(this); 1156 URLRequest::Deprecated::UnregisterRequestInterceptor(this);
1161 } 1157 }
1162 1158
1163 virtual URLRequestJob* MaybeIntercept( 1159 URLRequestJob* MaybeIntercept(URLRequest* request,
1164 URLRequest* request, 1160 NetworkDelegate* network_delegate) override {
1165 NetworkDelegate* network_delegate) override {
1166 if (restart_main_request_) { 1161 if (restart_main_request_) {
1167 restart_main_request_ = false; 1162 restart_main_request_ = false;
1168 did_restart_main_ = true; 1163 did_restart_main_ = true;
1169 return new RestartTestJob(request, network_delegate); 1164 return new RestartTestJob(request, network_delegate);
1170 } 1165 }
1171 if (cancel_main_request_) { 1166 if (cancel_main_request_) {
1172 cancel_main_request_ = false; 1167 cancel_main_request_ = false;
1173 did_cancel_main_ = true; 1168 did_cancel_main_ = true;
1174 return new CancelTestJob(request, network_delegate); 1169 return new CancelTestJob(request, network_delegate);
1175 } 1170 }
(...skipping 14 matching lines...) Expand all
1190 did_intercept_main_ = true; 1185 did_intercept_main_ = true;
1191 URLRequestTestJob* job = new URLRequestTestJob(request, 1186 URLRequestTestJob* job = new URLRequestTestJob(request,
1192 network_delegate, 1187 network_delegate,
1193 main_headers_, 1188 main_headers_,
1194 main_data_, 1189 main_data_,
1195 true); 1190 true);
1196 job->set_load_timing_info(main_request_load_timing_info_); 1191 job->set_load_timing_info(main_request_load_timing_info_);
1197 return job; 1192 return job;
1198 } 1193 }
1199 1194
1200 virtual URLRequestJob* MaybeInterceptRedirect( 1195 URLRequestJob* MaybeInterceptRedirect(URLRequest* request,
1201 URLRequest* request, 1196 NetworkDelegate* network_delegate,
1202 NetworkDelegate* network_delegate, 1197 const GURL& location) override {
1203 const GURL& location) override {
1204 if (cancel_redirect_request_) { 1198 if (cancel_redirect_request_) {
1205 cancel_redirect_request_ = false; 1199 cancel_redirect_request_ = false;
1206 did_cancel_redirect_ = true; 1200 did_cancel_redirect_ = true;
1207 return new CancelTestJob(request, network_delegate); 1201 return new CancelTestJob(request, network_delegate);
1208 } 1202 }
1209 if (!intercept_redirect_) 1203 if (!intercept_redirect_)
1210 return NULL; 1204 return NULL;
1211 intercept_redirect_ = false; 1205 intercept_redirect_ = false;
1212 did_intercept_redirect_ = true; 1206 did_intercept_redirect_ = true;
1213 return new URLRequestTestJob(request, 1207 return new URLRequestTestJob(request,
1214 network_delegate, 1208 network_delegate,
1215 redirect_headers_, 1209 redirect_headers_,
1216 redirect_data_, 1210 redirect_data_,
1217 true); 1211 true);
1218 } 1212 }
1219 1213
1220 virtual URLRequestJob* MaybeInterceptResponse( 1214 URLRequestJob* MaybeInterceptResponse(
1221 URLRequest* request, NetworkDelegate* network_delegate) override { 1215 URLRequest* request,
1216 NetworkDelegate* network_delegate) override {
1222 if (cancel_final_request_) { 1217 if (cancel_final_request_) {
1223 cancel_final_request_ = false; 1218 cancel_final_request_ = false;
1224 did_cancel_final_ = true; 1219 did_cancel_final_ = true;
1225 return new CancelTestJob(request, network_delegate); 1220 return new CancelTestJob(request, network_delegate);
1226 } 1221 }
1227 if (!intercept_final_response_) 1222 if (!intercept_final_response_)
1228 return NULL; 1223 return NULL;
1229 intercept_final_response_ = false; 1224 intercept_final_response_ = false;
1230 did_intercept_final_ = true; 1225 did_intercept_final_ = true;
1231 return new URLRequestTestJob(request, 1226 return new URLRequestTestJob(request,
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2384 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2390 } 2385 }
2391 } 2386 }
2392 2387
2393 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header 2388 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header
2394 // value for the |fixed_date| argument given to the constructor. 2389 // value for the |fixed_date| argument given to the constructor.
2395 class FixedDateNetworkDelegate : public TestNetworkDelegate { 2390 class FixedDateNetworkDelegate : public TestNetworkDelegate {
2396 public: 2391 public:
2397 explicit FixedDateNetworkDelegate(const std::string& fixed_date) 2392 explicit FixedDateNetworkDelegate(const std::string& fixed_date)
2398 : fixed_date_(fixed_date) {} 2393 : fixed_date_(fixed_date) {}
2399 virtual ~FixedDateNetworkDelegate() {} 2394 ~FixedDateNetworkDelegate() override {}
2400 2395
2401 // NetworkDelegate implementation 2396 // NetworkDelegate implementation
2402 virtual int OnHeadersReceived( 2397 int OnHeadersReceived(
2403 URLRequest* request, 2398 URLRequest* request,
2404 const CompletionCallback& callback, 2399 const CompletionCallback& callback,
2405 const HttpResponseHeaders* original_response_headers, 2400 const HttpResponseHeaders* original_response_headers,
2406 scoped_refptr<HttpResponseHeaders>* override_response_headers, 2401 scoped_refptr<HttpResponseHeaders>* override_response_headers,
2407 GURL* allowed_unsafe_redirect_url) override; 2402 GURL* allowed_unsafe_redirect_url) override;
2408 2403
2409 private: 2404 private:
2410 std::string fixed_date_; 2405 std::string fixed_date_;
2411 2406
2412 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate); 2407 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate);
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
3984 3979
3985 DISALLOW_COPY_AND_ASSIGN(AsyncDelegateLogger); 3980 DISALLOW_COPY_AND_ASSIGN(AsyncDelegateLogger);
3986 }; 3981 };
3987 3982
3988 // NetworkDelegate that logs delegate information before a request is started, 3983 // NetworkDelegate that logs delegate information before a request is started,
3989 // before headers are sent, when headers are read, and when auth information 3984 // before headers are sent, when headers are read, and when auth information
3990 // is requested. Uses AsyncDelegateLogger. 3985 // is requested. Uses AsyncDelegateLogger.
3991 class AsyncLoggingNetworkDelegate : public TestNetworkDelegate { 3986 class AsyncLoggingNetworkDelegate : public TestNetworkDelegate {
3992 public: 3987 public:
3993 AsyncLoggingNetworkDelegate() {} 3988 AsyncLoggingNetworkDelegate() {}
3994 virtual ~AsyncLoggingNetworkDelegate() {} 3989 ~AsyncLoggingNetworkDelegate() override {}
3995 3990
3996 // NetworkDelegate implementation. 3991 // NetworkDelegate implementation.
3997 virtual int OnBeforeURLRequest(URLRequest* request, 3992 int OnBeforeURLRequest(URLRequest* request,
3998 const CompletionCallback& callback, 3993 const CompletionCallback& callback,
3999 GURL* new_url) override { 3994 GURL* new_url) override {
4000 TestNetworkDelegate::OnBeforeURLRequest(request, callback, new_url); 3995 TestNetworkDelegate::OnBeforeURLRequest(request, callback, new_url);
4001 return RunCallbackAsynchronously(request, callback); 3996 return RunCallbackAsynchronously(request, callback);
4002 } 3997 }
4003 3998
4004 virtual int OnBeforeSendHeaders(URLRequest* request, 3999 int OnBeforeSendHeaders(URLRequest* request,
4005 const CompletionCallback& callback, 4000 const CompletionCallback& callback,
4006 HttpRequestHeaders* headers) override { 4001 HttpRequestHeaders* headers) override {
4007 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers); 4002 TestNetworkDelegate::OnBeforeSendHeaders(request, callback, headers);
4008 return RunCallbackAsynchronously(request, callback); 4003 return RunCallbackAsynchronously(request, callback);
4009 } 4004 }
4010 4005
4011 virtual int OnHeadersReceived( 4006 int OnHeadersReceived(
4012 URLRequest* request, 4007 URLRequest* request,
4013 const CompletionCallback& callback, 4008 const CompletionCallback& callback,
4014 const HttpResponseHeaders* original_response_headers, 4009 const HttpResponseHeaders* original_response_headers,
4015 scoped_refptr<HttpResponseHeaders>* override_response_headers, 4010 scoped_refptr<HttpResponseHeaders>* override_response_headers,
4016 GURL* allowed_unsafe_redirect_url) override { 4011 GURL* allowed_unsafe_redirect_url) override {
4017 TestNetworkDelegate::OnHeadersReceived(request, 4012 TestNetworkDelegate::OnHeadersReceived(request,
4018 callback, 4013 callback,
4019 original_response_headers, 4014 original_response_headers,
4020 override_response_headers, 4015 override_response_headers,
4021 allowed_unsafe_redirect_url); 4016 allowed_unsafe_redirect_url);
4022 return RunCallbackAsynchronously(request, callback); 4017 return RunCallbackAsynchronously(request, callback);
4023 } 4018 }
4024 4019
4025 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( 4020 NetworkDelegate::AuthRequiredResponse OnAuthRequired(
4026 URLRequest* request, 4021 URLRequest* request,
4027 const AuthChallengeInfo& auth_info, 4022 const AuthChallengeInfo& auth_info,
4028 const AuthCallback& callback, 4023 const AuthCallback& callback,
4029 AuthCredentials* credentials) override { 4024 AuthCredentials* credentials) override {
4030 AsyncDelegateLogger::Run( 4025 AsyncDelegateLogger::Run(
4031 request, 4026 request,
4032 LOAD_STATE_WAITING_FOR_DELEGATE, 4027 LOAD_STATE_WAITING_FOR_DELEGATE,
4033 LOAD_STATE_WAITING_FOR_DELEGATE, 4028 LOAD_STATE_WAITING_FOR_DELEGATE,
4034 LOAD_STATE_WAITING_FOR_DELEGATE, 4029 LOAD_STATE_WAITING_FOR_DELEGATE,
4035 base::Bind(&AsyncLoggingNetworkDelegate::SetAuthAndResume, 4030 base::Bind(&AsyncLoggingNetworkDelegate::SetAuthAndResume,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 4071
4077 explicit AsyncLoggingUrlRequestDelegate(CancelStage cancel_stage) 4072 explicit AsyncLoggingUrlRequestDelegate(CancelStage cancel_stage)
4078 : cancel_stage_(cancel_stage) { 4073 : cancel_stage_(cancel_stage) {
4079 if (cancel_stage == CANCEL_ON_RECEIVED_REDIRECT) 4074 if (cancel_stage == CANCEL_ON_RECEIVED_REDIRECT)
4080 set_cancel_in_received_redirect(true); 4075 set_cancel_in_received_redirect(true);
4081 else if (cancel_stage == CANCEL_ON_RESPONSE_STARTED) 4076 else if (cancel_stage == CANCEL_ON_RESPONSE_STARTED)
4082 set_cancel_in_response_started(true); 4077 set_cancel_in_response_started(true);
4083 else if (cancel_stage == CANCEL_ON_READ_COMPLETED) 4078 else if (cancel_stage == CANCEL_ON_READ_COMPLETED)
4084 set_cancel_in_received_data(true); 4079 set_cancel_in_received_data(true);
4085 } 4080 }
4086 virtual ~AsyncLoggingUrlRequestDelegate() {} 4081 ~AsyncLoggingUrlRequestDelegate() override {}
4087 4082
4088 // URLRequest::Delegate implementation: 4083 // URLRequest::Delegate implementation:
4089 void virtual OnReceivedRedirect(URLRequest* request, 4084 void OnReceivedRedirect(URLRequest* request,
4090 const RedirectInfo& redirect_info, 4085 const RedirectInfo& redirect_info,
4091 bool* defer_redirect) override { 4086 bool* defer_redirect) override {
4092 *defer_redirect = true; 4087 *defer_redirect = true;
4093 AsyncDelegateLogger::Run( 4088 AsyncDelegateLogger::Run(
4094 request, 4089 request,
4095 LOAD_STATE_WAITING_FOR_DELEGATE, 4090 LOAD_STATE_WAITING_FOR_DELEGATE,
4096 LOAD_STATE_WAITING_FOR_DELEGATE, 4091 LOAD_STATE_WAITING_FOR_DELEGATE,
4097 LOAD_STATE_WAITING_FOR_DELEGATE, 4092 LOAD_STATE_WAITING_FOR_DELEGATE,
4098 base::Bind( 4093 base::Bind(
4099 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete, 4094 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete,
4100 base::Unretained(this), request, redirect_info)); 4095 base::Unretained(this), request, redirect_info));
4101 } 4096 }
4102 4097
4103 virtual void OnResponseStarted(URLRequest* request) override { 4098 void OnResponseStarted(URLRequest* request) override {
4104 AsyncDelegateLogger::Run( 4099 AsyncDelegateLogger::Run(
4105 request, 4100 request,
4106 LOAD_STATE_WAITING_FOR_DELEGATE, 4101 LOAD_STATE_WAITING_FOR_DELEGATE,
4107 LOAD_STATE_WAITING_FOR_DELEGATE, 4102 LOAD_STATE_WAITING_FOR_DELEGATE,
4108 LOAD_STATE_WAITING_FOR_DELEGATE, 4103 LOAD_STATE_WAITING_FOR_DELEGATE,
4109 base::Bind( 4104 base::Bind(
4110 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete, 4105 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete,
4111 base::Unretained(this), request)); 4106 base::Unretained(this), request));
4112 } 4107 }
4113 4108
4114 virtual void OnReadCompleted(URLRequest* request, 4109 void OnReadCompleted(URLRequest* request, int bytes_read) override {
4115 int bytes_read) override {
4116 AsyncDelegateLogger::Run( 4110 AsyncDelegateLogger::Run(
4117 request, 4111 request,
4118 LOAD_STATE_IDLE, 4112 LOAD_STATE_IDLE,
4119 LOAD_STATE_IDLE, 4113 LOAD_STATE_IDLE,
4120 LOAD_STATE_IDLE, 4114 LOAD_STATE_IDLE,
4121 base::Bind( 4115 base::Bind(
4122 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete, 4116 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete,
4123 base::Unretained(this), request, bytes_read)); 4117 base::Unretained(this), request, bytes_read));
4124 } 4118 }
4125 4119
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
4571 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); 4565 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE));
4572 } 4566 }
4573 } 4567 }
4574 4568
4575 namespace { 4569 namespace {
4576 4570
4577 const char kExtraHeader[] = "Allow-Snafu"; 4571 const char kExtraHeader[] = "Allow-Snafu";
4578 const char kExtraValue[] = "fubar"; 4572 const char kExtraValue[] = "fubar";
4579 4573
4580 class RedirectWithAdditionalHeadersDelegate : public TestDelegate { 4574 class RedirectWithAdditionalHeadersDelegate : public TestDelegate {
4581 virtual void OnReceivedRedirect(URLRequest* request, 4575 void OnReceivedRedirect(URLRequest* request,
4582 const RedirectInfo& redirect_info, 4576 const RedirectInfo& redirect_info,
4583 bool* defer_redirect) override { 4577 bool* defer_redirect) override {
4584 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); 4578 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect);
4585 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false); 4579 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false);
4586 } 4580 }
4587 }; 4581 };
4588 4582
4589 } // namespace 4583 } // namespace
4590 4584
4591 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { 4585 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) {
4592 ASSERT_TRUE(test_server_.Start()); 4586 ASSERT_TRUE(test_server_.Start());
4593 4587
(...skipping 14 matching lines...) Expand all
4608 EXPECT_FALSE(req->is_pending()); 4602 EXPECT_FALSE(req->is_pending());
4609 EXPECT_FALSE(req->is_redirecting()); 4603 EXPECT_FALSE(req->is_redirecting());
4610 EXPECT_EQ(kExtraValue, d.data_received()); 4604 EXPECT_EQ(kExtraValue, d.data_received());
4611 } 4605 }
4612 4606
4613 namespace { 4607 namespace {
4614 4608
4615 const char kExtraHeaderToRemove[] = "To-Be-Removed"; 4609 const char kExtraHeaderToRemove[] = "To-Be-Removed";
4616 4610
4617 class RedirectWithHeaderRemovalDelegate : public TestDelegate { 4611 class RedirectWithHeaderRemovalDelegate : public TestDelegate {
4618 virtual void OnReceivedRedirect(URLRequest* request, 4612 void OnReceivedRedirect(URLRequest* request,
4619 const RedirectInfo& redirect_info, 4613 const RedirectInfo& redirect_info,
4620 bool* defer_redirect) override { 4614 bool* defer_redirect) override {
4621 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); 4615 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect);
4622 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); 4616 request->RemoveRequestHeaderByName(kExtraHeaderToRemove);
4623 } 4617 }
4624 }; 4618 };
4625 4619
4626 } // namespace 4620 } // namespace
4627 4621
4628 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { 4622 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) {
4629 ASSERT_TRUE(test_server_.Start()); 4623 ASSERT_TRUE(test_server_.Start());
4630 4624
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
6804 &received_cors_header)); 6798 &received_cors_header));
6805 EXPECT_EQ(kOriginHeaderValue, received_cors_header); 6799 EXPECT_EQ(kOriginHeaderValue, received_cors_header);
6806 } 6800 }
6807 6801
6808 namespace { 6802 namespace {
6809 6803
6810 class SSLClientAuthTestDelegate : public TestDelegate { 6804 class SSLClientAuthTestDelegate : public TestDelegate {
6811 public: 6805 public:
6812 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { 6806 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {
6813 } 6807 }
6814 virtual void OnCertificateRequested( 6808 void OnCertificateRequested(URLRequest* request,
6815 URLRequest* request, 6809 SSLCertRequestInfo* cert_request_info) override {
6816 SSLCertRequestInfo* cert_request_info) override {
6817 on_certificate_requested_count_++; 6810 on_certificate_requested_count_++;
6818 base::MessageLoop::current()->Quit(); 6811 base::MessageLoop::current()->Quit();
6819 } 6812 }
6820 int on_certificate_requested_count() { 6813 int on_certificate_requested_count() {
6821 return on_certificate_requested_count_; 6814 return on_certificate_requested_count_;
6822 } 6815 }
6823 private: 6816 private:
6824 int on_certificate_requested_count_; 6817 int on_certificate_requested_count_;
6825 }; 6818 };
6826 6819
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
7085 online_rev_checking_(online_rev_checking), 7078 online_rev_checking_(online_rev_checking),
7086 rev_checking_required_local_anchors_( 7079 rev_checking_required_local_anchors_(
7087 rev_checking_required_local_anchors), 7080 rev_checking_required_local_anchors),
7088 fallback_min_version_(0) {} 7081 fallback_min_version_(0) {}
7089 7082
7090 void set_fallback_min_version(uint16 version) { 7083 void set_fallback_min_version(uint16 version) {
7091 fallback_min_version_ = version; 7084 fallback_min_version_ = version;
7092 } 7085 }
7093 7086
7094 // SSLConfigService: 7087 // SSLConfigService:
7095 virtual void GetSSLConfig(SSLConfig* config) override { 7088 void GetSSLConfig(SSLConfig* config) override {
7096 *config = SSLConfig(); 7089 *config = SSLConfig();
7097 config->rev_checking_enabled = online_rev_checking_; 7090 config->rev_checking_enabled = online_rev_checking_;
7098 config->verify_ev_cert = ev_enabled_; 7091 config->verify_ev_cert = ev_enabled_;
7099 config->rev_checking_required_local_anchors = 7092 config->rev_checking_required_local_anchors =
7100 rev_checking_required_local_anchors_; 7093 rev_checking_required_local_anchors_;
7101 if (fallback_min_version_) { 7094 if (fallback_min_version_) {
7102 config->version_fallback_min = fallback_min_version_; 7095 config->version_fallback_min = fallback_min_version_;
7103 } 7096 }
7104 } 7097 }
7105 7098
7106 protected: 7099 protected:
7107 virtual ~TestSSLConfigService() {} 7100 ~TestSSLConfigService() override {}
7108 7101
7109 private: 7102 private:
7110 const bool ev_enabled_; 7103 const bool ev_enabled_;
7111 const bool online_rev_checking_; 7104 const bool online_rev_checking_;
7112 const bool rev_checking_required_local_anchors_; 7105 const bool rev_checking_required_local_anchors_;
7113 uint16 fallback_min_version_; 7106 uint16 fallback_min_version_;
7114 }; 7107 };
7115 7108
7116 class FallbackTestURLRequestContext : public TestURLRequestContext { 7109 class FallbackTestURLRequestContext : public TestURLRequestContext {
7117 public: 7110 public:
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
7657 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(), 7650 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(),
7658 cert_status & CERT_STATUS_ALL_ERRORS); 7651 cert_status & CERT_STATUS_ALL_ERRORS);
7659 7652
7660 // Without a positive OCSP response, we shouldn't show the EV status. 7653 // Without a positive OCSP response, we shouldn't show the EV status.
7661 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 7654 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
7662 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 7655 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
7663 } 7656 }
7664 7657
7665 class HTTPSHardFailTest : public HTTPSOCSPTest { 7658 class HTTPSHardFailTest : public HTTPSOCSPTest {
7666 protected: 7659 protected:
7667 virtual void SetupContext(URLRequestContext* context) override { 7660 void SetupContext(URLRequestContext* context) override {
7668 context->set_ssl_config_service( 7661 context->set_ssl_config_service(
7669 new TestSSLConfigService(false /* check for EV */, 7662 new TestSSLConfigService(false /* check for EV */,
7670 false /* online revocation checking */, 7663 false /* online revocation checking */,
7671 true /* require rev. checking for local 7664 true /* require rev. checking for local
7672 anchors */)); 7665 anchors */));
7673 } 7666 }
7674 }; 7667 };
7675 7668
7676 7669
7677 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { 7670 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) {
(...skipping 17 matching lines...) Expand all
7695 7688
7696 EXPECT_EQ(CERT_STATUS_REVOKED, 7689 EXPECT_EQ(CERT_STATUS_REVOKED,
7697 cert_status & CERT_STATUS_REVOKED); 7690 cert_status & CERT_STATUS_REVOKED);
7698 7691
7699 // Without a positive OCSP response, we shouldn't show the EV status. 7692 // Without a positive OCSP response, we shouldn't show the EV status.
7700 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 7693 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
7701 } 7694 }
7702 7695
7703 class HTTPSEVCRLSetTest : public HTTPSOCSPTest { 7696 class HTTPSEVCRLSetTest : public HTTPSOCSPTest {
7704 protected: 7697 protected:
7705 virtual void SetupContext(URLRequestContext* context) override { 7698 void SetupContext(URLRequestContext* context) override {
7706 context->set_ssl_config_service( 7699 context->set_ssl_config_service(
7707 new TestSSLConfigService(true /* check for EV */, 7700 new TestSSLConfigService(true /* check for EV */,
7708 false /* online revocation checking */, 7701 false /* online revocation checking */,
7709 false /* require rev. checking for local 7702 false /* require rev. checking for local
7710 anchors */)); 7703 anchors */));
7711 } 7704 }
7712 }; 7705 };
7713 7706
7714 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) { 7707 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) {
7715 if (!SystemSupportsOCSP()) { 7708 if (!SystemSupportsOCSP()) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
7880 DoConnection(ssl_options, &cert_status); 7873 DoConnection(ssl_options, &cert_status);
7881 7874
7882 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); 7875 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
7883 7876
7884 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 7877 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
7885 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 7878 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
7886 } 7879 }
7887 7880
7888 class HTTPSCRLSetTest : public HTTPSOCSPTest { 7881 class HTTPSCRLSetTest : public HTTPSOCSPTest {
7889 protected: 7882 protected:
7890 virtual void SetupContext(URLRequestContext* context) override { 7883 void SetupContext(URLRequestContext* context) override {
7891 context->set_ssl_config_service( 7884 context->set_ssl_config_service(
7892 new TestSSLConfigService(false /* check for EV */, 7885 new TestSSLConfigService(false /* check for EV */,
7893 false /* online revocation checking */, 7886 false /* online revocation checking */,
7894 false /* require rev. checking for local 7887 false /* require rev. checking for local
7895 anchors */)); 7888 anchors */));
7896 } 7889 }
7897 }; 7890 };
7898 7891
7899 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) { 7892 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) {
7900 SpawnedTestServer::SSLOptions ssl_options( 7893 SpawnedTestServer::SSLOptions ssl_options(
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
8283 8276
8284 EXPECT_FALSE(r->is_pending()); 8277 EXPECT_FALSE(r->is_pending());
8285 EXPECT_EQ(1, d->response_started_count()); 8278 EXPECT_EQ(1, d->response_started_count());
8286 EXPECT_FALSE(d->received_data_before_response()); 8279 EXPECT_FALSE(d->received_data_before_response());
8287 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8280 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8288 } 8281 }
8289 } 8282 }
8290 #endif // !defined(DISABLE_FTP_SUPPORT) 8283 #endif // !defined(DISABLE_FTP_SUPPORT)
8291 8284
8292 } // namespace net 8285 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_unittest.cc ('k') | net/url_request/view_cache_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698