| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 167 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 TEST_F(HttpStreamFactoryImplJobControllerTest, | 170 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 171 OnStreamFailedWithNoAlternativeJob) { | 171 OnStreamFailedWithNoAlternativeJob) { |
| 172 ProxyConfig proxy_config; | 172 ProxyConfig proxy_config; |
| 173 proxy_config.set_auto_detect(true); | 173 proxy_config.set_auto_detect(true); |
| 174 // Use asynchronous proxy resolver. | 174 // Use asynchronous proxy resolver. |
| 175 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 175 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 176 new MockAsyncProxyResolverFactory(false); | 176 new MockAsyncProxyResolverFactory(false); |
| 177 session_deps_.proxy_service.reset(new ProxyService( | 177 session_deps_.proxy_service.reset( |
| 178 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 178 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 179 base::WrapUnique(proxy_resolver_factory), nullptr)); | 179 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 180 Initialize(false); | 180 Initialize(false); |
| 181 | 181 |
| 182 HttpRequestInfo request_info; | 182 HttpRequestInfo request_info; |
| 183 request_info.method = "GET"; | 183 request_info.method = "GET"; |
| 184 request_info.url = GURL("http://www.google.com"); | 184 request_info.url = GURL("http://www.google.com"); |
| 185 | 185 |
| 186 request_.reset( | 186 request_.reset( |
| 187 job_controller_->Start(request_info, &request_delegate_, nullptr, | 187 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 188 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 188 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 189 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 189 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 190 | 190 |
| 191 EXPECT_TRUE(job_controller_->main_job()); | 191 EXPECT_TRUE(job_controller_->main_job()); |
| 192 | 192 |
| 193 // There's no other alternative job. Thus when stream failed, it should | 193 // There's no other alternative job. Thus when stream failed, it should |
| 194 // notify Request of the stream failure. | 194 // notify Request of the stream failure. |
| 195 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 195 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 196 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 196 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 197 SSLConfig()); | 197 SSLConfig()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(HttpStreamFactoryImplJobControllerTest, | 200 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 201 OnStreamReadyWithNoAlternativeJob) { | 201 OnStreamReadyWithNoAlternativeJob) { |
| 202 ProxyConfig proxy_config; | 202 ProxyConfig proxy_config; |
| 203 proxy_config.set_auto_detect(true); | 203 proxy_config.set_auto_detect(true); |
| 204 // Use asynchronous proxy resolver. | 204 // Use asynchronous proxy resolver. |
| 205 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 205 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 206 new MockAsyncProxyResolverFactory(false); | 206 new MockAsyncProxyResolverFactory(false); |
| 207 session_deps_.proxy_service.reset(new ProxyService( | 207 session_deps_.proxy_service.reset( |
| 208 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 208 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 209 base::WrapUnique(proxy_resolver_factory), nullptr)); | 209 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 210 Initialize(false); | 210 Initialize(false); |
| 211 | 211 |
| 212 HttpRequestInfo request_info; | 212 HttpRequestInfo request_info; |
| 213 request_info.method = "GET"; | 213 request_info.method = "GET"; |
| 214 request_info.url = GURL("http://www.google.com"); | 214 request_info.url = GURL("http://www.google.com"); |
| 215 | 215 |
| 216 request_.reset( | 216 request_.reset( |
| 217 job_controller_->Start(request_info, &request_delegate_, nullptr, | 217 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 218 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 218 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 219 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 219 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 request_.reset(); | 264 request_.reset(); |
| 265 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 265 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 268 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 269 ProxyConfig proxy_config; | 269 ProxyConfig proxy_config; |
| 270 proxy_config.set_auto_detect(true); | 270 proxy_config.set_auto_detect(true); |
| 271 // Use asynchronous proxy resolver. | 271 // Use asynchronous proxy resolver. |
| 272 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 272 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 273 new MockAsyncProxyResolverFactory(false); | 273 new MockAsyncProxyResolverFactory(false); |
| 274 session_deps_.proxy_service.reset(new ProxyService( | 274 session_deps_.proxy_service.reset( |
| 275 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 275 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 276 base::WrapUnique(proxy_resolver_factory), nullptr)); | 276 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 277 Initialize(false); | 277 Initialize(false); |
| 278 | 278 |
| 279 HttpRequestInfo request_info; | 279 HttpRequestInfo request_info; |
| 280 request_info.method = "GET"; | 280 request_info.method = "GET"; |
| 281 request_info.url = GURL("https://www.google.com"); | 281 request_info.url = GURL("https://www.google.com"); |
| 282 | 282 |
| 283 url::SchemeHostPort server(request_info.url); | 283 url::SchemeHostPort server(request_info.url); |
| 284 AlternativeService alternative_service(QUIC, server.host(), 443); | 284 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 285 SetAlternativeService(request_info, alternative_service); | 285 SetAlternativeService(request_info, alternative_service); |
| 286 | 286 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 308 SSLConfig()); | 308 SSLConfig()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST_F(HttpStreamFactoryImplJobControllerTest, | 311 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 312 SecondJobFailsAfterFirstJobSucceeds) { | 312 SecondJobFailsAfterFirstJobSucceeds) { |
| 313 ProxyConfig proxy_config; | 313 ProxyConfig proxy_config; |
| 314 proxy_config.set_auto_detect(true); | 314 proxy_config.set_auto_detect(true); |
| 315 // Use asynchronous proxy resolver. | 315 // Use asynchronous proxy resolver. |
| 316 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 316 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 317 new MockAsyncProxyResolverFactory(false); | 317 new MockAsyncProxyResolverFactory(false); |
| 318 session_deps_.proxy_service.reset(new ProxyService( | 318 session_deps_.proxy_service.reset( |
| 319 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 319 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 320 base::WrapUnique(proxy_resolver_factory), nullptr)); | 320 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 321 Initialize(false); | 321 Initialize(false); |
| 322 | 322 |
| 323 HttpRequestInfo request_info; | 323 HttpRequestInfo request_info; |
| 324 request_info.method = "GET"; | 324 request_info.method = "GET"; |
| 325 request_info.url = GURL("https://www.google.com"); | 325 request_info.url = GURL("https://www.google.com"); |
| 326 | 326 |
| 327 url::SchemeHostPort server(request_info.url); | 327 url::SchemeHostPort server(request_info.url); |
| 328 AlternativeService alternative_service(QUIC, server.host(), 443); | 328 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 329 SetAlternativeService(request_info, alternative_service); | 329 SetAlternativeService(request_info, alternative_service); |
| 330 | 330 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 360 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 360 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 361 } | 361 } |
| 362 | 362 |
| 363 TEST_F(HttpStreamFactoryImplJobControllerTest, | 363 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 364 SecondJobSucceedsAfterFirstJobFailed) { | 364 SecondJobSucceedsAfterFirstJobFailed) { |
| 365 ProxyConfig proxy_config; | 365 ProxyConfig proxy_config; |
| 366 proxy_config.set_auto_detect(true); | 366 proxy_config.set_auto_detect(true); |
| 367 // Use asynchronous proxy resolver. | 367 // Use asynchronous proxy resolver. |
| 368 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 368 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 369 new MockAsyncProxyResolverFactory(false); | 369 new MockAsyncProxyResolverFactory(false); |
| 370 session_deps_.proxy_service.reset(new ProxyService( | 370 session_deps_.proxy_service.reset( |
| 371 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 371 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 372 base::WrapUnique(proxy_resolver_factory), nullptr)); | 372 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 373 Initialize(false); | 373 Initialize(false); |
| 374 | 374 |
| 375 HttpRequestInfo request_info; | 375 HttpRequestInfo request_info; |
| 376 request_info.method = "GET"; | 376 request_info.method = "GET"; |
| 377 request_info.url = GURL("https://www.google.com"); | 377 request_info.url = GURL("https://www.google.com"); |
| 378 | 378 |
| 379 url::SchemeHostPort server(request_info.url); | 379 url::SchemeHostPort server(request_info.url); |
| 380 AlternativeService alternative_service(QUIC, server.host(), 443); | 380 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 381 SetAlternativeService(request_info, alternative_service); | 381 SetAlternativeService(request_info, alternative_service); |
| 382 | 382 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 461 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { |
| 462 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 462 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
| 463 // to stall the alternative job and report to controller to maybe resume the | 463 // to stall the alternative job and report to controller to maybe resume the |
| 464 // main job. | 464 // main job. |
| 465 ProxyConfig proxy_config; | 465 ProxyConfig proxy_config; |
| 466 proxy_config.set_auto_detect(true); | 466 proxy_config.set_auto_detect(true); |
| 467 proxy_config.set_pac_mandatory(true); | 467 proxy_config.set_pac_mandatory(true); |
| 468 session_deps_.proxy_service.reset(new ProxyService( | 468 session_deps_.proxy_service.reset(new ProxyService( |
| 469 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 469 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 470 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 470 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 471 | 471 |
| 472 Initialize(false); | 472 Initialize(false); |
| 473 | 473 |
| 474 HttpRequestInfo request_info; | 474 HttpRequestInfo request_info; |
| 475 request_info.method = "GET"; | 475 request_info.method = "GET"; |
| 476 request_info.url = GURL("https://www.google.com"); | 476 request_info.url = GURL("https://www.google.com"); |
| 477 | 477 |
| 478 url::SchemeHostPort server(request_info.url); | 478 url::SchemeHostPort server(request_info.url); |
| 479 AlternativeService alternative_service(QUIC, server.host(), 443); | 479 AlternativeService alternative_service(QUIC, server.host(), 443); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 NoAvailableSpdySessionToResumeMainJob) { | 522 NoAvailableSpdySessionToResumeMainJob) { |
| 523 // Test the alternative job is not resumed when the alternative job is | 523 // Test the alternative job is not resumed when the alternative job is |
| 524 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, | 524 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, |
| 525 // the latter part of this test tests controller resumes the main job | 525 // the latter part of this test tests controller resumes the main job |
| 526 // when there's no SPDY session for the alternative job. | 526 // when there's no SPDY session for the alternative job. |
| 527 ProxyConfig proxy_config; | 527 ProxyConfig proxy_config; |
| 528 proxy_config.set_auto_detect(true); | 528 proxy_config.set_auto_detect(true); |
| 529 // Use asynchronous proxy resolver. | 529 // Use asynchronous proxy resolver. |
| 530 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 530 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 531 new MockAsyncProxyResolverFactory(false); | 531 new MockAsyncProxyResolverFactory(false); |
| 532 session_deps_.proxy_service.reset(new ProxyService( | 532 session_deps_.proxy_service.reset( |
| 533 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 533 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 534 base::WrapUnique(proxy_resolver_factory), nullptr)); | 534 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 535 | 535 |
| 536 HangingResolver* host_resolver = new HangingResolver(); | 536 HangingResolver* host_resolver = new HangingResolver(); |
| 537 session_deps_.host_resolver.reset(host_resolver); | 537 session_deps_.host_resolver.reset(host_resolver); |
| 538 session_deps_.host_resolver->set_synchronous_mode(false); | 538 session_deps_.host_resolver->set_synchronous_mode(false); |
| 539 | 539 |
| 540 Initialize(false); | 540 Initialize(false); |
| 541 | 541 |
| 542 HttpRequestInfo request_info; | 542 HttpRequestInfo request_info; |
| 543 request_info.method = "GET"; | 543 request_info.method = "GET"; |
| 544 request_info.url = GURL("https://www.google.com"); | 544 request_info.url = GURL("https://www.google.com"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // Use failing HostResolver which is unable to resolve the host name for QUIC. | 590 // Use failing HostResolver which is unable to resolve the host name for QUIC. |
| 591 // No QUIC session is created and thus should resume the main job. | 591 // No QUIC session is created and thus should resume the main job. |
| 592 FailingHostResolver* host_resolver = new FailingHostResolver(); | 592 FailingHostResolver* host_resolver = new FailingHostResolver(); |
| 593 session_deps_.host_resolver.reset(host_resolver); | 593 session_deps_.host_resolver.reset(host_resolver); |
| 594 | 594 |
| 595 ProxyConfig proxy_config; | 595 ProxyConfig proxy_config; |
| 596 proxy_config.set_auto_detect(true); | 596 proxy_config.set_auto_detect(true); |
| 597 // Use asynchronous proxy resolver. | 597 // Use asynchronous proxy resolver. |
| 598 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 598 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 599 new MockAsyncProxyResolverFactory(false); | 599 new MockAsyncProxyResolverFactory(false); |
| 600 session_deps_.proxy_service.reset(new ProxyService( | 600 session_deps_.proxy_service.reset( |
| 601 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 601 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 602 base::WrapUnique(proxy_resolver_factory), nullptr)); | 602 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 603 | 603 |
| 604 Initialize(false); | 604 Initialize(false); |
| 605 | 605 |
| 606 HttpRequestInfo request_info; | 606 HttpRequestInfo request_info; |
| 607 request_info.method = "GET"; | 607 request_info.method = "GET"; |
| 608 request_info.url = GURL("https://www.google.com"); | 608 request_info.url = GURL("https://www.google.com"); |
| 609 | 609 |
| 610 url::SchemeHostPort server(request_info.url); | 610 url::SchemeHostPort server(request_info.url); |
| 611 AlternativeService alternative_service(QUIC, server.host(), 443); | 611 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 612 SetAlternativeService(request_info, alternative_service); | 612 SetAlternativeService(request_info, alternative_service); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 base::RunLoop().RunUntilIdle(); | 852 base::RunLoop().RunUntilIdle(); |
| 853 EXPECT_FALSE(job_controller_->alternative_job()); | 853 EXPECT_FALSE(job_controller_->alternative_job()); |
| 854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 855 // Since the main job did not complete successfully, the alternative proxy | 855 // Since the main job did not complete successfully, the alternative proxy |
| 856 // server should not be marked as bad. | 856 // server should not be marked as bad. |
| 857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 859 } | 859 } |
| 860 | 860 |
| 861 } // namespace net | 861 } // namespace net |
| OLD | NEW |