| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "crypto/ec_private_key.h" |
| 11 #include "crypto/ec_signature_creator.h" |
| 10 #include "net/base/cert_verifier.h" | 12 #include "net/base/cert_verifier.h" |
| 11 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 12 #include "net/base/mock_host_resolver.h" | 14 #include "net/base/mock_host_resolver.h" |
| 13 #include "net/base/request_priority.h" | 15 #include "net/base/request_priority.h" |
| 14 #include "net/base/ssl_config_service_defaults.h" | 16 #include "net/base/ssl_config_service_defaults.h" |
| 15 #include "net/http/http_auth_handler_factory.h" | 17 #include "net/http/http_auth_handler_factory.h" |
| 16 #include "net/http/http_cache.h" | 18 #include "net/http/http_cache.h" |
| 17 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_network_layer.h" | 20 #include "net/http/http_network_layer.h" |
| 19 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
| 20 #include "net/http/http_transaction_factory.h" | 22 #include "net/http/http_transaction_factory.h" |
| 21 #include "net/proxy/proxy_service.h" | 23 #include "net/proxy/proxy_service.h" |
| 22 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
| 25 #include "net/spdy/spdy_session.h" |
| 23 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_context_storage.h" | 27 #include "net/url_request/url_request_context_storage.h" |
| 25 | 28 |
| 26 namespace crypto { | 29 namespace crypto { |
| 27 class ECSignatureCreatorFactory; | 30 class ECSignatureCreatorFactory; |
| 28 } | 31 } |
| 29 | 32 |
| 30 namespace net { | 33 namespace net { |
| 31 | 34 |
| 32 namespace test_spdy3 { | 35 namespace test_spdy3 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 SpdyPriority priority; | 49 SpdyPriority priority; |
| 47 size_t credential_slot; | 50 size_t credential_slot; |
| 48 SpdyControlFlags control_flags; | 51 SpdyControlFlags control_flags; |
| 49 bool compressed; | 52 bool compressed; |
| 50 SpdyStatusCodes status; | 53 SpdyStatusCodes status; |
| 51 const char* data; | 54 const char* data; |
| 52 uint32 data_length; | 55 uint32 data_length; |
| 53 SpdyDataFlags data_flags; | 56 SpdyDataFlags data_flags; |
| 54 }; | 57 }; |
| 55 | 58 |
| 59 // An ECSignatureCreator that returns deterministic signatures. |
| 60 class MockECSignatureCreator : public crypto::ECSignatureCreator { |
| 61 public: |
| 62 explicit MockECSignatureCreator(crypto::ECPrivateKey* key); |
| 63 |
| 64 // crypto::ECSignatureCreator |
| 65 virtual bool Sign(const uint8* data, |
| 66 int data_len, |
| 67 std::vector<uint8>* signature) OVERRIDE; |
| 68 virtual bool DecodeSignature(const std::vector<uint8>& signature, |
| 69 std::vector<uint8>* out_raw_sig) OVERRIDE; |
| 70 |
| 71 private: |
| 72 crypto::ECPrivateKey* key_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); |
| 75 }; |
| 76 |
| 77 // An ECSignatureCreatorFactory creates MockECSignatureCreator. |
| 78 class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { |
| 79 public: |
| 80 MockECSignatureCreatorFactory(); |
| 81 virtual ~MockECSignatureCreatorFactory(); |
| 82 |
| 83 // crypto::ECSignatureCreatorFactory |
| 84 virtual crypto::ECSignatureCreator* Create( |
| 85 crypto::ECPrivateKey* key) OVERRIDE; |
| 86 |
| 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); |
| 89 }; |
| 90 |
| 56 // Chop a frame into an array of MockWrites. | 91 // Chop a frame into an array of MockWrites. |
| 57 // |data| is the frame to chop. | 92 // |data| is the frame to chop. |
| 58 // |length| is the length of the frame to chop. | 93 // |length| is the length of the frame to chop. |
| 59 // |num_chunks| is the number of chunks to create. | 94 // |num_chunks| is the number of chunks to create. |
| 60 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); | 95 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); |
| 61 | 96 |
| 62 // Chop a SpdyFrame into an array of MockWrites. | 97 // Chop a SpdyFrame into an array of MockWrites. |
| 63 // |frame| is the frame to chop. | 98 // |frame| is the frame to chop. |
| 64 // |num_chunks| is the number of chunks to create. | 99 // |num_chunks| is the number of chunks to create. |
| 65 MockWrite* ChopWriteFrame(const SpdyFrame& frame, int num_chunks); | 100 MockWrite* ChopWriteFrame(const SpdyFrame& frame, int num_chunks); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 398 |
| 364 // NOTE: host_resolver must be ordered before http_auth_handler_factory. | 399 // NOTE: host_resolver must be ordered before http_auth_handler_factory. |
| 365 scoped_ptr<MockHostResolverBase> host_resolver; | 400 scoped_ptr<MockHostResolverBase> host_resolver; |
| 366 scoped_ptr<CertVerifier> cert_verifier; | 401 scoped_ptr<CertVerifier> cert_verifier; |
| 367 scoped_ptr<ProxyService> proxy_service; | 402 scoped_ptr<ProxyService> proxy_service; |
| 368 scoped_refptr<SSLConfigService> ssl_config_service; | 403 scoped_refptr<SSLConfigService> ssl_config_service; |
| 369 scoped_ptr<MockClientSocketFactory> socket_factory; | 404 scoped_ptr<MockClientSocketFactory> socket_factory; |
| 370 scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; | 405 scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; |
| 371 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | 406 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
| 372 HttpServerPropertiesImpl http_server_properties; | 407 HttpServerPropertiesImpl http_server_properties; |
| 408 bool enable_ip_pooling; |
| 409 bool enable_compression; |
| 410 bool enable_ping; |
| 411 size_t initial_recv_window_size; |
| 412 SpdySession::TimeFunc time_func; |
| 373 std::string trusted_spdy_proxy; | 413 std::string trusted_spdy_proxy; |
| 374 NetLog* net_log; | 414 NetLog* net_log; |
| 375 }; | 415 }; |
| 376 | 416 |
| 377 class SpdyURLRequestContext : public URLRequestContext { | 417 class SpdyURLRequestContext : public URLRequestContext { |
| 378 public: | 418 public: |
| 379 SpdyURLRequestContext(); | 419 SpdyURLRequestContext(); |
| 380 virtual ~SpdyURLRequestContext(); | 420 virtual ~SpdyURLRequestContext(); |
| 381 | 421 |
| 382 MockClientSocketFactory& socket_factory() { return socket_factory_; } | 422 MockClientSocketFactory& socket_factory() { return socket_factory_; } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 412 void EnableSendingInitialSettings(bool enabled) { | 452 void EnableSendingInitialSettings(bool enabled) { |
| 413 pool_->enable_sending_initial_settings_ = enabled; | 453 pool_->enable_sending_initial_settings_ = enabled; |
| 414 } | 454 } |
| 415 | 455 |
| 416 private: | 456 private: |
| 417 SpdySessionPool* const pool_; | 457 SpdySessionPool* const pool_; |
| 418 | 458 |
| 419 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); | 459 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); |
| 420 }; | 460 }; |
| 421 | 461 |
| 422 // Helper to manage the state of a number of SPDY global variables. | |
| 423 class SpdyTestStateHelper { | |
| 424 public: | |
| 425 SpdyTestStateHelper(); | |
| 426 ~SpdyTestStateHelper(); | |
| 427 | |
| 428 private: | |
| 429 // In order to make CREDENTIAL frame creation deterministic, we need to | |
| 430 // use a mock EC signature creator, which needs to live throughout | |
| 431 // the life of the test. | |
| 432 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory_; | |
| 433 | |
| 434 DISALLOW_COPY_AND_ASSIGN(SpdyTestStateHelper); | |
| 435 }; | |
| 436 | |
| 437 } // namespace test_spdy3 | 462 } // namespace test_spdy3 |
| 438 | 463 |
| 439 } // namespace net | 464 } // namespace net |
| 440 | 465 |
| 441 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ | 466 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ |
| OLD | NEW |