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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 class SpdySession; | 39 class SpdySession; |
40 class SpdySessionKey; | 40 class SpdySessionKey; |
41 class SpdySessionPool; | 41 class SpdySessionPool; |
42 class SpdyStream; | 42 class SpdyStream; |
43 class SpdyStreamRequest; | 43 class SpdyStreamRequest; |
44 | 44 |
45 // Default upload data used by both, mock objects and framer when creating | 45 // Default upload data used by both, mock objects and framer when creating |
46 // data frames. | 46 // data frames. |
47 const char kDefaultURL[] = "http://www.google.com"; | 47 const char kDefaultURL[] = "http://www.google.com"; |
48 const char kUploadData[] = "hello!"; | 48 const char kUploadData[] = "hello!"; |
49 const int kUploadDataSize = arraysize(kUploadData)-1; | 49 const int kUploadDataSize = arraysize(kUploadData) - 1; |
50 | 50 |
51 // SpdyNextProtos returns a vector of next protocols for negotiating | 51 // SpdyNextProtos returns a vector of next protocols for negotiating |
52 // SPDY. | 52 // SPDY. |
53 std::vector<NextProto> SpdyNextProtos(); | 53 std::vector<NextProto> SpdyNextProtos(); |
54 | 54 |
55 // Chop a frame into an array of MockWrites. | 55 // Chop a frame into an array of MockWrites. |
56 // |data| is the frame to chop. | 56 // |data| is the frame to chop. |
57 // |length| is the length of the frame to chop. | 57 // |length| is the length of the frame to chop. |
58 // |num_chunks| is the number of chunks to create. | 58 // |num_chunks| is the number of chunks to create. |
59 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); | 59 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Create a MockRead from the given SpdyFrame. | 94 // Create a MockRead from the given SpdyFrame. |
95 MockRead CreateMockRead(const SpdyFrame& resp); | 95 MockRead CreateMockRead(const SpdyFrame& resp); |
96 | 96 |
97 // Create a MockRead from the given SpdyFrame and sequence number. | 97 // Create a MockRead from the given SpdyFrame and sequence number. |
98 MockRead CreateMockRead(const SpdyFrame& resp, int seq); | 98 MockRead CreateMockRead(const SpdyFrame& resp, int seq); |
99 | 99 |
100 MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode); | 100 MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode); |
101 | 101 |
102 // Combines the given SpdyFrames into the given char array and returns | 102 // Combines the given SpdyFrames into the given char array and returns |
103 // the total length. | 103 // the total length. |
104 int CombineFrames(const SpdyFrame** frames, int num_frames, | 104 int CombineFrames(const SpdyFrame** frames, |
105 char* buff, int buff_len); | 105 int num_frames, |
| 106 char* buff, |
| 107 int buff_len); |
106 | 108 |
107 // Returns the SpdyPriority embedded in the given frame. Returns true | 109 // Returns the SpdyPriority embedded in the given frame. Returns true |
108 // and fills in |priority| on success. | 110 // and fills in |priority| on success. |
109 bool GetSpdyPriority(SpdyMajorVersion version, | 111 bool GetSpdyPriority(SpdyMajorVersion version, |
110 const SpdyFrame& frame, | 112 const SpdyFrame& frame, |
111 SpdyPriority* priority); | 113 SpdyPriority* priority); |
112 | 114 |
113 // Tries to create a stream in |session| synchronously. Returns NULL | 115 // Tries to create a stream in |session| synchronously. Returns NULL |
114 // on failure. | 116 // on failure. |
115 base::WeakPtr<SpdyStream> CreateStreamSynchronously( | 117 base::WeakPtr<SpdyStream> CreateStreamSynchronously( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock( | 311 scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock( |
310 base::StringPiece url, | 312 base::StringPiece url, |
311 int64 content_length) const; | 313 int64 content_length) const; |
312 scoped_ptr<SpdyHeaderBlock> ConstructPutHeaderBlock( | 314 scoped_ptr<SpdyHeaderBlock> ConstructPutHeaderBlock( |
313 base::StringPiece url, | 315 base::StringPiece url, |
314 int64 content_length) const; | 316 int64 content_length) const; |
315 | 317 |
316 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as | 318 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as |
317 // specified in header_info.kind), the provided headers are included in the | 319 // specified in header_info.kind), the provided headers are included in the |
318 // frame. | 320 // frame. |
319 SpdyFrame* ConstructSpdyFrame( | 321 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
320 const SpdyHeaderInfo& header_info, | 322 scoped_ptr<SpdyHeaderBlock> headers) const; |
321 scoped_ptr<SpdyHeaderBlock> headers) const; | |
322 | 323 |
323 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as | 324 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as |
324 // specified in header_info.kind), the headers provided in extra_headers and | 325 // specified in header_info.kind), the headers provided in extra_headers and |
325 // (if non-NULL) tail_headers are concatenated and included in the frame. | 326 // (if non-NULL) tail_headers are concatenated and included in the frame. |
326 // (extra_headers must always be non-NULL.) | 327 // (extra_headers must always be non-NULL.) |
327 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, | 328 SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
328 const char* const extra_headers[], | 329 const char* const extra_headers[], |
329 int extra_header_count, | 330 int extra_header_count, |
330 const char* const tail_headers[], | 331 const char* const tail_headers[], |
331 int tail_header_count) const; | 332 int tail_header_count) const; |
332 | 333 |
333 // Construct a generic SpdyControlFrame. | 334 // Construct a generic SpdyControlFrame. |
334 SpdyFrame* ConstructSpdyControlFrame( | 335 SpdyFrame* ConstructSpdyControlFrame(scoped_ptr<SpdyHeaderBlock> headers, |
335 scoped_ptr<SpdyHeaderBlock> headers, | 336 bool compressed, |
336 bool compressed, | 337 SpdyStreamId stream_id, |
337 SpdyStreamId stream_id, | 338 RequestPriority request_priority, |
338 RequestPriority request_priority, | 339 SpdyFrameType type, |
339 SpdyFrameType type, | 340 SpdyControlFlags flags, |
340 SpdyControlFlags flags, | 341 SpdyStreamId associated_stream_id) const; |
341 SpdyStreamId associated_stream_id) const; | |
342 | 342 |
343 // Construct a generic SpdyControlFrame. | 343 // Construct a generic SpdyControlFrame. |
344 // | 344 // |
345 // Warning: extra_header_count is the number of header-value pairs in | 345 // Warning: extra_header_count is the number of header-value pairs in |
346 // extra_headers (so half the number of elements), but tail_headers_size is | 346 // extra_headers (so half the number of elements), but tail_headers_size is |
347 // the actual number of elements (both keys and values) in tail_headers. | 347 // the actual number of elements (both keys and values) in tail_headers. |
348 // TODO(ttuttle): Fix this inconsistency. | 348 // TODO(ttuttle): Fix this inconsistency. |
349 SpdyFrame* ConstructSpdyControlFrame( | 349 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
350 const char* const extra_headers[], | 350 int extra_header_count, |
351 int extra_header_count, | 351 bool compressed, |
352 bool compressed, | 352 SpdyStreamId stream_id, |
353 SpdyStreamId stream_id, | 353 RequestPriority request_priority, |
354 RequestPriority request_priority, | 354 SpdyFrameType type, |
355 SpdyFrameType type, | 355 SpdyControlFlags flags, |
356 SpdyControlFlags flags, | 356 const char* const* tail_headers, |
357 const char* const* tail_headers, | 357 int tail_headers_size, |
358 int tail_headers_size, | 358 SpdyStreamId associated_stream_id) const; |
359 SpdyStreamId associated_stream_id) const; | |
360 | 359 |
361 // Construct an expected SPDY reply string from the given headers. | 360 // Construct an expected SPDY reply string from the given headers. |
362 std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; | 361 std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; |
363 | 362 |
364 // Construct an expected SPDY SETTINGS frame. | 363 // Construct an expected SPDY SETTINGS frame. |
365 // |settings| are the settings to set. | 364 // |settings| are the settings to set. |
366 // Returns the constructed frame. The caller takes ownership of the frame. | 365 // Returns the constructed frame. The caller takes ownership of the frame. |
367 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) const; | 366 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) const; |
368 | 367 |
369 // Construct a SPDY PING frame. | 368 // Construct a SPDY PING frame. |
370 // Returns the constructed frame. The caller takes ownership of the frame. | 369 // Returns the constructed frame. The caller takes ownership of the frame. |
371 SpdyFrame* ConstructSpdyPing(uint32 ping_id, bool is_ack) const; | 370 SpdyFrame* ConstructSpdyPing(uint32 ping_id, bool is_ack) const; |
372 | 371 |
373 // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. | 372 // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. |
374 // Returns the constructed frame. The caller takes ownership of the frame. | 373 // Returns the constructed frame. The caller takes ownership of the frame. |
375 SpdyFrame* ConstructSpdyGoAway() const; | 374 SpdyFrame* ConstructSpdyGoAway() const; |
376 | 375 |
377 // Construct a SPDY GOAWAY frame with the specified last_good_stream_id. | 376 // Construct a SPDY GOAWAY frame with the specified last_good_stream_id. |
378 // Returns the constructed frame. The caller takes ownership of the frame. | 377 // Returns the constructed frame. The caller takes ownership of the frame. |
379 SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) const; | 378 SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) const; |
380 | 379 |
381 // Construct a SPDY WINDOW_UPDATE frame. | 380 // Construct a SPDY WINDOW_UPDATE frame. |
382 // Returns the constructed frame. The caller takes ownership of the frame. | 381 // Returns the constructed frame. The caller takes ownership of the frame. |
383 SpdyFrame* ConstructSpdyWindowUpdate( | 382 SpdyFrame* ConstructSpdyWindowUpdate(SpdyStreamId stream_id, |
384 SpdyStreamId stream_id, | 383 uint32 delta_window_size) const; |
385 uint32 delta_window_size) const; | |
386 | 384 |
387 // Construct a SPDY RST_STREAM frame. | 385 // Construct a SPDY RST_STREAM frame. |
388 // Returns the constructed frame. The caller takes ownership of the frame. | 386 // Returns the constructed frame. The caller takes ownership of the frame. |
389 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, | 387 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
390 SpdyRstStreamStatus status) const; | 388 SpdyRstStreamStatus status) const; |
391 | 389 |
392 // Constructs a standard SPDY GET SYN frame, optionally compressed | 390 // Constructs a standard SPDY GET SYN frame, optionally compressed |
393 // for the url |url|. | 391 // for the url |url|. |
394 // |extra_headers| are the extra header-value pairs, which typically | 392 // |extra_headers| are the extra header-value pairs, which typically |
395 // will vary the most between calls. | 393 // will vary the most between calls. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 int extra_header_count); | 486 int extra_header_count); |
489 | 487 |
490 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. | 488 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. |
491 // |extra_headers| are the extra header-value pairs, which typically | 489 // |extra_headers| are the extra header-value pairs, which typically |
492 // will vary the most between calls. | 490 // will vary the most between calls. |
493 // Returns a SpdyFrame. | 491 // Returns a SpdyFrame. |
494 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 492 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
495 int extra_header_count); | 493 int extra_header_count); |
496 | 494 |
497 // Constructs a single SPDY data frame with the contents "hello!" | 495 // Constructs a single SPDY data frame with the contents "hello!" |
498 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, | 496 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin); |
499 bool fin); | |
500 | 497 |
501 // Constructs a single SPDY data frame with the given content. | 498 // Constructs a single SPDY data frame with the given content. |
502 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 499 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, |
503 uint32 len, bool fin); | 500 const char* data, |
| 501 uint32 len, |
| 502 bool fin); |
504 | 503 |
505 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 504 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
506 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, | 505 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
507 int stream_id); | 506 int stream_id); |
508 | 507 |
509 const SpdyHeaderInfo MakeSpdyHeader(SpdyFrameType type); | 508 const SpdyHeaderInfo MakeSpdyHeader(SpdyFrameType type); |
510 | 509 |
511 // For versions below SPDY4, adds the version HTTP/1.1 header. | 510 // For versions below SPDY4, adds the version HTTP/1.1 header. |
512 void MaybeAddVersionHeader(SpdyFrameWithNameValueBlockIR* frame_ir) const; | 511 void MaybeAddVersionHeader(SpdyFrameWithNameValueBlockIR* frame_ir) const; |
513 | 512 |
514 // Maps |priority| to SPDY version priority, and sets it on |frame_ir|. | 513 // Maps |priority| to SPDY version priority, and sets it on |frame_ir|. |
515 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; | 514 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; |
516 | 515 |
517 NextProto protocol() const { return protocol_; } | 516 NextProto protocol() const { return protocol_; } |
518 SpdyMajorVersion spdy_version() const { return spdy_version_; } | 517 SpdyMajorVersion spdy_version() const { return spdy_version_; } |
519 bool is_spdy2() const { return protocol_ < kProtoSPDY3; } | 518 bool is_spdy2() const { return protocol_ < kProtoSPDY3; } |
520 bool include_version_header() const { return protocol_ < kProtoSPDY4; } | 519 bool include_version_header() const { return protocol_ < kProtoSPDY4; } |
521 scoped_ptr<SpdyFramer> CreateFramer(bool compressed) const; | 520 scoped_ptr<SpdyFramer> CreateFramer(bool compressed) const; |
522 | 521 |
523 const char* GetMethodKey() const; | 522 const char* GetMethodKey() const; |
524 const char* GetStatusKey() const; | 523 const char* GetStatusKey() const; |
525 const char* GetHostKey() const; | 524 const char* GetHostKey() const; |
526 const char* GetSchemeKey() const; | 525 const char* GetSchemeKey() const; |
527 const char* GetVersionKey() const; | 526 const char* GetVersionKey() const; |
528 const char* GetPathKey() const; | 527 const char* GetPathKey() const; |
529 | 528 |
530 private: | 529 private: |
531 // |content_length| may be NULL, in which case the content-length | 530 // |content_length| may be NULL, in which case the content-length |
532 // header will be omitted. | 531 // header will be omitted. |
533 scoped_ptr<SpdyHeaderBlock> ConstructHeaderBlock( | 532 scoped_ptr<SpdyHeaderBlock> ConstructHeaderBlock(base::StringPiece method, |
534 base::StringPiece method, | 533 base::StringPiece url, |
535 base::StringPiece url, | 534 int64* content_length) const; |
536 int64* content_length) const; | |
537 | 535 |
538 const NextProto protocol_; | 536 const NextProto protocol_; |
539 const SpdyMajorVersion spdy_version_; | 537 const SpdyMajorVersion spdy_version_; |
540 }; | 538 }; |
541 | 539 |
542 } // namespace net | 540 } // namespace net |
543 | 541 |
544 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ | 542 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ |
OLD | NEW |