| 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 #include "net/spdy/spdy_test_util.h" | 5 #include "net/spdy/spdy_test_util.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 9 | 11 |
| 10 namespace net { | 12 namespace net { |
| 11 | 13 |
| 12 // Chop a frame into an array of MockWrites. | 14 // Chop a frame into an array of MockWrites. |
| 13 // |data| is the frame to chop. | 15 // |data| is the frame to chop. |
| 14 // |length| is the length of the frame to chop. | 16 // |length| is the length of the frame to chop. |
| 15 // |num_chunks| is the number of chunks to create. | 17 // |num_chunks| is the number of chunks to create. |
| 16 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { | 18 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 this_header, | 230 this_header, |
| 229 this_value); | 231 this_value); |
| 230 return n; | 232 return n; |
| 231 } | 233 } |
| 232 | 234 |
| 233 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 235 // Constructs a standard SPDY GET SYN packet, optionally compressed. |
| 234 // |extra_headers| are the extra header-value pairs, which typically | 236 // |extra_headers| are the extra header-value pairs, which typically |
| 235 // will vary the most between calls. | 237 // will vary the most between calls. |
| 236 // Returns a SpdyFrame. | 238 // Returns a SpdyFrame. |
| 237 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 239 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
| 238 int extra_header_count, bool compressed) { | 240 int extra_header_count, |
| 241 bool compressed, |
| 242 int stream_id, |
| 243 RequestPriority request_priority) { |
| 239 const SpdyHeaderInfo kSynStartHeader = { | 244 const SpdyHeaderInfo kSynStartHeader = { |
| 240 spdy::SYN_STREAM, // Kind = Syn | 245 spdy::SYN_STREAM, // Kind = Syn |
| 241 1, // Stream ID | 246 stream_id, // Stream ID |
| 242 0, // Associated stream ID | 247 0, // Associated stream ID |
| 243 SPDY_PRIORITY_LOWEST, // Priority | 248 request_priority, // Priority |
| 244 spdy::CONTROL_FLAG_FIN, // Control Flags | 249 spdy::CONTROL_FLAG_FIN, // Control Flags |
| 245 compressed, // Compressed | 250 compressed, // Compressed |
| 246 spdy::INVALID, // Status | 251 spdy::INVALID, // Status |
| 247 NULL, // Data | 252 NULL, // Data |
| 248 0, // Length | 253 0, // Length |
| 249 spdy::DATA_FLAG_NONE // Data Flags | 254 spdy::DATA_FLAG_NONE // Data Flags |
| 250 }; | 255 }; |
| 251 static const char* const kStandardGetHeaders[] = { | 256 static const char* const kStandardGetHeaders[] = { |
| 252 "method", | 257 "method", |
| 253 "GET", | 258 "GET", |
| 254 "url", | 259 "url", |
| 255 "http://www.google.com/", | 260 "http://www.google.com/", |
| 256 "version", | 261 "version", |
| 257 "HTTP/1.1" | 262 "HTTP/1.1" |
| 258 }; | 263 }; |
| 259 return ConstructSpdyPacket( | 264 return ConstructSpdyPacket( |
| 260 kSynStartHeader, | 265 kSynStartHeader, |
| 261 extra_headers, | 266 extra_headers, |
| 262 extra_header_count, | 267 extra_header_count, |
| 263 kStandardGetHeaders, | 268 kStandardGetHeaders, |
| 264 arraysize(kStandardGetHeaders) / 2); | 269 arraysize(kStandardGetHeaders) / 2); |
| 265 } | 270 } |
| 266 | 271 |
| 267 // Constructs a standard SPDY GET SYN packet, not compressed. | |
| 268 // |extra_headers| are the extra header-value pairs, which typically | |
| 269 // will vary the most between calls. | |
| 270 // Returns a SpdyFrame. | |
| 271 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | |
| 272 int extra_header_count) { | |
| 273 return ConstructSpdyGet(extra_headers, extra_header_count, false); | |
| 274 } | |
| 275 | |
| 276 // 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. |
| 277 // |extra_headers| are the extra header-value pairs, which typically | 273 // |extra_headers| are the extra header-value pairs, which typically |
| 278 // will vary the most between calls. | 274 // will vary the most between calls. |
| 279 // Returns a SpdyFrame. | 275 // Returns a SpdyFrame. |
| 280 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 276 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
| 281 int extra_header_count) { | 277 int extra_header_count, |
| 278 int stream_id) { |
| 282 const SpdyHeaderInfo kSynStartHeader = { | 279 const SpdyHeaderInfo kSynStartHeader = { |
| 283 spdy::SYN_REPLY, // Kind = SynReply | 280 spdy::SYN_REPLY, // Kind = SynReply |
| 284 1, // Stream ID | 281 stream_id, // Stream ID |
| 285 0, // Associated stream ID | 282 0, // Associated stream ID |
| 286 SPDY_PRIORITY_LOWEST, // Priority | 283 SPDY_PRIORITY_LOWEST, // Priority |
| 287 spdy::CONTROL_FLAG_NONE, // Control Flags | 284 spdy::CONTROL_FLAG_NONE, // Control Flags |
| 288 false, // Compressed | 285 false, // Compressed |
| 289 spdy::INVALID, // Status | 286 spdy::INVALID, // Status |
| 290 NULL, // Data | 287 NULL, // Data |
| 291 0, // Length | 288 0, // Length |
| 292 spdy::DATA_FLAG_NONE // Data Flags | 289 spdy::DATA_FLAG_NONE // Data Flags |
| 293 }; | 290 }; |
| 294 static const char* const kStandardGetHeaders[] = { | 291 static const char* const kStandardGetHeaders[] = { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 }; | 370 }; |
| 374 return ConstructSpdyPacket( | 371 return ConstructSpdyPacket( |
| 375 kSynStartHeader, | 372 kSynStartHeader, |
| 376 extra_headers, | 373 extra_headers, |
| 377 extra_header_count, | 374 extra_header_count, |
| 378 kStandardGetHeaders, | 375 kStandardGetHeaders, |
| 379 arraysize(kStandardGetHeaders) / 2); | 376 arraysize(kStandardGetHeaders) / 2); |
| 380 } | 377 } |
| 381 | 378 |
| 382 // Constructs a single SPDY data frame with the contents "hello!" | 379 // Constructs a single SPDY data frame with the contents "hello!" |
| 383 spdy::SpdyFrame* ConstructSpdyBodyFrame() { | 380 spdy::SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { |
| 384 spdy::SpdyFramer framer; | 381 spdy::SpdyFramer framer; |
| 385 return framer.CreateDataFrame(1, "hello!", 6, spdy::DATA_FLAG_FIN); | 382 return |
| 383 framer.CreateDataFrame(stream_id, "hello!", 6, |
| 384 fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE); |
| 386 } | 385 } |
| 387 | 386 |
| 388 // Construct an expected SPDY reply string. | 387 // Construct an expected SPDY reply string. |
| 389 // |extra_headers| are the extra header-value pairs, which typically | 388 // |extra_headers| are the extra header-value pairs, which typically |
| 390 // will vary the most between calls. | 389 // will vary the most between calls. |
| 391 // |buffer| is the buffer we're filling in. | 390 // |buffer| is the buffer we're filling in. |
| 392 // Returns the number of bytes written into |buffer|. | 391 // Returns the number of bytes written into |buffer|. |
| 393 int ConstructSpdyReplyString(const char* const extra_headers[], | 392 int ConstructSpdyReplyString(const char* const extra_headers[], |
| 394 int extra_header_count, | 393 int extra_header_count, |
| 395 char* buffer, | 394 char* buffer, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 char* ptr = buff; | 498 char* ptr = buff; |
| 500 for (int i = 0; i < num_frames; ++i) { | 499 for (int i = 0; i < num_frames; ++i) { |
| 501 int len = frames[i]->length() + spdy::SpdyFrame::size(); | 500 int len = frames[i]->length() + spdy::SpdyFrame::size(); |
| 502 memcpy(ptr, frames[i]->data(), len); | 501 memcpy(ptr, frames[i]->data(), len); |
| 503 ptr += len; | 502 ptr += len; |
| 504 } | 503 } |
| 505 return total_len; | 504 return total_len; |
| 506 } | 505 } |
| 507 | 506 |
| 508 } // namespace net | 507 } // namespace net |
| OLD | NEW |