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