Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 return job->spdy_session_key_; | 145 return job->spdy_session_key_; |
| 146 } | 146 } |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 class JobControllerPeer { | 149 class JobControllerPeer { |
| 150 public: | 150 public: |
| 151 static bool main_job_is_blocked( | 151 static bool main_job_is_blocked( |
| 152 HttpStreamFactoryImpl::JobController* job_controller) { | 152 HttpStreamFactoryImpl::JobController* job_controller) { |
| 153 return job_controller->main_job_is_blocked_; | 153 return job_controller->main_job_is_blocked_; |
| 154 } | 154 } |
| 155 | |
| 155 static bool main_job_is_resumed( | 156 static bool main_job_is_resumed( |
| 156 HttpStreamFactoryImpl::JobController* job_controller) { | 157 HttpStreamFactoryImpl::JobController* job_controller) { |
| 157 return job_controller->main_job_is_resumed_; | 158 return job_controller->main_job_is_resumed_; |
| 158 } | 159 } |
| 160 | |
| 161 static AlternativeServiceInfo GetAlternativeServiceInfoFor( | |
| 162 HttpStreamFactoryImpl::JobController* job_controller, | |
| 163 const HttpRequestInfo& request_info, | |
| 164 HttpStreamRequest::Delegate* delegate, | |
| 165 HttpStreamRequest::StreamType stream_type) { | |
| 166 return job_controller->GetAlternativeServiceInfoFor(request_info, delegate, | |
| 167 stream_type); | |
| 168 } | |
| 159 }; | 169 }; |
| 160 | 170 |
| 161 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 171 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 162 public: | 172 public: |
| 163 HttpStreamFactoryImplJobControllerTest() | 173 HttpStreamFactoryImplJobControllerTest() |
| 164 : session_deps_(ProxyService::CreateDirect()), | 174 : session_deps_(ProxyService::CreateDirect()), |
| 165 random_generator_(0), | 175 random_generator_(0), |
| 166 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], | 176 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], |
| 167 0, | 177 0, |
| 168 &clock_, | 178 &clock_, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); | 257 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); |
| 248 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); | 258 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); |
| 249 } | 259 } |
| 250 } | 260 } |
| 251 | 261 |
| 252 void SetAlternativeService(const HttpRequestInfo& request_info, | 262 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 253 AlternativeService alternative_service) { | 263 AlternativeService alternative_service) { |
| 254 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 264 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 255 url::SchemeHostPort server(request_info.url); | 265 url::SchemeHostPort server(request_info.url); |
| 256 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 266 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 257 session_->http_server_properties()->SetAlternativeService( | 267 if (alternative_service.protocol == kProtoQUIC) { |
| 258 server, alternative_service, expiration); | 268 session_->http_server_properties()->SetQuicAlternativeService( |
| 269 server, alternative_service, expiration, | |
| 270 session_->params().quic_supported_versions); | |
| 271 } else { | |
| 272 session_->http_server_properties()->SetHttp2AlternativeService( | |
| 273 server, alternative_service, expiration); | |
| 274 } | |
| 259 } | 275 } |
| 260 | 276 |
| 261 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 277 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
| 262 bool should_mark_broken) { | 278 bool should_mark_broken) { |
| 263 const url::SchemeHostPort server(request_info.url); | 279 const url::SchemeHostPort server(request_info.url); |
| 264 const AlternativeServiceInfoVector alternative_service_info_vector = | 280 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 265 session_->http_server_properties()->GetAlternativeServiceInfos(server); | 281 session_->http_server_properties()->GetAlternativeServiceInfos(server); |
| 266 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 282 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 267 EXPECT_EQ(should_mark_broken, | 283 EXPECT_EQ(should_mark_broken, |
| 268 session_->http_server_properties()->IsAlternativeServiceBroken( | 284 session_->http_server_properties()->IsAlternativeServiceBroken( |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1701 Initialize(); | 1717 Initialize(); |
| 1702 Preconnect(kNumPreconects); | 1718 Preconnect(kNumPreconects); |
| 1703 // If experiment is enabled, only 1 stream is requested. | 1719 // If experiment is enabled, only 1 stream is requested. |
| 1704 EXPECT_EQ( | 1720 EXPECT_EQ( |
| 1705 (int)actual_num_connects, | 1721 (int)actual_num_connects, |
| 1706 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1722 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1707 base::RunLoop().RunUntilIdle(); | 1723 base::RunLoop().RunUntilIdle(); |
| 1708 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1724 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1709 } | 1725 } |
| 1710 | 1726 |
| 1727 // Test that GetAlternativeServiceInfoFor will include a list of advertised | |
|
Bence
2017/06/16 14:43:40
Since GetAlternativeServiceInfoFor() only has one
Zhongyi Shi
2017/06/20 23:23:37
Whoops. I probably should give some more context h
Bence
2017/06/21 12:39:25
Oh, I totally forgot about that. Sorry.
Optional
Zhongyi Shi
2017/06/21 21:01:33
Currently, we are returning a single AlternativerS
| |
| 1728 // versions. Returns an empty list if advertised versions are missing in | |
| 1729 // HttpServerProperties. | |
| 1730 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { | |
| 1731 HttpRequestInfo request_info; | |
| 1732 request_info.method = "GET"; | |
| 1733 request_info.url = GURL("https://www.google.com"); | |
| 1734 | |
| 1735 Initialize(request_info); | |
| 1736 url::SchemeHostPort server(request_info.url); | |
| 1737 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 1738 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | |
| 1739 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 1740 | |
| 1741 // Set alternative service with no advertised version. | |
| 1742 session_->http_server_properties()->SetQuicAlternativeService( | |
| 1743 server, alternative_service, expiration, QuicVersionVector()); | |
| 1744 | |
| 1745 AlternativeServiceInfo alt_svc_info = | |
| 1746 JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1747 job_controller_, request_info, &request_delegate_, | |
| 1748 HttpStreamRequest::HTTP_STREAM); | |
| 1749 // Verify that JobController get an empty list of supported QUIC versions. | |
| 1750 EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); | |
| 1751 | |
| 1752 // Set alternative service for the same server with QUIC_VERSION_39 specified. | |
| 1753 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( | |
| 1754 server, alternative_service, expiration, {QUIC_VERSION_39})); | |
| 1755 | |
| 1756 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1757 job_controller_, request_info, &request_delegate_, | |
| 1758 HttpStreamRequest::HTTP_STREAM); | |
| 1759 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); | |
| 1760 // Verify that JobController returns the single version specified in set. | |
| 1761 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); | |
| 1762 | |
| 1763 // Set alternative service for the same server with two QUIC versions: | |
| 1764 // QUIC_VERSION_35, QUIC_VERSION_39. | |
| 1765 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( | |
| 1766 server, alternative_service, expiration, | |
| 1767 {QUIC_VERSION_35, QUIC_VERSION_39})); | |
| 1768 | |
| 1769 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1770 job_controller_, request_info, &request_delegate_, | |
| 1771 HttpStreamRequest::HTTP_STREAM); | |
| 1772 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); | |
| 1773 // Verify that JobController returns the list of versions specified in set. | |
| 1774 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); | |
| 1775 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); | |
| 1776 } | |
| 1777 | |
| 1711 } // namespace net | 1778 } // namespace net |
| OLD | NEW |