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