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