Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: net/spdy/spdy_test_util.h

Issue 2881001: Cleaning up SPDY unit tests (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Undo mode changes Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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 "net/socket/socket_test_util.h"
10 #include "net/spdy/spdy_framer.h"
9 11
10 namespace net { 12 namespace net {
11 13
12 const uint8 kGetSyn[] = {
13 0x80, 0x01, 0x00, 0x01, // header
14 0x01, 0x00, 0x00, 0x49, // FIN, len
15 0x00, 0x00, 0x00, 0x01, // stream id
16 0x00, 0x00, 0x00, 0x00, // associated
17 0xc0, 0x00, 0x00, 0x03, // 3 headers
18 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd',
19 0x00, 0x03, 'G', 'E', 'T',
20 0x00, 0x03, 'u', 'r', 'l',
21 0x00, 0x16, 'h', 't', 't', 'p', ':', '/', '/', 'w', 'w', 'w',
22 '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o',
23 'm', '/',
24 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n',
25 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1',
26 };
27
28 const uint8 kGetSynReply[] = {
29 0x80, 0x01, 0x00, 0x02, // header
30 0x00, 0x00, 0x00, 0x45,
31 0x00, 0x00, 0x00, 0x01,
32 0x00, 0x00, 0x00, 0x04, // 4 headers
33 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', // "hello"
34 0x00, 0x03, 'b', 'y', 'e', // "bye"
35 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', // "status"
36 0x00, 0x03, '2', '0', '0', // "200"
37 0x00, 0x03, 'u', 'r', 'l', // "url"
38 0x00, 0x0a, '/', 'i', 'n', 'd', 'e', 'x', '.', 'p', 'h', 'p', // "/index...
39 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "version"
40 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "HTTP/1.1"
41 };
42
43 const uint8 kGetBodyFrame[] = { 14 const uint8 kGetBodyFrame[] = {
44 0x00, 0x00, 0x00, 0x01, // header 15 0x00, 0x00, 0x00, 0x01, // header
45 0x01, 0x00, 0x00, 0x06, // FIN, length 16 0x01, 0x00, 0x00, 0x06, // FIN, length
46 'h', 'e', 'l', 'l', 'o', '!', // "hello" 17 'h', 'e', 'l', 'l', 'o', '!', // "hello"
47 }; 18 };
48 19
49 const uint8 kGetSynCompressed[] = { 20 const uint8 kGetSynCompressed[] = {
50 0x80, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x47, 21 0x80, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x47,
51 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 22 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
52 0xc0, 0x00, 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2, 23 0xc0, 0x00, 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 0x01, 0x00, 0x00, 0x06, // FIN, length 74 0x01, 0x00, 0x00, 0x06, // FIN, length
104 'h', 'e', 'l', 'l', 'o', '!', // "hello" 75 'h', 'e', 'l', 'l', 'o', '!', // "hello"
105 }; 76 };
106 77
107 const uint8 kGoAway[] = { 78 const uint8 kGoAway[] = {
108 0x80, 0x01, 0x00, 0x07, // header 79 0x80, 0x01, 0x00, 0x07, // header
109 0x00, 0x00, 0x00, 0x04, // flags, len 80 0x00, 0x00, 0x00, 0x04, // flags, len
110 0x00, 0x00, 0x00, 0x00, // last-accepted-stream-id 81 0x00, 0x00, 0x00, 0x00, // last-accepted-stream-id
111 }; 82 };
112 83
84 // ----------------------------------------------------------------------------
85
86 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace!
87 // This struct holds information used to construct spdy control and data frames.
88 struct SpdyHeaderInfo {
89 spdy::SpdyControlType kind;
90 spdy::SpdyStreamId id;
91 spdy::SpdyStreamId assoc_id;
92 spdy::SpdyPriority priority;
93 spdy::SpdyControlFlags control_flags;
94 bool compressed;
95 spdy::SpdyStatusCodes status;
96 const char* data;
97 uint32 data_length;
98 spdy::SpdyDataFlags data_flags;
99 };
100
101 // Chop a frame into an array of MockWrites.
102 // |data| is the frame to chop.
103 // |length| is the length of the frame to chop.
104 // |num_chunks| is the number of chunks to create.
105 MockWrite* ChopFrame(const char* data, int length, int num_chunks);
106
107 // Chop a SpdyFrame into an array of MockWrites.
108 // |frame| is the frame to chop.
109 // |num_chunks| is the number of chunks to create.
110 MockWrite* ChopFrame(const spdy::SpdyFrame* frame, int num_chunks);
111
112 // Adds headers and values to a map.
113 // |extra_headers| is an array of { name, value } pairs, arranged as strings
114 // where the even entries are the header names, and the odd entries are the
115 // header values.
116 // |headers| gets filled in from |extra_headers|.
117 void AppendHeadersToSpdyFrame(const char* const extra_headers[],
118 int extra_header_count,
119 spdy::SpdyHeaderBlock* headers);
120
121 // Writes |str| of the given |len| to the buffer pointed to by |buffer_handle|.
122 // Uses a template so buffer_handle can be a char* or an unsigned char*.
123 // Updates the |*buffer_handle| pointer by |len|
124 // Returns the number of bytes written into *|buffer_handle|
125 template<class T>
126 int AppendToBuffer(const char* str,
127 int len,
128 T** buffer_handle,
129 int* buffer_len_remaining) {
130 DCHECK_GT(len, 0);
131 DCHECK(NULL != buffer_handle) << "NULL buffer handle";
132 DCHECK(NULL != *buffer_handle) << "NULL pointer";
133 DCHECK(NULL != buffer_len_remaining)
134 << "NULL buffer remainder length pointer";
135 DCHECK_GE(*buffer_len_remaining, len) << "Insufficient buffer size";
136 memcpy(*buffer_handle, str, len);
137 *buffer_handle += len;
138 *buffer_len_remaining -= len;
139 return len;
140 }
141
142 // Writes |val| to a location of size |len|, in big-endian format.
143 // in the buffer pointed to by |buffer_handle|.
144 // Updates the |*buffer_handle| pointer by |len|
145 // Returns the number of bytes written
146 int AppendToBuffer(int val,
147 int len,
148 unsigned char** buffer_handle,
149 int* buffer_len_remaining);
150
151 // Construct a SPDY packet.
152 // |head| is the start of the packet, up to but not including
153 // the header value pairs.
154 // |extra_headers| are the extra header-value pairs, which typically
155 // will vary the most between calls.
156 // |tail| is any (relatively constant) header-value pairs to add.
157 // |buffer| is the buffer we're filling in.
158 // Returns a SpdyFrame.
159 spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo* header_info,
160 const char* const extra_headers[],
161 int extra_header_count,
162 const char* const tail[],
163 int tail_header_count);
164
165 // Construct an expected SPDY reply string.
166 // |extra_headers| are the extra header-value pairs, which typically
167 // will vary the most between calls.
168 // |buffer| is the buffer we're filling in.
169 // Returns the number of bytes written into |buffer|.
170 int ConstructSpdyReplyString(const char* const extra_headers[],
171 int extra_header_count,
172 char* buffer,
173 int buffer_length);
174
175 // Construct an expected SPDY SETTINGS frame.
176 // |settings| are the settings to set.
177 // Returns the constructed frame. The caller takes ownership of the frame.
178 spdy::SpdyFrame* ConstructSpdySettings(spdy::SpdySettings settings);
179
180 // Construct a single SPDY header entry, for validation.
181 // |extra_headers| are the extra header-value pairs.
182 // |buffer| is the buffer we're filling in.
183 // |index| is the index of the header we want.
184 // Returns the number of bytes written into |buffer|.
185 int ConstructSpdyHeader(const char* const extra_headers[],
186 int extra_header_count,
187 char* buffer,
188 int buffer_length,
189 int index);
190
191 // Constructs a standard SPDY GET packet.
192 // |extra_headers| are the extra header-value pairs, which typically
193 // will vary the most between calls.
194 // Returns a SpdyFrame.
195 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
196 int extra_header_count);
197
198 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
199 // |extra_headers| are the extra header-value pairs, which typically
200 // will vary the most between calls.
201 // Returns a SpdyFrame.
202 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
203 int extra_header_count);
204
205 // Create an async MockWrite from the given SpdyFrame.
206 MockWrite CreateMockWrite(spdy::SpdyFrame* req);
207
208 // Create a MockRead from the given SpdyFrame.
209 MockRead CreateMockRead(spdy::SpdyFrame* resp);
210
211 // Create a MockRead from the given SpdyFrame and sequence number.
212 MockRead CreateMockRead(spdy::SpdyFrame* resp, int seq);
213
113 } // namespace net 214 } // namespace net
114 215
115 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ 216 #endif // NET_SPDY_SPDY_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698