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

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

Issue 2887773006: Fix SpdySessionKey for HTTP/2 alternative Jobs. (Closed)
Patch Set: Add test. 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.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 <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h"
12 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
13 #include "base/test/scoped_feature_list.h" 14 #include "base/test/scoped_feature_list.h"
14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 15 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
15 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
16 #include "net/base/test_proxy_delegate.h" 17 #include "net/base/test_proxy_delegate.h"
17 #include "net/dns/mock_host_resolver.h" 18 #include "net/dns/mock_host_resolver.h"
18 #include "net/http/http_basic_stream.h" 19 #include "net/http/http_basic_stream.h"
19 #include "net/http/http_stream_factory_impl_job.h" 20 #include "net/http/http_stream_factory_impl_job.h"
20 #include "net/http/http_stream_factory_impl_request.h" 21 #include "net/http/http_stream_factory_impl_request.h"
21 #include "net/http/http_stream_factory_test_util.h" 22 #include "net/http/http_stream_factory_test_util.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Start() is mocked for MockHttpStreamFactoryImplJob. 135 // Start() is mocked for MockHttpStreamFactoryImplJob.
135 // This is the alternative method to invoke real Start() method on Job. 136 // This is the alternative method to invoke real Start() method on Job.
136 job->stream_type_ = stream_type; 137 job->stream_type_ = stream_type;
137 job->StartInternal(); 138 job->StartInternal();
138 } 139 }
139 140
140 // Returns |num_streams_| of |job|. It should be 0 for non-preconnect Jobs. 141 // Returns |num_streams_| of |job|. It should be 0 for non-preconnect Jobs.
141 static int GetNumStreams(const HttpStreamFactoryImpl::Job* job) { 142 static int GetNumStreams(const HttpStreamFactoryImpl::Job* job) {
142 return job->num_streams_; 143 return job->num_streams_;
143 } 144 }
145
146 // Return SpdySessionKey of |job|.
147 static const SpdySessionKey GetSpdySessionKey(
148 const HttpStreamFactoryImpl::Job* job) {
149 return job->GetSpdySessionKey();
150 }
144 }; 151 };
145 152
146 class JobControllerPeer { 153 class JobControllerPeer {
147 public: 154 public:
148 static bool main_job_is_blocked( 155 static bool main_job_is_blocked(
149 HttpStreamFactoryImpl::JobController* job_controller) { 156 HttpStreamFactoryImpl::JobController* job_controller) {
150 return job_controller->main_job_is_blocked_; 157 return job_controller->main_job_is_blocked_;
151 } 158 }
152 static bool main_job_is_resumed( 159 static bool main_job_is_resumed(
153 HttpStreamFactoryImpl::JobController* job_controller) { 160 HttpStreamFactoryImpl::JobController* job_controller) {
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 EXPECT_TRUE(job_controller_->alternative_job()); 725 EXPECT_TRUE(job_controller_->alternative_job());
719 726
720 // Invoke OnRequestComplete() which should delete |job_controller_| from 727 // Invoke OnRequestComplete() which should delete |job_controller_| from
721 // |factory_|. 728 // |factory_|.
722 request_.reset(); 729 request_.reset();
723 VerifyBrokenAlternateProtocolMapping(request_info, false); 730 VerifyBrokenAlternateProtocolMapping(request_info, false);
724 // This fails without the fix for crbug.com/678768. 731 // This fails without the fix for crbug.com/678768.
725 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 732 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
726 } 733 }
727 734
735 TEST_F(HttpStreamFactoryImplJobControllerTest,
736 SpdySessionKeyHasOriginHostPortPair) {
737 session_deps_.enable_http2_alternative_service = true;
738
739 const char origin_host[] = "www.example.org";
740 const uint16_t origin_port = 443;
741 const char alternative_host[] = "mail.example.org";
742 const uint16_t alternative_port = 123;
743
744 HttpRequestInfo request_info;
745 request_info.method = "GET";
746 request_info.url =
747 GURL(base::StringPrintf("https://%s:%u", origin_host, origin_port));
748 Initialize(request_info);
749
750 url::SchemeHostPort server(request_info.url);
751 AlternativeService alternative_service(kProtoHTTP2, alternative_host,
752 alternative_port);
753 SetAlternativeService(request_info, alternative_service);
754
755 request_.reset(
756 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(),
757 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY));
758
759 HostPortPair main_host_port_pair =
760 HttpStreamFactoryImplJobPeer::GetSpdySessionKey(
761 job_controller_->main_job())
762 .host_port_pair();
763 EXPECT_EQ(origin_host, main_host_port_pair.host());
764 EXPECT_EQ(origin_port, main_host_port_pair.port());
765
766 HostPortPair alternative_host_port_pair =
767 HttpStreamFactoryImplJobPeer::GetSpdySessionKey(
768 job_controller_->alternative_job())
769 .host_port_pair();
770 EXPECT_EQ(origin_host, alternative_host_port_pair.host());
771 EXPECT_EQ(origin_port, alternative_host_port_pair.port());
772 }
773
728 // Tests that if an orphaned job completes after |request_| is gone, 774 // Tests that if an orphaned job completes after |request_| is gone,
729 // JobController will be cleaned up. 775 // JobController will be cleaned up.
730 TEST_F(HttpStreamFactoryImplJobControllerTest, 776 TEST_F(HttpStreamFactoryImplJobControllerTest,
731 OrphanedJobCompletesControllerDestroyed) { 777 OrphanedJobCompletesControllerDestroyed) {
732 quic_data_ = base::MakeUnique<test::MockQuicData>(); 778 quic_data_ = base::MakeUnique<test::MockQuicData>();
733 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING); 779 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING);
734 // Use cold start and complete alt job manually. 780 // Use cold start and complete alt job manually.
735 crypto_client_stream_factory_.set_handshake_mode( 781 crypto_client_stream_factory_.set_handshake_mode(
736 MockCryptoClientStream::COLD_START); 782 MockCryptoClientStream::COLD_START);
737 783
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 Preconnect(kNumPreconects); 1614 Preconnect(kNumPreconects);
1569 // If experiment is enabled, only 1 stream is requested. 1615 // If experiment is enabled, only 1 stream is requested.
1570 EXPECT_EQ( 1616 EXPECT_EQ(
1571 (int)actual_num_connects, 1617 (int)actual_num_connects,
1572 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 1618 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
1573 base::RunLoop().RunUntilIdle(); 1619 base::RunLoop().RunUntilIdle();
1574 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1620 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
1575 } 1621 }
1576 1622
1577 } // namespace net 1623 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698