| 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 "net/base/cert_verifier.h" | 10 #include "net/base/cert_verifier.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 // Construct a SPDY packet. | 117 // Construct a SPDY packet. |
| 118 // |head| is the start of the packet, up to but not including | 118 // |head| is the start of the packet, up to but not including |
| 119 // the header value pairs. | 119 // the header value pairs. |
| 120 // |extra_headers| are the extra header-value pairs, which typically | 120 // |extra_headers| are the extra header-value pairs, which typically |
| 121 // will vary the most between calls. | 121 // will vary the most between calls. |
| 122 // |tail| is any (relatively constant) header-value pairs to add. | 122 // |tail| is any (relatively constant) header-value pairs to add. |
| 123 // |buffer| is the buffer we're filling in. | 123 // |buffer| is the buffer we're filling in. |
| 124 // Returns a SpdyFrame. | 124 // Returns a SpdyFrame. |
| 125 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, | 125 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, |
| 126 const char* const extra_headers[], | 126 const char* const extra_headers[], |
| 127 int extra_header_count, | 127 int extra_header_count, |
| 128 const char* const tail[], | 128 const char* const tail[], |
| 129 int tail_header_count); | 129 int tail_header_count); |
| 130 | 130 |
| 131 // Construct a generic SpdyControlFrame. | 131 // Construct a generic SpdyControlFrame. |
| 132 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], | 132 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
| 133 int extra_header_count, | 133 int extra_header_count, |
| 134 bool compressed, | 134 bool compressed, |
| 135 int stream_id, | 135 int stream_id, |
| 136 RequestPriority request_priority, | 136 RequestPriority request_priority, |
| 137 SpdyControlType type, | 137 SpdyControlType type, |
| 138 SpdyControlFlags flags, | 138 SpdyControlFlags flags, |
| 139 const char* const* kHeaders, | 139 const char* const* kHeaders, |
| 140 int kHeadersSize); | 140 int kHeadersSize); |
| 141 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], | 141 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
| 142 int extra_header_count, | 142 int extra_header_count, |
| 143 bool compressed, | 143 bool compressed, |
| 144 int stream_id, | 144 int stream_id, |
| 145 RequestPriority request_priority, | 145 RequestPriority request_priority, |
| 146 SpdyControlType type, | 146 SpdyControlType type, |
| 147 SpdyControlFlags flags, | 147 SpdyControlFlags flags, |
| 148 const char* const* kHeaders, | 148 const char* const* kHeaders, |
| 149 int kHeadersSize, | 149 int kHeadersSize, |
| 150 int associated_stream_id); | 150 int associated_stream_id); |
| 151 | 151 |
| 152 // Construct an expected SPDY reply string. | 152 // Construct an expected SPDY reply string. |
| 153 // |extra_headers| are the extra header-value pairs, which typically | 153 // |extra_headers| are the extra header-value pairs, which typically |
| 154 // will vary the most between calls. | 154 // will vary the most between calls. |
| 155 // |buffer| is the buffer we're filling in. | 155 // |buffer| is the buffer we're filling in. |
| 156 // Returns the number of bytes written into |buffer|. | 156 // Returns the number of bytes written into |buffer|. |
| 157 int ConstructSpdyReplyString(const char* const extra_headers[], | 157 int ConstructSpdyReplyString(const char* const extra_headers[], |
| 158 int extra_header_count, | 158 int extra_header_count, |
| 159 char* buffer, | 159 char* buffer, |
| 160 int buffer_length); | 160 int buffer_length); |
| 161 | 161 |
| 162 // Construct an expected SPDY SETTINGS frame. | 162 // Construct an expected SPDY SETTINGS frame. |
| 163 // |settings| are the settings to set. | 163 // |settings| are the settings to set. |
| 164 // Returns the constructed frame. The caller takes ownership of the frame. | 164 // Returns the constructed frame. The caller takes ownership of the frame. |
| 165 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings); | 165 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings); |
| 166 | 166 |
| 167 // Construct an expected SPDY CREDENTIAL frame. | 167 // Construct an expected SPDY CREDENTIAL frame. |
| 168 // |credential| is the credential to send. | 168 // |credential| is the credential to send. |
| 169 // Returns the constructed frame. The caller takes ownership of the frame. | 169 // Returns the constructed frame. The caller takes ownership of the frame. |
| 170 SpdyFrame* ConstructSpdyCredential( | 170 SpdyFrame* ConstructSpdyCredential(const SpdyCredential& credential); |
| 171 const SpdyCredential& credential); | |
| 172 | 171 |
| 173 // Construct a SPDY PING frame. | 172 // Construct a SPDY PING frame. |
| 174 // Returns the constructed frame. The caller takes ownership of the frame. | 173 // Returns the constructed frame. The caller takes ownership of the frame. |
| 175 SpdyFrame* ConstructSpdyPing(); | 174 SpdyFrame* ConstructSpdyPing(); |
| 176 | 175 |
| 177 // Construct a SPDY GOAWAY frame. | 176 // Construct a SPDY GOAWAY frame. |
| 178 // Returns the constructed frame. The caller takes ownership of the frame. | 177 // Returns the constructed frame. The caller takes ownership of the frame. |
| 179 SpdyFrame* ConstructSpdyGoAway(); | 178 SpdyFrame* ConstructSpdyGoAway(); |
| 180 | 179 |
| 181 // Construct a SPDY WINDOW_UPDATE frame. | 180 // Construct a SPDY WINDOW_UPDATE frame. |
| 182 // Returns the constructed frame. The caller takes ownership of the frame. | 181 // Returns the constructed frame. The caller takes ownership of the frame. |
| 183 SpdyFrame* ConstructSpdyWindowUpdate(SpdyStreamId, | 182 SpdyFrame* ConstructSpdyWindowUpdate(SpdyStreamId, uint32 delta_window_size); |
| 184 uint32 delta_window_size); | |
| 185 | 183 |
| 186 // Construct a SPDY RST_STREAM frame. | 184 // Construct a SPDY RST_STREAM frame. |
| 187 // Returns the constructed frame. The caller takes ownership of the frame. | 185 // Returns the constructed frame. The caller takes ownership of the frame. |
| 188 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, | 186 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
| 189 SpdyStatusCodes status); | 187 SpdyStatusCodes status); |
| 190 | 188 |
| 191 // Construct a single SPDY header entry, for validation. | 189 // Construct a single SPDY header entry, for validation. |
| 192 // |extra_headers| are the extra header-value pairs. | 190 // |extra_headers| are the extra header-value pairs. |
| 193 // |buffer| is the buffer we're filling in. | 191 // |buffer| is the buffer we're filling in. |
| 194 // |index| is the index of the header we want. | 192 // |index| is the index of the header we want. |
| 195 // Returns the number of bytes written into |buffer|. | 193 // Returns the number of bytes written into |buffer|. |
| 196 int ConstructSpdyHeader(const char* const extra_headers[], | 194 int ConstructSpdyHeader(const char* const extra_headers[], |
| 197 int extra_header_count, | 195 int extra_header_count, |
| 198 char* buffer, | 196 char* buffer, |
| 199 int buffer_length, | 197 int buffer_length, |
| 200 int index); | 198 int index); |
| 201 | 199 |
| 202 // Constructs a standard SPDY GET SYN packet, optionally compressed | 200 // Constructs a standard SPDY GET SYN packet, optionally compressed |
| 203 // for the url |url|. | 201 // for the url |url|. |
| 204 // |extra_headers| are the extra header-value pairs, which typically | 202 // |extra_headers| are the extra header-value pairs, which typically |
| 205 // will vary the most between calls. | 203 // will vary the most between calls. |
| 206 // Returns a SpdyFrame. | 204 // Returns a SpdyFrame. |
| 207 SpdyFrame* ConstructSpdyGet(const char* const url, | 205 SpdyFrame* ConstructSpdyGet(const char* const url, |
| 208 bool compressed, | 206 bool compressed, |
| 209 int stream_id, | 207 int stream_id, |
| 210 RequestPriority request_priority); | 208 RequestPriority request_priority); |
| 211 | 209 |
| 212 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 210 // Constructs a standard SPDY GET SYN packet, optionally compressed. |
| 213 // |extra_headers| are the extra header-value pairs, which typically | 211 // |extra_headers| are the extra header-value pairs, which typically |
| 214 // will vary the most between calls. | 212 // will vary the most between calls. |
| 215 // Returns a SpdyFrame. | 213 // Returns a SpdyFrame. |
| 216 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 214 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 217 int extra_header_count, | 215 int extra_header_count, |
| 218 bool compressed, | 216 bool compressed, |
| 219 int stream_id, | 217 int stream_id, |
| 220 RequestPriority request_priority); | 218 RequestPriority request_priority); |
| 221 | 219 |
| 222 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 220 // Constructs a standard SPDY GET SYN packet, optionally compressed. |
| 223 // |extra_headers| are the extra header-value pairs, which typically | 221 // |extra_headers| are the extra header-value pairs, which typically |
| 224 // will vary the most between calls. If |direct| is false, the | 222 // will vary the most between calls. If |direct| is false, the |
| 225 // the full url will be used instead of simply the path. | 223 // the full url will be used instead of simply the path. |
| 226 // Returns a SpdyFrame. | 224 // Returns a SpdyFrame. |
| 227 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 225 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 228 int extra_header_count, | 226 int extra_header_count, |
| 229 bool compressed, | 227 bool compressed, |
| 230 int stream_id, | 228 int stream_id, |
| 231 RequestPriority request_priority, | 229 RequestPriority request_priority, |
| 232 bool direct); | 230 bool direct); |
| 233 | 231 |
| 234 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 232 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
| 235 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], | 233 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
| 236 int extra_header_count, | 234 int extra_header_count, |
| 237 int stream_id); | 235 int stream_id); |
| 236 |
| 237 // Constructs a standard SPDY SYN_STREAM frame for WebSocket over SPDY |
| 238 // opening handshake. |
| 239 SpdyFrame* ConstructSpdyWebSocket(int stream_id, |
| 240 const char* path, |
| 241 const char* host, |
| 242 const char* origin); |
| 238 | 243 |
| 239 // Constructs a standard SPDY push SYN packet. | 244 // Constructs a standard SPDY push SYN packet. |
| 240 // |extra_headers| are the extra header-value pairs, which typically | 245 // |extra_headers| are the extra header-value pairs, which typically |
| 241 // will vary the most between calls. | 246 // will vary the most between calls. |
| 242 // Returns a SpdyFrame. | 247 // Returns a SpdyFrame. |
| 243 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 248 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 244 int extra_header_count, | 249 int extra_header_count, |
| 245 int stream_id, | 250 int stream_id, |
| 246 int associated_stream_id); | 251 int associated_stream_id); |
| 247 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 252 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 248 int extra_header_count, | 253 int extra_header_count, |
| 249 int stream_id, | 254 int stream_id, |
| 250 int associated_stream_id, | 255 int associated_stream_id, |
| 251 const char* url); | 256 const char* url); |
| 252 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 257 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
| 253 int extra_header_count, | 258 int extra_header_count, |
| 254 int stream_id, | 259 int stream_id, |
| 255 int associated_stream_id, | 260 int associated_stream_id, |
| 256 const char* url, | 261 const char* url, |
| 257 const char* status, | 262 const char* status, |
| 258 const char* location); | 263 const char* location); |
| 259 SpdyFrame* ConstructSpdyPush(int stream_id, | 264 SpdyFrame* ConstructSpdyPush(int stream_id, |
| 260 int associated_stream_id, | 265 int associated_stream_id, |
| 261 const char* url); | 266 const char* url); |
| 262 | 267 |
| 263 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, | 268 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, |
| 264 const char* const extra_headers[], | 269 const char* const extra_headers[], |
| 265 int extra_header_count); | 270 int extra_header_count); |
| 266 | 271 |
| 267 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 272 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. |
| 268 // |extra_headers| are the extra header-value pairs, which typically | 273 // |extra_headers| are the extra header-value pairs, which typically |
| 269 // will vary the most between calls. | 274 // will vary the most between calls. |
| 270 // Returns a SpdyFrame. | 275 // Returns a SpdyFrame. |
| 271 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 276 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 272 int extra_header_count, | 277 int extra_header_count, |
| 273 int stream_id); | 278 int stream_id); |
| 274 | 279 |
| 275 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 280 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. |
| 276 // |extra_headers| are the extra header-value pairs, which typically | 281 // |extra_headers| are the extra header-value pairs, which typically |
| 277 // will vary the most between calls. | 282 // will vary the most between calls. |
| 278 // Returns a SpdyFrame. | 283 // Returns a SpdyFrame. |
| 279 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); | 284 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); |
| 280 | 285 |
| 286 // Constructs a standard SPDY SYN_REPLY packet to match the WebSocket over SPDY |
| 287 // opening handshake. |
| 288 // Returns a SpdyFrame. |
| 289 SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id); |
| 290 |
| 281 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server | 291 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server |
| 282 // Error status code. | 292 // Error status code. |
| 283 // Returns a SpdyFrame. | 293 // Returns a SpdyFrame. |
| 284 SpdyFrame* ConstructSpdySynReplyError(int stream_id); | 294 SpdyFrame* ConstructSpdySynReplyError(int stream_id); |
| 285 | 295 |
| 286 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. | 296 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. |
| 287 // Returns a SpdyFrame. | 297 // Returns a SpdyFrame. |
| 288 SpdyFrame* ConstructSpdySynReplyError( | 298 SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
| 289 const char* const status, | 299 const char* const* const extra_headers, |
| 290 const char* const* const extra_headers, | 300 int extra_header_count, |
| 291 int extra_header_count, | 301 int stream_id); |
| 292 int stream_id); | |
| 293 | 302 |
| 294 // Constructs a standard SPDY POST SYN packet. | 303 // Constructs a standard SPDY POST SYN packet. |
| 295 // |extra_headers| are the extra header-value pairs, which typically | 304 // |extra_headers| are the extra header-value pairs, which typically |
| 296 // will vary the most between calls. | 305 // will vary the most between calls. |
| 297 // Returns a SpdyFrame. | 306 // Returns a SpdyFrame. |
| 298 SpdyFrame* ConstructSpdyPost(int64 content_length, | 307 SpdyFrame* ConstructSpdyPost(int64 content_length, |
| 299 const char* const extra_headers[], | 308 const char* const extra_headers[], |
| 300 int extra_header_count); | 309 int extra_header_count); |
| 301 | 310 |
| 302 // Constructs a chunked transfer SPDY POST SYN packet. | 311 // Constructs a chunked transfer SPDY POST SYN packet. |
| 303 // |extra_headers| are the extra header-value pairs, which typically | 312 // |extra_headers| are the extra header-value pairs, which typically |
| 304 // will vary the most between calls. | 313 // will vary the most between calls. |
| 305 // Returns a SpdyFrame. | 314 // Returns a SpdyFrame. |
| 306 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], | 315 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], |
| 307 int extra_header_count); | 316 int extra_header_count); |
| 308 | 317 |
| 309 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. | 318 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. |
| 310 // |extra_headers| are the extra header-value pairs, which typically | 319 // |extra_headers| are the extra header-value pairs, which typically |
| 311 // will vary the most between calls. | 320 // will vary the most between calls. |
| 312 // Returns a SpdyFrame. | 321 // Returns a SpdyFrame. |
| 313 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 322 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
| 314 int extra_header_count); | 323 int extra_header_count); |
| 315 | 324 |
| 316 // Constructs a single SPDY data frame with the contents "hello!" | 325 // Constructs a single SPDY data frame with the contents "hello!" |
| 317 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, | 326 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, |
| 318 bool fin); | 327 bool fin); |
| 319 | 328 |
| 320 // Constructs a single SPDY data frame with the given content. | 329 // Constructs a single SPDY data frame with the given content. |
| 321 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 330 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
| 322 uint32 len, bool fin); | 331 uint32 len, bool fin); |
| 332 |
| 333 // Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. |
| 334 SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, |
| 335 const char* length, |
| 336 bool fin); |
| 323 | 337 |
| 324 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 338 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
| 325 SpdyFrame* ConstructWrappedSpdyFrame( | 339 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
| 326 const scoped_ptr<SpdyFrame>& frame, int stream_id); | 340 int stream_id); |
| 327 | 341 |
| 328 // Create an async MockWrite from the given SpdyFrame. | 342 // Create an async MockWrite from the given SpdyFrame. |
| 329 MockWrite CreateMockWrite(const SpdyFrame& req); | 343 MockWrite CreateMockWrite(const SpdyFrame& req); |
| 330 | 344 |
| 331 // Create an async MockWrite from the given SpdyFrame and sequence number. | 345 // Create an async MockWrite from the given SpdyFrame and sequence number. |
| 332 MockWrite CreateMockWrite(const SpdyFrame& req, int seq); | 346 MockWrite CreateMockWrite(const SpdyFrame& req, int seq); |
| 333 | 347 |
| 334 MockWrite CreateMockWrite(const SpdyFrame& req, int seq, IoMode mode); | 348 MockWrite CreateMockWrite(const SpdyFrame& req, int seq, IoMode mode); |
| 335 | 349 |
| 336 // Create a MockRead from the given SpdyFrame. | 350 // Create a MockRead from the given SpdyFrame. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory_; | 447 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory_; |
| 434 | 448 |
| 435 DISALLOW_COPY_AND_ASSIGN(SpdyTestStateHelper); | 449 DISALLOW_COPY_AND_ASSIGN(SpdyTestStateHelper); |
| 436 }; | 450 }; |
| 437 | 451 |
| 438 } // namespace test_spdy3 | 452 } // namespace test_spdy3 |
| 439 | 453 |
| 440 } // namespace net | 454 } // namespace net |
| 441 | 455 |
| 442 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ | 456 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ |
| OLD | NEW |