| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return job->spdy_session_key_; | 150 return job->spdy_session_key_; |
| 151 } | 151 } |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 class JobControllerPeer { | 154 class JobControllerPeer { |
| 155 public: | 155 public: |
| 156 static bool main_job_is_blocked( | 156 static bool main_job_is_blocked( |
| 157 HttpStreamFactoryImpl::JobController* job_controller) { | 157 HttpStreamFactoryImpl::JobController* job_controller) { |
| 158 return job_controller->main_job_is_blocked_; | 158 return job_controller->main_job_is_blocked_; |
| 159 } | 159 } |
| 160 |
| 160 static bool main_job_is_resumed( | 161 static bool main_job_is_resumed( |
| 161 HttpStreamFactoryImpl::JobController* job_controller) { | 162 HttpStreamFactoryImpl::JobController* job_controller) { |
| 162 return job_controller->main_job_is_resumed_; | 163 return job_controller->main_job_is_resumed_; |
| 163 } | 164 } |
| 165 |
| 166 static AlternativeServiceInfo GetAlternativeServiceInfoFor( |
| 167 HttpStreamFactoryImpl::JobController* job_controller, |
| 168 const HttpRequestInfo& request_info, |
| 169 HttpStreamRequest::Delegate* delegate, |
| 170 HttpStreamRequest::StreamType stream_type) { |
| 171 return job_controller->GetAlternativeServiceInfoFor(request_info, delegate, |
| 172 stream_type); |
| 173 } |
| 164 }; | 174 }; |
| 165 | 175 |
| 166 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 176 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 167 public: | 177 public: |
| 168 HttpStreamFactoryImplJobControllerTest() { session_deps_.enable_quic = true; } | 178 HttpStreamFactoryImplJobControllerTest() { session_deps_.enable_quic = true; } |
| 169 | 179 |
| 170 void UseAlternativeProxy() { | 180 void UseAlternativeProxy() { |
| 171 ASSERT_FALSE(test_proxy_delegate_); | 181 ASSERT_FALSE(test_proxy_delegate_); |
| 172 use_alternative_proxy_ = true; | 182 use_alternative_proxy_ = true; |
| 173 } | 183 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); | 256 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); |
| 247 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); | 257 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); |
| 248 } | 258 } |
| 249 } | 259 } |
| 250 | 260 |
| 251 void SetAlternativeService(const HttpRequestInfo& request_info, | 261 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 252 AlternativeService alternative_service) { | 262 AlternativeService alternative_service) { |
| 253 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 263 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 254 url::SchemeHostPort server(request_info.url); | 264 url::SchemeHostPort server(request_info.url); |
| 255 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 265 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 256 session_->http_server_properties()->SetAlternativeService( | 266 if (alternative_service.protocol == kProtoQUIC) { |
| 257 server, alternative_service, expiration); | 267 session_->http_server_properties()->SetQuicAlternativeService( |
| 268 server, alternative_service, expiration, |
| 269 session_->params().quic_supported_versions); |
| 270 } else { |
| 271 session_->http_server_properties()->SetHttp2AlternativeService( |
| 272 server, alternative_service, expiration); |
| 273 } |
| 258 } | 274 } |
| 259 | 275 |
| 260 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 276 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
| 261 bool should_mark_broken) { | 277 bool should_mark_broken) { |
| 262 const url::SchemeHostPort server(request_info.url); | 278 const url::SchemeHostPort server(request_info.url); |
| 263 const AlternativeServiceInfoVector alternative_service_info_vector = | 279 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 264 session_->http_server_properties()->GetAlternativeServiceInfos(server); | 280 session_->http_server_properties()->GetAlternativeServiceInfos(server); |
| 265 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 281 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 266 EXPECT_EQ(should_mark_broken, | 282 EXPECT_EQ(should_mark_broken, |
| 267 session_->http_server_properties()->IsAlternativeServiceBroken( | 283 session_->http_server_properties()->IsAlternativeServiceBroken( |
| (...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2062 Initialize(); | 2078 Initialize(); |
| 2063 Preconnect(kNumPreconects); | 2079 Preconnect(kNumPreconects); |
| 2064 // If experiment is enabled, only 1 stream is requested. | 2080 // If experiment is enabled, only 1 stream is requested. |
| 2065 EXPECT_EQ( | 2081 EXPECT_EQ( |
| 2066 (int)actual_num_connects, | 2082 (int)actual_num_connects, |
| 2067 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 2083 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 2068 base::RunLoop().RunUntilIdle(); | 2084 base::RunLoop().RunUntilIdle(); |
| 2069 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 2085 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 2070 } | 2086 } |
| 2071 | 2087 |
| 2088 // Test that GetAlternativeServiceInfoFor will include a list of advertised |
| 2089 // versions. Returns an empty list if advertised versions are missing in |
| 2090 // HttpServerProperties. |
| 2091 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { |
| 2092 HttpRequestInfo request_info; |
| 2093 request_info.method = "GET"; |
| 2094 request_info.url = GURL("https://www.google.com"); |
| 2095 |
| 2096 Initialize(request_info); |
| 2097 url::SchemeHostPort server(request_info.url); |
| 2098 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 2099 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 2100 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 2101 |
| 2102 // Set alternative service with no advertised version. |
| 2103 session_->http_server_properties()->SetQuicAlternativeService( |
| 2104 server, alternative_service, expiration, QuicVersionVector()); |
| 2105 |
| 2106 AlternativeServiceInfo alt_svc_info = |
| 2107 JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2108 job_controller_, request_info, &request_delegate_, |
| 2109 HttpStreamRequest::HTTP_STREAM); |
| 2110 // Verify that JobController get an empty list of supported QUIC versions. |
| 2111 EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); |
| 2112 |
| 2113 // Set alternative service for the same server with QUIC_VERSION_39 specified. |
| 2114 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( |
| 2115 server, alternative_service, expiration, {QUIC_VERSION_39})); |
| 2116 |
| 2117 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2118 job_controller_, request_info, &request_delegate_, |
| 2119 HttpStreamRequest::HTTP_STREAM); |
| 2120 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); |
| 2121 // Verify that JobController returns the single version specified in set. |
| 2122 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); |
| 2123 |
| 2124 // Set alternative service for the same server with two QUIC versions: |
| 2125 // QUIC_VERSION_35, QUIC_VERSION_39. |
| 2126 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( |
| 2127 server, alternative_service, expiration, |
| 2128 {QUIC_VERSION_35, QUIC_VERSION_39})); |
| 2129 |
| 2130 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2131 job_controller_, request_info, &request_delegate_, |
| 2132 HttpStreamRequest::HTTP_STREAM); |
| 2133 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); |
| 2134 // Verify that JobController returns the list of versions specified in set. |
| 2135 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); |
| 2136 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); |
| 2137 } |
| 2138 |
| 2072 } // namespace test | 2139 } // namespace test |
| 2073 | 2140 |
| 2074 } // namespace net | 2141 } // namespace net |
| OLD | NEW |