| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return job->num_streams_; | 115 return job->num_streams_; |
| 116 } | 116 } |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class JobControllerPeer { | 119 class JobControllerPeer { |
| 120 public: | 120 public: |
| 121 static bool main_job_is_blocked( | 121 static bool main_job_is_blocked( |
| 122 HttpStreamFactoryImpl::JobController* job_controller) { | 122 HttpStreamFactoryImpl::JobController* job_controller) { |
| 123 return job_controller->main_job_is_blocked_; | 123 return job_controller->main_job_is_blocked_; |
| 124 } | 124 } |
| 125 |
| 126 static AlternativeServiceInfo GetAlternativeServiceInfoFor( |
| 127 HttpStreamFactoryImpl::JobController* job_controller, |
| 128 const HttpRequestInfo& request_info, |
| 129 HttpStreamRequest::Delegate* delegate, |
| 130 HttpStreamRequest::StreamType stream_type) { |
| 131 return job_controller->GetAlternativeServiceInfoFor(request_info, delegate, |
| 132 stream_type); |
| 133 } |
| 125 }; | 134 }; |
| 126 | 135 |
| 127 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 136 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 128 public: | 137 public: |
| 129 HttpStreamFactoryImplJobControllerTest() | 138 HttpStreamFactoryImplJobControllerTest() |
| 130 : session_deps_(ProxyService::CreateDirect()), | 139 : session_deps_(ProxyService::CreateDirect()), |
| 131 use_alternative_proxy_(false), | 140 use_alternative_proxy_(false), |
| 132 is_preconnect_(false), | 141 is_preconnect_(false), |
| 133 enable_ip_based_pooling_(true), | 142 enable_ip_based_pooling_(true), |
| 134 enable_alternative_services_(true), | 143 enable_alternative_services_(true), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 195 } |
| 187 | 196 |
| 188 ~HttpStreamFactoryImplJobControllerTest() override {} | 197 ~HttpStreamFactoryImplJobControllerTest() override {} |
| 189 | 198 |
| 190 void SetAlternativeService(const HttpRequestInfo& request_info, | 199 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 191 AlternativeService alternative_service) { | 200 AlternativeService alternative_service) { |
| 192 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 201 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 193 url::SchemeHostPort server(request_info.url); | 202 url::SchemeHostPort server(request_info.url); |
| 194 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 203 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 195 session_->http_server_properties()->SetAlternativeService( | 204 session_->http_server_properties()->SetAlternativeService( |
| 196 server, alternative_service, expiration); | 205 server, alternative_service, expiration, |
| 206 HttpNetworkSession::Params().quic_supported_versions); |
| 197 } | 207 } |
| 198 | 208 |
| 199 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 209 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
| 200 bool should_mark_broken) { | 210 bool should_mark_broken) { |
| 201 const url::SchemeHostPort server(request_info.url); | 211 const url::SchemeHostPort server(request_info.url); |
| 202 const AlternativeServiceInfoVector alternative_service_info_vector = | 212 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 203 session_->http_server_properties()->GetAlternativeServiceInfos(server); | 213 session_->http_server_properties()->GetAlternativeServiceInfos(server); |
| 204 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 214 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 205 EXPECT_EQ(should_mark_broken, | 215 EXPECT_EQ(should_mark_broken, |
| 206 session_->http_server_properties()->IsAlternativeServiceBroken( | 216 session_->http_server_properties()->IsAlternativeServiceBroken( |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 Initialize(); | 1483 Initialize(); |
| 1474 Preconnect(kNumPreconects); | 1484 Preconnect(kNumPreconects); |
| 1475 // If experiment is enabled, only 1 stream is requested. | 1485 // If experiment is enabled, only 1 stream is requested. |
| 1476 EXPECT_EQ( | 1486 EXPECT_EQ( |
| 1477 (int)actual_num_connects, | 1487 (int)actual_num_connects, |
| 1478 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1488 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1479 base::RunLoop().RunUntilIdle(); | 1489 base::RunLoop().RunUntilIdle(); |
| 1480 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1490 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1481 } | 1491 } |
| 1482 | 1492 |
| 1493 // Test that GetAlternativeServiceInfoFor will include a list of advertised |
| 1494 // versions. |
| 1495 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { |
| 1496 HttpRequestInfo request_info; |
| 1497 request_info.method = "GET"; |
| 1498 request_info.url = GURL("https://www.google.com"); |
| 1499 |
| 1500 Initialize(request_info); |
| 1501 url::SchemeHostPort server(request_info.url); |
| 1502 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 1503 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 1504 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 1505 |
| 1506 // Set alternative service with no advertised version, JobController will |
| 1507 // append default supported quic versions when get alternative service info. |
| 1508 session_->http_server_properties()->SetAlternativeService( |
| 1509 server, alternative_service, expiration, QuicVersionVector()); |
| 1510 |
| 1511 AlternativeServiceInfo alt_svc_info = |
| 1512 JobControllerPeer::GetAlternativeServiceInfoFor( |
| 1513 job_controller_, request_info, &request_delegate_, |
| 1514 HttpStreamRequest::HTTP_STREAM); |
| 1515 const QuicVersionVector supported_versions = |
| 1516 session_->params().quic_supported_versions; |
| 1517 // Verify that JobController appends list of supported QUIC versions. |
| 1518 EXPECT_EQ(supported_versions.size(), |
| 1519 alt_svc_info.advertised_versions().size()); |
| 1520 for (unsigned int i = 0; i < supported_versions.size(); i++) { |
| 1521 EXPECT_EQ(supported_versions[i], alt_svc_info.advertised_versions()[i]); |
| 1522 } |
| 1523 |
| 1524 // Set alternative service for the same server with QUIC_VERSION_39 specified. |
| 1525 ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( |
| 1526 server, alternative_service, expiration, {QUIC_VERSION_39})); |
| 1527 |
| 1528 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 1529 job_controller_, request_info, &request_delegate_, |
| 1530 HttpStreamRequest::HTTP_STREAM); |
| 1531 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); |
| 1532 // Verify that JobController returns the single version specified in set. |
| 1533 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); |
| 1534 |
| 1535 // Set alternative service for the same server with two QUIC versions: |
| 1536 // QUIC_VERSION_35, QUIC_VERSION_39. |
| 1537 ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( |
| 1538 server, alternative_service, expiration, |
| 1539 {QUIC_VERSION_35, QUIC_VERSION_39})); |
| 1540 |
| 1541 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 1542 job_controller_, request_info, &request_delegate_, |
| 1543 HttpStreamRequest::HTTP_STREAM); |
| 1544 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); |
| 1545 // Verify that JobController returns the list of versions specified in set. |
| 1546 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); |
| 1547 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); |
| 1548 } |
| 1549 |
| 1483 } // namespace net | 1550 } // namespace net |
| OLD | NEW |