| 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 <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
| 13 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
| 14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "net/base/test_proxy_delegate.h" | 16 #include "net/base/test_proxy_delegate.h" |
| 17 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
| 18 #include "net/http/http_basic_stream.h" | 18 #include "net/http/http_basic_stream.h" |
| 19 #include "net/http/http_stream_factory_impl_job.h" |
| 19 #include "net/http/http_stream_factory_impl_request.h" | 20 #include "net/http/http_stream_factory_impl_request.h" |
| 20 #include "net/http/http_stream_factory_test_util.h" | 21 #include "net/http/http_stream_factory_test_util.h" |
| 21 #include "net/log/net_log_with_source.h" | 22 #include "net/log/net_log_with_source.h" |
| 22 #include "net/proxy/mock_proxy_resolver.h" | 23 #include "net/proxy/mock_proxy_resolver.h" |
| 23 #include "net/proxy/proxy_config_service_fixed.h" | 24 #include "net/proxy/proxy_config_service_fixed.h" |
| 24 #include "net/proxy/proxy_info.h" | 25 #include "net/proxy/proxy_info.h" |
| 25 #include "net/proxy/proxy_service.h" | 26 #include "net/proxy/proxy_service.h" |
| 27 #include "net/quic/chromium/mock_crypto_client_stream_factory.h" |
| 28 #include "net/quic/chromium/mock_quic_data.h" |
| 29 #include "net/quic/chromium/quic_stream_factory.h" |
| 26 #include "net/quic/chromium/quic_stream_factory_peer.h" | 30 #include "net/quic/chromium/quic_stream_factory_peer.h" |
| 31 #include "net/quic/chromium/quic_test_packet_maker.h" |
| 32 #include "net/quic/test_tools/mock_random.h" |
| 27 #include "net/socket/socket_test_util.h" | 33 #include "net/socket/socket_test_util.h" |
| 28 #include "net/spdy/chromium/spdy_test_util_common.h" | 34 #include "net/spdy/chromium/spdy_test_util_common.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gmock_mutant.h" | 36 #include "testing/gmock_mutant.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 38 |
| 33 using ::testing::_; | 39 using ::testing::_; |
| 34 using ::testing::Invoke; | 40 using ::testing::Invoke; |
| 35 | 41 |
| 36 namespace net { | 42 namespace net { |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| 46 const char kServerHostname[] = "www.example.com"; |
| 47 |
| 48 // List of errors that are used in the proxy resolution tests. |
| 49 const int proxy_test_mock_errors[] = { |
| 50 ERR_PROXY_CONNECTION_FAILED, |
| 51 ERR_NAME_NOT_RESOLVED, |
| 52 ERR_ADDRESS_UNREACHABLE, |
| 53 ERR_CONNECTION_CLOSED, |
| 54 ERR_CONNECTION_TIMED_OUT, |
| 55 ERR_CONNECTION_RESET, |
| 56 ERR_CONNECTION_REFUSED, |
| 57 ERR_CONNECTION_ABORTED, |
| 58 ERR_TIMED_OUT, |
| 59 ERR_TUNNEL_CONNECTION_FAILED, |
| 60 ERR_SOCKS_CONNECTION_FAILED, |
| 61 ERR_PROXY_CERTIFICATE_INVALID, |
| 62 ERR_QUIC_PROTOCOL_ERROR, |
| 63 ERR_QUIC_HANDSHAKE_FAILED, |
| 64 ERR_SSL_PROTOCOL_ERROR, |
| 65 ERR_MSG_TOO_BIG, |
| 66 }; |
| 67 |
| 40 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, | 68 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, |
| 41 const ProxyInfo& used_proxy_info, | 69 const ProxyInfo& used_proxy_info, |
| 42 HttpStream* stream) { | 70 HttpStream* stream) { |
| 43 delete stream; | 71 delete stream; |
| 44 } | 72 } |
| 45 | 73 |
| 46 class FailingProxyResolverFactory : public ProxyResolverFactory { | 74 class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 47 public: | 75 public: |
| 48 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} | 76 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 49 | 77 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 static bool main_job_is_blocked( | 148 static bool main_job_is_blocked( |
| 121 HttpStreamFactoryImpl::JobController* job_controller) { | 149 HttpStreamFactoryImpl::JobController* job_controller) { |
| 122 return job_controller->main_job_is_blocked_; | 150 return job_controller->main_job_is_blocked_; |
| 123 } | 151 } |
| 124 }; | 152 }; |
| 125 | 153 |
| 126 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { | 154 class HttpStreamFactoryImplJobControllerTest : public ::testing::Test { |
| 127 public: | 155 public: |
| 128 HttpStreamFactoryImplJobControllerTest() | 156 HttpStreamFactoryImplJobControllerTest() |
| 129 : session_deps_(ProxyService::CreateDirect()), | 157 : session_deps_(ProxyService::CreateDirect()), |
| 158 random_generator_(0), |
| 159 client_maker_(HttpNetworkSession::Params().quic_supported_versions[0], |
| 160 0, |
| 161 &clock_, |
| 162 kServerHostname, |
| 163 Perspective::IS_CLIENT), |
| 130 use_alternative_proxy_(false), | 164 use_alternative_proxy_(false), |
| 131 is_preconnect_(false), | 165 is_preconnect_(false), |
| 132 enable_ip_based_pooling_(true), | 166 enable_ip_based_pooling_(true), |
| 133 enable_alternative_services_(true), | 167 enable_alternative_services_(true), |
| 134 test_proxy_delegate_(nullptr) { | 168 test_proxy_delegate_(nullptr) { |
| 135 session_deps_.enable_quic = true; | 169 session_deps_.enable_quic = true; |
| 136 } | 170 } |
| 137 | 171 |
| 138 void UseAlternativeProxy() { | 172 void UseAlternativeProxy() { |
| 139 ASSERT_FALSE(test_proxy_delegate_); | 173 ASSERT_FALSE(test_proxy_delegate_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 159 ASSERT_FALSE(test_proxy_delegate_); | 193 ASSERT_FALSE(test_proxy_delegate_); |
| 160 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | 194 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( |
| 161 new TestProxyDelegate()); | 195 new TestProxyDelegate()); |
| 162 test_proxy_delegate_ = test_proxy_delegate.get(); | 196 test_proxy_delegate_ = test_proxy_delegate.get(); |
| 163 | 197 |
| 164 test_proxy_delegate->set_alternative_proxy_server( | 198 test_proxy_delegate->set_alternative_proxy_server( |
| 165 ProxyServer::FromPacString("QUIC myproxy.org:443")); | 199 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
| 166 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | 200 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
| 167 session_deps_.proxy_delegate = std::move(test_proxy_delegate); | 201 session_deps_.proxy_delegate = std::move(test_proxy_delegate); |
| 168 | 202 |
| 203 if (quic_data_) |
| 204 quic_data_->AddSocketDataToFactory(session_deps_.socket_factory.get()); |
| 205 if (tcp_data_) |
| 206 session_deps_.socket_factory->AddSocketDataProvider(tcp_data_.get()); |
| 207 |
| 169 if (use_alternative_proxy_) { | 208 if (use_alternative_proxy_) { |
| 170 std::unique_ptr<ProxyService> proxy_service = | 209 std::unique_ptr<ProxyService> proxy_service = |
| 171 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | 210 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
| 172 session_deps_.proxy_service = std::move(proxy_service); | 211 session_deps_.proxy_service = std::move(proxy_service); |
| 173 } | 212 } |
| 174 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 213 HttpNetworkSession::Params params = |
| 214 SpdySessionDependencies::CreateSessionParams(&session_deps_); |
| 215 params.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
| 216 params.quic_random = &random_generator_; |
| 217 session_ = base::MakeUnique<HttpNetworkSession>(params); |
| 175 factory_ = | 218 factory_ = |
| 176 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 219 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 177 job_controller_ = new HttpStreamFactoryImpl::JobController( | 220 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 178 factory_, &request_delegate_, session_.get(), &job_factory_, | 221 factory_, &request_delegate_, session_.get(), &job_factory_, |
| 179 request_info, is_preconnect_, enable_ip_based_pooling_, | 222 request_info, is_preconnect_, enable_ip_based_pooling_, |
| 180 enable_alternative_services_); | 223 enable_alternative_services_, SSLConfig(), SSLConfig()); |
| 181 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 224 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 182 } | 225 } |
| 183 | 226 |
| 184 TestProxyDelegate* test_proxy_delegate() const { | 227 TestProxyDelegate* test_proxy_delegate() const { |
| 185 return test_proxy_delegate_; | 228 return test_proxy_delegate_; |
| 186 } | 229 } |
| 187 | 230 |
| 188 ~HttpStreamFactoryImplJobControllerTest() override {} | 231 ~HttpStreamFactoryImplJobControllerTest() override { |
| 232 if (quic_data_) { |
| 233 EXPECT_TRUE(quic_data_->AllReadDataConsumed()); |
| 234 EXPECT_TRUE(quic_data_->AllWriteDataConsumed()); |
| 235 } |
| 236 if (tcp_data_) { |
| 237 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); |
| 238 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); |
| 239 } |
| 240 } |
| 189 | 241 |
| 190 void SetAlternativeService(const HttpRequestInfo& request_info, | 242 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 191 AlternativeService alternative_service) { | 243 AlternativeService alternative_service) { |
| 192 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 244 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 193 url::SchemeHostPort server(request_info.url); | 245 url::SchemeHostPort server(request_info.url); |
| 194 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 246 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 195 session_->http_server_properties()->SetAlternativeService( | 247 session_->http_server_properties()->SetAlternativeService( |
| 196 server, alternative_service, expiration); | 248 server, alternative_service, expiration); |
| 197 } | 249 } |
| 198 | 250 |
| 199 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 251 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
| 200 bool should_mark_broken) { | 252 bool should_mark_broken) { |
| 201 const url::SchemeHostPort server(request_info.url); | 253 const url::SchemeHostPort server(request_info.url); |
| 202 const AlternativeServiceVector alternative_service_vector = | 254 const AlternativeServiceVector alternative_service_vector = |
| 203 session_->http_server_properties()->GetAlternativeServices(server); | 255 session_->http_server_properties()->GetAlternativeServices(server); |
| 204 EXPECT_EQ(1u, alternative_service_vector.size()); | 256 EXPECT_EQ(1u, alternative_service_vector.size()); |
| 205 EXPECT_EQ(should_mark_broken, | 257 EXPECT_EQ(should_mark_broken, |
| 206 session_->http_server_properties()->IsAlternativeServiceBroken( | 258 session_->http_server_properties()->IsAlternativeServiceBroken( |
| 207 alternative_service_vector[0])); | 259 alternative_service_vector[0])); |
| 208 } | 260 } |
| 209 | 261 |
| 210 TestJobFactory job_factory_; | 262 TestJobFactory job_factory_; |
| 211 MockHttpStreamRequestDelegate request_delegate_; | 263 MockHttpStreamRequestDelegate request_delegate_; |
| 212 SpdySessionDependencies session_deps_; | 264 SpdySessionDependencies session_deps_; |
| 213 std::unique_ptr<HttpNetworkSession> session_; | 265 std::unique_ptr<HttpNetworkSession> session_; |
| 214 HttpStreamFactoryImpl* factory_; | 266 HttpStreamFactoryImpl* factory_; |
| 215 HttpStreamFactoryImpl::JobController* job_controller_; | 267 HttpStreamFactoryImpl::JobController* job_controller_; |
| 216 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 268 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
| 217 | 269 std::unique_ptr<SequencedSocketData> tcp_data_; |
| 218 private: | 270 std::unique_ptr<test::MockQuicData> quic_data_; |
| 271 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 272 MockClock clock_; |
| 273 test::MockRandom random_generator_; |
| 274 test::QuicTestPacketMaker client_maker_; |
| 275 |
| 276 protected: |
| 219 bool use_alternative_proxy_; | 277 bool use_alternative_proxy_; |
| 220 bool is_preconnect_; | 278 bool is_preconnect_; |
| 221 bool enable_ip_based_pooling_; | 279 bool enable_ip_based_pooling_; |
| 222 bool enable_alternative_services_; | 280 bool enable_alternative_services_; |
| 223 | 281 |
| 282 private: |
| 224 // Not owned by |this|. | 283 // Not owned by |this|. |
| 225 TestProxyDelegate* test_proxy_delegate_; | 284 TestProxyDelegate* test_proxy_delegate_; |
| 226 | 285 |
| 227 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 286 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 228 }; | 287 }; |
| 229 | 288 |
| 230 TEST_F(HttpStreamFactoryImplJobControllerTest, | 289 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsSync) { |
| 231 OnStreamFailedWithNoAlternativeJob) { | |
| 232 ProxyConfig proxy_config; | 290 ProxyConfig proxy_config; |
| 233 proxy_config.set_auto_detect(true); | 291 proxy_config.set_pac_url(GURL("http://www.example.com")); |
| 234 // Use asynchronous proxy resolver. | 292 proxy_config.set_pac_mandatory(true); |
| 293 MockAsyncProxyResolver resolver; |
| 294 session_deps_.proxy_service.reset(new ProxyService( |
| 295 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 296 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 297 HttpRequestInfo request_info; |
| 298 request_info.method = "GET"; |
| 299 request_info.url = GURL("http://www.google.com"); |
| 300 |
| 301 Initialize(request_info); |
| 302 |
| 303 EXPECT_CALL(request_delegate_, |
| 304 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) |
| 305 .Times(1); |
| 306 request_.reset( |
| 307 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 308 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 309 |
| 310 EXPECT_FALSE(job_controller_->main_job()); |
| 311 EXPECT_FALSE(job_controller_->alternative_job()); |
| 312 |
| 313 base::RunLoop().RunUntilIdle(); |
| 314 request_.reset(); |
| 315 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 316 } |
| 317 |
| 318 TEST_F(HttpStreamFactoryImplJobControllerTest, ProxyResolutionFailsAsync) { |
| 319 ProxyConfig proxy_config; |
| 320 proxy_config.set_pac_url(GURL("http://www.example.com")); |
| 321 proxy_config.set_pac_mandatory(true); |
| 235 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 322 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 236 new MockAsyncProxyResolverFactory(false); | 323 new MockAsyncProxyResolverFactory(false); |
| 324 MockAsyncProxyResolver resolver; |
| 237 session_deps_.proxy_service.reset( | 325 session_deps_.proxy_service.reset( |
| 238 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 326 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 239 base::WrapUnique(proxy_resolver_factory), nullptr)); | 327 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 240 | 328 HttpRequestInfo request_info; |
| 241 HttpRequestInfo request_info; | 329 request_info.method = "GET"; |
| 242 request_info.method = "GET"; | 330 request_info.url = GURL("http://www.google.com"); |
| 331 |
| 332 Initialize(request_info); |
| 333 |
| 334 request_.reset( |
| 335 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 336 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 337 |
| 338 EXPECT_FALSE(job_controller_->main_job()); |
| 339 EXPECT_FALSE(job_controller_->alternative_job()); |
| 340 |
| 341 EXPECT_CALL(request_delegate_, |
| 342 OnStreamFailed(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, _)) |
| 343 .Times(1); |
| 344 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 345 ERR_FAILED, &resolver); |
| 346 base::RunLoop().RunUntilIdle(); |
| 347 request_.reset(); |
| 348 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 349 } |
| 350 |
| 351 class JobControllerReconsiderProxyAfterErrorTest |
| 352 : public HttpStreamFactoryImplJobControllerTest, |
| 353 public ::testing::WithParamInterface<::testing::tuple<bool, int>> { |
| 354 public: |
| 355 void Initialize(std::unique_ptr<ProxyService> proxy_service, |
| 356 std::unique_ptr<ProxyDelegate> proxy_delegate) { |
| 357 session_deps_.proxy_delegate = std::move(proxy_delegate); |
| 358 session_deps_.proxy_service = std::move(proxy_service); |
| 359 HttpNetworkSession::Params params = |
| 360 SpdySessionDependencies::CreateSessionParams(&session_deps_); |
| 361 session_ = base::MakeUnique<HttpNetworkSession>(params); |
| 362 factory_ = |
| 363 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 364 } |
| 365 |
| 366 std::unique_ptr<HttpStreamRequest> CreateJobController( |
| 367 const HttpRequestInfo& request_info) { |
| 368 HttpStreamFactoryImpl::JobController* job_controller = |
| 369 new HttpStreamFactoryImpl::JobController( |
| 370 factory_, &request_delegate_, session_.get(), &default_job_factory_, |
| 371 request_info, is_preconnect_, enable_ip_based_pooling_, |
| 372 enable_alternative_services_, SSLConfig(), SSLConfig()); |
| 373 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller); |
| 374 return base::WrapUnique(job_controller->Start( |
| 375 &request_delegate_, nullptr, NetLogWithSource(), |
| 376 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 377 } |
| 378 |
| 379 private: |
| 380 // Use real Jobs so that Job::Resume() is not mocked out. When main job is |
| 381 // resumed it will use mock socket data. |
| 382 HttpStreamFactoryImpl::JobFactory default_job_factory_; |
| 383 }; |
| 384 |
| 385 INSTANTIATE_TEST_CASE_P( |
| 386 /* no prefix */, |
| 387 JobControllerReconsiderProxyAfterErrorTest, |
| 388 ::testing::Combine(::testing::Bool(), |
| 389 testing::ValuesIn(proxy_test_mock_errors))); |
| 390 |
| 391 TEST_P(JobControllerReconsiderProxyAfterErrorTest, ReconsiderProxyAfterError) { |
| 392 const bool set_alternative_proxy_server = ::testing::get<0>(GetParam()); |
| 393 const int mock_error = ::testing::get<1>(GetParam()); |
| 394 std::unique_ptr<ProxyService> proxy_service = |
| 395 ProxyService::CreateFixedFromPacResult( |
| 396 "HTTPS badproxy:99; HTTPS badfallbackproxy:98; DIRECT"); |
| 397 std::unique_ptr<TestProxyDelegate> test_proxy_delegate = |
| 398 base::MakeUnique<TestProxyDelegate>(); |
| 399 TestProxyDelegate* test_proxy_delegate_raw = test_proxy_delegate.get(); |
| 400 |
| 401 // Before starting the test, verify that there are no proxies marked as bad. |
| 402 ASSERT_TRUE(proxy_service->proxy_retry_info().empty()) << mock_error; |
| 403 |
| 404 StaticSocketDataProvider socket_data_proxy_main_job; |
| 405 socket_data_proxy_main_job.set_connect_data(MockConnect(ASYNC, mock_error)); |
| 406 session_deps_.socket_factory->AddSocketDataProvider( |
| 407 &socket_data_proxy_main_job); |
| 408 |
| 409 StaticSocketDataProvider socket_data_proxy_alternate_job; |
| 410 if (set_alternative_proxy_server) { |
| 411 // Mock socket used by the QUIC job. |
| 412 socket_data_proxy_alternate_job.set_connect_data( |
| 413 MockConnect(ASYNC, mock_error)); |
| 414 session_deps_.socket_factory->AddSocketDataProvider( |
| 415 &socket_data_proxy_alternate_job); |
| 416 test_proxy_delegate->set_alternative_proxy_server( |
| 417 ProxyServer::FromPacString("QUIC badproxy:99")); |
| 418 } |
| 419 |
| 420 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 421 |
| 422 // When retrying the job using the second proxy (badFallback:98), |
| 423 // alternative job must not be created. So, socket data for only the |
| 424 // main job is needed. |
| 425 StaticSocketDataProvider socket_data_proxy_main_job_2; |
| 426 socket_data_proxy_main_job_2.set_connect_data(MockConnect(ASYNC, mock_error)); |
| 427 session_deps_.socket_factory->AddSocketDataProvider( |
| 428 &socket_data_proxy_main_job_2); |
| 429 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 430 |
| 431 // First request would use DIRECT, and succeed. |
| 432 StaticSocketDataProvider socket_data_direct_first_request; |
| 433 socket_data_direct_first_request.set_connect_data(MockConnect(ASYNC, OK)); |
| 434 session_deps_.socket_factory->AddSocketDataProvider( |
| 435 &socket_data_direct_first_request); |
| 436 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 437 |
| 438 // Second request would use DIRECT, and succeed. |
| 439 StaticSocketDataProvider socket_data_direct_second_request; |
| 440 socket_data_direct_second_request.set_connect_data(MockConnect(ASYNC, OK)); |
| 441 session_deps_.socket_factory->AddSocketDataProvider( |
| 442 &socket_data_direct_second_request); |
| 443 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 444 |
| 445 // Now request a stream. It should succeed using the DIRECT. |
| 446 HttpRequestInfo request_info; |
| 447 request_info.method = "GET"; |
| 448 request_info.url = GURL("http://www.example.com"); |
| 449 |
| 450 Initialize(std::move(proxy_service), std::move(test_proxy_delegate)); |
| 451 EXPECT_EQ(set_alternative_proxy_server, |
| 452 test_proxy_delegate_raw->alternative_proxy_server().is_quic()); |
| 453 |
| 454 // Start two requests. The first request should consume data from |
| 455 // |socket_data_proxy_main_job|, |
| 456 // |socket_data_proxy_alternate_job| and |
| 457 // |socket_data_direct_first_request|. The second request should consume |
| 458 // data from |socket_data_direct_second_request|. |
| 459 |
| 460 for (size_t i = 0; i < 2; ++i) { |
| 461 ProxyInfo used_proxy_info; |
| 462 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 463 .Times(1) |
| 464 .WillOnce(DoAll(::testing::SaveArg<1>(&used_proxy_info), |
| 465 Invoke(DeleteHttpStreamPointer))); |
| 466 |
| 467 std::unique_ptr<HttpStreamRequest> request = |
| 468 CreateJobController(request_info); |
| 469 |
| 470 base::RunLoop().RunUntilIdle(); |
| 471 // The proxy that failed should now be known to the proxy_service as |
| 472 // bad. |
| 473 const ProxyRetryInfoMap retry_info = |
| 474 session_->proxy_service()->proxy_retry_info(); |
| 475 EXPECT_EQ(2u, retry_info.size()) << mock_error; |
| 476 EXPECT_NE(retry_info.end(), retry_info.find("https://badproxy:99")); |
| 477 EXPECT_NE(retry_info.end(), retry_info.find("https://badfallbackproxy:98")); |
| 478 |
| 479 // Verify that request was fetched without proxy. |
| 480 EXPECT_TRUE(used_proxy_info.is_direct()); |
| 481 |
| 482 // If alternative proxy server was specified, it should have been marked |
| 483 // as invalid so that it is not used for subsequent requests. |
| 484 EXPECT_FALSE( |
| 485 test_proxy_delegate_raw->alternative_proxy_server().is_valid()); |
| 486 |
| 487 if (set_alternative_proxy_server) { |
| 488 // GetAlternativeProxy should be called only once for the first |
| 489 // request. |
| 490 EXPECT_EQ(1, |
| 491 test_proxy_delegate_raw->get_alternative_proxy_invocations()); |
| 492 } else { |
| 493 // Alternative proxy server job is never started. So, ProxyDelegate is |
| 494 // queried once per request. |
| 495 EXPECT_EQ(2, |
| 496 test_proxy_delegate_raw->get_alternative_proxy_invocations()); |
| 497 } |
| 498 } |
| 499 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 500 } |
| 501 |
| 502 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 503 OnStreamFailedWithNoAlternativeJob) { |
| 504 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 505 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
| 506 |
| 507 HttpRequestInfo request_info; |
| 508 request_info.method = "GET"; |
| 243 request_info.url = GURL("http://www.google.com"); | 509 request_info.url = GURL("http://www.google.com"); |
| 244 | 510 |
| 245 Initialize(request_info); | 511 Initialize(request_info); |
| 246 | 512 |
| 247 request_.reset( | 513 request_.reset( |
| 248 job_controller_->Start(request_info, &request_delegate_, nullptr, | 514 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 249 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 515 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 250 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 251 | 516 |
| 252 EXPECT_TRUE(job_controller_->main_job()); | 517 EXPECT_TRUE(job_controller_->main_job()); |
| 518 EXPECT_FALSE(job_controller_->alternative_job()); |
| 253 | 519 |
| 254 // There's no other alternative job. Thus when stream failed, it should | 520 // There's no other alternative job. Thus when stream failed, it should |
| 255 // notify Request of the stream failure. | 521 // notify Request of the stream failure. |
| 256 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 522 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 257 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 523 base::RunLoop().RunUntilIdle(); |
| 258 SSLConfig()); | |
| 259 } | 524 } |
| 260 | 525 |
| 261 TEST_F(HttpStreamFactoryImplJobControllerTest, | 526 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 262 OnStreamReadyWithNoAlternativeJob) { | 527 OnStreamReadyWithNoAlternativeJob) { |
| 263 ProxyConfig proxy_config; | 528 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 264 proxy_config.set_auto_detect(true); | 529 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
| 265 // Use asynchronous proxy resolver. | 530 |
| 266 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 267 new MockAsyncProxyResolverFactory(false); | |
| 268 session_deps_.proxy_service.reset( | |
| 269 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 270 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 271 HttpRequestInfo request_info; | 531 HttpRequestInfo request_info; |
| 272 request_info.method = "GET"; | 532 request_info.method = "GET"; |
| 273 request_info.url = GURL("http://www.google.com"); | 533 request_info.url = GURL("http://www.google.com"); |
| 274 | 534 |
| 275 Initialize(request_info); | 535 Initialize(request_info); |
| 276 | 536 |
| 277 request_.reset( | 537 request_.reset( |
| 278 job_controller_->Start(request_info, &request_delegate_, nullptr, | 538 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 279 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 539 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 280 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 281 | 540 |
| 282 // There's no other alternative job. Thus when a stream is ready, it should | 541 // There's no other alternative job. Thus when a stream is ready, it should |
| 283 // notify Request. | 542 // notify Request. |
| 284 HttpStream* http_stream = | 543 EXPECT_TRUE(job_controller_->main_job()); |
| 285 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 286 job_factory_.main_job()->SetStream(http_stream); | |
| 287 | 544 |
| 288 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 545 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 289 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 546 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 290 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 547 base::RunLoop().RunUntilIdle(); |
| 291 } | 548 } |
| 292 | 549 |
| 293 // Test we cancel Jobs correctly when the Request is explicitly canceled | 550 // Test we cancel Jobs correctly when the Request is explicitly canceled |
| 294 // before any Job is bound to Request. | 551 // before any Job is bound to Request. |
| 295 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 552 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 296 ProxyConfig proxy_config; | 553 // Use COLD_START to make the alt job pending. |
| 297 proxy_config.set_auto_detect(true); | 554 crypto_client_stream_factory_.set_handshake_mode( |
| 298 // Use asynchronous proxy resolver. | 555 MockCryptoClientStream::COLD_START); |
| 299 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 556 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 300 new MockAsyncProxyResolverFactory(false); | 557 quic_data_->AddRead(SYNCHRONOUS, OK); |
| 301 session_deps_.proxy_service.reset(new ProxyService( | |
| 302 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 303 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 304 | 558 |
| 559 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 560 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
| 305 HttpRequestInfo request_info; | 561 HttpRequestInfo request_info; |
| 306 request_info.method = "GET"; | 562 request_info.method = "GET"; |
| 307 request_info.url = GURL("https://www.google.com"); | 563 request_info.url = GURL("https://www.google.com"); |
| 308 | 564 |
| 309 Initialize(request_info); | 565 Initialize(request_info); |
| 310 url::SchemeHostPort server(request_info.url); | 566 url::SchemeHostPort server(request_info.url); |
| 311 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 567 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 312 SetAlternativeService(request_info, alternative_service); | 568 SetAlternativeService(request_info, alternative_service); |
| 313 | 569 |
| 314 request_.reset( | 570 request_.reset( |
| 315 job_controller_->Start(request_info, &request_delegate_, nullptr, | 571 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 316 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 572 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 317 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 318 EXPECT_TRUE(job_controller_->main_job()); | 573 EXPECT_TRUE(job_controller_->main_job()); |
| 319 EXPECT_TRUE(job_controller_->alternative_job()); | 574 EXPECT_TRUE(job_controller_->alternative_job()); |
| 320 | 575 |
| 321 // Reset the Request will cancel all the Jobs since there's no Job determined | 576 // Reset the Request will cancel all the Jobs since there's no Job determined |
| 322 // to serve Request yet and JobController will notify the factory to delete | 577 // to serve Request yet and JobController will notify the factory to delete |
| 323 // itself upon completion. | 578 // itself upon completion. |
| 324 request_.reset(); | 579 request_.reset(); |
| 325 VerifyBrokenAlternateProtocolMapping(request_info, false); | 580 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 326 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 581 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 327 } | 582 } |
| 328 | 583 |
| 329 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 584 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 330 ProxyConfig proxy_config; | 585 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 331 proxy_config.set_auto_detect(true); | 586 quic_data_->AddConnect(ASYNC, ERR_FAILED); |
| 332 // Use asynchronous proxy resolver. | 587 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 333 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 588 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
| 334 new MockAsyncProxyResolverFactory(false); | |
| 335 session_deps_.proxy_service.reset( | |
| 336 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 337 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 338 | 589 |
| 339 HttpRequestInfo request_info; | 590 HttpRequestInfo request_info; |
| 340 request_info.method = "GET"; | 591 request_info.method = "GET"; |
| 341 request_info.url = GURL("https://www.google.com"); | 592 request_info.url = GURL("https://www.google.com"); |
| 342 | 593 |
| 343 Initialize(request_info); | 594 Initialize(request_info); |
| 344 url::SchemeHostPort server(request_info.url); | 595 url::SchemeHostPort server(request_info.url); |
| 345 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 596 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 346 SetAlternativeService(request_info, alternative_service); | 597 SetAlternativeService(request_info, alternative_service); |
| 347 | 598 |
| 348 request_.reset( | 599 request_.reset( |
| 349 job_controller_->Start(request_info, &request_delegate_, nullptr, | 600 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 350 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 601 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 351 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 352 EXPECT_TRUE(job_controller_->main_job()); | 602 EXPECT_TRUE(job_controller_->main_job()); |
| 353 EXPECT_TRUE(job_controller_->alternative_job()); | 603 EXPECT_TRUE(job_controller_->alternative_job()); |
| 354 | 604 |
| 355 // We have the main job with unknown status when the alternative job is failed | |
| 356 // thus should not notify Request of the alternative job's failure. But should | |
| 357 // notify the main job to mark the alternative job failed. | |
| 358 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
| 359 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | |
| 360 SSLConfig()); | |
| 361 EXPECT_TRUE(!job_controller_->alternative_job()); | |
| 362 EXPECT_TRUE(job_controller_->main_job()); | |
| 363 | |
| 364 // The failure of second Job should be reported to Request as there's no more | 605 // The failure of second Job should be reported to Request as there's no more |
| 365 // pending Job to serve the Request. | 606 // pending Job to serve the Request. |
| 366 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 607 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
| 367 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 608 base::RunLoop().RunUntilIdle(); |
| 368 SSLConfig()); | |
| 369 VerifyBrokenAlternateProtocolMapping(request_info, false); | 609 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 610 request_.reset(); |
| 611 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 370 } | 612 } |
| 371 | 613 |
| 372 TEST_F(HttpStreamFactoryImplJobControllerTest, | 614 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 373 AltJobFailsAfterMainJobSucceeds) { | 615 AltJobFailsAfterMainJobSucceeds) { |
| 374 ProxyConfig proxy_config; | 616 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 375 proxy_config.set_auto_detect(true); | 617 quic_data_->AddRead(ASYNC, ERR_FAILED); |
| 376 // Use asynchronous proxy resolver. | 618 crypto_client_stream_factory_.set_handshake_mode( |
| 377 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 619 MockCryptoClientStream::COLD_START); |
| 378 new MockAsyncProxyResolverFactory(false); | 620 |
| 379 session_deps_.proxy_service.reset( | 621 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 380 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 622 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 381 base::WrapUnique(proxy_resolver_factory), nullptr)); | 623 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(SYNCHRONOUS, OK); |
| 624 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 382 | 625 |
| 383 HttpRequestInfo request_info; | 626 HttpRequestInfo request_info; |
| 384 request_info.method = "GET"; | 627 request_info.method = "GET"; |
| 385 request_info.url = GURL("https://www.google.com"); | 628 request_info.url = GURL("https://www.google.com"); |
| 386 | 629 |
| 387 Initialize(request_info); | 630 Initialize(request_info); |
| 388 url::SchemeHostPort server(request_info.url); | 631 url::SchemeHostPort server(request_info.url); |
| 389 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 632 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 390 SetAlternativeService(request_info, alternative_service); | 633 SetAlternativeService(request_info, alternative_service); |
| 391 | 634 |
| 392 request_.reset( | 635 request_.reset( |
| 393 job_controller_->Start(request_info, &request_delegate_, nullptr, | 636 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 394 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 637 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 395 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 396 EXPECT_TRUE(job_controller_->main_job()); | 638 EXPECT_TRUE(job_controller_->main_job()); |
| 397 EXPECT_TRUE(job_controller_->alternative_job()); | 639 EXPECT_TRUE(job_controller_->alternative_job()); |
| 398 | 640 |
| 399 // Main job succeeds, starts serving Request and it should report status | 641 // Main job succeeds, starts serving Request and it should report status |
| 400 // to Request. The alternative job will mark the main job complete and gets | 642 // to Request. The alternative job will mark the main job complete and gets |
| 401 // orphaned. | 643 // orphaned. |
| 402 HttpStream* http_stream = | 644 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 403 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 404 job_factory_.main_job()->SetStream(http_stream); | |
| 405 | |
| 406 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 407 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 645 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 408 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
| 409 | |
| 410 // JobController shouldn't report the status of second job as request | 646 // JobController shouldn't report the status of second job as request |
| 411 // is already successfully served. | 647 // is already successfully served. |
| 412 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 648 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 413 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 649 |
| 414 SSLConfig()); | 650 base::RunLoop().RunUntilIdle(); |
| 415 | 651 |
| 416 VerifyBrokenAlternateProtocolMapping(request_info, true); | 652 VerifyBrokenAlternateProtocolMapping(request_info, true); |
| 417 // Reset the request as it's been successfully served. | 653 // Reset the request as it's been successfully served. |
| 418 request_.reset(); | 654 request_.reset(); |
| 419 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 655 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 420 } | 656 } |
| 421 | 657 |
| 422 // Tests that if alt job succeeds and main job is blocked, main job should be | 658 // Tests that if alt job succeeds and main job is blocked, main job should be |
| 423 // cancelled immediately. |request_| completion will clean up the JobController. | 659 // cancelled immediately. |request_| completion will clean up the JobController. |
| 424 // Regression test for crbug.com/678768. | 660 // Regression test for crbug.com/678768. |
| 425 TEST_F(HttpStreamFactoryImplJobControllerTest, | 661 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 426 AltJobSucceedsMainJobBlockedControllerDestroyed) { | 662 AltJobSucceedsMainJobBlockedControllerDestroyed) { |
| 427 ProxyConfig proxy_config; | 663 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 428 proxy_config.set_auto_detect(true); | 664 quic_data_->AddWrite(client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
| 429 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 665 quic_data_->AddRead(ASYNC, OK); |
| 430 new MockAsyncProxyResolverFactory(false); | 666 |
| 431 session_deps_.proxy_service.reset( | |
| 432 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 433 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 434 HttpRequestInfo request_info; | 667 HttpRequestInfo request_info; |
| 435 request_info.method = "GET"; | 668 request_info.method = "GET"; |
| 436 request_info.url = GURL("https://www.google.com"); | 669 request_info.url = GURL("https://www.google.com"); |
| 437 | 670 |
| 438 Initialize(request_info); | 671 Initialize(request_info); |
| 439 | 672 |
| 440 url::SchemeHostPort server(request_info.url); | 673 url::SchemeHostPort server(request_info.url); |
| 441 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 674 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 442 SetAlternativeService(request_info, alternative_service); | 675 SetAlternativeService(request_info, alternative_service); |
| 443 request_.reset( | 676 request_.reset( |
| 444 job_controller_->Start(request_info, &request_delegate_, nullptr, | 677 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 445 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 678 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 446 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 447 EXPECT_TRUE(job_controller_->main_job()); | 679 EXPECT_TRUE(job_controller_->main_job()); |
| 448 EXPECT_TRUE(job_controller_->alternative_job()); | 680 EXPECT_TRUE(job_controller_->alternative_job()); |
| 449 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 681 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 450 | 682 |
| 451 // |alternative_job| succeeds and should report status to Request. | 683 // |alternative_job| succeeds and should report status to |request_delegate_|. |
| 452 HttpStream* http_stream = | 684 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 453 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 454 job_factory_.alternative_job()->SetStream(http_stream); | |
| 455 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 456 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 685 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 457 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 686 |
| 687 base::RunLoop().RunUntilIdle(); |
| 458 | 688 |
| 459 EXPECT_FALSE(job_controller_->main_job()); | 689 EXPECT_FALSE(job_controller_->main_job()); |
| 460 EXPECT_TRUE(job_controller_->alternative_job()); | 690 EXPECT_TRUE(job_controller_->alternative_job()); |
| 461 | 691 |
| 462 // Invoke OnRequestComplete() which should delete |job_controller_| from | 692 // Invoke OnRequestComplete() which should delete |job_controller_| from |
| 463 // |factory_|. | 693 // |factory_|. |
| 464 request_.reset(); | 694 request_.reset(); |
| 465 VerifyBrokenAlternateProtocolMapping(request_info, false); | 695 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 466 // This fails without the fix for crbug.com/678768. | 696 // This fails without the fix for crbug.com/678768. |
| 467 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 697 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 468 } | 698 } |
| 469 | 699 |
| 470 // Tests that if an orphaned job completes after |request_| is gone, | 700 // Tests that if an orphaned job completes after |request_| is gone, |
| 471 // JobController will be cleaned up. | 701 // JobController will be cleaned up. |
| 472 TEST_F(HttpStreamFactoryImplJobControllerTest, | 702 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 473 OrphanedJobCompletesControllerDestroyed) { | 703 OrphanedJobCompletesControllerDestroyed) { |
| 474 ProxyConfig proxy_config; | 704 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 475 proxy_config.set_auto_detect(true); | 705 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 476 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 706 // Use cold start and complete alt job manually. |
| 477 new MockAsyncProxyResolverFactory(false); | 707 crypto_client_stream_factory_.set_handshake_mode( |
| 478 session_deps_.proxy_service.reset( | 708 MockCryptoClientStream::COLD_START); |
| 479 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 709 |
| 480 base::WrapUnique(proxy_resolver_factory), nullptr)); | 710 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 711 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 712 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 713 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 714 |
| 481 HttpRequestInfo request_info; | 715 HttpRequestInfo request_info; |
| 482 request_info.method = "GET"; | 716 request_info.method = "GET"; |
| 483 request_info.url = GURL("https://www.google.com"); | 717 request_info.url = GURL("https://www.google.com"); |
| 484 | 718 |
| 485 Initialize(request_info); | 719 Initialize(request_info); |
| 486 | 720 |
| 487 url::SchemeHostPort server(request_info.url); | 721 url::SchemeHostPort server(request_info.url); |
| 488 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 722 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 489 SetAlternativeService(request_info, alternative_service); | 723 SetAlternativeService(request_info, alternative_service); |
| 490 // Hack to use different URL for the main job to help differentiate the proxy | 724 |
| 491 // requests. | |
| 492 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
| 493 request_.reset( | 725 request_.reset( |
| 494 job_controller_->Start(request_info, &request_delegate_, nullptr, | 726 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 495 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 727 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 496 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 497 EXPECT_TRUE(job_controller_->main_job()); | 728 EXPECT_TRUE(job_controller_->main_job()); |
| 498 EXPECT_TRUE(job_controller_->alternative_job()); | 729 EXPECT_TRUE(job_controller_->alternative_job()); |
| 499 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 730 // main job should not be blocked because alt job returned ERR_IO_PENDING. |
| 731 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 732 |
| 733 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 734 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 500 | 735 |
| 501 // Complete main job now. | 736 // Complete main job now. |
| 502 MockAsyncProxyResolver resolver; | 737 base::RunLoop().RunUntilIdle(); |
| 503 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 504 net::OK, &resolver); | |
| 505 int main_job_request_id = | |
| 506 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
| 507 | 738 |
| 508 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
| 509 "result1:80"); | |
| 510 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
| 511 | |
| 512 HttpStream* http_stream = | |
| 513 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 514 job_factory_.main_job()->SetStream(http_stream); | |
| 515 | |
| 516 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 517 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 518 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
| 519 // Invoke OnRequestComplete() which should not delete |job_controller_| from | 739 // Invoke OnRequestComplete() which should not delete |job_controller_| from |
| 520 // |factory_| because alt job is yet to finish. | 740 // |factory_| because alt job is yet to finish. |
| 521 request_.reset(); | 741 request_.reset(); |
| 522 ASSERT_FALSE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 742 ASSERT_FALSE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 523 EXPECT_FALSE(job_controller_->main_job()); | 743 EXPECT_FALSE(job_controller_->main_job()); |
| 524 EXPECT_TRUE(job_controller_->alternative_job()); | 744 EXPECT_TRUE(job_controller_->alternative_job()); |
| 525 | 745 |
| 526 // Make |alternative_job| succeed. | 746 // Make |alternative_job| succeed. |
| 527 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80"); | 747 HttpStream* http_stream = |
| 528 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
| 529 HttpStream* http_stream2 = | |
| 530 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 748 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 531 job_factory_.alternative_job()->SetStream(http_stream2); | 749 job_factory_.alternative_job()->SetStream(http_stream); |
| 532 // This should not call request_delegate_::OnStreamReady. | 750 // This should not call request_delegate_::OnStreamReady. |
| 533 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 751 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
| 534 // Make sure that controller does not leak. | 752 // Make sure that controller does not leak. |
| 535 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 753 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 536 } | 754 } |
| 537 | 755 |
| 538 TEST_F(HttpStreamFactoryImplJobControllerTest, | 756 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 539 AltJobSucceedsAfterMainJobFailed) { | 757 AltJobSucceedsAfterMainJobFailed) { |
| 540 ProxyConfig proxy_config; | 758 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 541 proxy_config.set_auto_detect(true); | 759 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 542 // Use asynchronous proxy resolver. | 760 // Use cold start and complete alt job manually. |
| 543 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 761 crypto_client_stream_factory_.set_handshake_mode( |
| 544 new MockAsyncProxyResolverFactory(false); | 762 MockCryptoClientStream::COLD_START); |
| 545 session_deps_.proxy_service.reset( | 763 |
| 546 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 764 // One failed TCP connect. |
| 547 base::WrapUnique(proxy_resolver_factory), nullptr)); | 765 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 766 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, ERR_FAILED)); |
| 767 |
| 548 HttpRequestInfo request_info; | 768 HttpRequestInfo request_info; |
| 549 request_info.method = "GET"; | 769 request_info.method = "GET"; |
| 550 request_info.url = GURL("https://www.google.com"); | 770 request_info.url = GURL("https://www.google.com"); |
| 551 | 771 |
| 552 Initialize(request_info); | 772 Initialize(request_info); |
| 553 | 773 |
| 554 url::SchemeHostPort server(request_info.url); | 774 url::SchemeHostPort server(request_info.url); |
| 555 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 775 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 556 SetAlternativeService(request_info, alternative_service); | 776 SetAlternativeService(request_info, alternative_service); |
| 557 | 777 |
| 558 request_.reset( | |
| 559 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 560 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
| 561 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 562 EXPECT_TRUE(job_controller_->main_job()); | |
| 563 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 564 | |
| 565 // |main_job| fails but should not report status to Request. | 778 // |main_job| fails but should not report status to Request. |
| 566 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 779 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 567 | 780 |
| 568 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 781 request_.reset( |
| 569 SSLConfig()); | 782 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 783 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 784 EXPECT_TRUE(job_controller_->main_job()); |
| 785 EXPECT_TRUE(job_controller_->alternative_job()); |
| 570 | 786 |
| 571 // |alternative_job| succeeds and should report status to Request. | 787 base::RunLoop().RunUntilIdle(); |
| 788 |
| 789 // Make |alternative_job| succeed. |
| 572 HttpStream* http_stream = | 790 HttpStream* http_stream = |
| 573 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 791 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 574 job_factory_.alternative_job()->SetStream(http_stream); | |
| 575 | 792 |
| 576 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 793 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 577 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 794 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 795 |
| 796 job_factory_.alternative_job()->SetStream(http_stream); |
| 578 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 797 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
| 798 |
| 799 // |alternative_job| succeeds and should report status to Request. |
| 579 VerifyBrokenAlternateProtocolMapping(request_info, false); | 800 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 580 } | 801 } |
| 581 | 802 |
| 582 TEST_F(HttpStreamFactoryImplJobControllerTest, | 803 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 583 MainJobSucceedsAfterAltJobFailed) { | 804 MainJobSucceedsAfterAltJobFailed) { |
| 805 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 806 quic_data_->AddConnect(SYNCHRONOUS, ERR_FAILED); |
| 807 |
| 808 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 809 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 810 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 811 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 812 |
| 584 base::HistogramTester histogram_tester; | 813 base::HistogramTester histogram_tester; |
| 585 ProxyConfig proxy_config; | |
| 586 proxy_config.set_auto_detect(true); | |
| 587 // Use asynchronous proxy resolver. | |
| 588 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 589 new MockAsyncProxyResolverFactory(false); | |
| 590 session_deps_.proxy_service.reset( | |
| 591 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 592 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 593 HttpRequestInfo request_info; | 814 HttpRequestInfo request_info; |
| 594 request_info.method = "GET"; | 815 request_info.method = "GET"; |
| 595 request_info.url = GURL("https://www.google.com"); | 816 request_info.url = GURL("https://www.google.com"); |
| 596 | 817 |
| 597 Initialize(request_info); | 818 Initialize(request_info); |
| 598 | 819 |
| 599 url::SchemeHostPort server(request_info.url); | 820 url::SchemeHostPort server(request_info.url); |
| 600 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 821 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 601 SetAlternativeService(request_info, alternative_service); | 822 SetAlternativeService(request_info, alternative_service); |
| 602 | 823 |
| 603 request_.reset( | 824 request_.reset( |
| 604 job_controller_->Start(request_info, &request_delegate_, nullptr, | 825 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 605 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 826 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 606 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 607 EXPECT_TRUE(job_controller_->main_job()); | 827 EXPECT_TRUE(job_controller_->main_job()); |
| 608 EXPECT_TRUE(job_controller_->alternative_job()); | 828 EXPECT_TRUE(job_controller_->alternative_job()); |
| 609 | 829 |
| 610 // |alternative_job| fails but should not report status to Request. | 830 // |alternative_job| fails but should not report status to Request. |
| 611 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 831 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 832 // |main_job| succeeds and should report status to Request. |
| 833 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 834 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 612 | 835 |
| 613 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 836 base::RunLoop().RunUntilIdle(); |
| 614 SSLConfig()); | |
| 615 | |
| 616 // |main_job| succeeds and should report status to Request. | |
| 617 HttpStream* http_stream = | |
| 618 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 619 job_factory_.main_job()->SetStream(http_stream); | |
| 620 | |
| 621 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 622 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 623 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
| 624 | 837 |
| 625 // Verify that the alternate protocol is marked as broken. | 838 // Verify that the alternate protocol is marked as broken. |
| 626 VerifyBrokenAlternateProtocolMapping(request_info, true); | 839 VerifyBrokenAlternateProtocolMapping(request_info, true); |
| 627 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", -ERR_FAILED, | 840 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", -ERR_FAILED, |
| 628 1); | 841 1); |
| 629 } | 842 } |
| 630 | 843 |
| 631 // Verifies that if the alternative job fails due to a connection change event, | 844 // Verifies that if the alternative job fails due to a connection change event, |
| 632 // then the alternative service is not marked as broken. | 845 // then the alternative service is not marked as broken. |
| 633 TEST_F(HttpStreamFactoryImplJobControllerTest, | 846 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 634 MainJobSucceedsAfterConnectionChanged) { | 847 MainJobSucceedsAfterConnectionChanged) { |
| 848 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 849 quic_data_->AddConnect(SYNCHRONOUS, ERR_NETWORK_CHANGED); |
| 850 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 851 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 852 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 853 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 854 |
| 635 base::HistogramTester histogram_tester; | 855 base::HistogramTester histogram_tester; |
| 636 ProxyConfig proxy_config; | |
| 637 proxy_config.set_auto_detect(true); | |
| 638 // Use asynchronous proxy resolver. | |
| 639 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 640 new MockAsyncProxyResolverFactory(false); | |
| 641 session_deps_.proxy_service.reset( | |
| 642 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 643 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 644 session_deps_.quic_do_not_mark_as_broken_on_network_change = true; | 856 session_deps_.quic_do_not_mark_as_broken_on_network_change = true; |
| 645 | 857 |
| 646 HttpRequestInfo request_info; | 858 HttpRequestInfo request_info; |
| 647 request_info.method = "GET"; | 859 request_info.method = "GET"; |
| 648 request_info.url = GURL("https://www.google.com"); | 860 request_info.url = GURL("https://www.google.com"); |
| 649 Initialize(request_info); | 861 Initialize(request_info); |
| 650 | 862 |
| 651 url::SchemeHostPort server(request_info.url); | 863 url::SchemeHostPort server(request_info.url); |
| 652 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 864 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 653 SetAlternativeService(request_info, alternative_service); | 865 SetAlternativeService(request_info, alternative_service); |
| 654 | 866 |
| 655 request_.reset( | 867 request_.reset( |
| 656 job_controller_->Start(request_info, &request_delegate_, nullptr, | 868 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 657 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 869 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 658 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 659 EXPECT_TRUE(job_controller_->main_job()); | 870 EXPECT_TRUE(job_controller_->main_job()); |
| 660 EXPECT_TRUE(job_controller_->alternative_job()); | 871 EXPECT_TRUE(job_controller_->alternative_job()); |
| 661 | 872 |
| 662 // |alternative_job| fails but should not report status to Request. | 873 // |alternative_job| fails but should not report status to Request. |
| 663 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 874 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 664 | |
| 665 job_controller_->OnStreamFailed(job_factory_.alternative_job(), | |
| 666 ERR_NETWORK_CHANGED, SSLConfig()); | |
| 667 | |
| 668 // |main_job| succeeds and should report status to Request. | 875 // |main_job| succeeds and should report status to Request. |
| 669 HttpStream* http_stream = | 876 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 670 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 671 job_factory_.main_job()->SetStream(http_stream); | |
| 672 | |
| 673 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 674 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 877 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 675 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 878 base::RunLoop().RunUntilIdle(); |
| 676 | 879 |
| 677 // Verify that the alternate protocol is not marked as broken. | 880 // Verify that the alternate protocol is not marked as broken. |
| 678 VerifyBrokenAlternateProtocolMapping(request_info, false); | 881 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 679 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", | 882 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", |
| 680 -ERR_NETWORK_CHANGED, 1); | 883 -ERR_NETWORK_CHANGED, 1); |
| 681 } | 884 } |
| 682 | 885 |
| 683 // Regression test for crbug/621069. | 886 // Regression test for crbug/621069. |
| 684 // Get load state after main job fails and before alternative job succeeds. | 887 // Get load state after main job fails and before alternative job succeeds. |
| 685 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 888 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 686 ProxyConfig proxy_config; | 889 // Use COLD_START to complete alt job manually. |
| 687 proxy_config.set_auto_detect(true); | 890 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 688 // Use asynchronous proxy resolver. | 891 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 689 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 892 crypto_client_stream_factory_.set_handshake_mode( |
| 690 new MockAsyncProxyResolverFactory(false); | 893 MockCryptoClientStream::COLD_START); |
| 691 session_deps_.proxy_service.reset(new ProxyService( | 894 |
| 692 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 895 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 693 base::WrapUnique(proxy_resolver_factory), nullptr)); | 896 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
| 694 | 897 |
| 695 HttpRequestInfo request_info; | 898 HttpRequestInfo request_info; |
| 696 request_info.method = "GET"; | 899 request_info.method = "GET"; |
| 697 request_info.url = GURL("https://www.google.com"); | 900 request_info.url = GURL("https://www.google.com"); |
| 698 | 901 |
| 699 Initialize(request_info); | 902 Initialize(request_info); |
| 700 url::SchemeHostPort server(request_info.url); | 903 url::SchemeHostPort server(request_info.url); |
| 701 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 904 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 702 SetAlternativeService(request_info, alternative_service); | 905 SetAlternativeService(request_info, alternative_service); |
| 703 | 906 |
| 704 request_.reset( | 907 request_.reset( |
| 705 job_controller_->Start(request_info, &request_delegate_, nullptr, | 908 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 706 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 909 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 707 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 708 EXPECT_TRUE(job_controller_->main_job()); | 910 EXPECT_TRUE(job_controller_->main_job()); |
| 709 EXPECT_TRUE(job_controller_->alternative_job()); | 911 EXPECT_TRUE(job_controller_->alternative_job()); |
| 710 | 912 |
| 711 // |main_job| fails but should not report status to Request. | 913 // |main_job| fails but should not report status to Request. |
| 712 // The alternative job will mark the main job complete. | 914 // The alternative job will mark the main job complete. |
| 713 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 915 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 714 | 916 |
| 715 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 917 base::RunLoop().RunUntilIdle(); |
| 716 SSLConfig()); | |
| 717 | 918 |
| 718 // Controller should use alternative job to get load state. | 919 // Controller should use alternative job to get load state. |
| 719 job_controller_->GetLoadState(); | 920 job_controller_->GetLoadState(); |
| 720 | 921 |
| 721 // |alternative_job| succeeds and should report status to Request. | 922 // |alternative_job| succeeds and should report status to Request. |
| 722 HttpStream* http_stream = | 923 HttpStream* http_stream = |
| 723 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 924 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 724 job_factory_.alternative_job()->SetStream(http_stream); | 925 job_factory_.alternative_job()->SetStream(http_stream); |
| 725 | 926 |
| 726 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 927 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 727 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 928 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 728 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 929 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
| 729 } | 930 } |
| 730 | 931 |
| 731 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 932 TEST_F(HttpStreamFactoryImplJobControllerTest, ResumeMainJobWhenAltJobStalls) { |
| 732 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 933 // Use COLD_START to stall alt job. |
| 733 // to stall the alternative job and report to controller to maybe resume the | 934 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 734 // main job. | 935 quic_data_->AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 735 ProxyConfig proxy_config; | 936 crypto_client_stream_factory_.set_handshake_mode( |
| 736 proxy_config.set_auto_detect(true); | 937 MockCryptoClientStream::COLD_START); |
| 737 proxy_config.set_pac_mandatory(true); | 938 |
| 738 session_deps_.proxy_service.reset(new ProxyService( | 939 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 739 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 940 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 740 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 941 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 942 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 741 | 943 |
| 742 HttpRequestInfo request_info; | 944 HttpRequestInfo request_info; |
| 743 request_info.method = "GET"; | 945 request_info.method = "GET"; |
| 744 request_info.url = GURL("https://www.google.com"); | 946 request_info.url = GURL("https://www.google.com"); |
| 745 | 947 |
| 746 Initialize(request_info); | 948 Initialize(request_info); |
| 747 url::SchemeHostPort server(request_info.url); | 949 url::SchemeHostPort server(request_info.url); |
| 748 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 950 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 749 SetAlternativeService(request_info, alternative_service); | 951 SetAlternativeService(request_info, alternative_service); |
| 750 | 952 |
| 751 request_.reset( | 953 request_.reset( |
| 752 job_controller_->Start(request_info, &request_delegate_, nullptr, | 954 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 753 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 955 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 754 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 755 EXPECT_TRUE(job_controller_->main_job()); | 956 EXPECT_TRUE(job_controller_->main_job()); |
| 756 EXPECT_TRUE(job_controller_->alternative_job()); | 957 EXPECT_TRUE(job_controller_->alternative_job()); |
| 757 | 958 |
| 758 // Wait until OnStreamFailedCallback is executed on the alternative job. | 959 // Alt job is stalled and main job should complete successfully. |
| 759 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 960 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 961 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 962 |
| 760 base::RunLoop().RunUntilIdle(); | 963 base::RunLoop().RunUntilIdle(); |
| 761 } | 964 } |
| 762 | 965 |
| 763 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 966 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
| 764 HttpRequestInfo request_info; | 967 HttpRequestInfo request_info; |
| 765 request_info.method = "GET"; | 968 request_info.method = "GET"; |
| 766 request_info.url = GURL("https://www.google.com"); | 969 request_info.url = GURL("https://www.google.com"); |
| 767 | 970 |
| 768 // Using a restricted port 101 for QUIC should fail and the alternative job | 971 // Using a restricted port 101 for QUIC should fail and the alternative job |
| 769 // should post OnStreamFailedCall on the controller to resume the main job. | 972 // should post OnStreamFailedCall on the controller to resume the main job. |
| 770 Initialize(request_info); | 973 Initialize(request_info); |
| 771 | 974 |
| 772 url::SchemeHostPort server(request_info.url); | 975 url::SchemeHostPort server(request_info.url); |
| 773 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); | 976 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); |
| 774 SetAlternativeService(request_info, alternative_service); | 977 SetAlternativeService(request_info, alternative_service); |
| 775 | 978 |
| 776 request_.reset( | 979 request_.reset( |
| 777 job_controller_->Start(request_info, &request_delegate_, nullptr, | 980 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 778 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 981 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 779 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 780 | 982 |
| 781 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | 983 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); |
| 782 | 984 |
| 783 // Wait until OnStreamFailedCallback is executed on the alternative job. | 985 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 784 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 986 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 785 base::RunLoop().RunUntilIdle(); | 987 base::RunLoop().RunUntilIdle(); |
| 786 } | 988 } |
| 787 | 989 |
| 788 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
| 789 NoAvailableSpdySessionToResumeMainJob) { | |
| 790 // Test the alternative job is not resumed when the alternative job is | |
| 791 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, | |
| 792 // the latter part of this test tests controller resumes the main job | |
| 793 // when there's no SPDY session for the alternative job. | |
| 794 ProxyConfig proxy_config; | |
| 795 proxy_config.set_auto_detect(true); | |
| 796 // Use asynchronous proxy resolver. | |
| 797 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 798 new MockAsyncProxyResolverFactory(false); | |
| 799 session_deps_.proxy_service.reset( | |
| 800 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 801 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 802 | |
| 803 HangingResolver* host_resolver = new HangingResolver(); | |
| 804 session_deps_.host_resolver.reset(host_resolver); | |
| 805 session_deps_.host_resolver->set_synchronous_mode(false); | |
| 806 | |
| 807 HttpRequestInfo request_info; | |
| 808 request_info.method = "GET"; | |
| 809 request_info.url = GURL("https://www.google.com"); | |
| 810 | |
| 811 Initialize(request_info); | |
| 812 | |
| 813 // Set a SPDY alternative service for the server. | |
| 814 url::SchemeHostPort server(request_info.url); | |
| 815 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 816 SetAlternativeService(request_info, alternative_service); | |
| 817 // Hack to use different URL for the main job to help differentiate the proxy | |
| 818 // requests. | |
| 819 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
| 820 | |
| 821 request_.reset( | |
| 822 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 823 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
| 824 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 825 // Both jobs should be created but stalled as proxy resolution not completed. | |
| 826 EXPECT_TRUE(job_controller_->main_job()); | |
| 827 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 828 | |
| 829 MockAsyncProxyResolver resolver; | |
| 830 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 831 net::OK, &resolver); | |
| 832 | |
| 833 // Resolve proxy for the main job which then proceed to wait for the | |
| 834 // alternative job which is IO_PENDING. | |
| 835 int main_job_request_id = | |
| 836 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
| 837 | |
| 838 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
| 839 "result1:80"); | |
| 840 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
| 841 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
| 842 | |
| 843 // Resolve proxy for the alternative job to proceed to create a connection. | |
| 844 // Use hanging HostResolver to fail creation of a SPDY session for the | |
| 845 // alternative job. The alternative job will be IO_PENDING thus should resume | |
| 846 // the main job. | |
| 847 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
| 848 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
| 849 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 850 | |
| 851 base::RunLoop().RunUntilIdle(); | |
| 852 } | |
| 853 | |
| 854 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
| 855 NoAvailableQuicSessionToResumeMainJob) { | |
| 856 // Use failing HostResolver which is unable to resolve the host name for QUIC. | |
| 857 // No QUIC session is created and thus should resume the main job. | |
| 858 FailingHostResolver* host_resolver = new FailingHostResolver(); | |
| 859 session_deps_.host_resolver.reset(host_resolver); | |
| 860 | |
| 861 ProxyConfig proxy_config; | |
| 862 proxy_config.set_auto_detect(true); | |
| 863 // Use asynchronous proxy resolver. | |
| 864 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 865 new MockAsyncProxyResolverFactory(false); | |
| 866 session_deps_.proxy_service.reset( | |
| 867 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 868 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 869 | |
| 870 HttpRequestInfo request_info; | |
| 871 request_info.method = "GET"; | |
| 872 request_info.url = GURL("https://www.google.com"); | |
| 873 | |
| 874 Initialize(request_info); | |
| 875 url::SchemeHostPort server(request_info.url); | |
| 876 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 877 SetAlternativeService(request_info, alternative_service); | |
| 878 // Hack to use different URL for the main job to help differentiate the proxy | |
| 879 // requests. | |
| 880 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
| 881 | |
| 882 request_.reset( | |
| 883 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 884 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
| 885 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 886 EXPECT_TRUE(job_controller_->main_job()); | |
| 887 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 888 | |
| 889 MockAsyncProxyResolver resolver; | |
| 890 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 891 net::OK, &resolver); | |
| 892 | |
| 893 // Resolve proxy for the main job which then proceed to wait for the | |
| 894 // alternative job which is IO_PENDING. | |
| 895 int main_job_request_id = | |
| 896 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
| 897 | |
| 898 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
| 899 "result1:80"); | |
| 900 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
| 901 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
| 902 | |
| 903 // Resolve proxy for the alternative job to proceed to create a connection. | |
| 904 // Use failing HostResolver to fail creation of a QUIC session for the | |
| 905 // alternative job. The alternative job will thus resume the main job. | |
| 906 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80"); | |
| 907 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
| 908 | |
| 909 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 910 // Request shouldn't be notified as the main job is still pending status. | |
| 911 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
| 912 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 913 | |
| 914 base::RunLoop().RunUntilIdle(); | |
| 915 } | |
| 916 | |
| 917 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 990 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
| 918 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | 991 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; |
| 919 auto failing_resolver = base::MakeUnique<MockHostResolver>(); | 992 auto failing_resolver = base::MakeUnique<MockHostResolver>(); |
| 920 failing_resolver->set_ondemand_mode(true); | 993 failing_resolver->set_ondemand_mode(true); |
| 921 failing_resolver->rules()->AddSimulatedFailure("*google.com"); | 994 failing_resolver->rules()->AddSimulatedFailure("*google.com"); |
| 922 session_deps_.host_resolver = std::move(failing_resolver); | 995 session_deps_.host_resolver = std::move(failing_resolver); |
| 923 | 996 |
| 924 HttpRequestInfo request_info; | 997 HttpRequestInfo request_info; |
| 925 request_info.method = "GET"; | 998 request_info.method = "GET"; |
| 926 request_info.url = GURL("https://www.google.com"); | 999 request_info.url = GURL("https://www.google.com"); |
| 927 | 1000 |
| 928 Initialize(request_info); | 1001 Initialize(request_info); |
| 929 | 1002 |
| 930 // Enable delayed TCP and set time delay for waiting job. | 1003 // Enable delayed TCP and set time delay for waiting job. |
| 931 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 1004 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 932 quic_stream_factory->set_require_confirmation(false); | 1005 quic_stream_factory->set_require_confirmation(false); |
| 933 ServerNetworkStats stats1; | 1006 ServerNetworkStats stats1; |
| 934 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1007 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 935 session_->http_server_properties()->SetServerNetworkStats( | 1008 session_->http_server_properties()->SetServerNetworkStats( |
| 936 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 1009 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 937 | 1010 |
| 938 // Set a SPDY alternative service for the server. | |
| 939 url::SchemeHostPort server(request_info.url); | 1011 url::SchemeHostPort server(request_info.url); |
| 940 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1012 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 941 SetAlternativeService(request_info, alternative_service); | 1013 SetAlternativeService(request_info, alternative_service); |
| 942 | 1014 |
| 943 request_.reset( | 1015 request_.reset( |
| 944 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1016 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 945 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1017 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 946 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 947 EXPECT_TRUE(job_controller_->main_job()); | 1018 EXPECT_TRUE(job_controller_->main_job()); |
| 948 EXPECT_TRUE(job_controller_->alternative_job()); | 1019 EXPECT_TRUE(job_controller_->alternative_job()); |
| 949 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1020 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 950 | 1021 |
| 951 // The alternative job stalls as host resolution hangs when creating the QUIC | 1022 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 952 // request and controller should resume the main job after delay. | 1023 // request and controller should resume the main job after delay. |
| 953 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 1024 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
| 954 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1025 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 955 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 1026 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 956 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); | 1027 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 stats1.srtt = base::TimeDelta::FromSeconds(100); | 1073 stats1.srtt = base::TimeDelta::FromSeconds(100); |
| 1003 session_->http_server_properties()->SetServerNetworkStats( | 1074 session_->http_server_properties()->SetServerNetworkStats( |
| 1004 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 1075 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 1005 | 1076 |
| 1006 // Set a SPDY alternative service for the server. | 1077 // Set a SPDY alternative service for the server. |
| 1007 url::SchemeHostPort server(request_info.url); | 1078 url::SchemeHostPort server(request_info.url); |
| 1008 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1079 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 1009 SetAlternativeService(request_info, alternative_service); | 1080 SetAlternativeService(request_info, alternative_service); |
| 1010 | 1081 |
| 1011 request_.reset( | 1082 request_.reset( |
| 1012 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1083 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1013 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1084 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1014 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1015 EXPECT_TRUE(job_controller_->main_job()); | 1085 EXPECT_TRUE(job_controller_->main_job()); |
| 1016 EXPECT_TRUE(job_controller_->alternative_job()); | 1086 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1017 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1087 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1018 | 1088 |
| 1019 // The alternative job stalls as host resolution hangs when creating the QUIC | 1089 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 1020 // request and controller should resume the main job after delay. | 1090 // request and controller should resume the main job after delay. |
| 1021 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 1091 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
| 1022 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1092 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 1023 | 1093 |
| 1024 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 1094 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 | 1132 |
| 1063 // Set a SPDY alternative service for the server. | 1133 // Set a SPDY alternative service for the server. |
| 1064 url::SchemeHostPort server(request_info.url); | 1134 url::SchemeHostPort server(request_info.url); |
| 1065 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1135 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 1066 SetAlternativeService(request_info, alternative_service); | 1136 SetAlternativeService(request_info, alternative_service); |
| 1067 | 1137 |
| 1068 // The alternative job stalls as host resolution hangs when creating the QUIC | 1138 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 1069 // request and controller should resume the main job with delay. | 1139 // request and controller should resume the main job with delay. |
| 1070 // OnStreamFailed should resume the main job immediately. | 1140 // OnStreamFailed should resume the main job immediately. |
| 1071 request_.reset( | 1141 request_.reset( |
| 1072 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1142 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1073 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1143 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1074 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1075 EXPECT_TRUE(job_controller_->main_job()); | 1144 EXPECT_TRUE(job_controller_->main_job()); |
| 1076 EXPECT_TRUE(job_controller_->alternative_job()); | 1145 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1077 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1146 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1078 | 1147 |
| 1079 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 1148 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
| 1080 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1149 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 1081 | 1150 |
| 1082 // |alternative_job| fails but should not report status to Request. | 1151 // |alternative_job| fails but should not report status to Request. |
| 1083 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 1152 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 1084 // Now unblock Resolver to fail the alternate job. | 1153 // Now unblock Resolver to fail the alternate job. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1108 HangingResolver* resolver = new HangingResolver(); | 1177 HangingResolver* resolver = new HangingResolver(); |
| 1109 session_deps_.host_resolver.reset(resolver); | 1178 session_deps_.host_resolver.reset(resolver); |
| 1110 | 1179 |
| 1111 HttpRequestInfo request_info; | 1180 HttpRequestInfo request_info; |
| 1112 request_info.method = "GET"; | 1181 request_info.method = "GET"; |
| 1113 request_info.url = GURL("https://mail.example.org/"); | 1182 request_info.url = GURL("https://mail.example.org/"); |
| 1114 Initialize(request_info); | 1183 Initialize(request_info); |
| 1115 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1184 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 1116 | 1185 |
| 1117 request_.reset( | 1186 request_.reset( |
| 1118 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1187 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1119 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1188 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1120 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1121 EXPECT_TRUE(job_controller_->main_job()); | 1189 EXPECT_TRUE(job_controller_->main_job()); |
| 1122 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 1190 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 1123 EXPECT_FALSE(job_controller_->alternative_job()); | 1191 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1124 | 1192 |
| 1125 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1193 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 1126 base::RunLoop().RunUntilIdle(); | 1194 base::RunLoop().RunUntilIdle(); |
| 1127 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1195 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 1128 } | 1196 } |
| 1129 | 1197 |
| 1130 // Verifies that the alternative proxy server job is not created if the main job | 1198 // Verifies that the alternative proxy server job is not created if the main job |
| 1131 // does not fetch the resource through a proxy. | 1199 // does not fetch the resource through a proxy. |
| 1132 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { | 1200 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
| 1133 // Using hanging resolver will cause the alternative job to hang indefinitely. | 1201 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 1134 HangingResolver* resolver = new HangingResolver(); | 1202 HangingResolver* resolver = new HangingResolver(); |
| 1135 session_deps_.host_resolver.reset(resolver); | 1203 session_deps_.host_resolver.reset(resolver); |
| 1136 | 1204 |
| 1137 HttpRequestInfo request_info; | 1205 HttpRequestInfo request_info; |
| 1138 request_info.method = "GET"; | 1206 request_info.method = "GET"; |
| 1139 request_info.url = GURL("http://mail.example.org/"); | 1207 request_info.url = GURL("http://mail.example.org/"); |
| 1140 | 1208 |
| 1141 Initialize(request_info); | 1209 Initialize(request_info); |
| 1142 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1210 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 1143 | 1211 |
| 1144 request_.reset( | 1212 request_.reset( |
| 1145 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1213 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1146 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1214 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1147 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1148 EXPECT_TRUE(job_controller_->main_job()); | 1215 EXPECT_TRUE(job_controller_->main_job()); |
| 1149 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 1216 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 1150 EXPECT_FALSE(job_controller_->alternative_job()); | 1217 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1151 | 1218 |
| 1152 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1219 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 1153 base::RunLoop().RunUntilIdle(); | 1220 base::RunLoop().RunUntilIdle(); |
| 1154 | 1221 |
| 1155 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1222 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 1156 } | 1223 } |
| 1157 | 1224 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1178 | 1245 |
| 1179 // Enable delayed TCP and set time delay for waiting job. | 1246 // Enable delayed TCP and set time delay for waiting job. |
| 1180 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 1247 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 1181 quic_stream_factory->set_require_confirmation(false); | 1248 quic_stream_factory->set_require_confirmation(false); |
| 1182 ServerNetworkStats stats1; | 1249 ServerNetworkStats stats1; |
| 1183 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1250 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 1184 session_->http_server_properties()->SetServerNetworkStats( | 1251 session_->http_server_properties()->SetServerNetworkStats( |
| 1185 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 1252 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 1186 | 1253 |
| 1187 request_.reset( | 1254 request_.reset( |
| 1188 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1255 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1189 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1256 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1190 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1191 EXPECT_TRUE(job_controller_->main_job()); | 1257 EXPECT_TRUE(job_controller_->main_job()); |
| 1192 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1258 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1193 EXPECT_TRUE(job_controller_->alternative_job()); | 1259 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1194 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 1260 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 1195 | 1261 |
| 1196 // Alternative proxy server job will start in the next message loop. | 1262 // Alternative proxy server job will start in the next message loop. |
| 1197 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1263 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 1198 | 1264 |
| 1199 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1265 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 1200 // Run tasks with no remaining delay, this will start the alternative proxy | 1266 // Run tasks with no remaining delay, this will start the alternative proxy |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1215 EXPECT_FALSE(test_task_runner->HasPendingTask()); | 1281 EXPECT_FALSE(test_task_runner->HasPendingTask()); |
| 1216 | 1282 |
| 1217 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can | 1283 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can |
| 1218 // be cleaned up. | 1284 // be cleaned up. |
| 1219 session_deps_.host_resolver->ResolveAllPending(); | 1285 session_deps_.host_resolver->ResolveAllPending(); |
| 1220 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1286 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 1221 test_task_runner->FastForwardUntilNoTasksRemain(); | 1287 test_task_runner->FastForwardUntilNoTasksRemain(); |
| 1222 EXPECT_FALSE(job_controller_->alternative_job()); | 1288 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1223 } | 1289 } |
| 1224 | 1290 |
| 1225 // Verifies that the alternative proxy server job fails immediately, and the | 1291 // Verifies that if the alternative proxy server job fails immediately, the |
| 1226 // main job is not blocked. | 1292 // main job is not blocked. |
| 1227 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { | 1293 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { |
| 1294 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 1295 quic_data_->AddConnect(SYNCHRONOUS, ERR_FAILED); |
| 1296 // No TCP data because HttpStreamFactoryImpl::Job::Resume() is mocked out. |
| 1297 |
| 1228 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | 1298 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; |
| 1229 // Using failing resolver will cause the alternative job to fail. | |
| 1230 FailingHostResolver* resolver = new FailingHostResolver(); | |
| 1231 session_deps_.host_resolver.reset(resolver); | |
| 1232 | |
| 1233 UseAlternativeProxy(); | 1299 UseAlternativeProxy(); |
| 1234 | 1300 |
| 1235 HttpRequestInfo request_info; | 1301 HttpRequestInfo request_info; |
| 1236 request_info.method = "GET"; | 1302 request_info.method = "GET"; |
| 1237 request_info.url = GURL("http://mail.example.org/"); | 1303 request_info.url = GURL("http://mail.example.org/"); |
| 1238 Initialize(request_info); | 1304 Initialize(request_info); |
| 1239 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1305 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 1240 | 1306 |
| 1241 // Enable delayed TCP and set time delay for waiting job. | 1307 // Enable delayed TCP and set time delay for waiting job. |
| 1242 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 1308 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 1243 quic_stream_factory->set_require_confirmation(false); | 1309 quic_stream_factory->set_require_confirmation(false); |
| 1244 ServerNetworkStats stats1; | 1310 ServerNetworkStats stats1; |
| 1245 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | 1311 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); |
| 1246 session_->http_server_properties()->SetServerNetworkStats( | 1312 session_->http_server_properties()->SetServerNetworkStats( |
| 1247 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 1313 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 1248 | 1314 |
| 1249 request_.reset( | 1315 request_.reset( |
| 1250 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1316 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1251 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1317 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1252 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1253 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1318 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1254 EXPECT_TRUE(job_controller_->alternative_job()); | 1319 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1255 | 1320 |
| 1256 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1321 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
| 1257 | 1322 |
| 1258 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | 1323 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
| 1259 | 1324 |
| 1260 // Since the alternative proxy server job is started in the next message loop, | 1325 // Since the alternative proxy server job is started in the next message loop, |
| 1261 // the main job would remain blocked until the alternative proxy starts, and | 1326 // the main job would remain blocked until the alternative proxy starts, and |
| 1262 // fails. | 1327 // fails. |
| 1263 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 1328 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 1264 | 1329 |
| 1265 // Run tasks with no remaining delay. | 1330 // Run tasks with no remaining delay. |
| 1266 test_task_runner->RunUntilIdle(); | 1331 test_task_runner->RunUntilIdle(); |
| 1267 | 1332 |
| 1268 EXPECT_FALSE(job_controller_->alternative_job()); | 1333 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1269 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1334 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1270 // Since the main job did not complete successfully, the alternative proxy | 1335 // The alternative proxy server should be marked as bad. |
| 1271 // server should not be marked as bad. | 1336 EXPECT_FALSE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 1272 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
| 1273 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1337 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 1274 EXPECT_FALSE(test_task_runner->HasPendingTask()); | 1338 EXPECT_FALSE(test_task_runner->HasPendingTask()); |
| 1275 } | 1339 } |
| 1276 | 1340 |
| 1277 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1341 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 1278 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { | 1342 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { |
| 1279 base::HistogramTester histogram_tester; | 1343 base::HistogramTester histogram_tester; |
| 1280 | 1344 |
| 1281 UseAlternativeProxy(); | 1345 UseAlternativeProxy(); |
| 1282 | 1346 |
| 1283 HttpRequestInfo request_info; | 1347 HttpRequestInfo request_info; |
| 1284 request_info.method = "GET"; | 1348 request_info.method = "GET"; |
| 1285 request_info.url = GURL("http://www.google.com"); | 1349 request_info.url = GURL("http://www.google.com"); |
| 1286 Initialize(request_info); | 1350 Initialize(request_info); |
| 1287 | 1351 |
| 1288 url::SchemeHostPort server(request_info.url); | 1352 url::SchemeHostPort server(request_info.url); |
| 1289 | 1353 |
| 1290 request_.reset( | 1354 request_.reset( |
| 1291 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1355 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1292 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1356 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1293 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1294 EXPECT_TRUE(job_controller_->main_job()); | 1357 EXPECT_TRUE(job_controller_->main_job()); |
| 1295 EXPECT_TRUE(job_controller_->alternative_job()); | 1358 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1296 | 1359 |
| 1297 // Main job succeeds, starts serving Request and it should report status | 1360 // Main job succeeds, starts serving Request and it should report status |
| 1298 // to Request. The alternative job will mark the main job complete and gets | 1361 // to Request. The alternative job will mark the main job complete and gets |
| 1299 // orphaned. | 1362 // orphaned. |
| 1300 HttpStream* http_stream = | 1363 HttpStream* http_stream = |
| 1301 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 1364 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 1302 job_factory_.main_job()->SetStream(http_stream); | 1365 job_factory_.main_job()->SetStream(http_stream); |
| 1303 | 1366 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1316 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1379 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1317 | 1380 |
| 1318 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", | 1381 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", |
| 1319 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, | 1382 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, |
| 1320 1); | 1383 1); |
| 1321 } | 1384 } |
| 1322 | 1385 |
| 1323 // When preconnect to a H2 supported server, only 1 connection is opened. | 1386 // When preconnect to a H2 supported server, only 1 connection is opened. |
| 1324 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1387 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 1325 PreconnectMultipleStreamsToH2Server) { | 1388 PreconnectMultipleStreamsToH2Server) { |
| 1326 MockRead reads[] = {MockRead(ASYNC, OK)}; | 1389 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 1327 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); | 1390 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
| 1328 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 1329 | |
| 1330 SetPreconnect(); | 1391 SetPreconnect(); |
| 1331 | 1392 |
| 1332 HttpRequestInfo request_info; | 1393 HttpRequestInfo request_info; |
| 1333 request_info.method = "GET"; | 1394 request_info.method = "GET"; |
| 1334 request_info.url = GURL("http://www.example.com"); | 1395 request_info.url = GURL("http://www.example.com"); |
| 1335 Initialize(request_info); | 1396 Initialize(request_info); |
| 1336 | 1397 |
| 1337 url::SchemeHostPort server(request_info.url); | 1398 url::SchemeHostPort server(request_info.url); |
| 1338 | 1399 |
| 1339 // Sets server support Http/2. | 1400 // Sets server support Http/2. |
| 1340 session_->http_server_properties()->SetSupportsSpdy(server, true); | 1401 session_->http_server_properties()->SetSupportsSpdy(server, true); |
| 1341 | 1402 |
| 1342 job_controller_->Preconnect(/*num_streams=*/5, request_info, SSLConfig(), | 1403 job_controller_->Preconnect(/*num_streams=*/5); |
| 1343 SSLConfig()); | |
| 1344 // Only one job is started. | 1404 // Only one job is started. |
| 1345 EXPECT_TRUE(job_controller_->main_job()); | 1405 EXPECT_TRUE(job_controller_->main_job()); |
| 1346 EXPECT_FALSE(job_controller_->alternative_job()); | 1406 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1347 // There is only 1 connect even though multiple streams were requested. | 1407 // There is only 1 connect even though multiple streams were requested. |
| 1348 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( | 1408 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( |
| 1349 job_controller_->main_job())); | 1409 job_controller_->main_job())); |
| 1350 | 1410 |
| 1351 base::RunLoop().RunUntilIdle(); | 1411 base::RunLoop().RunUntilIdle(); |
| 1352 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1412 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1353 } | 1413 } |
| 1354 | 1414 |
| 1355 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry | 1415 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry |
| 1356 : public HttpStreamFactoryImplJobControllerTest, | 1416 : public HttpStreamFactoryImplJobControllerTest, |
| 1357 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; | 1417 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; |
| 1358 | 1418 |
| 1359 INSTANTIATE_TEST_CASE_P( | 1419 INSTANTIATE_TEST_CASE_P( |
| 1360 /* no prefix */, | 1420 /* no prefix */, |
| 1361 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1421 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
| 1362 ::testing::Combine(::testing::Bool(), ::testing::Bool())); | 1422 ::testing::Combine(::testing::Bool(), ::testing::Bool())); |
| 1363 | 1423 |
| 1364 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1424 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
| 1365 DisableIPBasedPoolingAndAlternativeServices) { | 1425 DisableIPBasedPoolingAndAlternativeServices) { |
| 1366 const bool enable_ip_based_pooling = ::testing::get<0>(GetParam()); | 1426 const bool enable_ip_based_pooling = ::testing::get<0>(GetParam()); |
| 1367 const bool enable_alternative_services = ::testing::get<1>(GetParam()); | 1427 const bool enable_alternative_services = ::testing::get<1>(GetParam()); |
| 1428 if (enable_alternative_services) { |
| 1429 quic_data_ = base::MakeUnique<test::MockQuicData>(); |
| 1430 quic_data_->AddConnect(SYNCHRONOUS, OK); |
| 1431 quic_data_->AddWrite(client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
| 1432 quic_data_->AddRead(ASYNC, OK); |
| 1433 } |
| 1434 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 1435 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 1436 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); |
| 1437 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); |
| 1368 | 1438 |
| 1369 ProxyConfig proxy_config; | |
| 1370 proxy_config.set_auto_detect(true); | |
| 1371 // Use asynchronous proxy resolver. | |
| 1372 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 1373 new MockAsyncProxyResolverFactory(false); | |
| 1374 session_deps_.proxy_service.reset( | |
| 1375 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 1376 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 1377 HttpRequestInfo request_info; | 1439 HttpRequestInfo request_info; |
| 1378 request_info.method = "GET"; | 1440 request_info.method = "GET"; |
| 1379 request_info.url = GURL("https://www.google.com"); | 1441 request_info.url = GURL("https://www.google.com"); |
| 1380 | 1442 |
| 1381 if (!enable_ip_based_pooling) | 1443 if (!enable_ip_based_pooling) |
| 1382 DisableIPBasedPooling(); | 1444 DisableIPBasedPooling(); |
| 1383 if (!enable_alternative_services) | 1445 if (!enable_alternative_services) |
| 1384 DisableAlternativeServices(); | 1446 DisableAlternativeServices(); |
| 1385 | 1447 |
| 1386 Initialize(request_info); | 1448 Initialize(request_info); |
| 1387 | 1449 |
| 1388 url::SchemeHostPort server(request_info.url); | 1450 url::SchemeHostPort server(request_info.url); |
| 1389 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1451 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 1390 SetAlternativeService(request_info, alternative_service); | 1452 SetAlternativeService(request_info, alternative_service); |
| 1391 | 1453 |
| 1392 request_.reset( | 1454 request_.reset( |
| 1393 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1455 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
| 1394 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1456 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
| 1395 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 1396 EXPECT_TRUE(job_controller_->main_job()); | 1457 EXPECT_TRUE(job_controller_->main_job()); |
| 1397 if (enable_alternative_services) { | 1458 if (enable_alternative_services) { |
| 1398 EXPECT_TRUE(job_controller_->alternative_job()); | 1459 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1399 } else { | 1460 } else { |
| 1400 EXPECT_FALSE(job_controller_->alternative_job()); | 1461 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1401 } | 1462 } |
| 1402 | 1463 |
| 1403 // |main_job| succeeds and should report status to Request. | 1464 // |main_job| succeeds and should report status to Request. |
| 1404 HttpStream* http_stream = | 1465 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
| 1405 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
| 1406 job_factory_.main_job()->SetStream(http_stream); | |
| 1407 | |
| 1408 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 1409 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 1466 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 1410 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 1467 base::RunLoop().RunUntilIdle(); |
| 1411 } | 1468 } |
| 1412 | 1469 |
| 1413 class HttpStreamFactoryImplJobControllerPreconnectTest | 1470 class HttpStreamFactoryImplJobControllerPreconnectTest |
| 1414 : public HttpStreamFactoryImplJobControllerTest, | 1471 : public HttpStreamFactoryImplJobControllerTest, |
| 1415 public ::testing::WithParamInterface<bool> { | 1472 public ::testing::WithParamInterface<bool> { |
| 1416 protected: | 1473 protected: |
| 1417 void SetUp() override { | 1474 void SetUp() override { |
| 1418 if (GetParam()) { | 1475 if (GetParam()) { |
| 1419 scoped_feature_list_.InitFromCommandLine("LimitEarlyPreconnects", | 1476 scoped_feature_list_.InitFromCommandLine("LimitEarlyPreconnects", |
| 1420 std::string()); | 1477 std::string()); |
| 1421 } | 1478 } |
| 1422 } | 1479 } |
| 1423 | 1480 |
| 1424 void Initialize() { | 1481 void Initialize() { |
| 1425 session_deps_.http_server_properties = | 1482 session_deps_.http_server_properties = |
| 1426 base::MakeUnique<MockHttpServerProperties>(); | 1483 base::MakeUnique<MockHttpServerProperties>(); |
| 1427 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 1484 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 1428 factory_ = | 1485 factory_ = |
| 1429 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 1486 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 1430 request_info_.method = "GET"; | 1487 request_info_.method = "GET"; |
| 1431 request_info_.url = GURL("https://www.example.com"); | 1488 request_info_.url = GURL("https://www.example.com"); |
| 1432 job_controller_ = new HttpStreamFactoryImpl::JobController( | 1489 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 1433 factory_, &request_delegate_, session_.get(), &job_factory_, | 1490 factory_, &request_delegate_, session_.get(), &job_factory_, |
| 1434 request_info_, /* is_preconnect = */ true, | 1491 request_info_, /* is_preconnect = */ true, |
| 1435 /* enable_ip_based_pooling = */ true, | 1492 /* enable_ip_based_pooling = */ true, |
| 1436 /* enable_alternative_services = */ true); | 1493 /* enable_alternative_services = */ true, SSLConfig(), SSLConfig()); |
| 1437 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 1494 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 1438 } | 1495 } |
| 1439 | 1496 |
| 1440 protected: | 1497 protected: |
| 1441 void Preconnect(int num_streams) { | 1498 void Preconnect(int num_streams) { |
| 1442 job_controller_->Preconnect(num_streams, request_info_, SSLConfig(), | 1499 job_controller_->Preconnect(num_streams); |
| 1443 SSLConfig()); | |
| 1444 // Only one job is started. | 1500 // Only one job is started. |
| 1445 EXPECT_TRUE(job_controller_->main_job()); | 1501 EXPECT_TRUE(job_controller_->main_job()); |
| 1446 EXPECT_FALSE(job_controller_->alternative_job()); | 1502 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1447 } | 1503 } |
| 1448 | 1504 |
| 1449 private: | 1505 private: |
| 1450 base::test::ScopedFeatureList scoped_feature_list_; | 1506 base::test::ScopedFeatureList scoped_feature_list_; |
| 1451 HttpRequestInfo request_info_; | 1507 HttpRequestInfo request_info_; |
| 1452 }; | 1508 }; |
| 1453 | 1509 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1477 Preconnect(kNumPreconects); | 1533 Preconnect(kNumPreconects); |
| 1478 // If experiment is enabled, only 1 stream is requested. | 1534 // If experiment is enabled, only 1 stream is requested. |
| 1479 EXPECT_EQ( | 1535 EXPECT_EQ( |
| 1480 (int)actual_num_connects, | 1536 (int)actual_num_connects, |
| 1481 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1537 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1482 base::RunLoop().RunUntilIdle(); | 1538 base::RunLoop().RunUntilIdle(); |
| 1483 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1539 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1484 } | 1540 } |
| 1485 | 1541 |
| 1486 } // namespace net | 1542 } // namespace net |
| OLD | NEW |