| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_SPDY_SPDY_TEST_UTIL_H_ | 5 #ifndef NET_SPDY_SPDY_TEST_UTIL_H_ |
| 6 #define NET_SPDY_SPDY_TEST_UTIL_H_ | 6 #define NET_SPDY_SPDY_TEST_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "net/base/cert_verifier.h" | 10 #include "net/base/cert_verifier.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Combines the given SpdyFrames into the given char array and returns | 319 // Combines the given SpdyFrames into the given char array and returns |
| 320 // the total length. | 320 // the total length. |
| 321 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, | 321 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, |
| 322 char* buff, int buff_len); | 322 char* buff, int buff_len); |
| 323 | 323 |
| 324 // Helper to manage the lifetimes of the dependencies for a | 324 // Helper to manage the lifetimes of the dependencies for a |
| 325 // HttpNetworkTransaction. | 325 // HttpNetworkTransaction. |
| 326 class SpdySessionDependencies { | 326 class SpdySessionDependencies { |
| 327 public: | 327 public: |
| 328 // Default set of dependencies -- "null" proxy service. | 328 // Default set of dependencies -- "null" proxy service. |
| 329 SpdySessionDependencies() | 329 SpdySessionDependencies(); |
| 330 : host_resolver(new MockHostResolver), | |
| 331 cert_verifier(new CertVerifier), | |
| 332 proxy_service(ProxyService::CreateDirect()), | |
| 333 ssl_config_service(new SSLConfigServiceDefaults), | |
| 334 socket_factory(new MockClientSocketFactory), | |
| 335 deterministic_socket_factory(new DeterministicMockClientSocketFactory), | |
| 336 http_auth_handler_factory( | |
| 337 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) { | |
| 338 // Note: The CancelledTransaction test does cleanup by running all | |
| 339 // tasks in the message loop (RunAllPending). Unfortunately, that | |
| 340 // doesn't clean up tasks on the host resolver thread; and | |
| 341 // TCPConnectJob is currently not cancellable. Using synchronous | |
| 342 // lookups allows the test to shutdown cleanly. Until we have | |
| 343 // cancellable TCPConnectJobs, use synchronous lookups. | |
| 344 host_resolver->set_synchronous_mode(true); | |
| 345 } | |
| 346 | 330 |
| 347 // Custom proxy service dependency. | 331 // Custom proxy service dependency. |
| 348 explicit SpdySessionDependencies(ProxyService* proxy_service) | 332 explicit SpdySessionDependencies(ProxyService* proxy_service); |
| 349 : host_resolver(new MockHostResolver), | 333 |
| 350 cert_verifier(new CertVerifier), | 334 ~SpdySessionDependencies(); |
| 351 proxy_service(proxy_service), | 335 |
| 352 ssl_config_service(new SSLConfigServiceDefaults), | 336 static HttpNetworkSession* SpdyCreateSession( |
| 353 socket_factory(new MockClientSocketFactory), | 337 SpdySessionDependencies* session_deps); |
| 354 deterministic_socket_factory(new DeterministicMockClientSocketFactory), | 338 static HttpNetworkSession* SpdyCreateSessionDeterministic( |
| 355 http_auth_handler_factory( | 339 SpdySessionDependencies* session_deps); |
| 356 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {} | |
| 357 | 340 |
| 358 // NOTE: host_resolver must be ordered before http_auth_handler_factory. | 341 // NOTE: host_resolver must be ordered before http_auth_handler_factory. |
| 359 scoped_ptr<MockHostResolverBase> host_resolver; | 342 scoped_ptr<MockHostResolverBase> host_resolver; |
| 360 scoped_ptr<CertVerifier> cert_verifier; | 343 scoped_ptr<CertVerifier> cert_verifier; |
| 361 scoped_refptr<ProxyService> proxy_service; | 344 scoped_refptr<ProxyService> proxy_service; |
| 362 scoped_refptr<SSLConfigService> ssl_config_service; | 345 scoped_refptr<SSLConfigService> ssl_config_service; |
| 363 scoped_ptr<MockClientSocketFactory> socket_factory; | 346 scoped_ptr<MockClientSocketFactory> socket_factory; |
| 364 scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; | 347 scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; |
| 365 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | 348 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
| 366 | |
| 367 static HttpNetworkSession* SpdyCreateSession( | |
| 368 SpdySessionDependencies* session_deps) { | |
| 369 return new HttpNetworkSession(session_deps->host_resolver.get(), | |
| 370 session_deps->cert_verifier.get(), | |
| 371 NULL /* dnsrr_resolver */, | |
| 372 NULL /* dns_cert_checker */, | |
| 373 NULL /* ssl_host_info_factory */, | |
| 374 session_deps->proxy_service, | |
| 375 session_deps->socket_factory.get(), | |
| 376 session_deps->ssl_config_service, | |
| 377 new SpdySessionPool(NULL), | |
| 378 session_deps->http_auth_handler_factory.get(), | |
| 379 NULL, | |
| 380 NULL); | |
| 381 } | |
| 382 static HttpNetworkSession* SpdyCreateSessionDeterministic( | |
| 383 SpdySessionDependencies* session_deps) { | |
| 384 return new HttpNetworkSession(session_deps->host_resolver.get(), | |
| 385 session_deps->cert_verifier.get(), | |
| 386 NULL /* dnsrr_resolver */, | |
| 387 NULL /* dns_cert_checker */, | |
| 388 NULL /* ssl_host_info_factory */, | |
| 389 session_deps->proxy_service, | |
| 390 session_deps-> | |
| 391 deterministic_socket_factory.get(), | |
| 392 session_deps->ssl_config_service, | |
| 393 new SpdySessionPool(NULL), | |
| 394 session_deps->http_auth_handler_factory.get(), | |
| 395 NULL, | |
| 396 NULL); | |
| 397 } | |
| 398 }; | 349 }; |
| 399 | 350 |
| 400 class SpdyURLRequestContext : public URLRequestContext { | 351 class SpdyURLRequestContext : public URLRequestContext { |
| 401 public: | 352 public: |
| 402 SpdyURLRequestContext() { | 353 SpdyURLRequestContext(); |
| 403 host_resolver_ = new MockHostResolver(); | |
| 404 cert_verifier_ = new CertVerifier; | |
| 405 proxy_service_ = ProxyService::CreateDirect(); | |
| 406 ssl_config_service_ = new SSLConfigServiceDefaults; | |
| 407 http_auth_handler_factory_ = HttpAuthHandlerFactory::CreateDefault( | |
| 408 host_resolver_); | |
| 409 http_transaction_factory_ = new HttpCache( | |
| 410 new HttpNetworkLayer(&socket_factory_, | |
| 411 host_resolver_, | |
| 412 cert_verifier_, | |
| 413 NULL /* dnsrr_resolver */, | |
| 414 NULL /* dns_cert_checker */, | |
| 415 NULL /* ssl_host_info_factory */, | |
| 416 proxy_service_, | |
| 417 ssl_config_service_, | |
| 418 new SpdySessionPool(NULL), | |
| 419 http_auth_handler_factory_, | |
| 420 network_delegate_, | |
| 421 NULL), | |
| 422 NULL /* net_log */, | |
| 423 HttpCache::DefaultBackend::InMemory(0)); | |
| 424 } | |
| 425 | 354 |
| 426 MockClientSocketFactory& socket_factory() { return socket_factory_; } | 355 MockClientSocketFactory& socket_factory() { return socket_factory_; } |
| 427 | 356 |
| 428 protected: | 357 protected: |
| 429 virtual ~SpdyURLRequestContext() { | 358 virtual ~SpdyURLRequestContext(); |
| 430 delete http_transaction_factory_; | |
| 431 delete http_auth_handler_factory_; | |
| 432 delete cert_verifier_; | |
| 433 delete host_resolver_; | |
| 434 } | |
| 435 | 359 |
| 436 private: | 360 private: |
| 437 MockClientSocketFactory socket_factory_; | 361 MockClientSocketFactory socket_factory_; |
| 438 }; | 362 }; |
| 439 | 363 |
| 440 const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type); | 364 const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type); |
| 441 } // namespace net | 365 } // namespace net |
| 442 | 366 |
| 443 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ | 367 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ |
| OLD | NEW |