Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "net/http/http_stream_factory_impl_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "net/base/test_proxy_delegate.h" | |
| 10 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
| 11 #include "net/http/http_basic_stream.h" | 12 #include "net/http/http_basic_stream.h" |
| 12 #include "net/http/http_stream_factory_impl_request.h" | 13 #include "net/http/http_stream_factory_impl_request.h" |
| 13 #include "net/http/http_stream_factory_test_util.h" | 14 #include "net/http/http_stream_factory_test_util.h" |
| 14 #include "net/proxy/mock_proxy_resolver.h" | 15 #include "net/proxy/mock_proxy_resolver.h" |
| 15 #include "net/proxy/proxy_config_service_fixed.h" | 16 #include "net/proxy/proxy_config_service_fixed.h" |
| 16 #include "net/proxy/proxy_info.h" | 17 #include "net/proxy/proxy_info.h" |
| 17 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
| 18 #include "net/quic/test_tools/quic_stream_factory_peer.h" | 19 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
| 19 #include "net/spdy/spdy_test_util_common.h" | 20 #include "net/spdy/spdy_test_util_common.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | |
| 20 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 23 using ::testing::_; | 25 using ::testing::_; |
| 24 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 std::unique_ptr<ProxyResolver>* resolver, | 70 std::unique_ptr<ProxyResolver>* resolver, |
| 69 const net::CompletionCallback& callback, | 71 const net::CompletionCallback& callback, |
| 70 std::unique_ptr<Request>* request) override { | 72 std::unique_ptr<Request>* request) override { |
| 71 resolver->reset(new ForwardingProxyResolver(resolver_)); | 73 resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 72 return OK; | 74 return OK; |
| 73 } | 75 } |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 HangingProxyResolver* resolver_; | 78 HangingProxyResolver* resolver_; |
| 77 }; | 79 }; |
| 78 | 80 |
|
Zhongyi Shi
2016/08/20 06:15:40
This probably needs a rebase as you have already r
tbansal1
2016/08/22 15:42:32
Acknowledged. I rebased in PS 2.
| |
| 79 class FailingProxyResolverFactory : public ProxyResolverFactory { | 81 class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 80 public: | 82 public: |
| 81 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} | 83 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 82 | 84 |
| 83 // ProxyResolverFactory override. | 85 // ProxyResolverFactory override. |
| 84 int CreateProxyResolver( | 86 int CreateProxyResolver( |
| 85 const scoped_refptr<ProxyResolverScriptData>& script_data, | 87 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 86 std::unique_ptr<ProxyResolver>* result, | 88 std::unique_ptr<ProxyResolver>* result, |
| 87 const CompletionCallback& callback, | 89 const CompletionCallback& callback, |
| 88 std::unique_ptr<Request>* request) override { | 90 std::unique_ptr<Request>* request) override { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 145 |
| 144 class HttpStreamFactoryImplJobControllerTest | 146 class HttpStreamFactoryImplJobControllerTest |
| 145 : public ::testing::Test, | 147 : public ::testing::Test, |
| 146 public ::testing::WithParamInterface<NextProto> { | 148 public ::testing::WithParamInterface<NextProto> { |
| 147 public: | 149 public: |
| 148 HttpStreamFactoryImplJobControllerTest() | 150 HttpStreamFactoryImplJobControllerTest() |
| 149 : session_deps_(ProxyService::CreateDirect()) { | 151 : session_deps_(ProxyService::CreateDirect()) { |
| 150 session_deps_.enable_quic = true; | 152 session_deps_.enable_quic = true; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void Initialize() { | 155 void Initialize(bool use_alternative_proxy) { |
| 156 if (use_alternative_proxy) { | |
| 157 std::unique_ptr<ProxyService> proxy_service = | |
| 158 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | |
| 159 session_deps_.proxy_service.reset(proxy_service.release()); | |
| 160 | |
| 161 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | |
| 162 new TestProxyDelegate()); | |
| 163 test_proxy_delegate_ = test_proxy_delegate.get(); | |
| 164 | |
| 165 test_proxy_delegate->SetAlternativeProxy( | |
| 166 ProxyServer::FromPacString("QUIC myproxy.org:443")); | |
| 167 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | |
| 168 session_deps_.proxy_delegate.reset(test_proxy_delegate.release()); | |
| 169 } | |
| 154 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 170 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 155 factory_ = | 171 factory_ = |
| 156 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 172 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 157 job_controller_ = new HttpStreamFactoryImpl::JobController( | 173 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 158 factory_, &request_delegate_, session_.get(), &job_factory_); | 174 factory_, &request_delegate_, session_.get(), &job_factory_); |
| 159 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 175 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 160 } | 176 } |
| 161 | 177 |
| 178 TestProxyDelegate* test_proxy_delegate() const { | |
| 179 return test_proxy_delegate_; | |
| 180 } | |
| 181 | |
| 162 ~HttpStreamFactoryImplJobControllerTest() {} | 182 ~HttpStreamFactoryImplJobControllerTest() {} |
| 163 | 183 |
| 164 void SetAlternativeService(const HttpRequestInfo& request_info, | 184 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 165 AlternativeService alternative_service) { | 185 AlternativeService alternative_service) { |
| 166 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 186 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 167 url::SchemeHostPort server(request_info.url); | 187 url::SchemeHostPort server(request_info.url); |
| 168 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 188 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 169 session_->http_server_properties()->SetAlternativeService( | 189 session_->http_server_properties()->SetAlternativeService( |
| 170 server, alternative_service, expiration); | 190 server, alternative_service, expiration); |
| 171 } | 191 } |
| 172 | 192 |
| 193 // Not owned by |this|. | |
| 194 TestProxyDelegate* test_proxy_delegate_; | |
| 173 TestJobFactory job_factory_; | 195 TestJobFactory job_factory_; |
| 174 MockHttpStreamRequestDelegate request_delegate_; | 196 MockHttpStreamRequestDelegate request_delegate_; |
| 175 SpdySessionDependencies session_deps_; | 197 SpdySessionDependencies session_deps_; |
| 176 std::unique_ptr<HttpNetworkSession> session_; | 198 std::unique_ptr<HttpNetworkSession> session_; |
| 177 HttpStreamFactoryImpl* factory_; | 199 HttpStreamFactoryImpl* factory_; |
| 178 HttpStreamFactoryImpl::JobController* job_controller_; | 200 HttpStreamFactoryImpl::JobController* job_controller_; |
| 179 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 201 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
| 180 | 202 |
| 181 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 203 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 182 }; | 204 }; |
| 183 | 205 |
| 184 TEST_F(HttpStreamFactoryImplJobControllerTest, | 206 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 185 OnStreamFailedWithNoAlternativeJob) { | 207 OnStreamFailedWithNoAlternativeJob) { |
| 186 ProxyConfig proxy_config; | 208 ProxyConfig proxy_config; |
| 187 proxy_config.set_auto_detect(true); | 209 proxy_config.set_auto_detect(true); |
| 188 // Use asynchronous proxy resolver. | 210 // Use asynchronous proxy resolver. |
| 189 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 211 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 190 new MockAsyncProxyResolverFactory(false); | 212 new MockAsyncProxyResolverFactory(false); |
| 191 session_deps_.proxy_service.reset(new ProxyService( | 213 session_deps_.proxy_service.reset(new ProxyService( |
| 192 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 214 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 193 base::WrapUnique(proxy_resolver_factory), nullptr)); | 215 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 194 Initialize(); | 216 Initialize(false); |
| 195 | 217 |
| 196 HttpRequestInfo request_info; | 218 HttpRequestInfo request_info; |
| 197 request_info.method = "GET"; | 219 request_info.method = "GET"; |
| 198 request_info.url = GURL("http://www.google.com"); | 220 request_info.url = GURL("http://www.google.com"); |
| 199 | 221 |
| 200 request_.reset( | 222 request_.reset( |
| 201 job_controller_->Start(request_info, &request_delegate_, nullptr, | 223 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 202 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 224 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 203 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 225 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 204 | 226 |
| 205 EXPECT_TRUE(job_controller_->main_job()); | 227 EXPECT_TRUE(job_controller_->main_job()); |
| 206 | 228 |
| 207 // There's no other alternative job. Thus when stream failed, it should | 229 // There's no other alternative job. Thus when stream failed, it should |
| 208 // notify Request of the stream failure. | 230 // notify Request of the stream failure. |
| 209 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 231 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 210 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 232 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 211 SSLConfig()); | 233 SSLConfig()); |
| 212 } | 234 } |
| 213 | 235 |
| 214 TEST_F(HttpStreamFactoryImplJobControllerTest, | 236 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 215 OnStreamReadyWithNoAlternativeJob) { | 237 OnStreamReadyWithNoAlternativeJob) { |
| 216 ProxyConfig proxy_config; | 238 ProxyConfig proxy_config; |
| 217 proxy_config.set_auto_detect(true); | 239 proxy_config.set_auto_detect(true); |
| 218 // Use asynchronous proxy resolver. | 240 // Use asynchronous proxy resolver. |
| 219 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 241 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 220 new MockAsyncProxyResolverFactory(false); | 242 new MockAsyncProxyResolverFactory(false); |
| 221 session_deps_.proxy_service.reset(new ProxyService( | 243 session_deps_.proxy_service.reset(new ProxyService( |
| 222 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 244 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 223 base::WrapUnique(proxy_resolver_factory), nullptr)); | 245 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 224 Initialize(); | 246 Initialize(false); |
| 225 | 247 |
| 226 HttpRequestInfo request_info; | 248 HttpRequestInfo request_info; |
| 227 request_info.method = "GET"; | 249 request_info.method = "GET"; |
| 228 request_info.url = GURL("http://www.google.com"); | 250 request_info.url = GURL("http://www.google.com"); |
| 229 | 251 |
| 230 request_.reset( | 252 request_.reset( |
| 231 job_controller_->Start(request_info, &request_delegate_, nullptr, | 253 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 232 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 254 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 233 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 255 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 234 | 256 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 248 // before any Job is bound to Request. | 270 // before any Job is bound to Request. |
| 249 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 271 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 250 ProxyConfig proxy_config; | 272 ProxyConfig proxy_config; |
| 251 proxy_config.set_auto_detect(true); | 273 proxy_config.set_auto_detect(true); |
| 252 // Use asynchronous proxy resolver. | 274 // Use asynchronous proxy resolver. |
| 253 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 275 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 254 new MockAsyncProxyResolverFactory(false); | 276 new MockAsyncProxyResolverFactory(false); |
| 255 session_deps_.proxy_service.reset(new ProxyService( | 277 session_deps_.proxy_service.reset(new ProxyService( |
| 256 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 278 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 257 base::WrapUnique(proxy_resolver_factory), nullptr)); | 279 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 258 Initialize(); | 280 Initialize(false); |
| 259 | 281 |
| 260 HttpRequestInfo request_info; | 282 HttpRequestInfo request_info; |
| 261 request_info.method = "GET"; | 283 request_info.method = "GET"; |
| 262 request_info.url = GURL("https://www.google.com"); | 284 request_info.url = GURL("https://www.google.com"); |
| 263 | 285 |
| 264 url::SchemeHostPort server(request_info.url); | 286 url::SchemeHostPort server(request_info.url); |
| 265 AlternativeService alternative_service(QUIC, server.host(), 443); | 287 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 266 SetAlternativeService(request_info, alternative_service); | 288 SetAlternativeService(request_info, alternative_service); |
| 267 | 289 |
| 268 request_.reset( | 290 request_.reset( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 281 | 303 |
| 282 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 304 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 283 ProxyConfig proxy_config; | 305 ProxyConfig proxy_config; |
| 284 proxy_config.set_auto_detect(true); | 306 proxy_config.set_auto_detect(true); |
| 285 // Use asynchronous proxy resolver. | 307 // Use asynchronous proxy resolver. |
| 286 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 308 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 287 new MockAsyncProxyResolverFactory(false); | 309 new MockAsyncProxyResolverFactory(false); |
| 288 session_deps_.proxy_service.reset(new ProxyService( | 310 session_deps_.proxy_service.reset(new ProxyService( |
| 289 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 311 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 290 base::WrapUnique(proxy_resolver_factory), nullptr)); | 312 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 291 Initialize(); | 313 Initialize(false); |
| 292 | 314 |
| 293 HttpRequestInfo request_info; | 315 HttpRequestInfo request_info; |
| 294 request_info.method = "GET"; | 316 request_info.method = "GET"; |
| 295 request_info.url = GURL("https://www.google.com"); | 317 request_info.url = GURL("https://www.google.com"); |
| 296 | 318 |
| 297 url::SchemeHostPort server(request_info.url); | 319 url::SchemeHostPort server(request_info.url); |
| 298 AlternativeService alternative_service(QUIC, server.host(), 443); | 320 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 299 SetAlternativeService(request_info, alternative_service); | 321 SetAlternativeService(request_info, alternative_service); |
| 300 | 322 |
| 301 request_.reset( | 323 request_.reset( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 325 TEST_F(HttpStreamFactoryImplJobControllerTest, | 347 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 326 SecondJobFailsAfterFirstJobSucceeds) { | 348 SecondJobFailsAfterFirstJobSucceeds) { |
| 327 ProxyConfig proxy_config; | 349 ProxyConfig proxy_config; |
| 328 proxy_config.set_auto_detect(true); | 350 proxy_config.set_auto_detect(true); |
| 329 // Use asynchronous proxy resolver. | 351 // Use asynchronous proxy resolver. |
| 330 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 352 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 331 new MockAsyncProxyResolverFactory(false); | 353 new MockAsyncProxyResolverFactory(false); |
| 332 session_deps_.proxy_service.reset(new ProxyService( | 354 session_deps_.proxy_service.reset(new ProxyService( |
| 333 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 355 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 334 base::WrapUnique(proxy_resolver_factory), nullptr)); | 356 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 335 Initialize(); | 357 Initialize(false); |
| 336 | 358 |
| 337 HttpRequestInfo request_info; | 359 HttpRequestInfo request_info; |
| 338 request_info.method = "GET"; | 360 request_info.method = "GET"; |
| 339 request_info.url = GURL("https://www.google.com"); | 361 request_info.url = GURL("https://www.google.com"); |
| 340 | 362 |
| 341 url::SchemeHostPort server(request_info.url); | 363 url::SchemeHostPort server(request_info.url); |
| 342 AlternativeService alternative_service(QUIC, server.host(), 443); | 364 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 343 SetAlternativeService(request_info, alternative_service); | 365 SetAlternativeService(request_info, alternative_service); |
| 344 | 366 |
| 345 request_.reset( | 367 request_.reset( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 TEST_F(HttpStreamFactoryImplJobControllerTest, | 399 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 378 SecondJobSucceedsAfterFirstJobFailed) { | 400 SecondJobSucceedsAfterFirstJobFailed) { |
| 379 ProxyConfig proxy_config; | 401 ProxyConfig proxy_config; |
| 380 proxy_config.set_auto_detect(true); | 402 proxy_config.set_auto_detect(true); |
| 381 // Use asynchronous proxy resolver. | 403 // Use asynchronous proxy resolver. |
| 382 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 404 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 383 new MockAsyncProxyResolverFactory(false); | 405 new MockAsyncProxyResolverFactory(false); |
| 384 session_deps_.proxy_service.reset(new ProxyService( | 406 session_deps_.proxy_service.reset(new ProxyService( |
| 385 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 407 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 386 base::WrapUnique(proxy_resolver_factory), nullptr)); | 408 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 387 Initialize(); | 409 Initialize(false); |
| 388 | 410 |
| 389 HttpRequestInfo request_info; | 411 HttpRequestInfo request_info; |
| 390 request_info.method = "GET"; | 412 request_info.method = "GET"; |
| 391 request_info.url = GURL("https://www.google.com"); | 413 request_info.url = GURL("https://www.google.com"); |
| 392 | 414 |
| 393 url::SchemeHostPort server(request_info.url); | 415 url::SchemeHostPort server(request_info.url); |
| 394 AlternativeService alternative_service(QUIC, server.host(), 443); | 416 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 395 SetAlternativeService(request_info, alternative_service); | 417 SetAlternativeService(request_info, alternative_service); |
| 396 | 418 |
| 397 request_.reset( | 419 request_.reset( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 425 // Get load state after main job fails and before alternative job succeeds. | 447 // Get load state after main job fails and before alternative job succeeds. |
| 426 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 448 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 427 ProxyConfig proxy_config; | 449 ProxyConfig proxy_config; |
| 428 proxy_config.set_auto_detect(true); | 450 proxy_config.set_auto_detect(true); |
| 429 // Use asynchronous proxy resolver. | 451 // Use asynchronous proxy resolver. |
| 430 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 452 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 431 new MockAsyncProxyResolverFactory(false); | 453 new MockAsyncProxyResolverFactory(false); |
| 432 session_deps_.proxy_service.reset(new ProxyService( | 454 session_deps_.proxy_service.reset(new ProxyService( |
| 433 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 455 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 434 base::WrapUnique(proxy_resolver_factory), nullptr)); | 456 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 435 Initialize(); | 457 Initialize(false); |
| 436 | 458 |
| 437 HttpRequestInfo request_info; | 459 HttpRequestInfo request_info; |
| 438 request_info.method = "GET"; | 460 request_info.method = "GET"; |
| 439 request_info.url = GURL("https://www.google.com"); | 461 request_info.url = GURL("https://www.google.com"); |
| 440 | 462 |
| 441 url::SchemeHostPort server(request_info.url); | 463 url::SchemeHostPort server(request_info.url); |
| 442 AlternativeService alternative_service(QUIC, server.host(), 443); | 464 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 443 SetAlternativeService(request_info, alternative_service); | 465 SetAlternativeService(request_info, alternative_service); |
| 444 | 466 |
| 445 request_.reset( | 467 request_.reset( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 476 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 498 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
| 477 // to stall the alternative job and report to controller to maybe resume the | 499 // to stall the alternative job and report to controller to maybe resume the |
| 478 // main job. | 500 // main job. |
| 479 ProxyConfig proxy_config; | 501 ProxyConfig proxy_config; |
| 480 proxy_config.set_auto_detect(true); | 502 proxy_config.set_auto_detect(true); |
| 481 proxy_config.set_pac_mandatory(true); | 503 proxy_config.set_pac_mandatory(true); |
| 482 session_deps_.proxy_service.reset(new ProxyService( | 504 session_deps_.proxy_service.reset(new ProxyService( |
| 483 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 505 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 484 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 506 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 485 | 507 |
| 486 Initialize(); | 508 Initialize(false); |
| 487 | 509 |
| 488 HttpRequestInfo request_info; | 510 HttpRequestInfo request_info; |
| 489 request_info.method = "GET"; | 511 request_info.method = "GET"; |
| 490 request_info.url = GURL("https://www.google.com"); | 512 request_info.url = GURL("https://www.google.com"); |
| 491 | 513 |
| 492 url::SchemeHostPort server(request_info.url); | 514 url::SchemeHostPort server(request_info.url); |
| 493 AlternativeService alternative_service(QUIC, server.host(), 443); | 515 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 494 SetAlternativeService(request_info, alternative_service); | 516 SetAlternativeService(request_info, alternative_service); |
| 495 | 517 |
| 496 request_.reset( | 518 request_.reset( |
| 497 job_controller_->Start(request_info, &request_delegate_, nullptr, | 519 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 498 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 520 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 499 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 521 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 500 EXPECT_TRUE(job_controller_->main_job()); | 522 EXPECT_TRUE(job_controller_->main_job()); |
| 501 EXPECT_TRUE(job_controller_->alternative_job()); | 523 EXPECT_TRUE(job_controller_->alternative_job()); |
| 502 | 524 |
| 503 // Wait until OnStreamFailedCallback is executed on the alternative job. | 525 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 504 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 526 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
| 505 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 527 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
| 506 base::RunLoop().RunUntilIdle(); | 528 base::RunLoop().RunUntilIdle(); |
| 507 } | 529 } |
| 508 | 530 |
| 509 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 531 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
| 510 // Using a restricted port 101 for QUIC should fail and the alternative job | 532 // Using a restricted port 101 for QUIC should fail and the alternative job |
| 511 // should post OnStreamFailedCall on the controller to resume the main job. | 533 // should post OnStreamFailedCall on the controller to resume the main job. |
| 512 Initialize(); | 534 Initialize(false); |
| 513 | 535 |
| 514 HttpRequestInfo request_info; | 536 HttpRequestInfo request_info; |
| 515 request_info.method = "GET"; | 537 request_info.method = "GET"; |
| 516 request_info.url = GURL("https://www.google.com"); | 538 request_info.url = GURL("https://www.google.com"); |
| 517 | 539 |
| 518 url::SchemeHostPort server(request_info.url); | 540 url::SchemeHostPort server(request_info.url); |
| 519 AlternativeService alternative_service(QUIC, server.host(), 101); | 541 AlternativeService alternative_service(QUIC, server.host(), 101); |
| 520 SetAlternativeService(request_info, alternative_service); | 542 SetAlternativeService(request_info, alternative_service); |
| 521 | 543 |
| 522 request_.reset( | 544 request_.reset( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 544 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 566 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 545 new MockAsyncProxyResolverFactory(false); | 567 new MockAsyncProxyResolverFactory(false); |
| 546 session_deps_.proxy_service.reset(new ProxyService( | 568 session_deps_.proxy_service.reset(new ProxyService( |
| 547 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 569 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 548 base::WrapUnique(proxy_resolver_factory), nullptr)); | 570 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 549 | 571 |
| 550 HangingResolver* host_resolver = new HangingResolver(); | 572 HangingResolver* host_resolver = new HangingResolver(); |
| 551 session_deps_.host_resolver.reset(host_resolver); | 573 session_deps_.host_resolver.reset(host_resolver); |
| 552 session_deps_.host_resolver->set_synchronous_mode(false); | 574 session_deps_.host_resolver->set_synchronous_mode(false); |
| 553 | 575 |
| 554 Initialize(); | 576 Initialize(false); |
| 555 | 577 |
| 556 HttpRequestInfo request_info; | 578 HttpRequestInfo request_info; |
| 557 request_info.method = "GET"; | 579 request_info.method = "GET"; |
| 558 request_info.url = GURL("https://www.google.com"); | 580 request_info.url = GURL("https://www.google.com"); |
| 559 | 581 |
| 560 // Set a SPDY alternative service for the server. | 582 // Set a SPDY alternative service for the server. |
| 561 url::SchemeHostPort server(request_info.url); | 583 url::SchemeHostPort server(request_info.url); |
| 562 AlternativeService alternative_service(QUIC, server.host(), 443); | 584 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 563 SetAlternativeService(request_info, alternative_service); | 585 SetAlternativeService(request_info, alternative_service); |
| 564 // Hack to use different URL for the main job to help differentiate the proxy | 586 // Hack to use different URL for the main job to help differentiate the proxy |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 | 630 |
| 609 ProxyConfig proxy_config; | 631 ProxyConfig proxy_config; |
| 610 proxy_config.set_auto_detect(true); | 632 proxy_config.set_auto_detect(true); |
| 611 // Use asynchronous proxy resolver. | 633 // Use asynchronous proxy resolver. |
| 612 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 634 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 613 new MockAsyncProxyResolverFactory(false); | 635 new MockAsyncProxyResolverFactory(false); |
| 614 session_deps_.proxy_service.reset(new ProxyService( | 636 session_deps_.proxy_service.reset(new ProxyService( |
| 615 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 637 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 616 base::WrapUnique(proxy_resolver_factory), nullptr)); | 638 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 617 | 639 |
| 618 Initialize(); | 640 Initialize(false); |
| 619 | 641 |
| 620 HttpRequestInfo request_info; | 642 HttpRequestInfo request_info; |
| 621 request_info.method = "GET"; | 643 request_info.method = "GET"; |
| 622 request_info.url = GURL("https://www.google.com"); | 644 request_info.url = GURL("https://www.google.com"); |
| 623 | 645 |
| 624 url::SchemeHostPort server(request_info.url); | 646 url::SchemeHostPort server(request_info.url); |
| 625 AlternativeService alternative_service(QUIC, server.host(), 443); | 647 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 626 SetAlternativeService(request_info, alternative_service); | 648 SetAlternativeService(request_info, alternative_service); |
| 627 // Hack to use different URL for the main job to help differentiate the proxy | 649 // Hack to use different URL for the main job to help differentiate the proxy |
| 628 // requests. | 650 // requests. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 683 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 662 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 684 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
| 663 | 685 |
| 664 base::RunLoop().RunUntilIdle(); | 686 base::RunLoop().RunUntilIdle(); |
| 665 } | 687 } |
| 666 | 688 |
| 667 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 689 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
| 668 HangingResolver* resolver = new HangingResolver(); | 690 HangingResolver* resolver = new HangingResolver(); |
| 669 session_deps_.host_resolver.reset(resolver); | 691 session_deps_.host_resolver.reset(resolver); |
| 670 | 692 |
| 671 Initialize(); | 693 Initialize(false); |
| 672 | 694 |
| 673 // Enable delayed TCP and set time delay for waiting job. | 695 // Enable delayed TCP and set time delay for waiting job. |
| 674 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 696 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 675 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 697 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 676 quic_stream_factory->set_require_confirmation(false); | 698 quic_stream_factory->set_require_confirmation(false); |
| 677 ServerNetworkStats stats1; | 699 ServerNetworkStats stats1; |
| 678 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 700 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 679 session_->http_server_properties()->SetServerNetworkStats( | 701 session_->http_server_properties()->SetServerNetworkStats( |
| 680 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 702 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 681 | 703 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 698 // The alternative job stalls as host resolution hangs when creating the QUIC | 720 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 699 // request and controller should resume the main job after delay. | 721 // request and controller should resume the main job after delay. |
| 700 // Verify the waiting time for delayed main job. | 722 // Verify the waiting time for delayed main job. |
| 701 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 723 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 702 .WillOnce(Invoke(testing::CreateFunctor( | 724 .WillOnce(Invoke(testing::CreateFunctor( |
| 703 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 725 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 704 base::TimeDelta::FromMicroseconds(15)))); | 726 base::TimeDelta::FromMicroseconds(15)))); |
| 705 | 727 |
| 706 base::RunLoop().RunUntilIdle(); | 728 base::RunLoop().RunUntilIdle(); |
| 707 } | 729 } |
| 730 | |
| 731 // Verifies that the main job is resumed properly after a delay when the | |
| 732 // alternative proxy server job hangs. | |
| 733 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { | |
| 734 // Using hanging resolver will cause the alternative job to hang indefinitely. | |
| 735 HangingResolver* resolver = new HangingResolver(); | |
| 736 session_deps_.host_resolver.reset(resolver); | |
| 737 | |
| 738 Initialize(true); | |
| 739 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
| 740 | |
| 741 // Enable delayed TCP and set time delay for waiting job. | |
| 742 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 743 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
| 744 quic_stream_factory->set_require_confirmation(false); | |
| 745 ServerNetworkStats stats1; | |
| 746 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | |
| 747 session_->http_server_properties()->SetServerNetworkStats( | |
| 748 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | |
| 749 | |
| 750 HttpRequestInfo request_info; | |
| 751 request_info.method = "GET"; | |
| 752 request_info.url = GURL("http://mail.example.org/"); | |
| 753 | |
| 754 request_.reset( | |
| 755 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 756 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 757 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 758 EXPECT_TRUE(job_controller_->main_job()); | |
| 759 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
| 760 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 761 | |
| 762 // The alternative proxy server job stalls when connecting to the alternative | |
| 763 // proxy server, and controller should resume the main job after delay. | |
| 764 // Verify the waiting time for delayed main job. | |
| 765 EXPECT_CALL(*job_factory_.main_job(), Resume()) | |
| 766 .WillOnce(Invoke(testing::CreateFunctor( | |
| 767 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | |
| 768 base::TimeDelta::FromMicroseconds(15)))); | |
| 769 | |
| 770 base::RunLoop().RunUntilIdle(); | |
| 771 // Since the main job did not complete successfully, the alternative proxy | |
| 772 // server should not be marked as bad. | |
| 773 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
| 774 } | |
| 775 | |
| 776 // Verifies that the alternative proxy server job fails immediately, and the | |
| 777 // main job is not blocked. | |
| 778 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { | |
| 779 // Using failing resolver will cause the alternative job to fail. | |
| 780 FailingHostResolver* resolver = new FailingHostResolver(); | |
| 781 session_deps_.host_resolver.reset(resolver); | |
| 782 | |
| 783 Initialize(true); | |
| 784 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
| 785 | |
| 786 // Enable delayed TCP and set time delay for waiting job. | |
| 787 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 788 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
| 789 quic_stream_factory->set_require_confirmation(false); | |
| 790 ServerNetworkStats stats1; | |
| 791 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | |
| 792 session_->http_server_properties()->SetServerNetworkStats( | |
| 793 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | |
| 794 | |
| 795 HttpRequestInfo request_info; | |
| 796 request_info.method = "GET"; | |
| 797 request_info.url = GURL("http://mail.example.org/"); | |
| 798 | |
| 799 request_.reset( | |
| 800 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 801 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 802 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 803 EXPECT_TRUE(job_controller_->main_job()); | |
| 804 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 805 | |
| 806 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | |
| 807 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | |
| 808 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 809 | |
| 810 // Since the alternative proxy server job fails to connect, the main job | |
| 811 // should not be blocked. | |
| 812 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
| 813 | |
| 814 base::RunLoop().RunUntilIdle(); | |
| 815 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 816 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | |
| 817 // Since the main job did not complete successfully, the alternative proxy | |
| 818 // server should not be marked as bad. | |
| 819 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
| 820 } | |
| 821 | |
| 708 } // namespace net | 822 } // namespace net |
| OLD | NEW |