| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 class FailingHostResolver : public MockHostResolverBase { | 54 class FailingHostResolver : public MockHostResolverBase { |
| 55 public: | 55 public: |
| 56 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {} | 56 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {} |
| 57 ~FailingHostResolver() override {} | 57 ~FailingHostResolver() override {} |
| 58 | 58 |
| 59 int Resolve(const RequestInfo& info, | 59 int Resolve(const RequestInfo& info, |
| 60 RequestPriority priority, | 60 RequestPriority priority, |
| 61 AddressList* addresses, | 61 AddressList* addresses, |
| 62 const CompletionCallback& callback, | 62 const CompletionCallback& callback, |
| 63 std::unique_ptr<Request>* out_req, | 63 std::unique_ptr<Request>* out_req, |
| 64 const BoundNetLog& net_log) override { | 64 const NetLogWithSource& net_log) override { |
| 65 return ERR_NAME_NOT_RESOLVED; | 65 return ERR_NAME_NOT_RESOLVED; |
| 66 } | 66 } |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class HangingResolver : public MockHostResolverBase { | 69 class HangingResolver : public MockHostResolverBase { |
| 70 public: | 70 public: |
| 71 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {} | 71 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {} |
| 72 ~HangingResolver() override {} | 72 ~HangingResolver() override {} |
| 73 | 73 |
| 74 int Resolve(const RequestInfo& info, | 74 int Resolve(const RequestInfo& info, |
| 75 RequestPriority priority, | 75 RequestPriority priority, |
| 76 AddressList* addresses, | 76 AddressList* addresses, |
| 77 const CompletionCallback& callback, | 77 const CompletionCallback& callback, |
| 78 std::unique_ptr<Request>* out_req, | 78 std::unique_ptr<Request>* out_req, |
| 79 const BoundNetLog& net_log) override { | 79 const NetLogWithSource& net_log) override { |
| 80 return ERR_IO_PENDING; | 80 return ERR_IO_PENDING; |
| 81 } | 81 } |
| 82 }; | 82 }; |
| 83 } // anonymous namespace | 83 } // anonymous namespace |
| 84 | 84 |
| 85 class HttpStreamFactoryImplJobPeer { | 85 class HttpStreamFactoryImplJobPeer { |
| 86 public: | 86 public: |
| 87 static void Start(HttpStreamFactoryImpl::Job* job, | 87 static void Start(HttpStreamFactoryImpl::Job* job, |
| 88 HttpStreamRequest::StreamType stream_type) { | 88 HttpStreamRequest::StreamType stream_type) { |
| 89 // Start() is mocked for MockHttpStreamFactoryImplJob. | 89 // Start() is mocked for MockHttpStreamFactoryImplJob. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 189 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 190 base::WrapUnique(proxy_resolver_factory), nullptr)); | 190 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 191 Initialize(false); | 191 Initialize(false); |
| 192 | 192 |
| 193 HttpRequestInfo request_info; | 193 HttpRequestInfo request_info; |
| 194 request_info.method = "GET"; | 194 request_info.method = "GET"; |
| 195 request_info.url = GURL("http://www.google.com"); | 195 request_info.url = GURL("http://www.google.com"); |
| 196 | 196 |
| 197 request_.reset( | 197 request_.reset( |
| 198 job_controller_->Start(request_info, &request_delegate_, nullptr, | 198 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 199 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 199 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 200 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 200 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 201 | 201 |
| 202 EXPECT_TRUE(job_controller_->main_job()); | 202 EXPECT_TRUE(job_controller_->main_job()); |
| 203 | 203 |
| 204 // There's no other alternative job. Thus when stream failed, it should | 204 // There's no other alternative job. Thus when stream failed, it should |
| 205 // notify Request of the stream failure. | 205 // notify Request of the stream failure. |
| 206 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 206 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 207 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 207 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 208 SSLConfig()); | 208 SSLConfig()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(HttpStreamFactoryImplJobControllerTest, | 211 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 212 OnStreamReadyWithNoAlternativeJob) { | 212 OnStreamReadyWithNoAlternativeJob) { |
| 213 ProxyConfig proxy_config; | 213 ProxyConfig proxy_config; |
| 214 proxy_config.set_auto_detect(true); | 214 proxy_config.set_auto_detect(true); |
| 215 // Use asynchronous proxy resolver. | 215 // Use asynchronous proxy resolver. |
| 216 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 216 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 217 new MockAsyncProxyResolverFactory(false); | 217 new MockAsyncProxyResolverFactory(false); |
| 218 session_deps_.proxy_service.reset( | 218 session_deps_.proxy_service.reset( |
| 219 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 219 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 220 base::WrapUnique(proxy_resolver_factory), nullptr)); | 220 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 221 Initialize(false); | 221 Initialize(false); |
| 222 | 222 |
| 223 HttpRequestInfo request_info; | 223 HttpRequestInfo request_info; |
| 224 request_info.method = "GET"; | 224 request_info.method = "GET"; |
| 225 request_info.url = GURL("http://www.google.com"); | 225 request_info.url = GURL("http://www.google.com"); |
| 226 | 226 |
| 227 request_.reset( | 227 request_.reset( |
| 228 job_controller_->Start(request_info, &request_delegate_, nullptr, | 228 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 229 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 229 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 230 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 230 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 231 | 231 |
| 232 // There's no other alternative job. Thus when a stream is ready, it should | 232 // There's no other alternative job. Thus when a stream is ready, it should |
| 233 // notify Request. | 233 // notify Request. |
| 234 HttpStream* http_stream = | 234 HttpStream* http_stream = |
| 235 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 235 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 236 job_factory_.main_job()->SetStream(http_stream); | 236 job_factory_.main_job()->SetStream(http_stream); |
| 237 | 237 |
| 238 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 238 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 239 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 239 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 257 HttpRequestInfo request_info; | 257 HttpRequestInfo request_info; |
| 258 request_info.method = "GET"; | 258 request_info.method = "GET"; |
| 259 request_info.url = GURL("https://www.google.com"); | 259 request_info.url = GURL("https://www.google.com"); |
| 260 | 260 |
| 261 url::SchemeHostPort server(request_info.url); | 261 url::SchemeHostPort server(request_info.url); |
| 262 AlternativeService alternative_service(QUIC, server.host(), 443); | 262 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 263 SetAlternativeService(request_info, alternative_service); | 263 SetAlternativeService(request_info, alternative_service); |
| 264 | 264 |
| 265 request_.reset( | 265 request_.reset( |
| 266 job_controller_->Start(request_info, &request_delegate_, nullptr, | 266 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 267 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 267 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 268 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 268 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 269 EXPECT_TRUE(job_controller_->main_job()); | 269 EXPECT_TRUE(job_controller_->main_job()); |
| 270 EXPECT_TRUE(job_controller_->alternative_job()); | 270 EXPECT_TRUE(job_controller_->alternative_job()); |
| 271 | 271 |
| 272 // Reset the Request will cancel all the Jobs since there's no Job determined | 272 // Reset the Request will cancel all the Jobs since there's no Job determined |
| 273 // to serve Request yet and JobController will notify the factory to delete | 273 // to serve Request yet and JobController will notify the factory to delete |
| 274 // itself upon completion. | 274 // itself upon completion. |
| 275 request_.reset(); | 275 request_.reset(); |
| 276 VerifyBrokenAlternateProtocolMapping(request_info, false); | 276 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 277 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 277 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 291 HttpRequestInfo request_info; | 291 HttpRequestInfo request_info; |
| 292 request_info.method = "GET"; | 292 request_info.method = "GET"; |
| 293 request_info.url = GURL("https://www.google.com"); | 293 request_info.url = GURL("https://www.google.com"); |
| 294 | 294 |
| 295 url::SchemeHostPort server(request_info.url); | 295 url::SchemeHostPort server(request_info.url); |
| 296 AlternativeService alternative_service(QUIC, server.host(), 443); | 296 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 297 SetAlternativeService(request_info, alternative_service); | 297 SetAlternativeService(request_info, alternative_service); |
| 298 | 298 |
| 299 request_.reset( | 299 request_.reset( |
| 300 job_controller_->Start(request_info, &request_delegate_, nullptr, | 300 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 301 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 301 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 302 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 302 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 303 EXPECT_TRUE(job_controller_->main_job()); | 303 EXPECT_TRUE(job_controller_->main_job()); |
| 304 EXPECT_TRUE(job_controller_->alternative_job()); | 304 EXPECT_TRUE(job_controller_->alternative_job()); |
| 305 | 305 |
| 306 // We have the main job with unknown status when the alternative job is failed | 306 // We have the main job with unknown status when the alternative job is failed |
| 307 // thus should not notify Request of the alternative job's failure. But should | 307 // thus should not notify Request of the alternative job's failure. But should |
| 308 // notify the main job to mark the alternative job failed. | 308 // notify the main job to mark the alternative job failed. |
| 309 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 309 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 310 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 310 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
| 311 SSLConfig()); | 311 SSLConfig()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 335 HttpRequestInfo request_info; | 335 HttpRequestInfo request_info; |
| 336 request_info.method = "GET"; | 336 request_info.method = "GET"; |
| 337 request_info.url = GURL("https://www.google.com"); | 337 request_info.url = GURL("https://www.google.com"); |
| 338 | 338 |
| 339 url::SchemeHostPort server(request_info.url); | 339 url::SchemeHostPort server(request_info.url); |
| 340 AlternativeService alternative_service(QUIC, server.host(), 443); | 340 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 341 SetAlternativeService(request_info, alternative_service); | 341 SetAlternativeService(request_info, alternative_service); |
| 342 | 342 |
| 343 request_.reset( | 343 request_.reset( |
| 344 job_controller_->Start(request_info, &request_delegate_, nullptr, | 344 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 345 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 345 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 346 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 346 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 347 EXPECT_TRUE(job_controller_->main_job()); | 347 EXPECT_TRUE(job_controller_->main_job()); |
| 348 EXPECT_TRUE(job_controller_->alternative_job()); | 348 EXPECT_TRUE(job_controller_->alternative_job()); |
| 349 | 349 |
| 350 // Main job succeeds, starts serving Request and it should report status | 350 // Main job succeeds, starts serving Request and it should report status |
| 351 // to Request. The alternative job will mark the main job complete and gets | 351 // to Request. The alternative job will mark the main job complete and gets |
| 352 // orphaned. | 352 // orphaned. |
| 353 HttpStream* http_stream = | 353 HttpStream* http_stream = |
| 354 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 354 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 355 job_factory_.main_job()->SetStream(http_stream); | 355 job_factory_.main_job()->SetStream(http_stream); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 386 HttpRequestInfo request_info; | 386 HttpRequestInfo request_info; |
| 387 request_info.method = "GET"; | 387 request_info.method = "GET"; |
| 388 request_info.url = GURL("https://www.google.com"); | 388 request_info.url = GURL("https://www.google.com"); |
| 389 | 389 |
| 390 url::SchemeHostPort server(request_info.url); | 390 url::SchemeHostPort server(request_info.url); |
| 391 AlternativeService alternative_service(QUIC, server.host(), 443); | 391 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 392 SetAlternativeService(request_info, alternative_service); | 392 SetAlternativeService(request_info, alternative_service); |
| 393 | 393 |
| 394 request_.reset( | 394 request_.reset( |
| 395 job_controller_->Start(request_info, &request_delegate_, nullptr, | 395 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 396 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 396 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 397 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 397 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 398 EXPECT_TRUE(job_controller_->main_job()); | 398 EXPECT_TRUE(job_controller_->main_job()); |
| 399 EXPECT_TRUE(job_controller_->alternative_job()); | 399 EXPECT_TRUE(job_controller_->alternative_job()); |
| 400 | 400 |
| 401 // |main_job| fails but should not report status to Request. | 401 // |main_job| fails but should not report status to Request. |
| 402 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 402 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 403 | 403 |
| 404 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 404 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 405 SSLConfig()); | 405 SSLConfig()); |
| 406 | 406 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 431 HttpRequestInfo request_info; | 431 HttpRequestInfo request_info; |
| 432 request_info.method = "GET"; | 432 request_info.method = "GET"; |
| 433 request_info.url = GURL("https://www.google.com"); | 433 request_info.url = GURL("https://www.google.com"); |
| 434 | 434 |
| 435 url::SchemeHostPort server(request_info.url); | 435 url::SchemeHostPort server(request_info.url); |
| 436 AlternativeService alternative_service(QUIC, server.host(), 443); | 436 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 437 SetAlternativeService(request_info, alternative_service); | 437 SetAlternativeService(request_info, alternative_service); |
| 438 | 438 |
| 439 request_.reset( | 439 request_.reset( |
| 440 job_controller_->Start(request_info, &request_delegate_, nullptr, | 440 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 441 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 441 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 442 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 442 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 443 EXPECT_TRUE(job_controller_->main_job()); | 443 EXPECT_TRUE(job_controller_->main_job()); |
| 444 EXPECT_TRUE(job_controller_->alternative_job()); | 444 EXPECT_TRUE(job_controller_->alternative_job()); |
| 445 | 445 |
| 446 // |alternative_job| fails but should not report status to Request. | 446 // |alternative_job| fails but should not report status to Request. |
| 447 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 447 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 448 | 448 |
| 449 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 449 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
| 450 SSLConfig()); | 450 SSLConfig()); |
| 451 | 451 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 478 HttpRequestInfo request_info; | 478 HttpRequestInfo request_info; |
| 479 request_info.method = "GET"; | 479 request_info.method = "GET"; |
| 480 request_info.url = GURL("https://www.google.com"); | 480 request_info.url = GURL("https://www.google.com"); |
| 481 | 481 |
| 482 url::SchemeHostPort server(request_info.url); | 482 url::SchemeHostPort server(request_info.url); |
| 483 AlternativeService alternative_service(QUIC, server.host(), 443); | 483 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 484 SetAlternativeService(request_info, alternative_service); | 484 SetAlternativeService(request_info, alternative_service); |
| 485 | 485 |
| 486 request_.reset( | 486 request_.reset( |
| 487 job_controller_->Start(request_info, &request_delegate_, nullptr, | 487 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 488 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 488 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 489 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 489 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 490 EXPECT_TRUE(job_controller_->main_job()); | 490 EXPECT_TRUE(job_controller_->main_job()); |
| 491 EXPECT_TRUE(job_controller_->alternative_job()); | 491 EXPECT_TRUE(job_controller_->alternative_job()); |
| 492 | 492 |
| 493 // |main_job| fails but should not report status to Request. | 493 // |main_job| fails but should not report status to Request. |
| 494 // The alternative job will mark the main job complete. | 494 // The alternative job will mark the main job complete. |
| 495 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 495 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 496 | 496 |
| 497 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 497 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 498 SSLConfig()); | 498 SSLConfig()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 527 HttpRequestInfo request_info; | 527 HttpRequestInfo request_info; |
| 528 request_info.method = "GET"; | 528 request_info.method = "GET"; |
| 529 request_info.url = GURL("https://www.google.com"); | 529 request_info.url = GURL("https://www.google.com"); |
| 530 | 530 |
| 531 url::SchemeHostPort server(request_info.url); | 531 url::SchemeHostPort server(request_info.url); |
| 532 AlternativeService alternative_service(QUIC, server.host(), 443); | 532 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 533 SetAlternativeService(request_info, alternative_service); | 533 SetAlternativeService(request_info, alternative_service); |
| 534 | 534 |
| 535 request_.reset( | 535 request_.reset( |
| 536 job_controller_->Start(request_info, &request_delegate_, nullptr, | 536 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 537 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 537 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 538 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 538 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 539 EXPECT_TRUE(job_controller_->main_job()); | 539 EXPECT_TRUE(job_controller_->main_job()); |
| 540 EXPECT_TRUE(job_controller_->alternative_job()); | 540 EXPECT_TRUE(job_controller_->alternative_job()); |
| 541 | 541 |
| 542 // Wait until OnStreamFailedCallback is executed on the alternative job. | 542 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 543 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 543 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
| 544 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 547 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
| 548 // Using a restricted port 101 for QUIC should fail and the alternative job | 548 // Using a restricted port 101 for QUIC should fail and the alternative job |
| 549 // should post OnStreamFailedCall on the controller to resume the main job. | 549 // should post OnStreamFailedCall on the controller to resume the main job. |
| 550 Initialize(false); | 550 Initialize(false); |
| 551 | 551 |
| 552 HttpRequestInfo request_info; | 552 HttpRequestInfo request_info; |
| 553 request_info.method = "GET"; | 553 request_info.method = "GET"; |
| 554 request_info.url = GURL("https://www.google.com"); | 554 request_info.url = GURL("https://www.google.com"); |
| 555 | 555 |
| 556 url::SchemeHostPort server(request_info.url); | 556 url::SchemeHostPort server(request_info.url); |
| 557 AlternativeService alternative_service(QUIC, server.host(), 101); | 557 AlternativeService alternative_service(QUIC, server.host(), 101); |
| 558 SetAlternativeService(request_info, alternative_service); | 558 SetAlternativeService(request_info, alternative_service); |
| 559 | 559 |
| 560 request_.reset( | 560 request_.reset( |
| 561 job_controller_->Start(request_info, &request_delegate_, nullptr, | 561 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 562 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 562 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 563 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 563 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 564 | 564 |
| 565 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | 565 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); |
| 566 | 566 |
| 567 // Wait until OnStreamFailedCallback is executed on the alternative job. | 567 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 568 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 568 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 569 base::RunLoop().RunUntilIdle(); | 569 base::RunLoop().RunUntilIdle(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 TEST_F(HttpStreamFactoryImplJobControllerTest, | 572 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 597 // Set a SPDY alternative service for the server. | 597 // Set a SPDY alternative service for the server. |
| 598 url::SchemeHostPort server(request_info.url); | 598 url::SchemeHostPort server(request_info.url); |
| 599 AlternativeService alternative_service(QUIC, server.host(), 443); | 599 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 600 SetAlternativeService(request_info, alternative_service); | 600 SetAlternativeService(request_info, alternative_service); |
| 601 // Hack to use different URL for the main job to help differentiate the proxy | 601 // Hack to use different URL for the main job to help differentiate the proxy |
| 602 // requests. | 602 // requests. |
| 603 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | 603 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); |
| 604 | 604 |
| 605 request_.reset( | 605 request_.reset( |
| 606 job_controller_->Start(request_info, &request_delegate_, nullptr, | 606 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 607 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 607 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 608 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 608 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 609 // Both jobs should be created but stalled as proxy resolution not completed. | 609 // Both jobs should be created but stalled as proxy resolution not completed. |
| 610 EXPECT_TRUE(job_controller_->main_job()); | 610 EXPECT_TRUE(job_controller_->main_job()); |
| 611 EXPECT_TRUE(job_controller_->alternative_job()); | 611 EXPECT_TRUE(job_controller_->alternative_job()); |
| 612 | 612 |
| 613 MockAsyncProxyResolver resolver; | 613 MockAsyncProxyResolver resolver; |
| 614 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | 614 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 615 net::OK, &resolver); | 615 net::OK, &resolver); |
| 616 | 616 |
| 617 // Resolve proxy for the main job which then proceed to wait for the | 617 // Resolve proxy for the main job which then proceed to wait for the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 659 |
| 660 url::SchemeHostPort server(request_info.url); | 660 url::SchemeHostPort server(request_info.url); |
| 661 AlternativeService alternative_service(QUIC, server.host(), 443); | 661 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 662 SetAlternativeService(request_info, alternative_service); | 662 SetAlternativeService(request_info, alternative_service); |
| 663 // Hack to use different URL for the main job to help differentiate the proxy | 663 // Hack to use different URL for the main job to help differentiate the proxy |
| 664 // requests. | 664 // requests. |
| 665 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | 665 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); |
| 666 | 666 |
| 667 request_.reset( | 667 request_.reset( |
| 668 job_controller_->Start(request_info, &request_delegate_, nullptr, | 668 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 669 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 669 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 670 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 670 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 671 EXPECT_TRUE(job_controller_->main_job()); | 671 EXPECT_TRUE(job_controller_->main_job()); |
| 672 EXPECT_TRUE(job_controller_->alternative_job()); | 672 EXPECT_TRUE(job_controller_->alternative_job()); |
| 673 | 673 |
| 674 MockAsyncProxyResolver resolver; | 674 MockAsyncProxyResolver resolver; |
| 675 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | 675 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 676 net::OK, &resolver); | 676 net::OK, &resolver); |
| 677 | 677 |
| 678 // Resolve proxy for the main job which then proceed to wait for the | 678 // Resolve proxy for the main job which then proceed to wait for the |
| 679 // alternative job which is IO_PENDING. | 679 // alternative job which is IO_PENDING. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 request_info.method = "GET"; | 718 request_info.method = "GET"; |
| 719 request_info.url = GURL("https://www.google.com"); | 719 request_info.url = GURL("https://www.google.com"); |
| 720 | 720 |
| 721 // Set a SPDY alternative service for the server. | 721 // Set a SPDY alternative service for the server. |
| 722 url::SchemeHostPort server(request_info.url); | 722 url::SchemeHostPort server(request_info.url); |
| 723 AlternativeService alternative_service(QUIC, server.host(), 443); | 723 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 724 SetAlternativeService(request_info, alternative_service); | 724 SetAlternativeService(request_info, alternative_service); |
| 725 | 725 |
| 726 request_.reset( | 726 request_.reset( |
| 727 job_controller_->Start(request_info, &request_delegate_, nullptr, | 727 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 728 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 728 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 729 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 729 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 730 EXPECT_TRUE(job_controller_->main_job()); | 730 EXPECT_TRUE(job_controller_->main_job()); |
| 731 EXPECT_TRUE(job_controller_->alternative_job()); | 731 EXPECT_TRUE(job_controller_->alternative_job()); |
| 732 | 732 |
| 733 // The alternative job stalls as host resolution hangs when creating the QUIC | 733 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 734 // request and controller should resume the main job after delay. | 734 // request and controller should resume the main job after delay. |
| 735 // Verify the waiting time for delayed main job. | 735 // Verify the waiting time for delayed main job. |
| 736 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 736 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 737 .WillOnce(Invoke(testing::CreateFunctor( | 737 .WillOnce(Invoke(testing::CreateFunctor( |
| 738 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 738 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 750 | 750 |
| 751 Initialize(true); | 751 Initialize(true); |
| 752 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 752 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 753 | 753 |
| 754 HttpRequestInfo request_info; | 754 HttpRequestInfo request_info; |
| 755 request_info.method = "GET"; | 755 request_info.method = "GET"; |
| 756 request_info.url = GURL("https://mail.example.org/"); | 756 request_info.url = GURL("https://mail.example.org/"); |
| 757 | 757 |
| 758 request_.reset( | 758 request_.reset( |
| 759 job_controller_->Start(request_info, &request_delegate_, nullptr, | 759 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 760 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 760 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 761 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 761 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 762 EXPECT_TRUE(job_controller_->main_job()); | 762 EXPECT_TRUE(job_controller_->main_job()); |
| 763 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 763 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 764 EXPECT_FALSE(job_controller_->alternative_job()); | 764 EXPECT_FALSE(job_controller_->alternative_job()); |
| 765 | 765 |
| 766 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 766 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 767 base::RunLoop().RunUntilIdle(); | 767 base::RunLoop().RunUntilIdle(); |
| 768 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 768 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 769 } | 769 } |
| 770 | 770 |
| 771 // Verifies that the alternative proxy server job is not created if the main job | 771 // Verifies that the alternative proxy server job is not created if the main job |
| 772 // does not fetch the resource through a proxy. | 772 // does not fetch the resource through a proxy. |
| 773 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { | 773 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
| 774 // Using hanging resolver will cause the alternative job to hang indefinitely. | 774 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 775 HangingResolver* resolver = new HangingResolver(); | 775 HangingResolver* resolver = new HangingResolver(); |
| 776 session_deps_.host_resolver.reset(resolver); | 776 session_deps_.host_resolver.reset(resolver); |
| 777 | 777 |
| 778 Initialize(false); | 778 Initialize(false); |
| 779 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 779 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 780 | 780 |
| 781 HttpRequestInfo request_info; | 781 HttpRequestInfo request_info; |
| 782 request_info.method = "GET"; | 782 request_info.method = "GET"; |
| 783 request_info.url = GURL("http://mail.example.org/"); | 783 request_info.url = GURL("http://mail.example.org/"); |
| 784 | 784 |
| 785 request_.reset( | 785 request_.reset( |
| 786 job_controller_->Start(request_info, &request_delegate_, nullptr, | 786 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 787 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 787 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 788 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 788 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 789 EXPECT_TRUE(job_controller_->main_job()); | 789 EXPECT_TRUE(job_controller_->main_job()); |
| 790 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 790 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 791 EXPECT_FALSE(job_controller_->alternative_job()); | 791 EXPECT_FALSE(job_controller_->alternative_job()); |
| 792 | 792 |
| 793 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 793 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 794 base::RunLoop().RunUntilIdle(); | 794 base::RunLoop().RunUntilIdle(); |
| 795 | 795 |
| 796 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 796 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 797 } | 797 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 814 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 814 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 815 session_->http_server_properties()->SetServerNetworkStats( | 815 session_->http_server_properties()->SetServerNetworkStats( |
| 816 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 816 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 817 | 817 |
| 818 HttpRequestInfo request_info; | 818 HttpRequestInfo request_info; |
| 819 request_info.method = "GET"; | 819 request_info.method = "GET"; |
| 820 request_info.url = GURL("http://mail.example.org/"); | 820 request_info.url = GURL("http://mail.example.org/"); |
| 821 | 821 |
| 822 request_.reset( | 822 request_.reset( |
| 823 job_controller_->Start(request_info, &request_delegate_, nullptr, | 823 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 824 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 824 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 825 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 825 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 826 EXPECT_TRUE(job_controller_->main_job()); | 826 EXPECT_TRUE(job_controller_->main_job()); |
| 827 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 827 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 828 EXPECT_TRUE(job_controller_->alternative_job()); | 828 EXPECT_TRUE(job_controller_->alternative_job()); |
| 829 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 829 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 830 | 830 |
| 831 // The alternative proxy server job stalls when connecting to the alternative | 831 // The alternative proxy server job stalls when connecting to the alternative |
| 832 // proxy server, and controller should resume the main job after delay. | 832 // proxy server, and controller should resume the main job after delay. |
| 833 // Verify the waiting time for delayed main job. | 833 // Verify the waiting time for delayed main job. |
| 834 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 834 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | 875 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); |
| 876 session_->http_server_properties()->SetServerNetworkStats( | 876 session_->http_server_properties()->SetServerNetworkStats( |
| 877 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 877 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 878 | 878 |
| 879 HttpRequestInfo request_info; | 879 HttpRequestInfo request_info; |
| 880 request_info.method = "GET"; | 880 request_info.method = "GET"; |
| 881 request_info.url = GURL("http://mail.example.org/"); | 881 request_info.url = GURL("http://mail.example.org/"); |
| 882 | 882 |
| 883 request_.reset( | 883 request_.reset( |
| 884 job_controller_->Start(request_info, &request_delegate_, nullptr, | 884 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 885 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 885 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 886 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 886 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 887 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 887 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 888 EXPECT_TRUE(job_controller_->alternative_job()); | 888 EXPECT_TRUE(job_controller_->alternative_job()); |
| 889 | 889 |
| 890 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | 890 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
| 891 | 891 |
| 892 // Since the alternative proxy server job is started in the next message loop, | 892 // Since the alternative proxy server job is started in the next message loop, |
| 893 // the main job would remain blocked until the alternative proxy starts, and | 893 // the main job would remain blocked until the alternative proxy starts, and |
| 894 // fails. | 894 // fails. |
| 895 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 895 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 896 .WillOnce(Invoke(testing::CreateFunctor( | 896 .WillOnce(Invoke(testing::CreateFunctor( |
| 897 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 897 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 898 base::TimeDelta::FromMicroseconds(0)))); | 898 base::TimeDelta::FromMicroseconds(0)))); |
| 899 | 899 |
| 900 base::RunLoop().RunUntilIdle(); | 900 base::RunLoop().RunUntilIdle(); |
| 901 EXPECT_FALSE(job_controller_->alternative_job()); | 901 EXPECT_FALSE(job_controller_->alternative_job()); |
| 902 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 902 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 903 // Since the main job did not complete successfully, the alternative proxy | 903 // Since the main job did not complete successfully, the alternative proxy |
| 904 // server should not be marked as bad. | 904 // server should not be marked as bad. |
| 905 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 905 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 906 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 906 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 907 } | 907 } |
| 908 | 908 |
| 909 } // namespace net | 909 } // namespace net |
| OLD | NEW |