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

Side by Side Diff: net/http/http_stream_factory_impl_job_controller_unittest.cc

Issue 2894723002: Revert of Return Request as unique_ptr from JobController::Start(). (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <string>
9 #include <utility>
10 #include <vector> 8 #include <vector>
11 9
12 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 11 #include "base/run_loop.h"
14 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
15 #include "base/test/scoped_feature_list.h" 13 #include "base/test/scoped_feature_list.h"
16 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 14 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
17 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
18 #include "net/base/test_proxy_delegate.h" 16 #include "net/base/test_proxy_delegate.h"
19 #include "net/dns/mock_host_resolver.h" 17 #include "net/dns/mock_host_resolver.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); 300 base::WrapUnique(new FailingProxyResolverFactory), nullptr));
303 HttpRequestInfo request_info; 301 HttpRequestInfo request_info;
304 request_info.method = "GET"; 302 request_info.method = "GET";
305 request_info.url = GURL("http://www.google.com"); 303 request_info.url = GURL("http://www.google.com");
306 304
307 Initialize(request_info); 305 Initialize(request_info);
308 306
309 EXPECT_CALL(request_delegate_, 307 EXPECT_CALL(request_delegate_,
310 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) 308 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _))
311 .Times(1); 309 .Times(1);
312 request_ = 310 request_.reset(
313 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 311 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
314 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 312 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
315 313
316 EXPECT_FALSE(job_controller_->main_job()); 314 EXPECT_FALSE(job_controller_->main_job());
317 EXPECT_FALSE(job_controller_->alternative_job()); 315 EXPECT_FALSE(job_controller_->alternative_job());
318 316
319 base::RunLoop().RunUntilIdle(); 317 base::RunLoop().RunUntilIdle();
320 request_.reset(); 318 request_.reset();
321 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 319 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
322 } 320 }
323 321
324 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsAsync) { 322 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsAsync) {
325 ProxyConfig proxy_config; 323 ProxyConfig proxy_config;
326 proxy_config.set_pac_url(GURL("http://fooproxyurl")); 324 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
327 proxy_config.set_pac_mandatory(true); 325 proxy_config.set_pac_mandatory(true);
328 MockAsyncProxyResolverFactory* proxy_resolver_factory = 326 MockAsyncProxyResolverFactory* proxy_resolver_factory =
329 new MockAsyncProxyResolverFactory(false); 327 new MockAsyncProxyResolverFactory(false);
330 MockAsyncProxyResolver resolver; 328 MockAsyncProxyResolver resolver;
331 session_deps_.proxy_service.reset( 329 session_deps_.proxy_service.reset(
332 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), 330 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
333 base::WrapUnique(proxy_resolver_factory), nullptr)); 331 base::WrapUnique(proxy_resolver_factory), nullptr));
334 HttpRequestInfo request_info; 332 HttpRequestInfo request_info;
335 request_info.method = "GET"; 333 request_info.method = "GET";
336 request_info.url = GURL("http://www.google.com"); 334 request_info.url = GURL("http://www.google.com");
337 335
338 Initialize(request_info); 336 Initialize(request_info);
339 337
340 request_ = 338 request_.reset(
341 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 339 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
342 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 340 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
343 341
344 EXPECT_FALSE(job_controller_->main_job()); 342 EXPECT_FALSE(job_controller_->main_job());
345 EXPECT_FALSE(job_controller_->alternative_job()); 343 EXPECT_FALSE(job_controller_->alternative_job());
346 344
347 EXPECT_CALL(request_delegate_, 345 EXPECT_CALL(request_delegate_,
348 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) 346 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _))
349 .Times(1); 347 .Times(1);
350 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( 348 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
351 ERR_FAILED, &resolver); 349 ERR_FAILED, &resolver);
352 base::RunLoop().RunUntilIdle(); 350 base::RunLoop().RunUntilIdle();
353 request_.reset(); 351 request_.reset();
354 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 352 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
355 } 353 }
356 354
357 TEST_F(HttpStreamFactoryImplJobControllerTest, NoSupportedProxies) { 355 TEST_F(HttpStreamFactoryImplJobControllerTest, NoSupportedProxies) {
358 session_deps_.proxy_service = 356 session_deps_.proxy_service =
359 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); 357 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443");
360 session_deps_.enable_quic = false; 358 session_deps_.enable_quic = false;
361 HttpRequestInfo request_info; 359 HttpRequestInfo request_info;
362 request_info.method = "GET"; 360 request_info.method = "GET";
363 request_info.url = GURL("http://www.google.com"); 361 request_info.url = GURL("http://www.google.com");
364 362
365 Initialize(request_info); 363 Initialize(request_info);
366 364
367 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_NO_SUPPORTED_PROXIES, _)) 365 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_NO_SUPPORTED_PROXIES, _))
368 .Times(1); 366 .Times(1);
369 request_ = 367 request_.reset(
370 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 368 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
371 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 369 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
372 370
373 EXPECT_FALSE(job_controller_->main_job()); 371 EXPECT_FALSE(job_controller_->main_job());
374 EXPECT_FALSE(job_controller_->alternative_job()); 372 EXPECT_FALSE(job_controller_->alternative_job());
375 373
376 base::RunLoop().RunUntilIdle(); 374 base::RunLoop().RunUntilIdle();
377 request_.reset(); 375 request_.reset();
378 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 376 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
379 } 377 }
380 378
381 class JobControllerReconsiderProxyAfterErrorTest 379 class JobControllerReconsiderProxyAfterErrorTest
(...skipping 12 matching lines...) Expand all
394 } 392 }
395 393
396 std::unique_ptr<HttpStreamRequest> CreateJobController( 394 std::unique_ptr<HttpStreamRequest> CreateJobController(
397 const HttpRequestInfo& request_info) { 395 const HttpRequestInfo& request_info) {
398 HttpStreamFactoryImpl::JobController* job_controller = 396 HttpStreamFactoryImpl::JobController* job_controller =
399 new HttpStreamFactoryImpl::JobController( 397 new HttpStreamFactoryImpl::JobController(
400 factory_, &request_delegate_, session_.get(), &default_job_factory_, 398 factory_, &request_delegate_, session_.get(), &default_job_factory_,
401 request_info, is_preconnect_, enable_ip_based_pooling_, 399 request_info, is_preconnect_, enable_ip_based_pooling_,
402 enable_alternative_services_, SSLConfig(), SSLConfig()); 400 enable_alternative_services_, SSLConfig(), SSLConfig());
403 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); 401 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller);
404 return job_controller->Start( 402 return base::WrapUnique(job_controller->Start(
405 &request_delegate_, nullptr, NetLogWithSource(), 403 &request_delegate_, nullptr, NetLogWithSource(),
406 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 404 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
407 } 405 }
408 406
409 private: 407 private:
410 // Use real Jobs so that Job::Resume() is not mocked out. When main job is 408 // Use real Jobs so that Job::Resume() is not mocked out. When main job is
411 // resumed it will use mock socket data. 409 // resumed it will use mock socket data.
412 HttpStreamFactoryImpl::JobFactory default_job_factory_; 410 HttpStreamFactoryImpl::JobFactory default_job_factory_;
413 }; 411 };
414 412
415 INSTANTIATE_TEST_CASE_P( 413 INSTANTIATE_TEST_CASE_P(
416 /* no prefix */, 414 /* no prefix */,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 OnStreamFailedWithNoAlternativeJob) { 531 OnStreamFailedWithNoAlternativeJob) {
534 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); 532 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0);
535 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); 533 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED));
536 534
537 HttpRequestInfo request_info; 535 HttpRequestInfo request_info;
538 request_info.method = "GET"; 536 request_info.method = "GET";
539 request_info.url = GURL("http://www.google.com"); 537 request_info.url = GURL("http://www.google.com");
540 538
541 Initialize(request_info); 539 Initialize(request_info);
542 540
543 request_ = 541 request_.reset(
544 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 542 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
545 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 543 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
546 544
547 EXPECT_TRUE(job_controller_->main_job()); 545 EXPECT_TRUE(job_controller_->main_job());
548 EXPECT_FALSE(job_controller_->alternative_job()); 546 EXPECT_FALSE(job_controller_->alternative_job());
549 547
550 // There's no other alternative job. Thus when stream failed, it should 548 // There's no other alternative job. Thus when stream failed, it should
551 // notify Request of the stream failure. 549 // notify Request of the stream failure.
552 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); 550 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1);
553 base::RunLoop().RunUntilIdle(); 551 base::RunLoop().RunUntilIdle();
554 } 552 }
555 553
556 TEST_F(HttpStreamFactoryImplJobControllerTest, 554 TEST_F(HttpStreamFactoryImplJobControllerTest,
557 OnStreamReadyWithNoAlternativeJob) { 555 OnStreamReadyWithNoAlternativeJob) {
558 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); 556 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0);
559 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); 557 tcp_data_->set_connect_data(MockConnect(ASYNC, OK));
560 558
561 HttpRequestInfo request_info; 559 HttpRequestInfo request_info;
562 request_info.method = "GET"; 560 request_info.method = "GET";
563 request_info.url = GURL("http://www.google.com"); 561 request_info.url = GURL("http://www.google.com");
564 562
565 Initialize(request_info); 563 Initialize(request_info);
566 564
567 request_ = 565 request_.reset(
568 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 566 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
569 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 567 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
570 568
571 // There's no other alternative job. Thus when a stream is ready, it should 569 // There's no other alternative job. Thus when a stream is ready, it should
572 // notify Request. 570 // notify Request.
573 EXPECT_TRUE(job_controller_->main_job()); 571 EXPECT_TRUE(job_controller_->main_job());
574 572
575 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 573 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
576 .WillOnce(Invoke(DeleteHttpStreamPointer)); 574 .WillOnce(Invoke(DeleteHttpStreamPointer));
577 base::RunLoop().RunUntilIdle(); 575 base::RunLoop().RunUntilIdle();
578 } 576 }
579 577
(...skipping 10 matching lines...) Expand all
590 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); 588 tcp_data_->set_connect_data(MockConnect(ASYNC, OK));
591 HttpRequestInfo request_info; 589 HttpRequestInfo request_info;
592 request_info.method = "GET"; 590 request_info.method = "GET";
593 request_info.url = GURL("https://www.google.com"); 591 request_info.url = GURL("https://www.google.com");
594 592
595 Initialize(request_info); 593 Initialize(request_info);
596 url::SchemeHostPort server(request_info.url); 594 url::SchemeHostPort server(request_info.url);
597 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 595 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
598 SetAlternativeService(request_info, alternative_service); 596 SetAlternativeService(request_info, alternative_service);
599 597
600 request_ = 598 request_.reset(
601 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 599 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
602 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 600 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
603 EXPECT_TRUE(job_controller_->main_job()); 601 EXPECT_TRUE(job_controller_->main_job());
604 EXPECT_TRUE(job_controller_->alternative_job()); 602 EXPECT_TRUE(job_controller_->alternative_job());
605 603
606 // Reset the Request will cancel all the Jobs since there's no Job determined 604 // Reset the Request will cancel all the Jobs since there's no Job determined
607 // to serve Request yet and JobController will notify the factory to delete 605 // to serve Request yet and JobController will notify the factory to delete
608 // itself upon completion. 606 // itself upon completion.
609 request_.reset(); 607 request_.reset();
610 VerifyBrokenAlternateProtocolMapping(request_info, false); 608 VerifyBrokenAlternateProtocolMapping(request_info, false);
611 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 609 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
612 } 610 }
613 611
614 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { 612 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) {
615 quic_data_ = base::MakeUnique<test::MockQuicData>(); 613 quic_data_ = base::MakeUnique<test::MockQuicData>();
616 quic_data_->AddConnect(ASYNC, ERR_FAILED); 614 quic_data_->AddConnect(ASYNC, ERR_FAILED);
617 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); 615 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0);
618 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); 616 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED));
619 617
620 HttpRequestInfo request_info; 618 HttpRequestInfo request_info;
621 request_info.method = "GET"; 619 request_info.method = "GET";
622 request_info.url = GURL("https://www.google.com"); 620 request_info.url = GURL("https://www.google.com");
623 621
624 Initialize(request_info); 622 Initialize(request_info);
625 url::SchemeHostPort server(request_info.url); 623 url::SchemeHostPort server(request_info.url);
626 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 624 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
627 SetAlternativeService(request_info, alternative_service); 625 SetAlternativeService(request_info, alternative_service);
628 626
629 request_ = 627 request_.reset(
630 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 628 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
631 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 629 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
632 EXPECT_TRUE(job_controller_->main_job()); 630 EXPECT_TRUE(job_controller_->main_job());
633 EXPECT_TRUE(job_controller_->alternative_job()); 631 EXPECT_TRUE(job_controller_->alternative_job());
634 632
635 // The failure of second Job should be reported to Request as there's no more 633 // The failure of second Job should be reported to Request as there's no more
636 // pending Job to serve the Request. 634 // pending Job to serve the Request.
637 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); 635 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1);
638 base::RunLoop().RunUntilIdle(); 636 base::RunLoop().RunUntilIdle();
639 VerifyBrokenAlternateProtocolMapping(request_info, false); 637 VerifyBrokenAlternateProtocolMapping(request_info, false);
640 request_.reset(); 638 request_.reset();
641 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 639 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
(...skipping 13 matching lines...) Expand all
655 653
656 HttpRequestInfo request_info; 654 HttpRequestInfo request_info;
657 request_info.method = "GET"; 655 request_info.method = "GET";
658 request_info.url = GURL("https://www.google.com"); 656 request_info.url = GURL("https://www.google.com");
659 657
660 Initialize(request_info); 658 Initialize(request_info);
661 url::SchemeHostPort server(request_info.url); 659 url::SchemeHostPort server(request_info.url);
662 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 660 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
663 SetAlternativeService(request_info, alternative_service); 661 SetAlternativeService(request_info, alternative_service);
664 662
665 request_ = 663 request_.reset(
666 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 664 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
667 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 665 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
668 EXPECT_TRUE(job_controller_->main_job()); 666 EXPECT_TRUE(job_controller_->main_job());
669 EXPECT_TRUE(job_controller_->alternative_job()); 667 EXPECT_TRUE(job_controller_->alternative_job());
670 668
671 // Main job succeeds, starts serving Request and it should report status 669 // Main job succeeds, starts serving Request and it should report status
672 // to Request. The alternative job will mark the main job complete and gets 670 // to Request. The alternative job will mark the main job complete and gets
673 // orphaned. 671 // orphaned.
674 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 672 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
675 .WillOnce(Invoke(DeleteHttpStreamPointer)); 673 .WillOnce(Invoke(DeleteHttpStreamPointer));
676 // JobController shouldn't report the status of second job as request 674 // JobController shouldn't report the status of second job as request
677 // is already successfully served. 675 // is already successfully served.
(...skipping 18 matching lines...) Expand all
696 694
697 HttpRequestInfo request_info; 695 HttpRequestInfo request_info;
698 request_info.method = "GET"; 696 request_info.method = "GET";
699 request_info.url = GURL("https://www.google.com"); 697 request_info.url = GURL("https://www.google.com");
700 698
701 Initialize(request_info); 699 Initialize(request_info);
702 700
703 url::SchemeHostPort server(request_info.url); 701 url::SchemeHostPort server(request_info.url);
704 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 702 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
705 SetAlternativeService(request_info, alternative_service); 703 SetAlternativeService(request_info, alternative_service);
706 request_ = 704 request_.reset(
707 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 705 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
708 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 706 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
709 EXPECT_TRUE(job_controller_->main_job()); 707 EXPECT_TRUE(job_controller_->main_job());
710 EXPECT_TRUE(job_controller_->alternative_job()); 708 EXPECT_TRUE(job_controller_->alternative_job());
711 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); 709 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_));
712 710
713 // |alternative_job| succeeds and should report status to |request_delegate_|. 711 // |alternative_job| succeeds and should report status to |request_delegate_|.
714 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 712 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
715 .WillOnce(Invoke(DeleteHttpStreamPointer)); 713 .WillOnce(Invoke(DeleteHttpStreamPointer));
716 714
717 base::RunLoop().RunUntilIdle(); 715 base::RunLoop().RunUntilIdle();
718 716
(...skipping 26 matching lines...) Expand all
745 HttpRequestInfo request_info; 743 HttpRequestInfo request_info;
746 request_info.method = "GET"; 744 request_info.method = "GET";
747 request_info.url = GURL("https://www.google.com"); 745 request_info.url = GURL("https://www.google.com");
748 746
749 Initialize(request_info); 747 Initialize(request_info);
750 748
751 url::SchemeHostPort server(request_info.url); 749 url::SchemeHostPort server(request_info.url);
752 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 750 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
753 SetAlternativeService(request_info, alternative_service); 751 SetAlternativeService(request_info, alternative_service);
754 752
755 request_ = 753 request_.reset(
756 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 754 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
757 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 755 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
758 EXPECT_TRUE(job_controller_->main_job()); 756 EXPECT_TRUE(job_controller_->main_job());
759 EXPECT_TRUE(job_controller_->alternative_job()); 757 EXPECT_TRUE(job_controller_->alternative_job());
760 // main job should not be blocked because alt job returned ERR_IO_PENDING. 758 // main job should not be blocked because alt job returned ERR_IO_PENDING.
761 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 759 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
762 760
763 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 761 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
764 .WillOnce(Invoke(DeleteHttpStreamPointer)); 762 .WillOnce(Invoke(DeleteHttpStreamPointer));
765 763
766 // Complete main job now. 764 // Complete main job now.
767 base::RunLoop().RunUntilIdle(); 765 base::RunLoop().RunUntilIdle();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 799
802 Initialize(request_info); 800 Initialize(request_info);
803 801
804 url::SchemeHostPort server(request_info.url); 802 url::SchemeHostPort server(request_info.url);
805 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 803 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
806 SetAlternativeService(request_info, alternative_service); 804 SetAlternativeService(request_info, alternative_service);
807 805
808 // |main_job| fails but should not report status to Request. 806 // |main_job| fails but should not report status to Request.
809 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 807 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
810 808
811 request_ = 809 request_.reset(
812 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 810 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
813 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 811 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
814 EXPECT_TRUE(job_controller_->main_job()); 812 EXPECT_TRUE(job_controller_->main_job());
815 EXPECT_TRUE(job_controller_->alternative_job()); 813 EXPECT_TRUE(job_controller_->alternative_job());
816 814
817 base::RunLoop().RunUntilIdle(); 815 base::RunLoop().RunUntilIdle();
818 816
819 // Make |alternative_job| succeed. 817 // Make |alternative_job| succeed.
820 HttpStream* http_stream = 818 HttpStream* http_stream =
821 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); 819 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false);
822 820
823 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 821 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
(...skipping 22 matching lines...) Expand all
846 HttpRequestInfo request_info; 844 HttpRequestInfo request_info;
847 request_info.method = "GET"; 845 request_info.method = "GET";
848 request_info.url = GURL("https://www.google.com"); 846 request_info.url = GURL("https://www.google.com");
849 847
850 Initialize(request_info); 848 Initialize(request_info);
851 849
852 url::SchemeHostPort server(request_info.url); 850 url::SchemeHostPort server(request_info.url);
853 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 851 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
854 SetAlternativeService(request_info, alternative_service); 852 SetAlternativeService(request_info, alternative_service);
855 853
856 request_ = 854 request_.reset(
857 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 855 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
858 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 856 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
859 EXPECT_TRUE(job_controller_->main_job()); 857 EXPECT_TRUE(job_controller_->main_job());
860 EXPECT_TRUE(job_controller_->alternative_job()); 858 EXPECT_TRUE(job_controller_->alternative_job());
861 859
862 // |alternative_job| fails but should not report status to Request. 860 // |alternative_job| fails but should not report status to Request.
863 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 861 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
864 // |main_job| succeeds and should report status to Request. 862 // |main_job| succeeds and should report status to Request.
865 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 863 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
866 .WillOnce(Invoke(DeleteHttpStreamPointer)); 864 .WillOnce(Invoke(DeleteHttpStreamPointer));
867 865
868 base::RunLoop().RunUntilIdle(); 866 base::RunLoop().RunUntilIdle();
(...skipping 21 matching lines...) Expand all
890 888
891 HttpRequestInfo request_info; 889 HttpRequestInfo request_info;
892 request_info.method = "GET"; 890 request_info.method = "GET";
893 request_info.url = GURL("https://www.google.com"); 891 request_info.url = GURL("https://www.google.com");
894 Initialize(request_info); 892 Initialize(request_info);
895 893
896 url::SchemeHostPort server(request_info.url); 894 url::SchemeHostPort server(request_info.url);
897 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 895 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
898 SetAlternativeService(request_info, alternative_service); 896 SetAlternativeService(request_info, alternative_service);
899 897
900 request_ = 898 request_.reset(
901 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 899 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
902 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 900 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
903 EXPECT_TRUE(job_controller_->main_job()); 901 EXPECT_TRUE(job_controller_->main_job());
904 EXPECT_TRUE(job_controller_->alternative_job()); 902 EXPECT_TRUE(job_controller_->alternative_job());
905 903
906 // |alternative_job| fails but should not report status to Request. 904 // |alternative_job| fails but should not report status to Request.
907 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 905 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
908 // |main_job| succeeds and should report status to Request. 906 // |main_job| succeeds and should report status to Request.
909 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 907 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
910 .WillOnce(Invoke(DeleteHttpStreamPointer)); 908 .WillOnce(Invoke(DeleteHttpStreamPointer));
911 base::RunLoop().RunUntilIdle(); 909 base::RunLoop().RunUntilIdle();
912 910
(...skipping 19 matching lines...) Expand all
932 930
933 HttpRequestInfo request_info; 931 HttpRequestInfo request_info;
934 request_info.method = "GET"; 932 request_info.method = "GET";
935 request_info.url = GURL("https://www.google.com"); 933 request_info.url = GURL("https://www.google.com");
936 934
937 Initialize(request_info); 935 Initialize(request_info);
938 url::SchemeHostPort server(request_info.url); 936 url::SchemeHostPort server(request_info.url);
939 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 937 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
940 SetAlternativeService(request_info, alternative_service); 938 SetAlternativeService(request_info, alternative_service);
941 939
942 request_ = 940 request_.reset(
943 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 941 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
944 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 942 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
945 EXPECT_TRUE(job_controller_->main_job()); 943 EXPECT_TRUE(job_controller_->main_job());
946 EXPECT_TRUE(job_controller_->alternative_job()); 944 EXPECT_TRUE(job_controller_->alternative_job());
947 945
948 // |main_job| fails but should not report status to Request. 946 // |main_job| fails but should not report status to Request.
949 // The alternative job will mark the main job complete. 947 // The alternative job will mark the main job complete.
950 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 948 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
951 949
952 base::RunLoop().RunUntilIdle(); 950 base::RunLoop().RunUntilIdle();
953 951
954 // Controller should use alternative job to get load state. 952 // Controller should use alternative job to get load state.
(...skipping 25 matching lines...) Expand all
980 978
981 HttpRequestInfo request_info; 979 HttpRequestInfo request_info;
982 request_info.method = "GET"; 980 request_info.method = "GET";
983 request_info.url = GURL("https://www.google.com"); 981 request_info.url = GURL("https://www.google.com");
984 982
985 Initialize(request_info); 983 Initialize(request_info);
986 url::SchemeHostPort server(request_info.url); 984 url::SchemeHostPort server(request_info.url);
987 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 985 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
988 SetAlternativeService(request_info, alternative_service); 986 SetAlternativeService(request_info, alternative_service);
989 987
990 request_ = 988 request_.reset(
991 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 989 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
992 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 990 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
993 EXPECT_TRUE(job_controller_->main_job()); 991 EXPECT_TRUE(job_controller_->main_job());
994 EXPECT_TRUE(job_controller_->alternative_job()); 992 EXPECT_TRUE(job_controller_->alternative_job());
995 993
996 // Alt job is stalled and main job should complete successfully. 994 // Alt job is stalled and main job should complete successfully.
997 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 995 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
998 .WillOnce(Invoke(DeleteHttpStreamPointer)); 996 .WillOnce(Invoke(DeleteHttpStreamPointer));
999 997
1000 base::RunLoop().RunUntilIdle(); 998 base::RunLoop().RunUntilIdle();
1001 } 999 }
1002 1000
1003 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { 1001 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) {
1004 HttpRequestInfo request_info; 1002 HttpRequestInfo request_info;
1005 request_info.method = "GET"; 1003 request_info.method = "GET";
1006 request_info.url = GURL("https://www.google.com"); 1004 request_info.url = GURL("https://www.google.com");
1007 1005
1008 // Using a restricted port 101 for QUIC should fail and the alternative job 1006 // Using a restricted port 101 for QUIC should fail and the alternative job
1009 // should post OnStreamFailedCall on the controller to resume the main job. 1007 // should post OnStreamFailedCall on the controller to resume the main job.
1010 Initialize(request_info); 1008 Initialize(request_info);
1011 1009
1012 url::SchemeHostPort server(request_info.url); 1010 url::SchemeHostPort server(request_info.url);
1013 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); 1011 AlternativeService alternative_service(kProtoQUIC, server.host(), 101);
1014 SetAlternativeService(request_info, alternative_service); 1012 SetAlternativeService(request_info, alternative_service);
1015 1013
1016 request_ = 1014 request_.reset(
1017 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1015 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1018 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1016 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1019 1017
1020 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); 1018 EXPECT_TRUE(job_factory_.main_job()->is_waiting());
1021 1019
1022 // Wait until OnStreamFailedCallback is executed on the alternative job. 1020 // Wait until OnStreamFailedCallback is executed on the alternative job.
1023 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1021 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1024 base::RunLoop().RunUntilIdle(); 1022 base::RunLoop().RunUntilIdle();
1025 } 1023 }
1026 1024
1027 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { 1025 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) {
1028 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1026 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
(...skipping 13 matching lines...) Expand all
1042 quic_stream_factory->set_require_confirmation(false); 1040 quic_stream_factory->set_require_confirmation(false);
1043 ServerNetworkStats stats1; 1041 ServerNetworkStats stats1;
1044 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 1042 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
1045 session_->http_server_properties()->SetServerNetworkStats( 1043 session_->http_server_properties()->SetServerNetworkStats(
1046 url::SchemeHostPort(GURL("https://www.google.com")), stats1); 1044 url::SchemeHostPort(GURL("https://www.google.com")), stats1);
1047 1045
1048 url::SchemeHostPort server(request_info.url); 1046 url::SchemeHostPort server(request_info.url);
1049 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 1047 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
1050 SetAlternativeService(request_info, alternative_service); 1048 SetAlternativeService(request_info, alternative_service);
1051 1049
1052 request_ = 1050 request_.reset(
1053 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1051 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1054 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1052 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1055 EXPECT_TRUE(job_controller_->main_job()); 1053 EXPECT_TRUE(job_controller_->main_job());
1056 EXPECT_TRUE(job_controller_->alternative_job()); 1054 EXPECT_TRUE(job_controller_->alternative_job());
1057 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1055 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1058 1056
1059 // The alternative job stalls as host resolution hangs when creating the QUIC 1057 // The alternative job stalls as host resolution hangs when creating the QUIC
1060 // request and controller should resume the main job after delay. 1058 // request and controller should resume the main job after delay.
1061 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1059 EXPECT_TRUE(test_task_runner->HasPendingTask());
1062 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1060 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1063 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1061 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1064 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); 1062 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 ServerNetworkStats stats1; 1107 ServerNetworkStats stats1;
1110 stats1.srtt = base::TimeDelta::FromSeconds(100); 1108 stats1.srtt = base::TimeDelta::FromSeconds(100);
1111 session_->http_server_properties()->SetServerNetworkStats( 1109 session_->http_server_properties()->SetServerNetworkStats(
1112 url::SchemeHostPort(GURL("https://www.google.com")), stats1); 1110 url::SchemeHostPort(GURL("https://www.google.com")), stats1);
1113 1111
1114 // Set a SPDY alternative service for the server. 1112 // Set a SPDY alternative service for the server.
1115 url::SchemeHostPort server(request_info.url); 1113 url::SchemeHostPort server(request_info.url);
1116 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 1114 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
1117 SetAlternativeService(request_info, alternative_service); 1115 SetAlternativeService(request_info, alternative_service);
1118 1116
1119 request_ = 1117 request_.reset(
1120 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1118 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1121 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1119 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1122 EXPECT_TRUE(job_controller_->main_job()); 1120 EXPECT_TRUE(job_controller_->main_job());
1123 EXPECT_TRUE(job_controller_->alternative_job()); 1121 EXPECT_TRUE(job_controller_->alternative_job());
1124 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1122 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1125 1123
1126 // The alternative job stalls as host resolution hangs when creating the QUIC 1124 // The alternative job stalls as host resolution hangs when creating the QUIC
1127 // request and controller should resume the main job after delay. 1125 // request and controller should resume the main job after delay.
1128 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1126 EXPECT_TRUE(test_task_runner->HasPendingTask());
1129 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1127 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1130 1128
1131 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1129 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 url::SchemeHostPort(GURL("https://www.google.com")), stats1); 1166 url::SchemeHostPort(GURL("https://www.google.com")), stats1);
1169 1167
1170 // Set a SPDY alternative service for the server. 1168 // Set a SPDY alternative service for the server.
1171 url::SchemeHostPort server(request_info.url); 1169 url::SchemeHostPort server(request_info.url);
1172 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 1170 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
1173 SetAlternativeService(request_info, alternative_service); 1171 SetAlternativeService(request_info, alternative_service);
1174 1172
1175 // The alternative job stalls as host resolution hangs when creating the QUIC 1173 // The alternative job stalls as host resolution hangs when creating the QUIC
1176 // request and controller should resume the main job with delay. 1174 // request and controller should resume the main job with delay.
1177 // OnStreamFailed should resume the main job immediately. 1175 // OnStreamFailed should resume the main job immediately.
1178 request_ = 1176 request_.reset(
1179 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1177 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1180 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1178 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1181 EXPECT_TRUE(job_controller_->main_job()); 1179 EXPECT_TRUE(job_controller_->main_job());
1182 EXPECT_TRUE(job_controller_->alternative_job()); 1180 EXPECT_TRUE(job_controller_->alternative_job());
1183 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1181 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1184 1182
1185 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1183 EXPECT_TRUE(test_task_runner->HasPendingTask());
1186 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1184 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1187 1185
1188 // |alternative_job| fails but should not report status to Request. 1186 // |alternative_job| fails but should not report status to Request.
1189 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 1187 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
1190 // Now unblock Resolver to fail the alternate job. 1188 // Now unblock Resolver to fail the alternate job.
(...skipping 22 matching lines...) Expand all
1213 // Using hanging resolver will cause the alternative job to hang indefinitely. 1211 // Using hanging resolver will cause the alternative job to hang indefinitely.
1214 HangingResolver* resolver = new HangingResolver(); 1212 HangingResolver* resolver = new HangingResolver();
1215 session_deps_.host_resolver.reset(resolver); 1213 session_deps_.host_resolver.reset(resolver);
1216 1214
1217 HttpRequestInfo request_info; 1215 HttpRequestInfo request_info;
1218 request_info.method = "GET"; 1216 request_info.method = "GET";
1219 request_info.url = GURL("https://mail.example.org/"); 1217 request_info.url = GURL("https://mail.example.org/");
1220 Initialize(request_info); 1218 Initialize(request_info);
1221 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1219 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1222 1220
1223 request_ = 1221 request_.reset(
1224 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1222 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1225 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1223 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1226 EXPECT_TRUE(job_controller_->main_job()); 1224 EXPECT_TRUE(job_controller_->main_job());
1227 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); 1225 EXPECT_FALSE(job_controller_->main_job()->is_waiting());
1228 EXPECT_FALSE(job_controller_->alternative_job()); 1226 EXPECT_FALSE(job_controller_->alternative_job());
1229 1227
1230 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 1228 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
1231 base::RunLoop().RunUntilIdle(); 1229 base::RunLoop().RunUntilIdle();
1232 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 1230 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
1233 } 1231 }
1234 1232
1235 // Verifies that the alternative proxy server job is not created if the main job 1233 // Verifies that the alternative proxy server job is not created if the main job
1236 // does not fetch the resource through a proxy. 1234 // does not fetch the resource through a proxy.
1237 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { 1235 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) {
1238 // Using hanging resolver will cause the alternative job to hang indefinitely. 1236 // Using hanging resolver will cause the alternative job to hang indefinitely.
1239 HangingResolver* resolver = new HangingResolver(); 1237 HangingResolver* resolver = new HangingResolver();
1240 session_deps_.host_resolver.reset(resolver); 1238 session_deps_.host_resolver.reset(resolver);
1241 1239
1242 HttpRequestInfo request_info; 1240 HttpRequestInfo request_info;
1243 request_info.method = "GET"; 1241 request_info.method = "GET";
1244 request_info.url = GURL("http://mail.example.org/"); 1242 request_info.url = GURL("http://mail.example.org/");
1245 1243
1246 Initialize(request_info); 1244 Initialize(request_info);
1247 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1245 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1248 1246
1249 request_ = 1247 request_.reset(
1250 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1248 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1251 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1249 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1252 EXPECT_TRUE(job_controller_->main_job()); 1250 EXPECT_TRUE(job_controller_->main_job());
1253 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); 1251 EXPECT_FALSE(job_controller_->main_job()->is_waiting());
1254 EXPECT_FALSE(job_controller_->alternative_job()); 1252 EXPECT_FALSE(job_controller_->alternative_job());
1255 1253
1256 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 1254 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
1257 base::RunLoop().RunUntilIdle(); 1255 base::RunLoop().RunUntilIdle();
1258 1256
1259 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 1257 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
1260 } 1258 }
1261 1259
(...skipping 19 matching lines...) Expand all
1281 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1279 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1282 1280
1283 // Enable delayed TCP and set time delay for waiting job. 1281 // Enable delayed TCP and set time delay for waiting job.
1284 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 1282 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
1285 quic_stream_factory->set_require_confirmation(false); 1283 quic_stream_factory->set_require_confirmation(false);
1286 ServerNetworkStats stats1; 1284 ServerNetworkStats stats1;
1287 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 1285 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
1288 session_->http_server_properties()->SetServerNetworkStats( 1286 session_->http_server_properties()->SetServerNetworkStats(
1289 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); 1287 url::SchemeHostPort(GURL("https://myproxy.org")), stats1);
1290 1288
1291 request_ = 1289 request_.reset(
1292 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1290 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1293 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1291 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1294 EXPECT_TRUE(job_controller_->main_job()); 1292 EXPECT_TRUE(job_controller_->main_job());
1295 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1293 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1296 EXPECT_TRUE(job_controller_->alternative_job()); 1294 EXPECT_TRUE(job_controller_->alternative_job());
1297 // The main job is unblocked but is resumed one message loop iteration later. 1295 // The main job is unblocked but is resumed one message loop iteration later.
1298 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 1296 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
1299 EXPECT_FALSE(JobControllerPeer::main_job_is_resumed(job_controller_)); 1297 EXPECT_FALSE(JobControllerPeer::main_job_is_resumed(job_controller_));
1300 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1298 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1301 1299
1302 // Move forward the delay and verify the main job is resumed. 1300 // Move forward the delay and verify the main job is resumed.
1303 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1301 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1335 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1338 1336
1339 // Enable delayed TCP and set time delay for waiting job. 1337 // Enable delayed TCP and set time delay for waiting job.
1340 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 1338 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
1341 quic_stream_factory->set_require_confirmation(false); 1339 quic_stream_factory->set_require_confirmation(false);
1342 ServerNetworkStats stats1; 1340 ServerNetworkStats stats1;
1343 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); 1341 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000);
1344 session_->http_server_properties()->SetServerNetworkStats( 1342 session_->http_server_properties()->SetServerNetworkStats(
1345 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); 1343 url::SchemeHostPort(GURL("https://myproxy.org")), stats1);
1346 1344
1347 request_ = 1345 request_.reset(
1348 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1346 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1349 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1347 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1350 EXPECT_TRUE(job_controller_->main_job()); 1348 EXPECT_TRUE(job_controller_->main_job());
1351 EXPECT_TRUE(job_controller_->alternative_job()); 1349 EXPECT_TRUE(job_controller_->alternative_job());
1352 1350
1353 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 1351 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
1354 .WillOnce(Invoke(DeleteHttpStreamPointer)); 1352 .WillOnce(Invoke(DeleteHttpStreamPointer));
1355 1353
1356 base::RunLoop().RunUntilIdle(); 1354 base::RunLoop().RunUntilIdle();
1357 1355
1358 EXPECT_FALSE(job_controller_->alternative_job()); 1356 EXPECT_FALSE(job_controller_->alternative_job());
1359 EXPECT_TRUE(job_controller_->main_job()); 1357 EXPECT_TRUE(job_controller_->main_job());
(...skipping 21 matching lines...) Expand all
1381 1379
1382 UseAlternativeProxy(); 1380 UseAlternativeProxy();
1383 1381
1384 HttpRequestInfo request_info; 1382 HttpRequestInfo request_info;
1385 request_info.method = "GET"; 1383 request_info.method = "GET";
1386 request_info.url = GURL("http://www.google.com"); 1384 request_info.url = GURL("http://www.google.com");
1387 Initialize(request_info); 1385 Initialize(request_info);
1388 1386
1389 url::SchemeHostPort server(request_info.url); 1387 url::SchemeHostPort server(request_info.url);
1390 1388
1391 request_ = 1389 request_.reset(
1392 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1390 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1393 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1391 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1394 EXPECT_TRUE(job_controller_->main_job()); 1392 EXPECT_TRUE(job_controller_->main_job());
1395 EXPECT_TRUE(job_controller_->alternative_job()); 1393 EXPECT_TRUE(job_controller_->alternative_job());
1396 1394
1397 // Main job succeeds, starts serving Request and it should report status 1395 // Main job succeeds, starts serving Request and it should report status
1398 // to Request. The alternative job will mark the main job complete and gets 1396 // to Request. The alternative job will mark the main job complete and gets
1399 // orphaned. 1397 // orphaned.
1400 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 1398 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
1401 .WillOnce(Invoke(DeleteHttpStreamPointer)); 1399 .WillOnce(Invoke(DeleteHttpStreamPointer));
1402 1400
1403 base::RunLoop().RunUntilIdle(); 1401 base::RunLoop().RunUntilIdle();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 DisableIPBasedPooling(); 1479 DisableIPBasedPooling();
1482 if (!enable_alternative_services) 1480 if (!enable_alternative_services)
1483 DisableAlternativeServices(); 1481 DisableAlternativeServices();
1484 1482
1485 Initialize(request_info); 1483 Initialize(request_info);
1486 1484
1487 url::SchemeHostPort server(request_info.url); 1485 url::SchemeHostPort server(request_info.url);
1488 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 1486 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
1489 SetAlternativeService(request_info, alternative_service); 1487 SetAlternativeService(request_info, alternative_service);
1490 1488
1491 request_ = 1489 request_.reset(
1492 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), 1490 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
1493 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); 1491 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
1494 EXPECT_TRUE(job_controller_->main_job()); 1492 EXPECT_TRUE(job_controller_->main_job());
1495 if (enable_alternative_services) { 1493 if (enable_alternative_services) {
1496 EXPECT_TRUE(job_controller_->alternative_job()); 1494 EXPECT_TRUE(job_controller_->alternative_job());
1497 } else { 1495 } else {
1498 EXPECT_FALSE(job_controller_->alternative_job()); 1496 EXPECT_FALSE(job_controller_->alternative_job());
1499 } 1497 }
1500 1498
1501 // |main_job| succeeds and should report status to Request. 1499 // |main_job| succeeds and should report status to Request.
1502 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) 1500 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _))
1503 .WillOnce(Invoke(DeleteHttpStreamPointer)); 1501 .WillOnce(Invoke(DeleteHttpStreamPointer));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 Preconnect(kNumPreconects); 1568 Preconnect(kNumPreconects);
1571 // If experiment is enabled, only 1 stream is requested. 1569 // If experiment is enabled, only 1 stream is requested.
1572 EXPECT_EQ( 1570 EXPECT_EQ(
1573 (int)actual_num_connects, 1571 (int)actual_num_connects,
1574 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 1572 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
1575 base::RunLoop().RunUntilIdle(); 1573 base::RunLoop().RunUntilIdle();
1576 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1574 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
1577 } 1575 }
1578 1576
1579 } // namespace net 1577 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698