| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_COMMON_H_ | 5 #ifndef NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
| 6 #define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ | 6 #define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 23 #include "net/cert/cert_verifier.h" | 23 #include "net/cert/cert_verifier.h" |
| 24 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
| 25 #include "net/http/http_auth_handler_factory.h" | 25 #include "net/http/http_auth_handler_factory.h" |
| 26 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
| 27 #include "net/http/http_response_info.h" | 27 #include "net/http/http_response_info.h" |
| 28 #include "net/http/http_server_properties_impl.h" | 28 #include "net/http/http_server_properties_impl.h" |
| 29 #include "net/http/transport_security_state.h" | 29 #include "net/http/transport_security_state.h" |
| 30 #include "net/proxy/proxy_server.h" | 30 #include "net/proxy/proxy_server.h" |
| 31 #include "net/proxy/proxy_service.h" | 31 #include "net/proxy/proxy_service.h" |
| 32 #include "net/socket/next_proto.h" | |
| 33 #include "net/socket/socket_test_util.h" | 32 #include "net/socket/socket_test_util.h" |
| 34 #include "net/spdy/spdy_protocol.h" | 33 #include "net/spdy/spdy_protocol.h" |
| 35 #include "net/ssl/ssl_config_service_defaults.h" | 34 #include "net/ssl/ssl_config_service_defaults.h" |
| 36 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
| 37 #include "net/url_request/url_request_context_storage.h" | 36 #include "net/url_request/url_request_context_storage.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 38 |
| 40 class GURL; | 39 class GURL; |
| 41 | 40 |
| 42 namespace net { | 41 namespace net { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 89 |
| 91 // Combines the given SpdySerializedFrame into the given char array and returns | 90 // Combines the given SpdySerializedFrame into the given char array and returns |
| 92 // the total length. | 91 // the total length. |
| 93 int CombineFrames(const SpdySerializedFrame** frames, | 92 int CombineFrames(const SpdySerializedFrame** frames, |
| 94 int num_frames, | 93 int num_frames, |
| 95 char* buf, | 94 char* buf, |
| 96 int buf_len); | 95 int buf_len); |
| 97 | 96 |
| 98 // Returns the SpdyPriority embedded in the given frame. Returns true | 97 // Returns the SpdyPriority embedded in the given frame. Returns true |
| 99 // and fills in |priority| on success. | 98 // and fills in |priority| on success. |
| 100 bool GetSpdyPriority(SpdyMajorVersion version, | 99 bool GetSpdyPriority(const SpdySerializedFrame& frame, SpdyPriority* priority); |
| 101 const SpdySerializedFrame& frame, | |
| 102 SpdyPriority* priority); | |
| 103 | 100 |
| 104 // Tries to create a stream in |session| synchronously. Returns NULL | 101 // Tries to create a stream in |session| synchronously. Returns NULL |
| 105 // on failure. | 102 // on failure. |
| 106 base::WeakPtr<SpdyStream> CreateStreamSynchronously( | 103 base::WeakPtr<SpdyStream> CreateStreamSynchronously( |
| 107 SpdyStreamType type, | 104 SpdyStreamType type, |
| 108 const base::WeakPtr<SpdySession>& session, | 105 const base::WeakPtr<SpdySession>& session, |
| 109 const GURL& url, | 106 const GURL& url, |
| 110 RequestPriority priority, | 107 RequestPriority priority, |
| 111 const BoundNetLog& net_log); | 108 const BoundNetLog& net_log); |
| 112 | 109 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 crypto::ECPrivateKey* key) override; | 165 crypto::ECPrivateKey* key) override; |
| 169 | 166 |
| 170 private: | 167 private: |
| 171 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); | 168 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); |
| 172 }; | 169 }; |
| 173 | 170 |
| 174 // Helper to manage the lifetimes of the dependencies for a | 171 // Helper to manage the lifetimes of the dependencies for a |
| 175 // HttpNetworkTransaction. | 172 // HttpNetworkTransaction. |
| 176 struct SpdySessionDependencies { | 173 struct SpdySessionDependencies { |
| 177 // Default set of dependencies -- "null" proxy service. | 174 // Default set of dependencies -- "null" proxy service. |
| 178 explicit SpdySessionDependencies(NextProto protocol); | 175 SpdySessionDependencies(); |
| 179 | 176 |
| 180 // Custom proxy service dependency. | 177 // Custom proxy service dependency. |
| 181 SpdySessionDependencies(NextProto protocol, | 178 explicit SpdySessionDependencies(std::unique_ptr<ProxyService> proxy_service); |
| 182 std::unique_ptr<ProxyService> proxy_service); | |
| 183 | 179 |
| 184 ~SpdySessionDependencies(); | 180 ~SpdySessionDependencies(); |
| 185 | 181 |
| 186 static std::unique_ptr<HttpNetworkSession> SpdyCreateSession( | 182 static std::unique_ptr<HttpNetworkSession> SpdyCreateSession( |
| 187 SpdySessionDependencies* session_deps); | 183 SpdySessionDependencies* session_deps); |
| 188 static HttpNetworkSession::Params CreateSessionParams( | 184 static HttpNetworkSession::Params CreateSessionParams( |
| 189 SpdySessionDependencies* session_deps); | 185 SpdySessionDependencies* session_deps); |
| 190 | 186 |
| 191 // NOTE: host_resolver must be ordered before http_auth_handler_factory. | 187 // NOTE: host_resolver must be ordered before http_auth_handler_factory. |
| 192 std::unique_ptr<MockHostResolverBase> host_resolver; | 188 std::unique_ptr<MockHostResolverBase> host_resolver; |
| 193 std::unique_ptr<CertVerifier> cert_verifier; | 189 std::unique_ptr<CertVerifier> cert_verifier; |
| 194 std::unique_ptr<ChannelIDService> channel_id_service; | 190 std::unique_ptr<ChannelIDService> channel_id_service; |
| 195 std::unique_ptr<TransportSecurityState> transport_security_state; | 191 std::unique_ptr<TransportSecurityState> transport_security_state; |
| 196 std::unique_ptr<CTVerifier> cert_transparency_verifier; | 192 std::unique_ptr<CTVerifier> cert_transparency_verifier; |
| 197 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer; | 193 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer; |
| 198 std::unique_ptr<ProxyService> proxy_service; | 194 std::unique_ptr<ProxyService> proxy_service; |
| 199 scoped_refptr<SSLConfigService> ssl_config_service; | 195 scoped_refptr<SSLConfigService> ssl_config_service; |
| 200 std::unique_ptr<MockClientSocketFactory> socket_factory; | 196 std::unique_ptr<MockClientSocketFactory> socket_factory; |
| 201 std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | 197 std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
| 202 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties; | 198 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties; |
| 203 bool enable_ip_pooling; | 199 bool enable_ip_pooling; |
| 204 bool enable_ping; | 200 bool enable_ping; |
| 205 bool enable_user_alternate_protocol_ports; | 201 bool enable_user_alternate_protocol_ports; |
| 206 bool enable_priority_dependencies; | 202 bool enable_priority_dependencies; |
| 207 bool enable_quic; | 203 bool enable_quic; |
| 208 NextProto protocol; | |
| 209 size_t session_max_recv_window_size; | 204 size_t session_max_recv_window_size; |
| 210 size_t stream_max_recv_window_size; | 205 size_t stream_max_recv_window_size; |
| 211 SpdySession::TimeFunc time_func; | 206 SpdySession::TimeFunc time_func; |
| 212 std::unique_ptr<ProxyDelegate> proxy_delegate; | 207 std::unique_ptr<ProxyDelegate> proxy_delegate; |
| 213 bool enable_http2_alternative_service_with_different_host; | 208 bool enable_http2_alternative_service_with_different_host; |
| 214 NetLog* net_log; | 209 NetLog* net_log; |
| 215 }; | 210 }; |
| 216 | 211 |
| 217 class SpdyURLRequestContext : public URLRequestContext { | 212 class SpdyURLRequestContext : public URLRequestContext { |
| 218 public: | 213 public: |
| 219 explicit SpdyURLRequestContext(NextProto protocol); | 214 SpdyURLRequestContext(); |
| 220 ~SpdyURLRequestContext() override; | 215 ~SpdyURLRequestContext() override; |
| 221 | 216 |
| 222 MockClientSocketFactory& socket_factory() { return socket_factory_; } | 217 MockClientSocketFactory& socket_factory() { return socket_factory_; } |
| 223 | 218 |
| 224 private: | 219 private: |
| 225 MockClientSocketFactory socket_factory_; | 220 MockClientSocketFactory socket_factory_; |
| 226 URLRequestContextStorage storage_; | 221 URLRequestContextStorage storage_; |
| 227 }; | 222 }; |
| 228 | 223 |
| 229 // Equivalent to pool->GetIfExists(spdy_session_key, BoundNetLog()) != NULL. | 224 // Equivalent to pool->GetIfExists(spdy_session_key, BoundNetLog()) != NULL. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 void SetStreamInitialRecvWindowSize(size_t window); | 275 void SetStreamInitialRecvWindowSize(size_t window); |
| 281 | 276 |
| 282 private: | 277 private: |
| 283 SpdySessionPool* const pool_; | 278 SpdySessionPool* const pool_; |
| 284 | 279 |
| 285 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); | 280 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); |
| 286 }; | 281 }; |
| 287 | 282 |
| 288 class SpdyTestUtil { | 283 class SpdyTestUtil { |
| 289 public: | 284 public: |
| 290 explicit SpdyTestUtil(NextProto protocol, bool dependency_priorities); | 285 explicit SpdyTestUtil(bool dependency_priorities); |
| 291 ~SpdyTestUtil(); | 286 ~SpdyTestUtil(); |
| 292 | 287 |
| 293 // Add the appropriate headers to put |url| into |block|. | 288 // Add the appropriate headers to put |url| into |block|. |
| 294 void AddUrlToHeaderBlock(base::StringPiece url, | 289 void AddUrlToHeaderBlock(base::StringPiece url, |
| 295 SpdyHeaderBlock* headers) const; | 290 SpdyHeaderBlock* headers) const; |
| 296 | 291 |
| 297 SpdyHeaderBlock ConstructGetHeaderBlock(base::StringPiece url) const; | 292 SpdyHeaderBlock ConstructGetHeaderBlock(base::StringPiece url) const; |
| 298 SpdyHeaderBlock ConstructGetHeaderBlockForProxy(base::StringPiece url) const; | 293 SpdyHeaderBlock ConstructGetHeaderBlockForProxy(base::StringPiece url) const; |
| 299 SpdyHeaderBlock ConstructHeadHeaderBlock(base::StringPiece url, | 294 SpdyHeaderBlock ConstructHeadHeaderBlock(base::StringPiece url, |
| 300 int64_t content_length) const; | 295 int64_t content_length) const; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 320 int tail_header_count) const; | 315 int tail_header_count) const; |
| 321 | 316 |
| 322 // Construct an expected SPDY reply string from the given headers. | 317 // Construct an expected SPDY reply string from the given headers. |
| 323 std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; | 318 std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; |
| 324 | 319 |
| 325 // Construct an expected SPDY SETTINGS frame. | 320 // Construct an expected SPDY SETTINGS frame. |
| 326 // |settings| are the settings to set. | 321 // |settings| are the settings to set. |
| 327 // Returns the constructed frame. The caller takes ownership of the frame. | 322 // Returns the constructed frame. The caller takes ownership of the frame. |
| 328 SpdySerializedFrame* ConstructSpdySettings(const SettingsMap& settings); | 323 SpdySerializedFrame* ConstructSpdySettings(const SettingsMap& settings); |
| 329 | 324 |
| 330 // Constructs an expected SPDY SETTINGS acknowledgement frame, if the protocol | 325 // Constructs an expected SPDY SETTINGS acknowledgement frame. |
| 331 // version is SPDY4 or higher, or an empty placeholder frame otherwise. | |
| 332 SpdySerializedFrame* ConstructSpdySettingsAck(); | 326 SpdySerializedFrame* ConstructSpdySettingsAck(); |
| 333 | 327 |
| 334 // Construct a SPDY PING frame. | 328 // Construct a SPDY PING frame. |
| 335 // Returns the constructed frame. The caller takes ownership of the frame. | 329 // Returns the constructed frame. The caller takes ownership of the frame. |
| 336 SpdySerializedFrame* ConstructSpdyPing(uint32_t ping_id, bool is_ack); | 330 SpdySerializedFrame* ConstructSpdyPing(uint32_t ping_id, bool is_ack); |
| 337 | 331 |
| 338 // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. | 332 // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. |
| 339 // Returns the constructed frame. The caller takes ownership of the frame. | 333 // Returns the constructed frame. The caller takes ownership of the frame. |
| 340 SpdySerializedFrame* ConstructSpdyGoAway(); | 334 SpdySerializedFrame* ConstructSpdyGoAway(); |
| 341 | 335 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 399 |
| 406 SpdySerializedFrame* ConstructInitialSpdyPushFrame(SpdyHeaderBlock headers, | 400 SpdySerializedFrame* ConstructInitialSpdyPushFrame(SpdyHeaderBlock headers, |
| 407 int stream_id, | 401 int stream_id, |
| 408 int associated_stream_id); | 402 int associated_stream_id); |
| 409 | 403 |
| 410 SpdySerializedFrame* ConstructSpdyPushHeaders( | 404 SpdySerializedFrame* ConstructSpdyPushHeaders( |
| 411 int stream_id, | 405 int stream_id, |
| 412 const char* const extra_headers[], | 406 const char* const extra_headers[], |
| 413 int extra_header_count); | 407 int extra_header_count); |
| 414 | 408 |
| 415 // Constructs a SPDY header frame with the request header compression context | 409 // Constructs a HEADERS frame with the request header compression context with |
| 416 // with END_STREAM flag set to |fin|. | 410 // END_STREAM flag set to |fin|. |
| 417 SpdySerializedFrame* ConstructSpdyResponseHeaders(int stream_id, | 411 SpdySerializedFrame* ConstructSpdyResponseHeaders(int stream_id, |
| 418 SpdyHeaderBlock headers, | 412 SpdyHeaderBlock headers, |
| 419 bool fin); | 413 bool fin); |
| 420 | 414 |
| 421 // Construct a SPDY syn (HEADERS or SYN_STREAM, depending on protocol | 415 // Construct a HEADERS frame carrying exactly the given headers and priority. |
| 422 // version) carrying exactly the given headers and priority. | |
| 423 SpdySerializedFrame* ConstructSpdySyn(int stream_id, | 416 SpdySerializedFrame* ConstructSpdySyn(int stream_id, |
| 424 SpdyHeaderBlock headers, | 417 SpdyHeaderBlock headers, |
| 425 RequestPriority priority, | 418 RequestPriority priority, |
| 426 bool fin); | 419 bool fin); |
| 427 | 420 |
| 428 // Construct a SPDY reply (HEADERS or SYN_REPLY, depending on protocol | 421 // Construct a reply HEADERS frame carrying exactly the given headers and the |
| 429 // version) carrying exactly the given headers, and the default priority | 422 // default priority. |
| 430 // (or no priority, depending on protocol version). | |
| 431 SpdySerializedFrame* ConstructSpdyReply(int stream_id, | 423 SpdySerializedFrame* ConstructSpdyReply(int stream_id, |
| 432 SpdyHeaderBlock headers); | 424 SpdyHeaderBlock headers); |
| 433 | 425 |
| 434 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. | 426 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. |
| 435 // |extra_headers| are the extra header-value pairs, which typically | 427 // |extra_headers| are the extra header-value pairs, which typically |
| 436 // will vary the most between calls. | 428 // will vary the most between calls. |
| 437 // Returns a SpdySerializedFrame. | 429 // Returns a SpdySerializedFrame. |
| 438 SpdySerializedFrame* ConstructSpdyGetSynReply( | 430 SpdySerializedFrame* ConstructSpdyGetSynReply( |
| 439 const char* const extra_headers[], | 431 const char* const extra_headers[], |
| 440 int extra_header_count, | 432 int extra_header_count, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 int stream_id); | 500 int stream_id); |
| 509 | 501 |
| 510 // Serialize a SpdyFrameIR with |headerless_spdy_framer_|. | 502 // Serialize a SpdyFrameIR with |headerless_spdy_framer_|. |
| 511 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame_ir); | 503 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame_ir); |
| 512 | 504 |
| 513 // Called when necessary (when it will affect stream dependency specification | 505 // Called when necessary (when it will affect stream dependency specification |
| 514 // when setting dependencies based on priorioties) to notify the utility | 506 // when setting dependencies based on priorioties) to notify the utility |
| 515 // class of stream destruction. | 507 // class of stream destruction. |
| 516 void UpdateWithStreamDestruction(int stream_id); | 508 void UpdateWithStreamDestruction(int stream_id); |
| 517 | 509 |
| 518 // For versions below SPDY4, adds the version HTTP/1.1 header. | 510 // Maps |priority| to SPDY priority, and sets it on |frame_ir|. |
| 519 void MaybeAddVersionHeader(SpdyHeaderBlock* block) const; | |
| 520 | |
| 521 // Maps |priority| to SPDY version priority, and sets it on |frame_ir|. | |
| 522 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; | 511 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; |
| 523 | 512 |
| 524 NextProto protocol() const { return protocol_; } | |
| 525 SpdyMajorVersion spdy_version() const { return spdy_version_; } | |
| 526 bool include_version_header() const { return protocol_ < kProtoHTTP2; } | |
| 527 | |
| 528 void set_default_url(const GURL& url) { default_url_ = url; } | 513 void set_default_url(const GURL& url) { default_url_ = url; } |
| 529 | 514 |
| 530 const char* GetMethodKey() const; | 515 const char* GetMethodKey() const; |
| 531 const char* GetStatusKey() const; | 516 const char* GetStatusKey() const; |
| 532 const char* GetHostKey() const; | 517 const char* GetHostKey() const; |
| 533 const char* GetSchemeKey() const; | 518 const char* GetSchemeKey() const; |
| 534 const char* GetVersionKey() const; | |
| 535 const char* GetPathKey() const; | 519 const char* GetPathKey() const; |
| 536 | 520 |
| 537 private: | 521 private: |
| 538 // |content_length| may be NULL, in which case the content-length | 522 // |content_length| may be NULL, in which case the content-length |
| 539 // header will be omitted. | 523 // header will be omitted. |
| 540 SpdyHeaderBlock ConstructHeaderBlock(base::StringPiece method, | 524 SpdyHeaderBlock ConstructHeaderBlock(base::StringPiece method, |
| 541 base::StringPiece url, | 525 base::StringPiece url, |
| 542 int64_t* content_length) const; | 526 int64_t* content_length) const; |
| 543 | 527 |
| 544 const NextProto protocol_; | |
| 545 const SpdyMajorVersion spdy_version_; | |
| 546 | |
| 547 // Multiple SpdyFramers are required to keep track of header compression | 528 // Multiple SpdyFramers are required to keep track of header compression |
| 548 // state. | 529 // state. |
| 549 // Use to serialize frames (request or response) without headers. | 530 // Use to serialize frames (request or response) without headers. |
| 550 SpdyFramer headerless_spdy_framer_; | 531 SpdyFramer headerless_spdy_framer_; |
| 551 // Use to serialize request frames with headers. | 532 // Use to serialize request frames with headers. |
| 552 SpdyFramer request_spdy_framer_; | 533 SpdyFramer request_spdy_framer_; |
| 553 // Use to serialize response frames with headers. | 534 // Use to serialize response frames with headers. |
| 554 SpdyFramer response_spdy_framer_; | 535 SpdyFramer response_spdy_framer_; |
| 555 | 536 |
| 556 GURL default_url_; | 537 GURL default_url_; |
| 557 bool dependency_priorities_; | 538 bool dependency_priorities_; |
| 558 | 539 |
| 559 // Track a FIFO list of the stream_id of all created requests by priority. | 540 // Track a FIFO list of the stream_id of all created requests by priority. |
| 560 std::map<int, std::vector<int>> priority_to_stream_id_list_; | 541 std::map<int, std::vector<int>> priority_to_stream_id_list_; |
| 561 }; | 542 }; |
| 562 | 543 |
| 563 } // namespace net | 544 } // namespace net |
| 564 | 545 |
| 565 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ | 546 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
| OLD | NEW |