Index: net/http/http_stream_factory_impl_job_controller_unittest.cc |
diff --git a/net/http/http_stream_factory_impl_job_controller_unittest.cc b/net/http/http_stream_factory_impl_job_controller_unittest.cc |
index cf7e526a5b3887d6ba52a9caa4155609cd75340b..dcb1347305ed7ff8b648efcf420fd3fc114c11bf 100644 |
--- a/net/http/http_stream_factory_impl_job_controller_unittest.cc |
+++ b/net/http/http_stream_factory_impl_job_controller_unittest.cc |
@@ -152,10 +152,20 @@ class JobControllerPeer { |
HttpStreamFactoryImpl::JobController* job_controller) { |
return job_controller->main_job_is_blocked_; |
} |
+ |
static bool main_job_is_resumed( |
HttpStreamFactoryImpl::JobController* job_controller) { |
return job_controller->main_job_is_resumed_; |
} |
+ |
+ static AlternativeServiceInfo GetAlternativeServiceInfoFor( |
+ HttpStreamFactoryImpl::JobController* job_controller, |
+ const HttpRequestInfo& request_info, |
+ HttpStreamRequest::Delegate* delegate, |
+ HttpStreamRequest::StreamType stream_type) { |
+ return job_controller->GetAlternativeServiceInfoFor(request_info, delegate, |
+ stream_type); |
+ } |
}; |
class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
@@ -254,8 +264,12 @@ class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
url::SchemeHostPort server(request_info.url); |
base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
+ QuicVersionVector advertised_versions; |
+ if (alternative_service.protocol == kProtoQUIC) |
+ advertised_versions = session_->params().quic_supported_versions; |
+ |
session_->http_server_properties()->SetAlternativeService( |
- server, alternative_service, expiration); |
+ server, alternative_service, expiration, advertised_versions); |
} |
void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
@@ -1708,4 +1722,55 @@ TEST_P(HttpStreamFactoryImplJobControllerPreconnectTest, |
EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
} |
+// Test that GetAlternativeServiceInfoFor will include a list of advertised |
+// versions. Returns an empty list if advertised versions are missing in |
+// HttpServerProperties. |
+TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { |
+ HttpRequestInfo request_info; |
+ request_info.method = "GET"; |
+ request_info.url = GURL("https://www.google.com"); |
+ |
+ Initialize(request_info); |
+ url::SchemeHostPort server(request_info.url); |
+ AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
+ HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
+ base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
+ |
+ // Set alternative service with no advertised version. |
+ session_->http_server_properties()->SetAlternativeService( |
+ server, alternative_service, expiration, QuicVersionVector()); |
+ |
+ AlternativeServiceInfo alt_svc_info = |
+ JobControllerPeer::GetAlternativeServiceInfoFor( |
+ job_controller_, request_info, &request_delegate_, |
+ HttpStreamRequest::HTTP_STREAM); |
+ // Verify that JobController get an empty list of supported QUIC versions. |
+ EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); |
+ |
+ // Set alternative service for the same server with QUIC_VERSION_39 specified. |
+ ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( |
+ server, alternative_service, expiration, {QUIC_VERSION_39})); |
+ |
+ alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
+ job_controller_, request_info, &request_delegate_, |
+ HttpStreamRequest::HTTP_STREAM); |
+ EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); |
+ // Verify that JobController returns the single version specified in set. |
+ EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); |
+ |
+ // Set alternative service for the same server with two QUIC versions: |
+ // QUIC_VERSION_35, QUIC_VERSION_39. |
+ ASSERT_TRUE(session_->http_server_properties()->SetAlternativeService( |
+ server, alternative_service, expiration, |
+ {QUIC_VERSION_35, QUIC_VERSION_39})); |
+ |
+ alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
+ job_controller_, request_info, &request_delegate_, |
+ HttpStreamRequest::HTTP_STREAM); |
+ EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); |
+ // Verify that JobController returns the list of versions specified in set. |
+ EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); |
+ EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); |
+} |
+ |
} // namespace net |