| 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 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/threading/platform_thread.h" |
| 12 #include "net/base/test_proxy_delegate.h" |
| 11 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
| 12 #include "net/http/http_basic_stream.h" | 14 #include "net/http/http_basic_stream.h" |
| 13 #include "net/http/http_stream_factory_impl_request.h" | 15 #include "net/http/http_stream_factory_impl_request.h" |
| 14 #include "net/http/http_stream_factory_test_util.h" | 16 #include "net/http/http_stream_factory_test_util.h" |
| 15 #include "net/proxy/mock_proxy_resolver.h" | 17 #include "net/proxy/mock_proxy_resolver.h" |
| 16 #include "net/proxy/proxy_config_service_fixed.h" | 18 #include "net/proxy/proxy_config_service_fixed.h" |
| 17 #include "net/proxy/proxy_info.h" | 19 #include "net/proxy/proxy_info.h" |
| 18 #include "net/proxy/proxy_service.h" | 20 #include "net/proxy/proxy_service.h" |
| 19 #include "net/quic/test_tools/quic_stream_factory_peer.h" | 21 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
| 20 #include "net/spdy/spdy_test_util_common.h" | 22 #include "net/spdy/spdy_test_util_common.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gmock_mutant.h" | 24 #include "testing/gmock_mutant.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 26 |
| 24 using ::testing::_; | 27 using ::testing::_; |
| 25 using ::testing::Invoke; | 28 using ::testing::Invoke; |
| 26 | 29 |
| 27 namespace net { | 30 namespace net { |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 93 } |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 class JobControllerPeer { | 96 class JobControllerPeer { |
| 94 public: | 97 public: |
| 95 static void VerifyWaitingTimeForMainJob( | 98 static void VerifyWaitingTimeForMainJob( |
| 96 HttpStreamFactoryImpl::JobController* job_controller, | 99 HttpStreamFactoryImpl::JobController* job_controller, |
| 97 const base::TimeDelta& delay) { | 100 const base::TimeDelta& delay) { |
| 98 EXPECT_EQ(delay, job_controller->main_job_wait_time_); | 101 EXPECT_EQ(delay, job_controller->main_job_wait_time_); |
| 99 } | 102 } |
| 103 |
| 104 static bool main_job_is_blocked( |
| 105 HttpStreamFactoryImpl::JobController* job_controller) { |
| 106 return job_controller->main_job_is_blocked_; |
| 107 } |
| 100 }; | 108 }; |
| 101 | 109 |
| 102 class HttpStreamFactoryImplJobControllerTest | 110 class HttpStreamFactoryImplJobControllerTest |
| 103 : public ::testing::Test, | 111 : public ::testing::Test, |
| 104 public ::testing::WithParamInterface<NextProto> { | 112 public ::testing::WithParamInterface<NextProto> { |
| 105 public: | 113 public: |
| 106 HttpStreamFactoryImplJobControllerTest() | 114 HttpStreamFactoryImplJobControllerTest() |
| 107 : session_deps_(ProxyService::CreateDirect()) { | 115 : session_deps_(ProxyService::CreateDirect()) { |
| 108 session_deps_.enable_quic = true; | 116 session_deps_.enable_quic = true; |
| 109 } | 117 } |
| 110 | 118 |
| 111 void Initialize() { | 119 void Initialize(bool use_alternative_proxy) { |
| 120 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( |
| 121 new TestProxyDelegate()); |
| 122 test_proxy_delegate_ = test_proxy_delegate.get(); |
| 123 |
| 124 test_proxy_delegate->set_alternative_proxy_server( |
| 125 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
| 126 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
| 127 session_deps_.proxy_delegate.reset(test_proxy_delegate.release()); |
| 128 |
| 129 if (use_alternative_proxy) { |
| 130 std::unique_ptr<ProxyService> proxy_service = |
| 131 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
| 132 session_deps_.proxy_service.reset(proxy_service.release()); |
| 133 } |
| 112 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 134 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 113 factory_ = | 135 factory_ = |
| 114 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 136 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 115 job_controller_ = new HttpStreamFactoryImpl::JobController( | 137 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 116 factory_, &request_delegate_, session_.get(), &job_factory_); | 138 factory_, &request_delegate_, session_.get(), &job_factory_); |
| 117 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 139 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 118 } | 140 } |
| 119 | 141 |
| 142 TestProxyDelegate* test_proxy_delegate() const { |
| 143 return test_proxy_delegate_; |
| 144 } |
| 145 |
| 120 ~HttpStreamFactoryImplJobControllerTest() {} | 146 ~HttpStreamFactoryImplJobControllerTest() {} |
| 121 | 147 |
| 122 void SetAlternativeService(const HttpRequestInfo& request_info, | 148 void SetAlternativeService(const HttpRequestInfo& request_info, |
| 123 AlternativeService alternative_service) { | 149 AlternativeService alternative_service) { |
| 124 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 150 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 125 url::SchemeHostPort server(request_info.url); | 151 url::SchemeHostPort server(request_info.url); |
| 126 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 152 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 127 session_->http_server_properties()->SetAlternativeService( | 153 session_->http_server_properties()->SetAlternativeService( |
| 128 server, alternative_service, expiration); | 154 server, alternative_service, expiration); |
| 129 } | 155 } |
| 130 | 156 |
| 157 // Not owned by |this|. |
| 158 TestProxyDelegate* test_proxy_delegate_; |
| 131 TestJobFactory job_factory_; | 159 TestJobFactory job_factory_; |
| 132 MockHttpStreamRequestDelegate request_delegate_; | 160 MockHttpStreamRequestDelegate request_delegate_; |
| 133 SpdySessionDependencies session_deps_; | 161 SpdySessionDependencies session_deps_; |
| 134 std::unique_ptr<HttpNetworkSession> session_; | 162 std::unique_ptr<HttpNetworkSession> session_; |
| 135 HttpStreamFactoryImpl* factory_; | 163 HttpStreamFactoryImpl* factory_; |
| 136 HttpStreamFactoryImpl::JobController* job_controller_; | 164 HttpStreamFactoryImpl::JobController* job_controller_; |
| 137 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 165 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
| 138 | 166 |
| 139 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 167 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 140 }; | 168 }; |
| 141 | 169 |
| 142 TEST_F(HttpStreamFactoryImplJobControllerTest, | 170 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 143 OnStreamFailedWithNoAlternativeJob) { | 171 OnStreamFailedWithNoAlternativeJob) { |
| 144 ProxyConfig proxy_config; | 172 ProxyConfig proxy_config; |
| 145 proxy_config.set_auto_detect(true); | 173 proxy_config.set_auto_detect(true); |
| 146 // Use asynchronous proxy resolver. | 174 // Use asynchronous proxy resolver. |
| 147 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 175 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 148 new MockAsyncProxyResolverFactory(false); | 176 new MockAsyncProxyResolverFactory(false); |
| 149 session_deps_.proxy_service.reset(new ProxyService( | 177 session_deps_.proxy_service.reset(new ProxyService( |
| 150 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 178 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 151 base::WrapUnique(proxy_resolver_factory), nullptr)); | 179 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 152 Initialize(); | 180 Initialize(false); |
| 153 | 181 |
| 154 HttpRequestInfo request_info; | 182 HttpRequestInfo request_info; |
| 155 request_info.method = "GET"; | 183 request_info.method = "GET"; |
| 156 request_info.url = GURL("http://www.google.com"); | 184 request_info.url = GURL("http://www.google.com"); |
| 157 | 185 |
| 158 request_.reset( | 186 request_.reset( |
| 159 job_controller_->Start(request_info, &request_delegate_, nullptr, | 187 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 160 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 188 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 161 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 189 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 162 | 190 |
| 163 EXPECT_TRUE(job_controller_->main_job()); | 191 EXPECT_TRUE(job_controller_->main_job()); |
| 164 | 192 |
| 165 // There's no other alternative job. Thus when stream failed, it should | 193 // There's no other alternative job. Thus when stream failed, it should |
| 166 // notify Request of the stream failure. | 194 // notify Request of the stream failure. |
| 167 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 195 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 168 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 196 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 169 SSLConfig()); | 197 SSLConfig()); |
| 170 } | 198 } |
| 171 | 199 |
| 172 TEST_F(HttpStreamFactoryImplJobControllerTest, | 200 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 173 OnStreamReadyWithNoAlternativeJob) { | 201 OnStreamReadyWithNoAlternativeJob) { |
| 174 ProxyConfig proxy_config; | 202 ProxyConfig proxy_config; |
| 175 proxy_config.set_auto_detect(true); | 203 proxy_config.set_auto_detect(true); |
| 176 // Use asynchronous proxy resolver. | 204 // Use asynchronous proxy resolver. |
| 177 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 205 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 178 new MockAsyncProxyResolverFactory(false); | 206 new MockAsyncProxyResolverFactory(false); |
| 179 session_deps_.proxy_service.reset(new ProxyService( | 207 session_deps_.proxy_service.reset(new ProxyService( |
| 180 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 208 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 181 base::WrapUnique(proxy_resolver_factory), nullptr)); | 209 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 182 Initialize(); | 210 Initialize(false); |
| 183 | 211 |
| 184 HttpRequestInfo request_info; | 212 HttpRequestInfo request_info; |
| 185 request_info.method = "GET"; | 213 request_info.method = "GET"; |
| 186 request_info.url = GURL("http://www.google.com"); | 214 request_info.url = GURL("http://www.google.com"); |
| 187 | 215 |
| 188 request_.reset( | 216 request_.reset( |
| 189 job_controller_->Start(request_info, &request_delegate_, nullptr, | 217 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 190 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 218 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 191 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 219 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 192 | 220 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 206 // before any Job is bound to Request. | 234 // before any Job is bound to Request. |
| 207 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 235 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 208 ProxyConfig proxy_config; | 236 ProxyConfig proxy_config; |
| 209 proxy_config.set_auto_detect(true); | 237 proxy_config.set_auto_detect(true); |
| 210 // Use asynchronous proxy resolver. | 238 // Use asynchronous proxy resolver. |
| 211 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 239 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 212 new MockAsyncProxyResolverFactory(false); | 240 new MockAsyncProxyResolverFactory(false); |
| 213 session_deps_.proxy_service.reset(new ProxyService( | 241 session_deps_.proxy_service.reset(new ProxyService( |
| 214 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 242 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 215 base::WrapUnique(proxy_resolver_factory), nullptr)); | 243 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 216 Initialize(); | 244 Initialize(false); |
| 217 | 245 |
| 218 HttpRequestInfo request_info; | 246 HttpRequestInfo request_info; |
| 219 request_info.method = "GET"; | 247 request_info.method = "GET"; |
| 220 request_info.url = GURL("https://www.google.com"); | 248 request_info.url = GURL("https://www.google.com"); |
| 221 | 249 |
| 222 url::SchemeHostPort server(request_info.url); | 250 url::SchemeHostPort server(request_info.url); |
| 223 AlternativeService alternative_service(QUIC, server.host(), 443); | 251 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 224 SetAlternativeService(request_info, alternative_service); | 252 SetAlternativeService(request_info, alternative_service); |
| 225 | 253 |
| 226 request_.reset( | 254 request_.reset( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 239 | 267 |
| 240 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 268 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 241 ProxyConfig proxy_config; | 269 ProxyConfig proxy_config; |
| 242 proxy_config.set_auto_detect(true); | 270 proxy_config.set_auto_detect(true); |
| 243 // Use asynchronous proxy resolver. | 271 // Use asynchronous proxy resolver. |
| 244 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 272 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 245 new MockAsyncProxyResolverFactory(false); | 273 new MockAsyncProxyResolverFactory(false); |
| 246 session_deps_.proxy_service.reset(new ProxyService( | 274 session_deps_.proxy_service.reset(new ProxyService( |
| 247 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 275 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 248 base::WrapUnique(proxy_resolver_factory), nullptr)); | 276 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 249 Initialize(); | 277 Initialize(false); |
| 250 | 278 |
| 251 HttpRequestInfo request_info; | 279 HttpRequestInfo request_info; |
| 252 request_info.method = "GET"; | 280 request_info.method = "GET"; |
| 253 request_info.url = GURL("https://www.google.com"); | 281 request_info.url = GURL("https://www.google.com"); |
| 254 | 282 |
| 255 url::SchemeHostPort server(request_info.url); | 283 url::SchemeHostPort server(request_info.url); |
| 256 AlternativeService alternative_service(QUIC, server.host(), 443); | 284 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 257 SetAlternativeService(request_info, alternative_service); | 285 SetAlternativeService(request_info, alternative_service); |
| 258 | 286 |
| 259 request_.reset( | 287 request_.reset( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 283 TEST_F(HttpStreamFactoryImplJobControllerTest, | 311 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 284 SecondJobFailsAfterFirstJobSucceeds) { | 312 SecondJobFailsAfterFirstJobSucceeds) { |
| 285 ProxyConfig proxy_config; | 313 ProxyConfig proxy_config; |
| 286 proxy_config.set_auto_detect(true); | 314 proxy_config.set_auto_detect(true); |
| 287 // Use asynchronous proxy resolver. | 315 // Use asynchronous proxy resolver. |
| 288 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 316 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 289 new MockAsyncProxyResolverFactory(false); | 317 new MockAsyncProxyResolverFactory(false); |
| 290 session_deps_.proxy_service.reset(new ProxyService( | 318 session_deps_.proxy_service.reset(new ProxyService( |
| 291 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 319 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 292 base::WrapUnique(proxy_resolver_factory), nullptr)); | 320 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 293 Initialize(); | 321 Initialize(false); |
| 294 | 322 |
| 295 HttpRequestInfo request_info; | 323 HttpRequestInfo request_info; |
| 296 request_info.method = "GET"; | 324 request_info.method = "GET"; |
| 297 request_info.url = GURL("https://www.google.com"); | 325 request_info.url = GURL("https://www.google.com"); |
| 298 | 326 |
| 299 url::SchemeHostPort server(request_info.url); | 327 url::SchemeHostPort server(request_info.url); |
| 300 AlternativeService alternative_service(QUIC, server.host(), 443); | 328 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 301 SetAlternativeService(request_info, alternative_service); | 329 SetAlternativeService(request_info, alternative_service); |
| 302 | 330 |
| 303 request_.reset( | 331 request_.reset( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 TEST_F(HttpStreamFactoryImplJobControllerTest, | 363 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 336 SecondJobSucceedsAfterFirstJobFailed) { | 364 SecondJobSucceedsAfterFirstJobFailed) { |
| 337 ProxyConfig proxy_config; | 365 ProxyConfig proxy_config; |
| 338 proxy_config.set_auto_detect(true); | 366 proxy_config.set_auto_detect(true); |
| 339 // Use asynchronous proxy resolver. | 367 // Use asynchronous proxy resolver. |
| 340 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 368 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 341 new MockAsyncProxyResolverFactory(false); | 369 new MockAsyncProxyResolverFactory(false); |
| 342 session_deps_.proxy_service.reset(new ProxyService( | 370 session_deps_.proxy_service.reset(new ProxyService( |
| 343 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 371 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 344 base::WrapUnique(proxy_resolver_factory), nullptr)); | 372 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 345 Initialize(); | 373 Initialize(false); |
| 346 | 374 |
| 347 HttpRequestInfo request_info; | 375 HttpRequestInfo request_info; |
| 348 request_info.method = "GET"; | 376 request_info.method = "GET"; |
| 349 request_info.url = GURL("https://www.google.com"); | 377 request_info.url = GURL("https://www.google.com"); |
| 350 | 378 |
| 351 url::SchemeHostPort server(request_info.url); | 379 url::SchemeHostPort server(request_info.url); |
| 352 AlternativeService alternative_service(QUIC, server.host(), 443); | 380 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 353 SetAlternativeService(request_info, alternative_service); | 381 SetAlternativeService(request_info, alternative_service); |
| 354 | 382 |
| 355 request_.reset( | 383 request_.reset( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 383 // Get load state after main job fails and before alternative job succeeds. | 411 // Get load state after main job fails and before alternative job succeeds. |
| 384 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 412 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 385 ProxyConfig proxy_config; | 413 ProxyConfig proxy_config; |
| 386 proxy_config.set_auto_detect(true); | 414 proxy_config.set_auto_detect(true); |
| 387 // Use asynchronous proxy resolver. | 415 // Use asynchronous proxy resolver. |
| 388 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 416 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 389 new MockAsyncProxyResolverFactory(false); | 417 new MockAsyncProxyResolverFactory(false); |
| 390 session_deps_.proxy_service.reset(new ProxyService( | 418 session_deps_.proxy_service.reset(new ProxyService( |
| 391 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 419 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 392 base::WrapUnique(proxy_resolver_factory), nullptr)); | 420 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 393 Initialize(); | 421 Initialize(false); |
| 394 | 422 |
| 395 HttpRequestInfo request_info; | 423 HttpRequestInfo request_info; |
| 396 request_info.method = "GET"; | 424 request_info.method = "GET"; |
| 397 request_info.url = GURL("https://www.google.com"); | 425 request_info.url = GURL("https://www.google.com"); |
| 398 | 426 |
| 399 url::SchemeHostPort server(request_info.url); | 427 url::SchemeHostPort server(request_info.url); |
| 400 AlternativeService alternative_service(QUIC, server.host(), 443); | 428 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 401 SetAlternativeService(request_info, alternative_service); | 429 SetAlternativeService(request_info, alternative_service); |
| 402 | 430 |
| 403 request_.reset( | 431 request_.reset( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 434 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 462 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
| 435 // to stall the alternative job and report to controller to maybe resume the | 463 // to stall the alternative job and report to controller to maybe resume the |
| 436 // main job. | 464 // main job. |
| 437 ProxyConfig proxy_config; | 465 ProxyConfig proxy_config; |
| 438 proxy_config.set_auto_detect(true); | 466 proxy_config.set_auto_detect(true); |
| 439 proxy_config.set_pac_mandatory(true); | 467 proxy_config.set_pac_mandatory(true); |
| 440 session_deps_.proxy_service.reset(new ProxyService( | 468 session_deps_.proxy_service.reset(new ProxyService( |
| 441 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 469 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 442 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 470 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 443 | 471 |
| 444 Initialize(); | 472 Initialize(false); |
| 445 | 473 |
| 446 HttpRequestInfo request_info; | 474 HttpRequestInfo request_info; |
| 447 request_info.method = "GET"; | 475 request_info.method = "GET"; |
| 448 request_info.url = GURL("https://www.google.com"); | 476 request_info.url = GURL("https://www.google.com"); |
| 449 | 477 |
| 450 url::SchemeHostPort server(request_info.url); | 478 url::SchemeHostPort server(request_info.url); |
| 451 AlternativeService alternative_service(QUIC, server.host(), 443); | 479 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 452 SetAlternativeService(request_info, alternative_service); | 480 SetAlternativeService(request_info, alternative_service); |
| 453 | 481 |
| 454 request_.reset( | 482 request_.reset( |
| 455 job_controller_->Start(request_info, &request_delegate_, nullptr, | 483 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 456 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 484 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 457 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 485 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 458 EXPECT_TRUE(job_controller_->main_job()); | 486 EXPECT_TRUE(job_controller_->main_job()); |
| 459 EXPECT_TRUE(job_controller_->alternative_job()); | 487 EXPECT_TRUE(job_controller_->alternative_job()); |
| 460 | 488 |
| 461 // Wait until OnStreamFailedCallback is executed on the alternative job. | 489 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 462 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 490 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
| 463 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 491 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
| 464 base::RunLoop().RunUntilIdle(); | 492 base::RunLoop().RunUntilIdle(); |
| 465 } | 493 } |
| 466 | 494 |
| 467 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 495 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
| 468 // Using a restricted port 101 for QUIC should fail and the alternative job | 496 // Using a restricted port 101 for QUIC should fail and the alternative job |
| 469 // should post OnStreamFailedCall on the controller to resume the main job. | 497 // should post OnStreamFailedCall on the controller to resume the main job. |
| 470 Initialize(); | 498 Initialize(false); |
| 471 | 499 |
| 472 HttpRequestInfo request_info; | 500 HttpRequestInfo request_info; |
| 473 request_info.method = "GET"; | 501 request_info.method = "GET"; |
| 474 request_info.url = GURL("https://www.google.com"); | 502 request_info.url = GURL("https://www.google.com"); |
| 475 | 503 |
| 476 url::SchemeHostPort server(request_info.url); | 504 url::SchemeHostPort server(request_info.url); |
| 477 AlternativeService alternative_service(QUIC, server.host(), 101); | 505 AlternativeService alternative_service(QUIC, server.host(), 101); |
| 478 SetAlternativeService(request_info, alternative_service); | 506 SetAlternativeService(request_info, alternative_service); |
| 479 | 507 |
| 480 request_.reset( | 508 request_.reset( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 502 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 530 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 503 new MockAsyncProxyResolverFactory(false); | 531 new MockAsyncProxyResolverFactory(false); |
| 504 session_deps_.proxy_service.reset(new ProxyService( | 532 session_deps_.proxy_service.reset(new ProxyService( |
| 505 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 533 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 506 base::WrapUnique(proxy_resolver_factory), nullptr)); | 534 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 507 | 535 |
| 508 HangingResolver* host_resolver = new HangingResolver(); | 536 HangingResolver* host_resolver = new HangingResolver(); |
| 509 session_deps_.host_resolver.reset(host_resolver); | 537 session_deps_.host_resolver.reset(host_resolver); |
| 510 session_deps_.host_resolver->set_synchronous_mode(false); | 538 session_deps_.host_resolver->set_synchronous_mode(false); |
| 511 | 539 |
| 512 Initialize(); | 540 Initialize(false); |
| 513 | 541 |
| 514 HttpRequestInfo request_info; | 542 HttpRequestInfo request_info; |
| 515 request_info.method = "GET"; | 543 request_info.method = "GET"; |
| 516 request_info.url = GURL("https://www.google.com"); | 544 request_info.url = GURL("https://www.google.com"); |
| 517 | 545 |
| 518 // Set a SPDY alternative service for the server. | 546 // Set a SPDY alternative service for the server. |
| 519 url::SchemeHostPort server(request_info.url); | 547 url::SchemeHostPort server(request_info.url); |
| 520 AlternativeService alternative_service(QUIC, server.host(), 443); | 548 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 521 SetAlternativeService(request_info, alternative_service); | 549 SetAlternativeService(request_info, alternative_service); |
| 522 // Hack to use different URL for the main job to help differentiate the proxy | 550 // Hack to use different URL for the main job to help differentiate the proxy |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 594 |
| 567 ProxyConfig proxy_config; | 595 ProxyConfig proxy_config; |
| 568 proxy_config.set_auto_detect(true); | 596 proxy_config.set_auto_detect(true); |
| 569 // Use asynchronous proxy resolver. | 597 // Use asynchronous proxy resolver. |
| 570 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 598 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 571 new MockAsyncProxyResolverFactory(false); | 599 new MockAsyncProxyResolverFactory(false); |
| 572 session_deps_.proxy_service.reset(new ProxyService( | 600 session_deps_.proxy_service.reset(new ProxyService( |
| 573 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 601 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 574 base::WrapUnique(proxy_resolver_factory), nullptr)); | 602 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 575 | 603 |
| 576 Initialize(); | 604 Initialize(false); |
| 577 | 605 |
| 578 HttpRequestInfo request_info; | 606 HttpRequestInfo request_info; |
| 579 request_info.method = "GET"; | 607 request_info.method = "GET"; |
| 580 request_info.url = GURL("https://www.google.com"); | 608 request_info.url = GURL("https://www.google.com"); |
| 581 | 609 |
| 582 url::SchemeHostPort server(request_info.url); | 610 url::SchemeHostPort server(request_info.url); |
| 583 AlternativeService alternative_service(QUIC, server.host(), 443); | 611 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 584 SetAlternativeService(request_info, alternative_service); | 612 SetAlternativeService(request_info, alternative_service); |
| 585 // Hack to use different URL for the main job to help differentiate the proxy | 613 // Hack to use different URL for the main job to help differentiate the proxy |
| 586 // requests. | 614 // requests. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 647 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 620 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 648 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
| 621 | 649 |
| 622 base::RunLoop().RunUntilIdle(); | 650 base::RunLoop().RunUntilIdle(); |
| 623 } | 651 } |
| 624 | 652 |
| 625 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 653 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
| 626 HangingResolver* resolver = new HangingResolver(); | 654 HangingResolver* resolver = new HangingResolver(); |
| 627 session_deps_.host_resolver.reset(resolver); | 655 session_deps_.host_resolver.reset(resolver); |
| 628 | 656 |
| 629 Initialize(); | 657 Initialize(false); |
| 630 | 658 |
| 631 // Enable delayed TCP and set time delay for waiting job. | 659 // Enable delayed TCP and set time delay for waiting job. |
| 632 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 660 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 633 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 661 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 634 quic_stream_factory->set_require_confirmation(false); | 662 quic_stream_factory->set_require_confirmation(false); |
| 635 ServerNetworkStats stats1; | 663 ServerNetworkStats stats1; |
| 636 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 664 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 637 session_->http_server_properties()->SetServerNetworkStats( | 665 session_->http_server_properties()->SetServerNetworkStats( |
| 638 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 666 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 639 | 667 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 656 // The alternative job stalls as host resolution hangs when creating the QUIC | 684 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 657 // request and controller should resume the main job after delay. | 685 // request and controller should resume the main job after delay. |
| 658 // Verify the waiting time for delayed main job. | 686 // Verify the waiting time for delayed main job. |
| 659 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 687 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 660 .WillOnce(Invoke(testing::CreateFunctor( | 688 .WillOnce(Invoke(testing::CreateFunctor( |
| 661 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 689 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 662 base::TimeDelta::FromMicroseconds(15)))); | 690 base::TimeDelta::FromMicroseconds(15)))); |
| 663 | 691 |
| 664 base::RunLoop().RunUntilIdle(); | 692 base::RunLoop().RunUntilIdle(); |
| 665 } | 693 } |
| 694 |
| 695 // Verifies that the alternative proxy server job is not created if the URL |
| 696 // scheme is HTTPS. |
| 697 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { |
| 698 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 699 HangingResolver* resolver = new HangingResolver(); |
| 700 session_deps_.host_resolver.reset(resolver); |
| 701 |
| 702 Initialize(true); |
| 703 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 704 |
| 705 HttpRequestInfo request_info; |
| 706 request_info.method = "GET"; |
| 707 request_info.url = GURL("https://mail.example.org/"); |
| 708 |
| 709 request_.reset( |
| 710 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 711 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 712 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 713 EXPECT_TRUE(job_controller_->main_job()); |
| 714 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 715 EXPECT_FALSE(job_controller_->alternative_job()); |
| 716 |
| 717 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 718 base::RunLoop().RunUntilIdle(); |
| 719 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 720 } |
| 721 |
| 722 // Verifies that the alternative proxy server job is not created if the main job |
| 723 // does not fetch the resource through a proxy. |
| 724 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
| 725 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 726 HangingResolver* resolver = new HangingResolver(); |
| 727 session_deps_.host_resolver.reset(resolver); |
| 728 |
| 729 Initialize(false); |
| 730 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 731 |
| 732 HttpRequestInfo request_info; |
| 733 request_info.method = "GET"; |
| 734 request_info.url = GURL("http://mail.example.org/"); |
| 735 |
| 736 request_.reset( |
| 737 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 738 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 739 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 740 EXPECT_TRUE(job_controller_->main_job()); |
| 741 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 742 EXPECT_FALSE(job_controller_->alternative_job()); |
| 743 |
| 744 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 745 base::RunLoop().RunUntilIdle(); |
| 746 |
| 747 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 748 } |
| 749 |
| 750 // Verifies that the main job is resumed properly after a delay when the |
| 751 // alternative proxy server job hangs. |
| 752 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { |
| 753 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 754 HangingResolver* resolver = new HangingResolver(); |
| 755 session_deps_.host_resolver.reset(resolver); |
| 756 |
| 757 Initialize(true); |
| 758 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 759 |
| 760 // Enable delayed TCP and set time delay for waiting job. |
| 761 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 762 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 763 quic_stream_factory->set_require_confirmation(false); |
| 764 ServerNetworkStats stats1; |
| 765 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 766 session_->http_server_properties()->SetServerNetworkStats( |
| 767 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 768 |
| 769 HttpRequestInfo request_info; |
| 770 request_info.method = "GET"; |
| 771 request_info.url = GURL("http://mail.example.org/"); |
| 772 |
| 773 request_.reset( |
| 774 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 775 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 776 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 777 EXPECT_TRUE(job_controller_->main_job()); |
| 778 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 779 EXPECT_TRUE(job_controller_->alternative_job()); |
| 780 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 781 |
| 782 // The alternative proxy server job stalls when connecting to the alternative |
| 783 // proxy server, and controller should resume the main job after delay. |
| 784 // Verify the waiting time for delayed main job. |
| 785 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 786 .WillOnce(Invoke(testing::CreateFunctor( |
| 787 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 788 base::TimeDelta::FromMicroseconds(15)))); |
| 789 |
| 790 // This message loop should cause the alternative proxy server job to start, |
| 791 // and schedule resumption of the main job. |
| 792 base::RunLoop().RunUntilIdle(); |
| 793 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 794 |
| 795 // Wait for the Resume to post. |
| 796 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 797 |
| 798 // This message loop should cause the main job to resume. |
| 799 base::RunLoop().RunUntilIdle(); |
| 800 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 801 |
| 802 JobControllerPeer::VerifyWaitingTimeForMainJob( |
| 803 job_controller_, base::TimeDelta::FromMicroseconds(0)); |
| 804 |
| 805 // Since the main job did not complete successfully, the alternative proxy |
| 806 // server should not be marked as bad. |
| 807 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 808 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 809 } |
| 810 |
| 811 // Verifies that the alternative proxy server job fails immediately, and the |
| 812 // main job is not blocked. |
| 813 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { |
| 814 // Using failing resolver will cause the alternative job to fail. |
| 815 FailingHostResolver* resolver = new FailingHostResolver(); |
| 816 session_deps_.host_resolver.reset(resolver); |
| 817 |
| 818 Initialize(true); |
| 819 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 820 |
| 821 // Enable delayed TCP and set time delay for waiting job. |
| 822 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 823 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 824 quic_stream_factory->set_require_confirmation(false); |
| 825 ServerNetworkStats stats1; |
| 826 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); |
| 827 session_->http_server_properties()->SetServerNetworkStats( |
| 828 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 829 |
| 830 HttpRequestInfo request_info; |
| 831 request_info.method = "GET"; |
| 832 request_info.url = GURL("http://mail.example.org/"); |
| 833 |
| 834 request_.reset( |
| 835 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 836 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 837 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 838 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 839 EXPECT_TRUE(job_controller_->alternative_job()); |
| 840 |
| 841 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
| 842 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
| 843 |
| 844 // Since the alternative proxy server job is started in the next message loop, |
| 845 // the main job would remain blocked until the alternative proxy starts, and |
| 846 // fails. |
| 847 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 848 .WillOnce(Invoke(testing::CreateFunctor( |
| 849 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 850 base::TimeDelta::FromMicroseconds(0)))); |
| 851 |
| 852 base::RunLoop().RunUntilIdle(); |
| 853 EXPECT_FALSE(job_controller_->alternative_job()); |
| 854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 855 // Since the main job did not complete successfully, the alternative proxy |
| 856 // server should not be marked as bad. |
| 857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 859 } |
| 860 |
| 666 } // namespace net | 861 } // namespace net |
| OLD | NEW |