| 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 #include "net/spdy/spdy_test_util.h" | 5 #include "net/spdy/spdy_test_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // |data| is the frame to chop. | 22 // |data| is the frame to chop. |
| 23 // |length| is the length of the frame to chop. | 23 // |length| is the length of the frame to chop. |
| 24 // |num_chunks| is the number of chunks to create. | 24 // |num_chunks| is the number of chunks to create. |
| 25 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { | 25 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { |
| 26 MockWrite* chunks = new MockWrite[num_chunks]; | 26 MockWrite* chunks = new MockWrite[num_chunks]; |
| 27 int chunk_size = length / num_chunks; | 27 int chunk_size = length / num_chunks; |
| 28 for (int index = 0; index < num_chunks; index++) { | 28 for (int index = 0; index < num_chunks; index++) { |
| 29 const char* ptr = data + (index * chunk_size); | 29 const char* ptr = data + (index * chunk_size); |
| 30 if (index == num_chunks - 1) | 30 if (index == num_chunks - 1) |
| 31 chunk_size += length % chunk_size; // The last chunk takes the remainder. | 31 chunk_size += length % chunk_size; // The last chunk takes the remainder. |
| 32 chunks[index] = MockWrite(true, ptr, chunk_size); | 32 chunks[index] = MockWrite(ASYNC, ptr, chunk_size); |
| 33 } | 33 } |
| 34 return chunks; | 34 return chunks; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Chop a SpdyFrame into an array of MockWrites. | 37 // Chop a SpdyFrame into an array of MockWrites. |
| 38 // |frame| is the frame to chop. | 38 // |frame| is the frame to chop. |
| 39 // |num_chunks| is the number of chunks to create. | 39 // |num_chunks| is the number of chunks to create. |
| 40 MockWrite* ChopWriteFrame(const spdy::SpdyFrame& frame, int num_chunks) { | 40 MockWrite* ChopWriteFrame(const spdy::SpdyFrame& frame, int num_chunks) { |
| 41 return ChopWriteFrame(frame.data(), | 41 return ChopWriteFrame(frame.data(), |
| 42 frame.length() + spdy::SpdyFrame::kHeaderSize, | 42 frame.length() + spdy::SpdyFrame::kHeaderSize, |
| 43 num_chunks); | 43 num_chunks); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Chop a frame into an array of MockReads. | 46 // Chop a frame into an array of MockReads. |
| 47 // |data| is the frame to chop. | 47 // |data| is the frame to chop. |
| 48 // |length| is the length of the frame to chop. | 48 // |length| is the length of the frame to chop. |
| 49 // |num_chunks| is the number of chunks to create. | 49 // |num_chunks| is the number of chunks to create. |
| 50 MockRead* ChopReadFrame(const char* data, int length, int num_chunks) { | 50 MockRead* ChopReadFrame(const char* data, int length, int num_chunks) { |
| 51 MockRead* chunks = new MockRead[num_chunks]; | 51 MockRead* chunks = new MockRead[num_chunks]; |
| 52 int chunk_size = length / num_chunks; | 52 int chunk_size = length / num_chunks; |
| 53 for (int index = 0; index < num_chunks; index++) { | 53 for (int index = 0; index < num_chunks; index++) { |
| 54 const char* ptr = data + (index * chunk_size); | 54 const char* ptr = data + (index * chunk_size); |
| 55 if (index == num_chunks - 1) | 55 if (index == num_chunks - 1) |
| 56 chunk_size += length % chunk_size; // The last chunk takes the remainder. | 56 chunk_size += length % chunk_size; // The last chunk takes the remainder. |
| 57 chunks[index] = MockRead(true, ptr, chunk_size); | 57 chunks[index] = MockRead(ASYNC, ptr, chunk_size); |
| 58 } | 58 } |
| 59 return chunks; | 59 return chunks; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Chop a SpdyFrame into an array of MockReads. | 62 // Chop a SpdyFrame into an array of MockReads. |
| 63 // |frame| is the frame to chop. | 63 // |frame| is the frame to chop. |
| 64 // |num_chunks| is the number of chunks to create. | 64 // |num_chunks| is the number of chunks to create. |
| 65 MockRead* ChopReadFrame(const spdy::SpdyFrame& frame, int num_chunks) { | 65 MockRead* ChopReadFrame(const spdy::SpdyFrame& frame, int num_chunks) { |
| 66 return ChopReadFrame(frame.data(), | 66 return ChopReadFrame(frame.data(), |
| 67 frame.length() + spdy::SpdyFrame::kHeaderSize, | 67 frame.length() + spdy::SpdyFrame::kHeaderSize, |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 strlen("\n"), | 844 strlen("\n"), |
| 845 &buffer_write, | 845 &buffer_write, |
| 846 &buffer_left); | 846 &buffer_left); |
| 847 } | 847 } |
| 848 return packet_size; | 848 return packet_size; |
| 849 } | 849 } |
| 850 | 850 |
| 851 // Create a MockWrite from the given SpdyFrame. | 851 // Create a MockWrite from the given SpdyFrame. |
| 852 MockWrite CreateMockWrite(const spdy::SpdyFrame& req) { | 852 MockWrite CreateMockWrite(const spdy::SpdyFrame& req) { |
| 853 return MockWrite( | 853 return MockWrite( |
| 854 true, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize); | 854 ASYNC, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize); |
| 855 } | 855 } |
| 856 | 856 |
| 857 // Create a MockWrite from the given SpdyFrame and sequence number. | 857 // Create a MockWrite from the given SpdyFrame and sequence number. |
| 858 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq) { | 858 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq) { |
| 859 return CreateMockWrite(req, seq, true); | 859 return CreateMockWrite(req, seq, ASYNC); |
| 860 } | 860 } |
| 861 | 861 |
| 862 // Create a MockWrite from the given SpdyFrame and sequence number. | 862 // Create a MockWrite from the given SpdyFrame and sequence number. |
| 863 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq, bool async) { | 863 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq, IoMode mode) { |
| 864 return MockWrite( | 864 return MockWrite( |
| 865 async, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize, seq); | 865 mode, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize, seq); |
| 866 } | 866 } |
| 867 | 867 |
| 868 // Create a MockRead from the given SpdyFrame. | 868 // Create a MockRead from the given SpdyFrame. |
| 869 MockRead CreateMockRead(const spdy::SpdyFrame& resp) { | 869 MockRead CreateMockRead(const spdy::SpdyFrame& resp) { |
| 870 return MockRead( | 870 return MockRead( |
| 871 true, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize); | 871 ASYNC, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize); |
| 872 } | 872 } |
| 873 | 873 |
| 874 // Create a MockRead from the given SpdyFrame and sequence number. | 874 // Create a MockRead from the given SpdyFrame and sequence number. |
| 875 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq) { | 875 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq) { |
| 876 return CreateMockRead(resp, seq, true); | 876 return CreateMockRead(resp, seq, ASYNC); |
| 877 } | 877 } |
| 878 | 878 |
| 879 // Create a MockRead from the given SpdyFrame and sequence number. | 879 // Create a MockRead from the given SpdyFrame and sequence number. |
| 880 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq, bool async) { | 880 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq, IoMode mode) { |
| 881 return MockRead( | 881 return MockRead( |
| 882 async, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize, seq); | 882 mode, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize, seq); |
| 883 } | 883 } |
| 884 | 884 |
| 885 // Combines the given SpdyFrames into the given char array and returns | 885 // Combines the given SpdyFrames into the given char array and returns |
| 886 // the total length. | 886 // the total length. |
| 887 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, | 887 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, |
| 888 char* buff, int buff_len) { | 888 char* buff, int buff_len) { |
| 889 int total_len = 0; | 889 int total_len = 0; |
| 890 for (int i = 0; i < num_frames; ++i) { | 890 for (int i = 0; i < num_frames; ++i) { |
| 891 total_len += frames[i]->length() + spdy::SpdyFrame::kHeaderSize; | 891 total_len += frames[i]->length() + spdy::SpdyFrame::kHeaderSize; |
| 892 } | 892 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 spdy::CONTROL_FLAG_FIN, // Control Flags | 998 spdy::CONTROL_FLAG_FIN, // Control Flags |
| 999 false, // Compressed | 999 false, // Compressed |
| 1000 spdy::INVALID, // Status | 1000 spdy::INVALID, // Status |
| 1001 NULL, // Data | 1001 NULL, // Data |
| 1002 0, // Length | 1002 0, // Length |
| 1003 spdy::DATA_FLAG_NONE // Data Flags | 1003 spdy::DATA_FLAG_NONE // Data Flags |
| 1004 }; | 1004 }; |
| 1005 return kHeader; | 1005 return kHeader; |
| 1006 } | 1006 } |
| 1007 } // namespace net | 1007 } // namespace net |
| OLD | NEW |