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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 return job->GetSpdySessionKey(); | 151 return job->GetSpdySessionKey(); |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 class JobControllerPeer { | 155 class JobControllerPeer { |
| 156 public: | 156 public: |
| 157 static bool main_job_is_blocked( | 157 static bool main_job_is_blocked( |
| 158 HttpStreamFactoryImpl::JobController* job_controller) { | 158 HttpStreamFactoryImpl::JobController* job_controller) { |
| 159 return job_controller->main_job_is_blocked_; | 159 return job_controller->main_job_is_blocked_; |
| 160 } | 160 } |
| 161 | |
| 161 static bool main_job_is_resumed( | 162 static bool main_job_is_resumed( |
| 162 HttpStreamFactoryImpl::JobController* job_controller) { | 163 HttpStreamFactoryImpl::JobController* job_controller) { |
| 163 return job_controller->main_job_is_resumed_; | 164 return job_controller->main_job_is_resumed_; |
| 164 } | 165 } |
| 166 | |
| 167 static AlternativeServiceInfo GetAlternativeServiceInfoFor( | |
| 168 HttpStreamFactoryImpl::JobController* job_controller, | |
| 169 const HttpRequestInfo& request_info, | |
| 170 HttpStreamRequest::Delegate* delegate, | |
| 171 HttpStreamRequest::StreamType stream_type) { | |
| 172 return job_controller->GetAlternativeServiceInfoFor(request_info, delegate, | |
| 173 stream_type); | |
| 174 } | |
| 165 }; | 175 }; |
| 166 | 176 |
| 167 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 177 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 168 public: | 178 public: |
| 169 HttpStreamFactoryImplJobControllerTest() | 179 HttpStreamFactoryImplJobControllerTest() |
| 170 : session_deps_(ProxyService::CreateDirect()), | 180 : session_deps_(ProxyService::CreateDirect()), |
| 171 random_generator_(0), | 181 random_generator_(0), |
| 172 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], | 182 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], |
| 173 0, | 183 0, |
| 174 &clock_, | 184 &clock_, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); | 264 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); |
| 255 } | 265 } |
| 256 } | 266 } |
| 257 | 267 |
| 258 void SetAlternativeService(const HttpRequestInfo& request_info, | 268 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 259 AlternativeService alternative_service) { | 269 AlternativeService alternative_service) { |
| 260 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 270 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 261 url::SchemeHostPort server(request_info.url); | 271 url::SchemeHostPort server(request_info.url); |
| 262 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 272 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 263 session_->http_server_properties()->SetAlternativeService( | 273 session_->http_server_properties()->SetAlternativeService( |
| 264 server, alternative_service, expiration); | 274 server, alternative_service, expiration, |
| 275 HttpNetworkSession::Params().quic_supported_versions); | |
| 265 } | 276 } |
| 266 | 277 |
| 267 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 278 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
| 268 bool should_mark_broken) { | 279 bool should_mark_broken) { |
| 269 const url::SchemeHostPort server(request_info.url); | 280 const url::SchemeHostPort server(request_info.url); |
| 270 const AlternativeServiceInfoVector alternative_service_info_vector = | 281 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 271 session_->http_server_properties()->GetAlternativeServiceInfos(server); | 282 session_->http_server_properties()->GetAlternativeServiceInfos(server); |
| 272 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 283 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 273 EXPECT_EQ(should_mark_broken, | 284 EXPECT_EQ(should_mark_broken, |
| 274 session_->http_server_properties()->IsAlternativeServiceBroken( | 285 session_->http_server_properties()->IsAlternativeServiceBroken( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 342 |
| 332 base::RunLoop().RunUntilIdle(); | 343 base::RunLoop().RunUntilIdle(); |
| 333 request_.reset(); | 344 request_.reset(); |
| 334 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 345 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 335 } | 346 } |
| 336 | 347 |
| 337 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsAsync) { | 348 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsAsync) { |
| 338 ProxyConfig proxy_config; | 349 ProxyConfig proxy_config; |
| 339 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | 350 proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 340 proxy_config.set_pac_mandatory(true); | 351 proxy_config.set_pac_mandatory(true); |
| 341 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 352 session_deps_.proxy_service.reset(new ProxyService( |
|
Bence
2017/06/08 17:44:51
session_deps_.proxy_service = base::MakeUnique<Pro
Zhongyi Shi
2017/06/08 23:11:16
This is a change not related to this CL. Not sure
| |
| 342 new MockAsyncProxyResolverFactory(false); | 353 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 343 MockAsyncProxyResolver resolver; | 354 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
|
Bence
2017/06/08 17:44:52
base::MakeUnique<FailingProxyResolverFactory>()
Zhongyi Shi
2017/06/08 23:11:16
ditto.
| |
| 344 session_deps_.proxy_service.reset( | |
| 345 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 346 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 347 HttpRequestInfo request_info; | 355 HttpRequestInfo request_info; |
| 348 request_info.method = "GET"; | 356 request_info.method = "GET"; |
| 349 request_info.url = GURL("http://www.google.com"); | 357 request_info.url = GURL("http://www.google.com"); |
| 350 | 358 |
| 351 Initialize(request_info); | 359 Initialize(request_info); |
| 352 | 360 |
| 361 EXPECT_CALL(request_delegate_, | |
| 362 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) | |
| 363 .Times(1); | |
| 353 request_ = | 364 request_ = |
| 354 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), | 365 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 355 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); | 366 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); |
| 356 | 367 |
| 357 EXPECT_FALSE(job_controller_->main_job()); | 368 EXPECT_FALSE(job_controller_->main_job()); |
| 358 EXPECT_FALSE(job_controller_->alternative_job()); | 369 EXPECT_FALSE(job_controller_->alternative_job()); |
| 359 | 370 |
| 360 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, | 371 // Make sure calling GetLoadState() when before job |
| 361 job_controller_->GetLoadState()); | 372 // creation does not crash. |
| 373 // Regression test for crbug.com/723920. | |
| 374 EXPECT_EQ(LOAD_STATE_IDLE, job_controller_->GetLoadState()); | |
| 362 | 375 |
| 363 EXPECT_CALL(request_delegate_, | |
| 364 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) | |
| 365 .Times(1); | |
| 366 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 367 ERR_FAILED, &resolver); | |
| 368 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
| 369 request_.reset(); | 377 request_.reset(); |
| 370 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 378 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 371 } | 379 } |
| 372 | 380 |
| 373 TEST_F(HttpStreamFactoryImplJobControllerTest, NoSupportedProxies) { | 381 TEST_F(HttpStreamFactoryImplJobControllerTest, NoSupportedProxies) { |
| 374 session_deps_.proxy_service = | 382 session_deps_.proxy_service = |
| 375 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); | 383 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 376 session_deps_.enable_quic = false; | 384 session_deps_.enable_quic = false; |
| 377 HttpRequestInfo request_info; | 385 HttpRequestInfo request_info; |
| (...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 Initialize(); | 1729 Initialize(); |
| 1722 Preconnect(kNumPreconects); | 1730 Preconnect(kNumPreconects); |
| 1723 // If experiment is enabled, only 1 stream is requested. | 1731 // If experiment is enabled, only 1 stream is requested. |
| 1724 EXPECT_EQ( | 1732 EXPECT_EQ( |
| 1725 (int)actual_num_connects, | 1733 (int)actual_num_connects, |
| 1726 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1734 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1727 base::RunLoop().RunUntilIdle(); | 1735 base::RunLoop().RunUntilIdle(); |
| 1728 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1736 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1729 } | 1737 } |
| 1730 | 1738 |
| 1739 // Test that GetAlternativeServiceInfoFor will include a list of advertised | |
| 1740 // versions. | |
| 1741 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { | |
| 1742 HttpRequestInfo request_info; | |
| 1743 request_info.method = "GET"; | |
| 1744 request_info.url = GURL("https://www.google.com"); | |
| 1745 | |
| 1746 Initialize(request_info); | |
| 1747 url::SchemeHostPort server(request_info.url); | |
| 1748 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 1749 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | |
| 1750 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 1751 | |
| 1752 // Set alternative service with no advertised version, JobController will | |
| 1753 // append default supported quic versions when get alternative service info. | |
| 1754 session_->http_server_properties()->SetAlternativeService( | |
| 1755 server, alternative_service, expiration, QuicVersionVector()); | |
| 1756 | |
| 1757 AlternativeServiceInfo alt_svc_info = | |
| 1758 JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1759 job_controller_, request_info, &request_delegate_, | |
| 1760 HttpStreamRequest::HTTP_STREAM); | |
| 1761 const QuicVersionVector supported_versions = | |
| 1762 session_->params().quic_supported_versions; | |
| 1763 // Verify that JobController appends list of supported QUIC versions. | |
| 1764 EXPECT_EQ(supported_versions.size(), | |
| 1765 alt_svc_info.advertised_versions().size()); | |
| 1766 for (unsigned int i = 0; i < supported_versions.size(); i++) { | |
| 1767 EXPECT_EQ(supported_versions[i], alt_svc_info.advertised_versions()[i]); | |
| 1768 } | |
| 1769 | |
| 1770 // Set alternative service for the same server with QUIC_VERSION_39 specified. | |
| 1771 ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( | |
| 1772 server, alternative_service, expiration, {QUIC_VERSION_39})); | |
| 1773 | |
| 1774 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1775 job_controller_, request_info, &request_delegate_, | |
| 1776 HttpStreamRequest::HTTP_STREAM); | |
| 1777 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); | |
| 1778 // Verify that JobController returns the single version specified in set. | |
| 1779 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); | |
| 1780 | |
| 1781 // Set alternative service for the same server with two QUIC versions: | |
| 1782 // QUIC_VERSION_35, QUIC_VERSION_39. | |
| 1783 ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( | |
| 1784 server, alternative_service, expiration, | |
| 1785 {QUIC_VERSION_35, QUIC_VERSION_39})); | |
| 1786 | |
| 1787 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 1788 job_controller_, request_info, &request_delegate_, | |
| 1789 HttpStreamRequest::HTTP_STREAM); | |
| 1790 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); | |
| 1791 // Verify that JobController returns the list of versions specified in set. | |
| 1792 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); | |
| 1793 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); | |
| 1794 } | |
| 1795 | |
| 1731 } // namespace net | 1796 } // namespace net |
| OLD | NEW |