[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
| 6 | #define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
| 7 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13 | #include "crypto/ec_private_key.h" |
| 14 | #include "crypto/ec_signature_creator.h" |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 15 | #include "net/base/completion_callback.h" |
| 16 | #include "net/base/request_priority.h" |
| 17 | #include "net/base/test_completion_callback.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 18 | #include "net/cert/cert_verifier.h" |
| 19 | #include "net/dns/mock_host_resolver.h" |
| 20 | #include "net/http/http_auth_handler_factory.h" |
| 21 | #include "net/http/http_network_session.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 22 | #include "net/http/http_response_info.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 23 | #include "net/http/http_server_properties_impl.h" |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 24 | #include "net/http/transport_security_state.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 25 | #include "net/proxy/proxy_service.h" |
| 26 | #include "net/socket/next_proto.h" |
[email protected] | 5a62b8b | 2013-04-04 09:26:24 | [diff] [blame] | 27 | #include "net/socket/socket_test_util.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 28 | #include "net/spdy/spdy_protocol.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 29 | #include "net/ssl/ssl_config_service_defaults.h" |
| 30 | #include "net/url_request/url_request_context.h" |
| 31 | #include "net/url_request/url_request_context_storage.h" |
| 32 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 33 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 34 | class GURL; |
| 35 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 36 | namespace net { |
| 37 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 38 | class BoundNetLog; |
| 39 | class SpdySession; |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 40 | class SpdySessionKey; |
| 41 | class SpdySessionPool; |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 42 | class SpdyStream; |
| 43 | class SpdyStreamRequest; |
| 44 | |
[email protected] | 5a62b8b | 2013-04-04 09:26:24 | [diff] [blame] | 45 | // Default upload data used by both, mock objects and framer when creating |
| 46 | // data frames. |
| 47 | const char kDefaultURL[] = "http://www.google.com"; |
| 48 | const char kUploadData[] = "hello!"; |
| 49 | const int kUploadDataSize = arraysize(kUploadData)-1; |
| 50 | |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 51 | // SpdyNextProtos returns a vector of next protocols for negotiating |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 52 | // SPDY. |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 53 | std::vector<NextProto> SpdyNextProtos(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 54 | |
[email protected] | 5a62b8b | 2013-04-04 09:26:24 | [diff] [blame] | 55 | // Chop a frame into an array of MockWrites. |
| 56 | // |data| is the frame to chop. |
| 57 | // |length| is the length of the frame to chop. |
| 58 | // |num_chunks| is the number of chunks to create. |
| 59 | MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); |
| 60 | |
| 61 | // Chop a SpdyFrame into an array of MockWrites. |
| 62 | // |frame| is the frame to chop. |
| 63 | // |num_chunks| is the number of chunks to create. |
| 64 | MockWrite* ChopWriteFrame(const SpdyFrame& frame, int num_chunks); |
| 65 | |
| 66 | // Chop a frame into an array of MockReads. |
| 67 | // |data| is the frame to chop. |
| 68 | // |length| is the length of the frame to chop. |
| 69 | // |num_chunks| is the number of chunks to create. |
| 70 | MockRead* ChopReadFrame(const char* data, int length, int num_chunks); |
| 71 | |
| 72 | // Chop a SpdyFrame into an array of MockReads. |
| 73 | // |frame| is the frame to chop. |
| 74 | // |num_chunks| is the number of chunks to create. |
| 75 | MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks); |
| 76 | |
| 77 | // Adds headers and values to a map. |
| 78 | // |extra_headers| is an array of { name, value } pairs, arranged as strings |
| 79 | // where the even entries are the header names, and the odd entries are the |
| 80 | // header values. |
| 81 | // |headers| gets filled in from |extra_headers|. |
| 82 | void AppendToHeaderBlock(const char* const extra_headers[], |
| 83 | int extra_header_count, |
| 84 | SpdyHeaderBlock* headers); |
| 85 | |
[email protected] | 5a62b8b | 2013-04-04 09:26:24 | [diff] [blame] | 86 | // Create an async MockWrite from the given SpdyFrame. |
| 87 | MockWrite CreateMockWrite(const SpdyFrame& req); |
| 88 | |
| 89 | // Create an async MockWrite from the given SpdyFrame and sequence number. |
| 90 | MockWrite CreateMockWrite(const SpdyFrame& req, int seq); |
| 91 | |
| 92 | MockWrite CreateMockWrite(const SpdyFrame& req, int seq, IoMode mode); |
| 93 | |
| 94 | // Create a MockRead from the given SpdyFrame. |
| 95 | MockRead CreateMockRead(const SpdyFrame& resp); |
| 96 | |
| 97 | // Create a MockRead from the given SpdyFrame and sequence number. |
| 98 | MockRead CreateMockRead(const SpdyFrame& resp, int seq); |
| 99 | |
| 100 | MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode); |
| 101 | |
| 102 | // Combines the given SpdyFrames into the given char array and returns |
| 103 | // the total length. |
| 104 | int CombineFrames(const SpdyFrame** frames, int num_frames, |
| 105 | char* buff, int buff_len); |
| 106 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 107 | // Returns the SpdyPriority embedded in the given frame. Returns true |
| 108 | // and fills in |priority| on success. |
[email protected] | 977bd84 | 2013-05-16 17:43:42 | [diff] [blame] | 109 | bool GetSpdyPriority(SpdyMajorVersion version, |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 110 | const SpdyFrame& frame, |
| 111 | SpdyPriority* priority); |
| 112 | |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 113 | // Tries to create a stream in |session| synchronously. Returns NULL |
| 114 | // on failure. |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 115 | base::WeakPtr<SpdyStream> CreateStreamSynchronously( |
[email protected] | fb73cd67 | 2013-05-27 12:53:08 | [diff] [blame] | 116 | SpdyStreamType type, |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 117 | const base::WeakPtr<SpdySession>& session, |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 118 | const GURL& url, |
| 119 | RequestPriority priority, |
| 120 | const BoundNetLog& net_log); |
| 121 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 122 | // Helper class used by some tests to release a stream as soon as it's |
| 123 | // created. |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 124 | class StreamReleaserCallback : public TestCompletionCallbackBase { |
| 125 | public: |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 126 | StreamReleaserCallback(); |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 127 | |
| 128 | virtual ~StreamReleaserCallback(); |
| 129 | |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 130 | // Returns a callback that releases |request|'s stream. |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 131 | CompletionCallback MakeCallback(SpdyStreamRequest* request); |
| 132 | |
| 133 | private: |
| 134 | void OnComplete(SpdyStreamRequest* request, int result); |
[email protected] | e3861ca | 2013-03-02 01:00:45 | [diff] [blame] | 135 | }; |
| 136 | |
[email protected] | 29d54a6 | 2013-04-18 07:01:32 | [diff] [blame] | 137 | const size_t kSpdyCredentialSlotUnused = 0; |
| 138 | |
| 139 | // This struct holds information used to construct spdy control and data frames. |
| 140 | struct SpdyHeaderInfo { |
| 141 | SpdyFrameType kind; |
| 142 | SpdyStreamId id; |
| 143 | SpdyStreamId assoc_id; |
| 144 | SpdyPriority priority; |
| 145 | size_t credential_slot; // SPDY3 only |
| 146 | SpdyControlFlags control_flags; |
| 147 | bool compressed; |
| 148 | SpdyRstStreamStatus status; |
| 149 | const char* data; |
| 150 | uint32 data_length; |
| 151 | SpdyDataFlags data_flags; |
| 152 | }; |
| 153 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 154 | // An ECSignatureCreator that returns deterministic signatures. |
| 155 | class MockECSignatureCreator : public crypto::ECSignatureCreator { |
| 156 | public: |
| 157 | explicit MockECSignatureCreator(crypto::ECPrivateKey* key); |
| 158 | |
| 159 | // crypto::ECSignatureCreator |
| 160 | virtual bool Sign(const uint8* data, |
| 161 | int data_len, |
| 162 | std::vector<uint8>* signature) OVERRIDE; |
| 163 | virtual bool DecodeSignature(const std::vector<uint8>& signature, |
| 164 | std::vector<uint8>* out_raw_sig) OVERRIDE; |
| 165 | |
| 166 | private: |
| 167 | crypto::ECPrivateKey* key_; |
| 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); |
| 170 | }; |
| 171 | |
| 172 | // An ECSignatureCreatorFactory creates MockECSignatureCreator. |
| 173 | class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { |
| 174 | public: |
| 175 | MockECSignatureCreatorFactory(); |
| 176 | virtual ~MockECSignatureCreatorFactory(); |
| 177 | |
| 178 | // crypto::ECSignatureCreatorFactory |
| 179 | virtual crypto::ECSignatureCreator* Create( |
| 180 | crypto::ECPrivateKey* key) OVERRIDE; |
| 181 | |
| 182 | private: |
| 183 | DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); |
| 184 | }; |
| 185 | |
| 186 | // Helper to manage the lifetimes of the dependencies for a |
| 187 | // HttpNetworkTransaction. |
| 188 | struct SpdySessionDependencies { |
| 189 | // Default set of dependencies -- "null" proxy service. |
| 190 | explicit SpdySessionDependencies(NextProto protocol); |
| 191 | |
| 192 | // Custom proxy service dependency. |
| 193 | SpdySessionDependencies(NextProto protocol, ProxyService* proxy_service); |
| 194 | |
| 195 | ~SpdySessionDependencies(); |
| 196 | |
| 197 | static HttpNetworkSession* SpdyCreateSession( |
| 198 | SpdySessionDependencies* session_deps); |
| 199 | static HttpNetworkSession* SpdyCreateSessionDeterministic( |
| 200 | SpdySessionDependencies* session_deps); |
| 201 | static HttpNetworkSession::Params CreateSessionParams( |
| 202 | SpdySessionDependencies* session_deps); |
| 203 | |
| 204 | // NOTE: host_resolver must be ordered before http_auth_handler_factory. |
| 205 | scoped_ptr<MockHostResolverBase> host_resolver; |
| 206 | scoped_ptr<CertVerifier> cert_verifier; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 207 | scoped_ptr<TransportSecurityState> transport_security_state; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 208 | scoped_ptr<ProxyService> proxy_service; |
| 209 | scoped_refptr<SSLConfigService> ssl_config_service; |
| 210 | scoped_ptr<MockClientSocketFactory> socket_factory; |
| 211 | scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; |
| 212 | scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
| 213 | HttpServerPropertiesImpl http_server_properties; |
| 214 | bool enable_ip_pooling; |
| 215 | bool enable_compression; |
| 216 | bool enable_ping; |
| 217 | bool enable_user_alternate_protocol_ports; |
| 218 | NextProto protocol; |
| 219 | size_t stream_initial_recv_window_size; |
| 220 | SpdySession::TimeFunc time_func; |
| 221 | std::string trusted_spdy_proxy; |
| 222 | NetLog* net_log; |
| 223 | }; |
| 224 | |
| 225 | class SpdyURLRequestContext : public URLRequestContext { |
| 226 | public: |
| 227 | explicit SpdyURLRequestContext(NextProto protocol); |
| 228 | virtual ~SpdyURLRequestContext(); |
| 229 | |
| 230 | MockClientSocketFactory& socket_factory() { return socket_factory_; } |
| 231 | |
| 232 | private: |
| 233 | MockClientSocketFactory socket_factory_; |
| 234 | net::URLRequestContextStorage storage_; |
| 235 | }; |
| 236 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 237 | // Equivalent to pool->GetIfExists(spdy_session_key, BoundNetLog()) != NULL. |
| 238 | bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key); |
| 239 | |
| 240 | // Creates a SPDY session for the given key and puts it in the SPDY |
| 241 | // session pool in |http_session|. A SPDY session for |key| must not |
| 242 | // already exist. |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 243 | base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 244 | const scoped_refptr<HttpNetworkSession>& http_session, |
| 245 | const SpdySessionKey& key, |
| 246 | const BoundNetLog& net_log); |
| 247 | |
[email protected] | b55d42c | 2013-07-22 01:41:25 | [diff] [blame] | 248 | // Tries to create a SPDY session for the given key but expects the |
| 249 | // attempt to fail with the given error. A SPDY session for |key| must |
| 250 | // not already exist. |
| 251 | void TryCreateInsecureSpdySessionExpectingFailure( |
| 252 | const scoped_refptr<HttpNetworkSession>& http_session, |
| 253 | const SpdySessionKey& key, |
| 254 | Error expected_error, |
| 255 | const BoundNetLog& net_log); |
| 256 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 257 | // Like CreateInsecureSpdySession(), but uses TLS. |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 258 | base::WeakPtr<SpdySession> CreateSecureSpdySession( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 259 | const scoped_refptr<HttpNetworkSession>& http_session, |
| 260 | const SpdySessionKey& key, |
| 261 | const BoundNetLog& net_log); |
| 262 | |
| 263 | // Creates an insecure SPDY session for the given key and puts it in |
[email protected] | b55d42c | 2013-07-22 01:41:25 | [diff] [blame] | 264 | // |pool|. The returned session will neither receive nor send any |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 265 | // data. A SPDY session for |key| must not already exist. |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 266 | base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 267 | const SpdySessionKey& key); |
| 268 | |
[email protected] | b55d42c | 2013-07-22 01:41:25 | [diff] [blame] | 269 | // Tries to create an insecure SPDY session for the given key but |
| 270 | // expects the attempt to fail with the given error. The session will |
| 271 | // neither receive nor send any data. A SPDY session for |key| must |
| 272 | // not already exist. |
| 273 | void TryCreateFakeSpdySessionExpectingFailure(SpdySessionPool* pool, |
| 274 | const SpdySessionKey& key, |
| 275 | Error expected_error); |
| 276 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 277 | class SpdySessionPoolPeer { |
| 278 | public: |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 279 | explicit SpdySessionPoolPeer(SpdySessionPool* pool); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 280 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 281 | void RemoveAliases(const SpdySessionKey& key); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 282 | void DisableDomainAuthenticationVerification(); |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 283 | void SetEnableSendingInitialData(bool enabled); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 284 | |
| 285 | private: |
| 286 | SpdySessionPool* const pool_; |
| 287 | |
| 288 | DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); |
| 289 | }; |
| 290 | |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 291 | class SpdyTestUtil { |
| 292 | public: |
| 293 | explicit SpdyTestUtil(NextProto protocol); |
| 294 | |
[email protected] | 3d58737 | 2013-06-01 04:31:45 | [diff] [blame] | 295 | // Add the appropriate headers to put |url| into |block|. |
| 296 | void AddUrlToHeaderBlock(base::StringPiece url, |
| 297 | SpdyHeaderBlock* headers) const; |
| 298 | |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 299 | scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock( |
| 300 | base::StringPiece url) const; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 301 | scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlockForProxy( |
| 302 | base::StringPiece url) const; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 303 | scoped_ptr<SpdyHeaderBlock> ConstructHeadHeaderBlock( |
| 304 | base::StringPiece url, |
| 305 | int64 content_length) const; |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 306 | scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock( |
| 307 | base::StringPiece url, |
| 308 | int64 content_length) const; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 309 | scoped_ptr<SpdyHeaderBlock> ConstructPutHeaderBlock( |
| 310 | base::StringPiece url, |
| 311 | int64 content_length) const; |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 312 | |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 313 | // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as |
| 314 | // specified in header_info.kind), the provided headers are included in the |
| 315 | // frame. |
| 316 | SpdyFrame* ConstructSpdyFrame( |
| 317 | const SpdyHeaderInfo& header_info, |
| 318 | scoped_ptr<SpdyHeaderBlock> headers) const; |
| 319 | |
| 320 | // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as |
| 321 | // specified in header_info.kind), the headers provided in extra_headers and |
| 322 | // (if non-NULL) tail_headers are concatenated and included in the frame. |
| 323 | // (extra_headers must always be non-NULL.) |
| 324 | SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
| 325 | const char* const extra_headers[], |
| 326 | int extra_header_count, |
| 327 | const char* const tail_headers[], |
| 328 | int tail_header_count) const; |
| 329 | |
[email protected] | e5bfe36 | 2013-05-15 04:50:34 | [diff] [blame] | 330 | // Construct a generic SpdyControlFrame. |
[email protected] | 80c3294 | 2013-06-01 01:05:21 | [diff] [blame] | 331 | SpdyFrame* ConstructSpdyControlFrame( |
| 332 | scoped_ptr<SpdyHeaderBlock> headers, |
| 333 | bool compressed, |
| 334 | SpdyStreamId stream_id, |
| 335 | RequestPriority request_priority, |
| 336 | SpdyFrameType type, |
| 337 | SpdyControlFlags flags, |
| 338 | SpdyStreamId associated_stream_id) const; |
| 339 | |
| 340 | // Construct a generic SpdyControlFrame. |
[email protected] | e5bfe36 | 2013-05-15 04:50:34 | [diff] [blame] | 341 | // |
| 342 | // Warning: extra_header_count is the number of header-value pairs in |
| 343 | // extra_headers (so half the number of elements), but tail_headers_size is |
| 344 | // the actual number of elements (both keys and values) in tail_headers. |
| 345 | // TODO(ttuttle): Fix this inconsistency. |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 346 | SpdyFrame* ConstructSpdyControlFrame( |
| 347 | const char* const extra_headers[], |
| 348 | int extra_header_count, |
| 349 | bool compressed, |
| 350 | SpdyStreamId stream_id, |
| 351 | RequestPriority request_priority, |
| 352 | SpdyFrameType type, |
| 353 | SpdyControlFlags flags, |
[email protected] | e5bfe36 | 2013-05-15 04:50:34 | [diff] [blame] | 354 | const char* const* tail_headers, |
| 355 | int tail_headers_size, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 356 | SpdyStreamId associated_stream_id) const; |
| 357 | |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 358 | // Construct an expected SPDY reply string from the given headers. |
| 359 | std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; |
[email protected] | 5fb3b32 | 2013-05-20 03:50:56 | [diff] [blame] | 360 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 361 | // Construct an expected SPDY SETTINGS frame. |
| 362 | // |settings| are the settings to set. |
| 363 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 364 | SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) const; |
| 365 | |
| 366 | // Construct an expected SPDY CREDENTIAL frame. |
| 367 | // |credential| is the credential to send. |
| 368 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 369 | SpdyFrame* ConstructSpdyCredential(const SpdyCredential& credential) const; |
| 370 | |
| 371 | // Construct a SPDY PING frame. |
| 372 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 373 | SpdyFrame* ConstructSpdyPing(uint32 ping_id) const; |
| 374 | |
| 375 | // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. |
| 376 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 377 | SpdyFrame* ConstructSpdyGoAway() const; |
| 378 | |
| 379 | // Construct a SPDY GOAWAY frame with the specified last_good_stream_id. |
| 380 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 381 | SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) const; |
| 382 | |
| 383 | // Construct a SPDY WINDOW_UPDATE frame. |
| 384 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 385 | SpdyFrame* ConstructSpdyWindowUpdate( |
| 386 | SpdyStreamId stream_id, |
| 387 | uint32 delta_window_size) const; |
| 388 | |
| 389 | // Construct a SPDY RST_STREAM frame. |
| 390 | // Returns the constructed frame. The caller takes ownership of the frame. |
| 391 | SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
| 392 | SpdyRstStreamStatus status) const; |
| 393 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 394 | // Constructs a standard SPDY GET SYN frame, optionally compressed |
| 395 | // for the url |url|. |
| 396 | // |extra_headers| are the extra header-value pairs, which typically |
| 397 | // will vary the most between calls. |
| 398 | // Returns a SpdyFrame. |
| 399 | SpdyFrame* ConstructSpdyGet(const char* const url, |
| 400 | bool compressed, |
| 401 | SpdyStreamId stream_id, |
| 402 | RequestPriority request_priority) const; |
| 403 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 404 | SpdyFrame* ConstructSpdyGetForProxy(const char* const url, |
| 405 | bool compressed, |
| 406 | SpdyStreamId stream_id, |
| 407 | RequestPriority request_priority) const; |
| 408 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 409 | // Constructs a standard SPDY GET SYN frame, optionally compressed. |
| 410 | // |extra_headers| are the extra header-value pairs, which typically |
| 411 | // will vary the most between calls. If |direct| is false, the |
| 412 | // the full url will be used instead of simply the path. |
| 413 | // Returns a SpdyFrame. |
| 414 | SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 415 | int extra_header_count, |
| 416 | bool compressed, |
| 417 | int stream_id, |
| 418 | RequestPriority request_priority, |
| 419 | bool direct) const; |
| 420 | |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 421 | // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
| 422 | SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
| 423 | int extra_header_count, |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 424 | int stream_id, |
| 425 | RequestPriority priority) const; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 426 | |
[email protected] | ab026dc4 | 2013-05-31 23:59:18 | [diff] [blame] | 427 | // Constructs a standard SPDY push SYN frame. |
| 428 | // |extra_headers| are the extra header-value pairs, which typically |
| 429 | // will vary the most between calls. |
| 430 | // Returns a SpdyFrame. |
| 431 | SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 432 | int extra_header_count, |
| 433 | int stream_id, |
[email protected] | ab026dc4 | 2013-05-31 23:59:18 | [diff] [blame] | 434 | int associated_stream_id, |
| 435 | const char* url); |
| 436 | SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 437 | int extra_header_count, |
| 438 | int stream_id, |
| 439 | int associated_stream_id, |
| 440 | const char* url, |
| 441 | const char* status, |
| 442 | const char* location); |
| 443 | |
| 444 | SpdyFrame* ConstructSpdyPushHeaders(int stream_id, |
| 445 | const char* const extra_headers[], |
| 446 | int extra_header_count); |
| 447 | |
| 448 | // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. |
| 449 | // |extra_headers| are the extra header-value pairs, which typically |
| 450 | // will vary the most between calls. |
| 451 | // Returns a SpdyFrame. |
| 452 | SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 453 | int extra_header_count, |
| 454 | int stream_id); |
| 455 | |
| 456 | // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. |
| 457 | // |extra_headers| are the extra header-value pairs, which typically |
| 458 | // will vary the most between calls. |
| 459 | // Returns a SpdyFrame. |
| 460 | SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); |
| 461 | |
| 462 | // Constructs a standard SPDY SYN_REPLY frame with an Internal Server |
| 463 | // Error status code. |
| 464 | // Returns a SpdyFrame. |
| 465 | SpdyFrame* ConstructSpdySynReplyError(int stream_id); |
| 466 | |
| 467 | // Constructs a standard SPDY SYN_REPLY frame with the specified status code. |
| 468 | // Returns a SpdyFrame. |
| 469 | SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
| 470 | const char* const* const extra_headers, |
| 471 | int extra_header_count, |
| 472 | int stream_id); |
| 473 | |
| 474 | // Constructs a standard SPDY POST SYN frame. |
| 475 | // |extra_headers| are the extra header-value pairs, which typically |
| 476 | // will vary the most between calls. |
| 477 | // Returns a SpdyFrame. |
| 478 | SpdyFrame* ConstructSpdyPost(const char* url, |
| 479 | SpdyStreamId stream_id, |
| 480 | int64 content_length, |
| 481 | RequestPriority priority, |
| 482 | const char* const extra_headers[], |
| 483 | int extra_header_count); |
| 484 | |
| 485 | // Constructs a chunked transfer SPDY POST SYN frame. |
| 486 | // |extra_headers| are the extra header-value pairs, which typically |
| 487 | // will vary the most between calls. |
| 488 | // Returns a SpdyFrame. |
| 489 | SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], |
| 490 | int extra_header_count); |
| 491 | |
| 492 | // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. |
| 493 | // |extra_headers| are the extra header-value pairs, which typically |
| 494 | // will vary the most between calls. |
| 495 | // Returns a SpdyFrame. |
| 496 | SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
| 497 | int extra_header_count); |
| 498 | |
| 499 | // Constructs a single SPDY data frame with the contents "hello!" |
| 500 | SpdyFrame* ConstructSpdyBodyFrame(int stream_id, |
| 501 | bool fin); |
| 502 | |
| 503 | // Constructs a single SPDY data frame with the given content. |
| 504 | SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
| 505 | uint32 len, bool fin); |
| 506 | |
| 507 | // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
| 508 | SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
| 509 | int stream_id); |
| 510 | |
| 511 | const SpdyHeaderInfo MakeSpdyHeader(SpdyFrameType type); |
| 512 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 513 | NextProto protocol() const { return protocol_; } |
[email protected] | 977bd84 | 2013-05-16 17:43:42 | [diff] [blame] | 514 | SpdyMajorVersion spdy_version() const { return spdy_version_; } |
[email protected] | 1723f69 | 2013-05-16 03:39:37 | [diff] [blame] | 515 | bool is_spdy2() const { return protocol_ < kProtoSPDY3; } |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 516 | scoped_ptr<SpdyFramer> CreateFramer() const; |
| 517 | |
[email protected] | ab026dc4 | 2013-05-31 23:59:18 | [diff] [blame] | 518 | const char* GetMethodKey() const; |
| 519 | const char* GetStatusKey() const; |
| 520 | const char* GetHostKey() const; |
| 521 | const char* GetSchemeKey() const; |
| 522 | const char* GetVersionKey() const; |
| 523 | const char* GetPathKey() const; |
| 524 | |
[email protected] | 3d58737 | 2013-06-01 04:31:45 | [diff] [blame] | 525 | private: |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 526 | // |content_length| may be NULL, in which case the content-length |
| 527 | // header will be omitted. |
| 528 | scoped_ptr<SpdyHeaderBlock> ConstructHeaderBlock( |
| 529 | base::StringPiece method, |
| 530 | base::StringPiece url, |
| 531 | int64* content_length) const; |
| 532 | |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 533 | const NextProto protocol_; |
[email protected] | 977bd84 | 2013-05-16 17:43:42 | [diff] [blame] | 534 | const SpdyMajorVersion spdy_version_; |
[email protected] | a4a6777 | 2013-05-08 22:56:07 | [diff] [blame] | 535 | }; |
| 536 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 537 | } // namespace net |
| 538 | |
| 539 | #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |