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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 job_controller_->Start(request_info, &request_delegate_, nullptr, | 288 job_controller_->Start(request_info, &request_delegate_, nullptr, |
289 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 289 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
290 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 290 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
291 EXPECT_TRUE(job_controller_->main_job()); | 291 EXPECT_TRUE(job_controller_->main_job()); |
292 EXPECT_TRUE(job_controller_->alternative_job()); | 292 EXPECT_TRUE(job_controller_->alternative_job()); |
293 | 293 |
294 // We have the main job with unknown status when the alternative job is failed | 294 // We have the main job with unknown status when the alternative job is failed |
295 // thus should not notify Request of the alternative job's failure. But should | 295 // thus should not notify Request of the alternative job's failure. But should |
296 // notify the main job to mark the alternative job failed. | 296 // notify the main job to mark the alternative job failed. |
297 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 297 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
298 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
299 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 298 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
300 SSLConfig()); | 299 SSLConfig()); |
301 EXPECT_TRUE(!job_controller_->alternative_job()); | 300 EXPECT_TRUE(!job_controller_->alternative_job()); |
302 EXPECT_TRUE(job_controller_->main_job()); | 301 EXPECT_TRUE(job_controller_->main_job()); |
303 | 302 |
304 // The failure of second Job should be reported to Request as there's no more | 303 // The failure of second Job should be reported to Request as there's no more |
305 // pending Job to serve the Request. | 304 // pending Job to serve the Request. |
306 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 305 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
307 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 306 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
308 SSLConfig()); | 307 SSLConfig()); |
(...skipping 28 matching lines...) Expand all Loading... |
337 | 336 |
338 // Main job succeeds, starts serving Request and it should report status | 337 // Main job succeeds, starts serving Request and it should report status |
339 // to Request. The alternative job will mark the main job complete and gets | 338 // to Request. The alternative job will mark the main job complete and gets |
340 // orphaned. | 339 // orphaned. |
341 HttpStream* http_stream = | 340 HttpStream* http_stream = |
342 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 341 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
343 job_factory_.main_job()->SetStream(http_stream); | 342 job_factory_.main_job()->SetStream(http_stream); |
344 | 343 |
345 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 344 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
346 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 345 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
347 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | |
348 .Times(1); | |
349 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 346 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
350 ProxyInfo()); | 347 ProxyInfo()); |
351 | 348 |
352 // JobController shouldn't report the status of second job as request | 349 // JobController shouldn't report the status of second job as request |
353 // is already successfully served. | 350 // is already successfully served. |
354 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 351 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
355 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 352 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
356 SSLConfig()); | 353 SSLConfig()); |
357 | 354 |
358 // Reset the request as it's been successfully served. | 355 // Reset the request as it's been successfully served. |
(...skipping 24 matching lines...) Expand all Loading... |
383 request_.reset( | 380 request_.reset( |
384 job_controller_->Start(request_info, &request_delegate_, nullptr, | 381 job_controller_->Start(request_info, &request_delegate_, nullptr, |
385 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 382 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
386 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 383 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
387 EXPECT_TRUE(job_controller_->main_job()); | 384 EXPECT_TRUE(job_controller_->main_job()); |
388 EXPECT_TRUE(job_controller_->alternative_job()); | 385 EXPECT_TRUE(job_controller_->alternative_job()); |
389 | 386 |
390 // |main_job| fails but should not report status to Request. | 387 // |main_job| fails but should not report status to Request. |
391 // The alternative job will mark the main job complete. | 388 // The alternative job will mark the main job complete. |
392 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 389 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
393 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | |
394 .Times(1); | |
395 | 390 |
396 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 391 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
397 SSLConfig()); | 392 SSLConfig()); |
398 | 393 |
399 // |alternative_job| succeeds and should report status to Request. | 394 // |alternative_job| succeeds and should report status to Request. |
400 HttpStream* http_stream = | 395 HttpStream* http_stream = |
401 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 396 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
402 job_factory_.alternative_job()->SetStream(http_stream); | 397 job_factory_.alternative_job()->SetStream(http_stream); |
403 | 398 |
404 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 399 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
(...skipping 26 matching lines...) Expand all Loading... |
431 request_.reset( | 426 request_.reset( |
432 job_controller_->Start(request_info, &request_delegate_, nullptr, | 427 job_controller_->Start(request_info, &request_delegate_, nullptr, |
433 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 428 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
434 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 429 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
435 EXPECT_TRUE(job_controller_->main_job()); | 430 EXPECT_TRUE(job_controller_->main_job()); |
436 EXPECT_TRUE(job_controller_->alternative_job()); | 431 EXPECT_TRUE(job_controller_->alternative_job()); |
437 | 432 |
438 // |main_job| fails but should not report status to Request. | 433 // |main_job| fails but should not report status to Request. |
439 // The alternative job will mark the main job complete. | 434 // The alternative job will mark the main job complete. |
440 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 435 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
441 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | |
442 .Times(1); | |
443 | 436 |
444 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 437 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
445 SSLConfig()); | 438 SSLConfig()); |
446 | 439 |
447 // Controller should use alternative job to get load state. | 440 // Controller should use alternative job to get load state. |
448 job_controller_->GetLoadState(); | 441 job_controller_->GetLoadState(); |
449 | 442 |
450 // |alternative_job| succeeds and should report status to Request. | 443 // |alternative_job| succeeds and should report status to Request. |
451 HttpStream* http_stream = | 444 HttpStream* http_stream = |
452 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 445 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
(...skipping 28 matching lines...) Expand all Loading... |
481 | 474 |
482 request_.reset( | 475 request_.reset( |
483 job_controller_->Start(request_info, &request_delegate_, nullptr, | 476 job_controller_->Start(request_info, &request_delegate_, nullptr, |
484 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 477 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
485 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 478 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
486 EXPECT_TRUE(job_controller_->main_job()); | 479 EXPECT_TRUE(job_controller_->main_job()); |
487 EXPECT_TRUE(job_controller_->alternative_job()); | 480 EXPECT_TRUE(job_controller_->alternative_job()); |
488 | 481 |
489 // Wait until OnStreamFailedCallback is executed on the alternative job. | 482 // Wait until OnStreamFailedCallback is executed on the alternative job. |
490 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 483 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
491 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
492 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
493 } | 485 } |
494 | 486 |
495 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 487 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
496 // Using a restricted port 101 for QUIC should fail and the alternative job | 488 // Using a restricted port 101 for QUIC should fail and the alternative job |
497 // should post OnStreamFailedCall on the controller to resume the main job. | 489 // should post OnStreamFailedCall on the controller to resume the main job. |
498 Initialize(false); | 490 Initialize(false); |
499 | 491 |
500 HttpRequestInfo request_info; | 492 HttpRequestInfo request_info; |
501 request_info.method = "GET"; | 493 request_info.method = "GET"; |
502 request_info.url = GURL("https://www.google.com"); | 494 request_info.url = GURL("https://www.google.com"); |
503 | 495 |
504 url::SchemeHostPort server(request_info.url); | 496 url::SchemeHostPort server(request_info.url); |
505 AlternativeService alternative_service(QUIC, server.host(), 101); | 497 AlternativeService alternative_service(QUIC, server.host(), 101); |
506 SetAlternativeService(request_info, alternative_service); | 498 SetAlternativeService(request_info, alternative_service); |
507 | 499 |
508 request_.reset( | 500 request_.reset( |
509 job_controller_->Start(request_info, &request_delegate_, nullptr, | 501 job_controller_->Start(request_info, &request_delegate_, nullptr, |
510 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 502 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
511 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 503 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
512 | 504 |
513 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | 505 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); |
514 | 506 |
515 // Wait until OnStreamFailedCallback is executed on the alternative job. | 507 // Wait until OnStreamFailedCallback is executed on the alternative job. |
516 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 508 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
517 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
518 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
519 } | 510 } |
520 | 511 |
521 TEST_F(HttpStreamFactoryImplJobControllerTest, | 512 TEST_F(HttpStreamFactoryImplJobControllerTest, |
522 NoAvailableSpdySessionToResumeMainJob) { | 513 NoAvailableSpdySessionToResumeMainJob) { |
523 // Test the alternative job is not resumed when the alternative job is | 514 // Test the alternative job is not resumed when the alternative job is |
524 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, | 515 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, |
525 // the latter part of this test tests controller resumes the main job | 516 // the latter part of this test tests controller resumes the main job |
526 // when there's no SPDY session for the alternative job. | 517 // when there's no SPDY session for the alternative job. |
527 ProxyConfig proxy_config; | 518 ProxyConfig proxy_config; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); | 564 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); |
574 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 565 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
575 | 566 |
576 // Resolve proxy for the alternative job to proceed to create a connection. | 567 // Resolve proxy for the alternative job to proceed to create a connection. |
577 // Use hanging HostResolver to fail creation of a SPDY session for the | 568 // Use hanging HostResolver to fail creation of a SPDY session for the |
578 // alternative job. The alternative job will be IO_PENDING thus should resume | 569 // alternative job. The alternative job will be IO_PENDING thus should resume |
579 // the main job. | 570 // the main job. |
580 resolver.pending_requests()[0]->CompleteNow(net::OK); | 571 resolver.pending_requests()[0]->CompleteNow(net::OK); |
581 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 572 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
582 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 573 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
583 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
584 | 574 |
585 base::RunLoop().RunUntilIdle(); | 575 base::RunLoop().RunUntilIdle(); |
586 } | 576 } |
587 | 577 |
588 TEST_F(HttpStreamFactoryImplJobControllerTest, | 578 TEST_F(HttpStreamFactoryImplJobControllerTest, |
589 NoAvailableQuicSessionToResumeMainJob) { | 579 NoAvailableQuicSessionToResumeMainJob) { |
590 // Use failing HostResolver which is unable to resolve the host name for QUIC. | 580 // 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. | 581 // No QUIC session is created and thus should resume the main job. |
592 FailingHostResolver* host_resolver = new FailingHostResolver(); | 582 FailingHostResolver* host_resolver = new FailingHostResolver(); |
593 session_deps_.host_resolver.reset(host_resolver); | 583 session_deps_.host_resolver.reset(host_resolver); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // Resolve proxy for the alternative job to proceed to create a connection. | 628 // Resolve proxy for the alternative job to proceed to create a connection. |
639 // Use failing HostResolver to fail creation of a QUIC session for the | 629 // Use failing HostResolver to fail creation of a QUIC session for the |
640 // alternative job. The alternative job will thus resume the main job. | 630 // alternative job. The alternative job will thus resume the main job. |
641 resolver.pending_requests()[0]->results()->UseNamedProxy("result1:80"); | 631 resolver.pending_requests()[0]->results()->UseNamedProxy("result1:80"); |
642 resolver.pending_requests()[0]->CompleteNow(net::OK); | 632 resolver.pending_requests()[0]->CompleteNow(net::OK); |
643 | 633 |
644 // Wait until OnStreamFailedCallback is executed on the alternative job. | 634 // Wait until OnStreamFailedCallback is executed on the alternative job. |
645 // Request shouldn't be notified as the main job is still pending status. | 635 // Request shouldn't be notified as the main job is still pending status. |
646 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 636 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
647 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 637 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
648 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
649 | 638 |
650 base::RunLoop().RunUntilIdle(); | 639 base::RunLoop().RunUntilIdle(); |
651 } | 640 } |
652 | 641 |
653 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 642 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
654 HangingResolver* resolver = new HangingResolver(); | 643 HangingResolver* resolver = new HangingResolver(); |
655 session_deps_.host_resolver.reset(resolver); | 644 session_deps_.host_resolver.reset(resolver); |
656 | 645 |
657 Initialize(false); | 646 Initialize(false); |
658 | 647 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 request_info.url = GURL("http://mail.example.org/"); | 821 request_info.url = GURL("http://mail.example.org/"); |
833 | 822 |
834 request_.reset( | 823 request_.reset( |
835 job_controller_->Start(request_info, &request_delegate_, nullptr, | 824 job_controller_->Start(request_info, &request_delegate_, nullptr, |
836 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 825 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
837 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 826 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
838 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 827 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
839 EXPECT_TRUE(job_controller_->alternative_job()); | 828 EXPECT_TRUE(job_controller_->alternative_job()); |
840 | 829 |
841 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | 830 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
842 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
843 | 831 |
844 // Since the alternative proxy server job is started in the next message loop, | 832 // Since the alternative proxy server job is started in the next message loop, |
845 // the main job would remain blocked until the alternative proxy starts, and | 833 // the main job would remain blocked until the alternative proxy starts, and |
846 // fails. | 834 // fails. |
847 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 835 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
848 .WillOnce(Invoke(testing::CreateFunctor( | 836 .WillOnce(Invoke(testing::CreateFunctor( |
849 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 837 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
850 base::TimeDelta::FromMicroseconds(0)))); | 838 base::TimeDelta::FromMicroseconds(0)))); |
851 | 839 |
852 base::RunLoop().RunUntilIdle(); | 840 base::RunLoop().RunUntilIdle(); |
853 EXPECT_FALSE(job_controller_->alternative_job()); | 841 EXPECT_FALSE(job_controller_->alternative_job()); |
854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 842 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
855 // Since the main job did not complete successfully, the alternative proxy | 843 // Since the main job did not complete successfully, the alternative proxy |
856 // server should not be marked as bad. | 844 // server should not be marked as bad. |
857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 845 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 846 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
859 } | 847 } |
860 | 848 |
861 } // namespace net | 849 } // namespace net |
OLD | NEW |