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_spdy3.h" | 5 #include "net/spdy/spdy_test_util_spdy3.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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "crypto/ec_private_key.h" | |
14 #include "crypto/ec_signature_creator.h" | |
15 #include "net/base/mock_cert_verifier.h" | 13 #include "net/base/mock_cert_verifier.h" |
16 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
17 #include "net/http/http_network_transaction.h" | 15 #include "net/http/http_network_transaction.h" |
18 #include "net/http/http_server_properties_impl.h" | 16 #include "net/http/http_server_properties_impl.h" |
19 #include "net/spdy/buffered_spdy_framer.h" | 17 #include "net/spdy/buffered_spdy_framer.h" |
20 #include "net/spdy/spdy_http_utils.h" | 18 #include "net/spdy/spdy_http_utils.h" |
21 #include "net/spdy/spdy_session.h" | 19 #include "net/spdy/spdy_session.h" |
22 | 20 |
23 namespace net { | 21 namespace net { |
24 | 22 |
25 namespace test_spdy3 { | 23 namespace test_spdy3 { |
26 | 24 |
27 namespace { | 25 namespace { |
28 | 26 |
29 // Parses a URL into the scheme, host, and path components required for a | 27 // Parses a URL into the scheme, host, and path components required for a |
30 // SPDY request. | 28 // SPDY request. |
31 void ParseUrl(const char* const url, std::string* scheme, std::string* host, | 29 void ParseUrl(const char* const url, std::string* scheme, std::string* host, |
32 std::string* path) { | 30 std::string* path) { |
33 GURL gurl(url); | 31 GURL gurl(url); |
34 path->assign(gurl.PathForRequest()); | 32 path->assign(gurl.PathForRequest()); |
35 scheme->assign(gurl.scheme()); | 33 scheme->assign(gurl.scheme()); |
36 host->assign(gurl.host()); | 34 host->assign(gurl.host()); |
37 if (gurl.has_port()) { | 35 if (gurl.has_port()) { |
38 host->append(":"); | 36 host->append(":"); |
39 host->append(gurl.port()); | 37 host->append(gurl.port()); |
40 } | 38 } |
41 } | 39 } |
42 | 40 |
43 // An ECSignatureCreator that returns deterministic signatures. | 41 } // namespace |
44 class MockECSignatureCreator : public crypto::ECSignatureCreator { | |
45 public: | |
46 explicit MockECSignatureCreator(crypto::ECPrivateKey* key) : key_(key) {} | |
47 | 42 |
48 virtual bool Sign(const uint8* data, | |
49 int data_len, | |
50 std::vector<uint8>* signature) OVERRIDE { | |
51 std::vector<uint8> private_key_value; | |
52 key_->ExportValue(&private_key_value); | |
53 std::string head = "fakesignature"; | |
54 std::string tail = "/fakesignature"; | |
55 | 43 |
56 signature->clear(); | 44 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) |
57 signature->insert(signature->end(), head.begin(), head.end()); | 45 : key_(key) { |
willchan no longer on Chromium
2012/12/01 20:49:13
indent 4 spaces, as per style guide
Ryan Hamilton
2012/12/01 23:02:25
Whoops, done.
| |
58 signature->insert(signature->end(), private_key_value.begin(), | 46 } |
59 private_key_value.end()); | |
60 signature->insert(signature->end(), '-'); | |
61 signature->insert(signature->end(), data, data + data_len); | |
62 signature->insert(signature->end(), tail.begin(), tail.end()); | |
63 return true; | |
64 } | |
65 | 47 |
66 virtual bool DecodeSignature(const std::vector<uint8>& signature, | 48 bool MockECSignatureCreator::Sign(const uint8* data, |
67 std::vector<uint8>* out_raw_sig) { | 49 int data_len, |
68 *out_raw_sig = signature; | 50 std::vector<uint8>* signature) { |
69 return true; | 51 std::vector<uint8> private_key_value; |
70 } | 52 key_->ExportValue(&private_key_value); |
53 std::string head = "fakesignature"; | |
54 std::string tail = "/fakesignature"; | |
71 | 55 |
72 private: | 56 signature->clear(); |
73 crypto::ECPrivateKey* key_; | 57 signature->insert(signature->end(), head.begin(), head.end()); |
58 signature->insert(signature->end(), private_key_value.begin(), | |
59 private_key_value.end()); | |
60 signature->insert(signature->end(), '-'); | |
61 signature->insert(signature->end(), data, data + data_len); | |
62 signature->insert(signature->end(), tail.begin(), tail.end()); | |
63 return true; | |
64 } | |
74 | 65 |
75 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); | 66 bool MockECSignatureCreator::DecodeSignature( |
76 }; | 67 const std::vector<uint8>& signature, |
68 std::vector<uint8>* out_raw_sig) { | |
69 *out_raw_sig = signature; | |
70 return true; | |
71 } | |
77 | 72 |
78 // An ECSignatureCreatorFactory creates MockECSignatureCreator. | 73 MockECSignatureCreatorFactory::MockECSignatureCreatorFactory() { |
79 class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { | 74 crypto::ECSignatureCreator::SetFactoryForTesting(this); |
80 public: | 75 } |
81 MockECSignatureCreatorFactory() {} | |
82 virtual ~MockECSignatureCreatorFactory() {} | |
83 | 76 |
84 virtual crypto::ECSignatureCreator* Create( | 77 MockECSignatureCreatorFactory::~MockECSignatureCreatorFactory() { |
85 crypto::ECPrivateKey* key) OVERRIDE { | 78 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
86 return new MockECSignatureCreator(key); | 79 } |
87 } | |
88 | 80 |
89 private: | 81 crypto::ECSignatureCreator* MockECSignatureCreatorFactory::Create( |
90 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); | 82 crypto::ECPrivateKey* key) { |
91 }; | 83 return new MockECSignatureCreator(key); |
92 | 84 } |
93 } // namespace | |
94 | 85 |
95 // Chop a frame into an array of MockWrites. | 86 // Chop a frame into an array of MockWrites. |
96 // |data| is the frame to chop. | 87 // |data| is the frame to chop. |
97 // |length| is the length of the frame to chop. | 88 // |length| is the length of the frame to chop. |
98 // |num_chunks| is the number of chunks to create. | 89 // |num_chunks| is the number of chunks to create. |
99 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { | 90 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { |
100 MockWrite* chunks = new MockWrite[num_chunks]; | 91 MockWrite* chunks = new MockWrite[num_chunks]; |
101 int chunk_size = length / num_chunks; | 92 int chunk_size = length / num_chunks; |
102 for (int index = 0; index < num_chunks; index++) { | 93 for (int index = 0; index < num_chunks; index++) { |
103 const char* ptr = data + (index * chunk_size); | 94 const char* ptr = data + (index * chunk_size); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 207 |
217 // Construct a SPDY packet. | 208 // Construct a SPDY packet. |
218 // |head| is the start of the packet, up to but not including | 209 // |head| is the start of the packet, up to but not including |
219 // the header value pairs. | 210 // the header value pairs. |
220 // |extra_headers| are the extra header-value pairs, which typically | 211 // |extra_headers| are the extra header-value pairs, which typically |
221 // will vary the most between calls. | 212 // will vary the most between calls. |
222 // |tail| is any (relatively constant) header-value pairs to add. | 213 // |tail| is any (relatively constant) header-value pairs to add. |
223 // |buffer| is the buffer we're filling in. | 214 // |buffer| is the buffer we're filling in. |
224 // Returns a SpdyFrame. | 215 // Returns a SpdyFrame. |
225 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, | 216 SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, |
226 const char* const extra_headers[], | 217 const char* const extra_headers[], |
227 int extra_header_count, | 218 int extra_header_count, |
228 const char* const tail[], | 219 const char* const tail[], |
229 int tail_header_count) { | 220 int tail_header_count) { |
230 BufferedSpdyFramer framer(3); | 221 BufferedSpdyFramer framer(3, header_info.compressed); |
231 SpdyHeaderBlock headers; | 222 SpdyHeaderBlock headers; |
232 // Copy in the extra headers to our map. | 223 // Copy in the extra headers to our map. |
233 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); | 224 AppendHeadersToSpdyFrame(extra_headers, extra_header_count, &headers); |
234 // Copy in the tail headers to our map. | 225 // Copy in the tail headers to our map. |
235 if (tail && tail_header_count) | 226 if (tail && tail_header_count) |
236 AppendHeadersToSpdyFrame(tail, tail_header_count, &headers); | 227 AppendHeadersToSpdyFrame(tail, tail_header_count, &headers); |
237 SpdyFrame* frame = NULL; | 228 SpdyFrame* frame = NULL; |
238 switch (header_info.kind) { | 229 switch (header_info.kind) { |
239 case SYN_STREAM: | 230 case SYN_STREAM: |
240 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, | 231 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, |
(...skipping 19 matching lines...) Expand all Loading... | |
260 header_info.data_flags); | 251 header_info.data_flags); |
261 break; | 252 break; |
262 } | 253 } |
263 return frame; | 254 return frame; |
264 } | 255 } |
265 | 256 |
266 // Construct an expected SPDY SETTINGS frame. | 257 // Construct an expected SPDY SETTINGS frame. |
267 // |settings| are the settings to set. | 258 // |settings| are the settings to set. |
268 // Returns the constructed frame. The caller takes ownership of the frame. | 259 // Returns the constructed frame. The caller takes ownership of the frame. |
269 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { | 260 SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) { |
270 BufferedSpdyFramer framer(3); | 261 BufferedSpdyFramer framer(3, false); |
271 return framer.CreateSettings(settings); | 262 return framer.CreateSettings(settings); |
272 } | 263 } |
273 | 264 |
274 // Construct an expected SPDY CREDENTIAL frame. | 265 // Construct an expected SPDY CREDENTIAL frame. |
275 // |credential| is the credential to sen. | 266 // |credential| is the credential to sen. |
276 // Returns the constructed frame. The caller takes ownership of the frame. | 267 // Returns the constructed frame. The caller takes ownership of the frame. |
277 SpdyFrame* ConstructSpdyCredential( | 268 SpdyFrame* ConstructSpdyCredential( |
278 const SpdyCredential& credential) { | 269 const SpdyCredential& credential) { |
279 BufferedSpdyFramer framer(3); | 270 BufferedSpdyFramer framer(3, false); |
280 return framer.CreateCredentialFrame(credential); | 271 return framer.CreateCredentialFrame(credential); |
281 } | 272 } |
282 | 273 |
283 // Construct a SPDY PING frame. | 274 // Construct a SPDY PING frame. |
284 // Returns the constructed frame. The caller takes ownership of the frame. | 275 // Returns the constructed frame. The caller takes ownership of the frame. |
285 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { | 276 SpdyFrame* ConstructSpdyPing(uint32 ping_id) { |
286 BufferedSpdyFramer framer(3); | 277 BufferedSpdyFramer framer(3, false); |
287 return framer.CreatePingFrame(ping_id); | 278 return framer.CreatePingFrame(ping_id); |
288 } | 279 } |
289 | 280 |
290 // Construct a SPDY GOAWAY frame. | 281 // Construct a SPDY GOAWAY frame. |
291 // Returns the constructed frame. The caller takes ownership of the frame. | 282 // Returns the constructed frame. The caller takes ownership of the frame. |
292 SpdyFrame* ConstructSpdyGoAway() { | 283 SpdyFrame* ConstructSpdyGoAway() { |
293 BufferedSpdyFramer framer(3); | 284 BufferedSpdyFramer framer(3, false); |
294 return framer.CreateGoAway(0, GOAWAY_OK); | 285 return framer.CreateGoAway(0, GOAWAY_OK); |
295 } | 286 } |
296 | 287 |
297 // Construct a SPDY WINDOW_UPDATE frame. | 288 // Construct a SPDY WINDOW_UPDATE frame. |
298 // Returns the constructed frame. The caller takes ownership of the frame. | 289 // Returns the constructed frame. The caller takes ownership of the frame. |
299 SpdyFrame* ConstructSpdyWindowUpdate( | 290 SpdyFrame* ConstructSpdyWindowUpdate( |
300 const SpdyStreamId stream_id, uint32 delta_window_size) { | 291 const SpdyStreamId stream_id, uint32 delta_window_size) { |
301 BufferedSpdyFramer framer(3); | 292 BufferedSpdyFramer framer(3, false); |
302 return framer.CreateWindowUpdate(stream_id, delta_window_size); | 293 return framer.CreateWindowUpdate(stream_id, delta_window_size); |
303 } | 294 } |
304 | 295 |
305 // Construct a SPDY RST_STREAM frame. | 296 // Construct a SPDY RST_STREAM frame. |
306 // Returns the constructed frame. The caller takes ownership of the frame. | 297 // Returns the constructed frame. The caller takes ownership of the frame. |
307 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, | 298 SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, |
308 SpdyStatusCodes status) { | 299 SpdyStatusCodes status) { |
309 BufferedSpdyFramer framer(3); | 300 BufferedSpdyFramer framer(3, false); |
310 return framer.CreateRstStream(stream_id, status); | 301 return framer.CreateRstStream(stream_id, status); |
311 } | 302 } |
312 | 303 |
313 // Construct a single SPDY header entry, for validation. | 304 // Construct a single SPDY header entry, for validation. |
314 // |extra_headers| are the extra header-value pairs. | 305 // |extra_headers| are the extra header-value pairs. |
315 // |buffer| is the buffer we're filling in. | 306 // |buffer| is the buffer we're filling in. |
316 // |index| is the index of the header we want. | 307 // |index| is the index of the header we want. |
317 // Returns the number of bytes written into |buffer|. | 308 // Returns the number of bytes written into |buffer|. |
318 int ConstructSpdyHeader(const char* const extra_headers[], | 309 int ConstructSpdyHeader(const char* const extra_headers[], |
319 int extra_header_count, | 310 int extra_header_count, |
(...skipping 24 matching lines...) Expand all Loading... | |
344 this_value = ""; | 335 this_value = ""; |
345 int n = base::snprintf(buffer, | 336 int n = base::snprintf(buffer, |
346 buffer_length, | 337 buffer_length, |
347 "%s: %s\r\n", | 338 "%s: %s\r\n", |
348 this_header, | 339 this_header, |
349 this_value); | 340 this_value); |
350 return n; | 341 return n; |
351 } | 342 } |
352 | 343 |
353 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], | 344 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
354 int extra_header_count, | 345 int extra_header_count, |
355 bool compressed, | 346 bool compressed, |
356 int stream_id, | 347 int stream_id, |
357 RequestPriority request_priority, | 348 RequestPriority request_priority, |
358 SpdyControlType type, | 349 SpdyControlType type, |
359 SpdyControlFlags flags, | 350 SpdyControlFlags flags, |
360 const char* const* kHeaders, | 351 const char* const* kHeaders, |
361 int kHeadersSize) { | 352 int kHeadersSize) { |
362 return ConstructSpdyControlFrame(extra_headers, | 353 return ConstructSpdyControlFrame(extra_headers, |
363 extra_header_count, | 354 extra_header_count, |
364 compressed, | 355 compressed, |
365 stream_id, | 356 stream_id, |
366 request_priority, | 357 request_priority, |
367 type, | 358 type, |
368 flags, | 359 flags, |
369 kHeaders, | 360 kHeaders, |
370 kHeadersSize, | 361 kHeadersSize, |
371 0); | 362 0); |
372 } | 363 } |
373 | 364 |
374 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], | 365 SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[], |
375 int extra_header_count, | 366 int extra_header_count, |
376 bool compressed, | 367 bool compressed, |
377 int stream_id, | 368 int stream_id, |
378 RequestPriority request_priority, | 369 RequestPriority request_priority, |
379 SpdyControlType type, | 370 SpdyControlType type, |
380 SpdyControlFlags flags, | 371 SpdyControlFlags flags, |
381 const char* const* kHeaders, | 372 const char* const* kHeaders, |
382 int kHeadersSize, | 373 int kHeadersSize, |
383 int associated_stream_id) { | 374 int associated_stream_id) { |
384 const SpdyHeaderInfo kSynStartHeader = { | 375 const SpdyHeaderInfo kSynStartHeader = { |
385 type, // Kind = Syn | 376 type, // Kind = Syn |
386 stream_id, // Stream ID | 377 stream_id, // Stream ID |
387 associated_stream_id, // Associated stream ID | 378 associated_stream_id, // Associated stream ID |
388 ConvertRequestPriorityToSpdyPriority(request_priority, 3), | 379 ConvertRequestPriorityToSpdyPriority(request_priority, 3), |
389 // Priority | 380 // Priority |
390 0, // Credential Slot | 381 0, // Credential Slot |
391 flags, // Control Flags | 382 flags, // Control Flags |
392 compressed, // Compressed | 383 compressed, // Compressed |
393 INVALID, // Status | 384 INVALID, // Status |
394 NULL, // Data | 385 NULL, // Data |
395 0, // Length | 386 0, // Length |
396 DATA_FLAG_NONE // Data Flags | 387 DATA_FLAG_NONE // Data Flags |
397 }; | 388 }; |
398 return ConstructSpdyPacket(kSynStartHeader, | 389 return ConstructSpdyPacket(kSynStartHeader, |
399 extra_headers, | 390 extra_headers, |
400 extra_header_count, | 391 extra_header_count, |
401 kHeaders, | 392 kHeaders, |
402 kHeadersSize / 2); | 393 kHeadersSize / 2); |
403 } | 394 } |
404 | 395 |
405 // Constructs a standard SPDY GET SYN packet, optionally compressed | 396 // Constructs a standard SPDY GET SYN packet, optionally compressed |
406 // for the url |url|. | 397 // for the url |url|. |
407 // |extra_headers| are the extra header-value pairs, which typically | 398 // |extra_headers| are the extra header-value pairs, which typically |
408 // will vary the most between calls. | 399 // will vary the most between calls. |
409 // Returns a SpdyFrame. | 400 // Returns a SpdyFrame. |
410 SpdyFrame* ConstructSpdyGet(const char* const url, | 401 SpdyFrame* ConstructSpdyGet(const char* const url, |
411 bool compressed, | 402 bool compressed, |
412 int stream_id, | 403 int stream_id, |
413 RequestPriority request_priority) { | 404 RequestPriority request_priority) { |
414 const SpdyHeaderInfo kSynStartHeader = { | 405 const SpdyHeaderInfo kSynStartHeader = { |
415 SYN_STREAM, // Kind = Syn | 406 SYN_STREAM, // Kind = Syn |
416 stream_id, // Stream ID | 407 stream_id, // Stream ID |
417 0, // Associated stream ID | 408 0, // Associated stream ID |
418 ConvertRequestPriorityToSpdyPriority(request_priority, 3), | 409 ConvertRequestPriorityToSpdyPriority(request_priority, 3), |
419 // Priority | 410 // Priority |
420 0, // Credential Slot | 411 0, // Credential Slot |
421 CONTROL_FLAG_FIN, // Control Flags | 412 CONTROL_FLAG_FIN, // Control Flags |
422 compressed, // Compressed | 413 compressed, // Compressed |
423 INVALID, // Status | 414 INVALID, // Status |
424 NULL, // Data | 415 NULL, // Data |
425 0, // Length | 416 0, // Length |
426 DATA_FLAG_NONE // Data Flags | 417 DATA_FLAG_NONE // Data Flags |
427 }; | 418 }; |
428 | 419 |
429 std::string scheme, host, path; | 420 std::string scheme, host, path; |
430 ParseUrl(url, &scheme, &host, &path); | 421 ParseUrl(url, &scheme, &host, &path); |
431 const char* const headers[] = { | 422 const char* const headers[] = { |
432 ":method", "GET", | 423 ":method", "GET", |
433 ":path", path.c_str(), | 424 ":path", path.c_str(), |
434 ":host", host.c_str(), | 425 ":host", host.c_str(), |
435 ":scheme", scheme.c_str(), | 426 ":scheme", scheme.c_str(), |
436 ":version", "HTTP/1.1" | 427 ":version", "HTTP/1.1" |
437 }; | 428 }; |
438 return ConstructSpdyPacket( | 429 return ConstructSpdyPacket( |
439 kSynStartHeader, | 430 kSynStartHeader, |
440 NULL, | 431 NULL, |
441 0, | 432 0, |
442 headers, | 433 headers, |
443 arraysize(headers) / 2); | 434 arraysize(headers) / 2); |
444 } | 435 } |
445 | 436 |
446 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 437 // Constructs a standard SPDY GET SYN packet, optionally compressed. |
447 // |extra_headers| are the extra header-value pairs, which typically | 438 // |extra_headers| are the extra header-value pairs, which typically |
448 // will vary the most between calls. | 439 // will vary the most between calls. |
449 // Returns a SpdyFrame. | 440 // Returns a SpdyFrame. |
450 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 441 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
451 int extra_header_count, | 442 int extra_header_count, |
452 bool compressed, | 443 bool compressed, |
453 int stream_id, | 444 int stream_id, |
454 RequestPriority request_priority) { | 445 RequestPriority request_priority) { |
455 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, | 446 return ConstructSpdyGet(extra_headers, extra_header_count, compressed, |
456 stream_id, request_priority, true); | 447 stream_id, request_priority, true); |
457 } | 448 } |
458 | 449 |
459 // Constructs a standard SPDY GET SYN packet, optionally compressed. | 450 // Constructs a standard SPDY GET SYN packet, optionally compressed. |
460 // |extra_headers| are the extra header-value pairs, which typically | 451 // |extra_headers| are the extra header-value pairs, which typically |
461 // will vary the most between calls. | 452 // will vary the most between calls. |
462 // Returns a SpdyFrame. | 453 // Returns a SpdyFrame. |
463 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], | 454 SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], |
464 int extra_header_count, | 455 int extra_header_count, |
465 bool compressed, | 456 bool compressed, |
466 int stream_id, | 457 int stream_id, |
467 RequestPriority request_priority, | 458 RequestPriority request_priority, |
468 bool direct) { | 459 bool direct) { |
469 const char* const kStandardGetHeaders[] = { | 460 const char* const kStandardGetHeaders[] = { |
470 ":method", | 461 ":method", "GET", |
471 "GET", | 462 ":host", "www.google.com", |
472 ":host", | 463 ":scheme", "http", |
473 "www.google.com", | 464 ":version", "HTTP/1.1", |
474 ":scheme", | 465 ":path", (direct ? "/" : "/") |
475 "http", | |
476 ":version", | |
477 "HTTP/1.1", | |
478 ":path", | |
479 (direct ? "/" : "/") | |
480 }; | 466 }; |
481 return ConstructSpdyControlFrame(extra_headers, | 467 return ConstructSpdyControlFrame(extra_headers, |
482 extra_header_count, | 468 extra_header_count, |
483 compressed, | 469 compressed, |
484 stream_id, | 470 stream_id, |
485 request_priority, | 471 request_priority, |
486 SYN_STREAM, | 472 SYN_STREAM, |
487 CONTROL_FLAG_FIN, | 473 CONTROL_FLAG_FIN, |
488 kStandardGetHeaders, | 474 kStandardGetHeaders, |
489 arraysize(kStandardGetHeaders)); | 475 arraysize(kStandardGetHeaders)); |
490 } | 476 } |
491 | 477 |
492 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 478 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
493 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], | 479 SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], |
494 int extra_header_count, | 480 int extra_header_count, |
495 int stream_id) { | 481 int stream_id) { |
496 const char* const kConnectHeaders[] = { | 482 const char* const kConnectHeaders[] = { |
497 ":method", "CONNECT", | 483 ":method", "CONNECT", |
498 ":path", "www.google.com:443", | 484 ":path", "www.google.com:443", |
499 ":host", "www.google.com", | 485 ":host", "www.google.com", |
500 ":version", "HTTP/1.1", | 486 ":version", "HTTP/1.1", |
501 }; | 487 }; |
502 return ConstructSpdyControlFrame(extra_headers, | 488 return ConstructSpdyControlFrame(extra_headers, |
503 extra_header_count, | 489 extra_header_count, |
504 /*compressed*/ false, | 490 /*compressed*/ false, |
505 stream_id, | 491 stream_id, |
506 LOWEST, | 492 LOWEST, |
507 SYN_STREAM, | 493 SYN_STREAM, |
508 CONTROL_FLAG_NONE, | 494 CONTROL_FLAG_NONE, |
509 kConnectHeaders, | 495 kConnectHeaders, |
510 arraysize(kConnectHeaders)); | 496 arraysize(kConnectHeaders)); |
511 } | 497 } |
512 | 498 |
513 // Constructs a standard SPDY push SYN packet. | 499 // Constructs a standard SPDY push SYN packet. |
514 // |extra_headers| are the extra header-value pairs, which typically | 500 // |extra_headers| are the extra header-value pairs, which typically |
515 // will vary the most between calls. | 501 // will vary the most between calls. |
516 // Returns a SpdyFrame. | 502 // Returns a SpdyFrame. |
517 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 503 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
518 int extra_header_count, | 504 int extra_header_count, |
519 int stream_id, | 505 int stream_id, |
520 int associated_stream_id) { | 506 int associated_stream_id) { |
521 const char* const kStandardPushHeaders[] = { | 507 const char* const kStandardPushHeaders[] = { |
522 "hello", "bye", | 508 "hello", "bye", |
523 ":status", "200", | 509 ":status", "200", |
524 ":version", "HTTP/1.1" | 510 ":version", "HTTP/1.1" |
525 }; | 511 }; |
526 return ConstructSpdyControlFrame(extra_headers, | 512 return ConstructSpdyControlFrame(extra_headers, |
527 extra_header_count, | 513 extra_header_count, |
528 false, | 514 false, |
529 stream_id, | 515 stream_id, |
530 LOWEST, | 516 LOWEST, |
531 SYN_STREAM, | 517 SYN_STREAM, |
532 CONTROL_FLAG_NONE, | 518 CONTROL_FLAG_NONE, |
533 kStandardPushHeaders, | 519 kStandardPushHeaders, |
534 arraysize(kStandardPushHeaders), | 520 arraysize(kStandardPushHeaders), |
535 associated_stream_id); | 521 associated_stream_id); |
536 } | 522 } |
537 | 523 |
538 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 524 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
539 int extra_header_count, | 525 int extra_header_count, |
540 int stream_id, | 526 int stream_id, |
541 int associated_stream_id, | 527 int associated_stream_id, |
542 const char* url) { | 528 const char* url) { |
543 std::string scheme, host, path; | 529 std::string scheme, host, path; |
544 ParseUrl(url, &scheme, &host, &path); | 530 ParseUrl(url, &scheme, &host, &path); |
545 const char* const headers[] = { | 531 const char* const headers[] = { |
546 "hello", "bye", | 532 "hello", "bye", |
547 ":status", "200 OK", | 533 ":status", "200 OK", |
548 ":version", "HTTP/1.1", | 534 ":version", "HTTP/1.1", |
549 ":path", path.c_str(), | 535 ":path", path.c_str(), |
550 ":host", host.c_str(), | 536 ":host", host.c_str(), |
551 ":scheme", scheme.c_str(), | 537 ":scheme", scheme.c_str(), |
552 }; | 538 }; |
553 return ConstructSpdyControlFrame(extra_headers, | 539 return ConstructSpdyControlFrame(extra_headers, |
554 extra_header_count, | 540 extra_header_count, |
555 false, | 541 false, |
556 stream_id, | 542 stream_id, |
557 LOWEST, | 543 LOWEST, |
558 SYN_STREAM, | 544 SYN_STREAM, |
559 CONTROL_FLAG_NONE, | 545 CONTROL_FLAG_NONE, |
560 headers, | 546 headers, |
561 arraysize(headers), | 547 arraysize(headers), |
562 associated_stream_id); | 548 associated_stream_id); |
563 | 549 |
564 } | 550 } |
565 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], | 551 SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], |
566 int extra_header_count, | 552 int extra_header_count, |
567 int stream_id, | 553 int stream_id, |
568 int associated_stream_id, | 554 int associated_stream_id, |
569 const char* url, | 555 const char* url, |
570 const char* status, | 556 const char* status, |
571 const char* location) { | 557 const char* location) { |
572 std::string scheme, host, path; | 558 std::string scheme, host, path; |
573 ParseUrl(url, &scheme, &host, &path); | 559 ParseUrl(url, &scheme, &host, &path); |
574 const char* const headers[] = { | 560 const char* const headers[] = { |
575 "hello", "bye", | 561 "hello", "bye", |
576 ":status", status, | 562 ":status", status, |
577 "location", location, | 563 "location", location, |
578 ":path", path.c_str(), | 564 ":path", path.c_str(), |
579 ":host", host.c_str(), | 565 ":host", host.c_str(), |
580 ":scheme", scheme.c_str(), | 566 ":scheme", scheme.c_str(), |
581 ":version", "HTTP/1.1" | 567 ":version", "HTTP/1.1" |
582 }; | 568 }; |
583 return ConstructSpdyControlFrame(extra_headers, | 569 return ConstructSpdyControlFrame(extra_headers, |
584 extra_header_count, | 570 extra_header_count, |
585 false, | 571 false, |
586 stream_id, | 572 stream_id, |
587 LOWEST, | 573 LOWEST, |
588 SYN_STREAM, | 574 SYN_STREAM, |
589 CONTROL_FLAG_NONE, | 575 CONTROL_FLAG_NONE, |
590 headers, | 576 headers, |
591 arraysize(headers), | 577 arraysize(headers), |
592 associated_stream_id); | 578 associated_stream_id); |
593 } | 579 } |
594 | 580 |
595 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, | 581 SpdyFrame* ConstructSpdyPushHeaders(int stream_id, |
596 const char* const extra_headers[], | 582 const char* const extra_headers[], |
597 int extra_header_count) { | 583 int extra_header_count) { |
598 const char* const kStandardGetHeaders[] = { | 584 const char* const kStandardGetHeaders[] = { |
599 ":status", | 585 ":status", "200 OK", |
600 "200 OK", | 586 ":version", "HTTP/1.1" |
601 ":version", | |
602 "HTTP/1.1" | |
603 }; | 587 }; |
604 return ConstructSpdyControlFrame(extra_headers, | 588 return ConstructSpdyControlFrame(extra_headers, |
605 extra_header_count, | 589 extra_header_count, |
606 false, | 590 false, |
607 stream_id, | 591 stream_id, |
608 LOWEST, | 592 LOWEST, |
609 HEADERS, | 593 HEADERS, |
610 CONTROL_FLAG_NONE, | 594 CONTROL_FLAG_NONE, |
611 kStandardGetHeaders, | 595 kStandardGetHeaders, |
612 arraysize(kStandardGetHeaders)); | 596 arraysize(kStandardGetHeaders)); |
613 } | 597 } |
614 | 598 |
615 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. | 599 // Constructs a standard SPDY SYN_REPLY packet with the specified status code. |
616 // Returns a SpdyFrame. | 600 // Returns a SpdyFrame. |
617 SpdyFrame* ConstructSpdySynReplyError( | 601 SpdyFrame* ConstructSpdySynReplyError(const char* const status, |
618 const char* const status, | 602 const char* const* const extra_headers, |
619 const char* const* const extra_headers, | 603 int extra_header_count, |
620 int extra_header_count, | 604 int stream_id) { |
621 int stream_id) { | |
622 const char* const kStandardGetHeaders[] = { | 605 const char* const kStandardGetHeaders[] = { |
623 "hello", | 606 "hello", "bye", |
624 "bye", | 607 ":status", status, |
625 ":status", | 608 ":version", "HTTP/1.1" |
626 status, | |
627 ":version", | |
628 "HTTP/1.1" | |
629 }; | 609 }; |
630 return ConstructSpdyControlFrame(extra_headers, | 610 return ConstructSpdyControlFrame(extra_headers, |
631 extra_header_count, | 611 extra_header_count, |
632 false, | 612 false, |
633 stream_id, | 613 stream_id, |
634 LOWEST, | 614 LOWEST, |
635 SYN_REPLY, | 615 SYN_REPLY, |
636 CONTROL_FLAG_NONE, | 616 CONTROL_FLAG_NONE, |
637 kStandardGetHeaders, | 617 kStandardGetHeaders, |
638 arraysize(kStandardGetHeaders)); | 618 arraysize(kStandardGetHeaders)); |
639 } | 619 } |
640 | 620 |
641 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 621 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. |
642 // |extra_headers| are the extra header-value pairs, which typically | 622 // |extra_headers| are the extra header-value pairs, which typically |
643 // will vary the most between calls. | 623 // will vary the most between calls. |
644 // Returns a SpdyFrame. | 624 // Returns a SpdyFrame. |
645 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { | 625 SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id) { |
646 static const char* const kExtraHeaders[] = { | 626 static const char* const kExtraHeaders[] = { |
647 "location", | 627 "location", "http://www.foo.com/index.php", |
648 "http://www.foo.com/index.php", | |
649 }; | 628 }; |
650 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 629 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, |
651 arraysize(kExtraHeaders)/2, stream_id); | 630 arraysize(kExtraHeaders)/2, stream_id); |
652 } | 631 } |
653 | 632 |
654 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server | 633 // Constructs a standard SPDY SYN_REPLY packet with an Internal Server |
655 // Error status code. | 634 // Error status code. |
656 // Returns a SpdyFrame. | 635 // Returns a SpdyFrame. |
657 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { | 636 SpdyFrame* ConstructSpdySynReplyError(int stream_id) { |
658 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 637 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
659 } | 638 } |
660 | 639 |
661 | 640 |
662 | 641 |
663 | 642 |
664 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. | 643 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. |
665 // |extra_headers| are the extra header-value pairs, which typically | 644 // |extra_headers| are the extra header-value pairs, which typically |
666 // will vary the most between calls. | 645 // will vary the most between calls. |
667 // Returns a SpdyFrame. | 646 // Returns a SpdyFrame. |
668 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], | 647 SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], |
669 int extra_header_count, | 648 int extra_header_count, |
670 int stream_id) { | 649 int stream_id) { |
671 static const char* const kStandardGetHeaders[] = { | 650 static const char* const kStandardGetHeaders[] = { |
672 "hello", | 651 "hello", "bye", |
673 "bye", | 652 ":status", "200", |
674 ":status", | 653 ":version", "HTTP/1.1" |
675 "200", | |
676 ":version", | |
677 "HTTP/1.1" | |
678 }; | 654 }; |
679 return ConstructSpdyControlFrame(extra_headers, | 655 return ConstructSpdyControlFrame(extra_headers, |
680 extra_header_count, | 656 extra_header_count, |
681 false, | 657 false, |
682 stream_id, | 658 stream_id, |
683 LOWEST, | 659 LOWEST, |
684 SYN_REPLY, | 660 SYN_REPLY, |
685 CONTROL_FLAG_NONE, | 661 CONTROL_FLAG_NONE, |
686 kStandardGetHeaders, | 662 kStandardGetHeaders, |
687 arraysize(kStandardGetHeaders)); | 663 arraysize(kStandardGetHeaders)); |
688 } | 664 } |
689 | 665 |
690 // Constructs a standard SPDY POST SYN packet. | 666 // Constructs a standard SPDY POST SYN packet. |
691 // |content_length| is the size of post data. | 667 // |content_length| is the size of post data. |
692 // |extra_headers| are the extra header-value pairs, which typically | 668 // |extra_headers| are the extra header-value pairs, which typically |
693 // will vary the most between calls. | 669 // will vary the most between calls. |
694 // Returns a SpdyFrame. | 670 // Returns a SpdyFrame. |
695 SpdyFrame* ConstructSpdyPost(int64 content_length, | 671 SpdyFrame* ConstructSpdyPost(int64 content_length, |
696 const char* const extra_headers[], | 672 const char* const extra_headers[], |
697 int extra_header_count) { | 673 int extra_header_count) { |
698 std::string length_str = base::Int64ToString(content_length); | 674 std::string length_str = base::Int64ToString(content_length); |
699 const char* post_headers[] = { | 675 const char* post_headers[] = { |
700 ":method", | 676 ":method", "POST", |
701 "POST", | 677 ":path", "/", |
702 ":path", | 678 ":host", "www.google.com", |
703 "/", | 679 ":scheme", "http", |
704 ":host", | 680 ":version", "HTTP/1.1", |
705 "www.google.com", | 681 "content-length", length_str.c_str() |
706 ":scheme", | |
707 "http", | |
708 ":version", | |
709 "HTTP/1.1", | |
710 "content-length", | |
711 length_str.c_str() | |
712 }; | 682 }; |
713 return ConstructSpdyControlFrame(extra_headers, | 683 return ConstructSpdyControlFrame(extra_headers, |
714 extra_header_count, | 684 extra_header_count, |
715 false, | 685 false, |
716 1, | 686 1, |
717 LOWEST, | 687 LOWEST, |
718 SYN_STREAM, | 688 SYN_STREAM, |
719 CONTROL_FLAG_NONE, | 689 CONTROL_FLAG_NONE, |
720 post_headers, | 690 post_headers, |
721 arraysize(post_headers)); | 691 arraysize(post_headers)); |
722 } | 692 } |
723 | 693 |
724 // Constructs a chunked transfer SPDY POST SYN packet. | 694 // Constructs a chunked transfer SPDY POST SYN packet. |
725 // |extra_headers| are the extra header-value pairs, which typically | 695 // |extra_headers| are the extra header-value pairs, which typically |
726 // will vary the most between calls. | 696 // will vary the most between calls. |
727 // Returns a SpdyFrame. | 697 // Returns a SpdyFrame. |
728 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], | 698 SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], |
729 int extra_header_count) { | 699 int extra_header_count) { |
730 const char* post_headers[] = { | 700 const char* post_headers[] = { |
731 ":method", | 701 ":method", "POST", |
732 "POST", | 702 ":path", "/", |
733 ":path", | 703 ":host", "www.google.com", |
734 "/", | 704 ":scheme", "http", |
735 ":host", | 705 ":version", "HTTP/1.1" |
736 "www.google.com", | |
737 ":scheme", | |
738 "http", | |
739 ":version", | |
740 "HTTP/1.1" | |
741 }; | 706 }; |
742 return ConstructSpdyControlFrame(extra_headers, | 707 return ConstructSpdyControlFrame(extra_headers, |
743 extra_header_count, | 708 extra_header_count, |
744 false, | 709 false, |
745 1, | 710 1, |
746 LOWEST, | 711 LOWEST, |
747 SYN_STREAM, | 712 SYN_STREAM, |
748 CONTROL_FLAG_NONE, | 713 CONTROL_FLAG_NONE, |
749 post_headers, | 714 post_headers, |
750 arraysize(post_headers)); | 715 arraysize(post_headers)); |
751 } | 716 } |
752 | 717 |
753 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. | 718 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. |
754 // |extra_headers| are the extra header-value pairs, which typically | 719 // |extra_headers| are the extra header-value pairs, which typically |
755 // will vary the most between calls. | 720 // will vary the most between calls. |
756 // Returns a SpdyFrame. | 721 // Returns a SpdyFrame. |
757 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], | 722 SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], |
758 int extra_header_count) { | 723 int extra_header_count) { |
759 static const char* const kStandardGetHeaders[] = { | 724 static const char* const kStandardGetHeaders[] = { |
760 "hello", | 725 "hello", "bye", |
761 "bye", | 726 ":status", "200", |
762 ":status", | 727 "url", "/index.php", |
763 "200", | 728 ":version", "HTTP/1.1" |
764 "url", | |
765 "/index.php", | |
766 ":version", | |
767 "HTTP/1.1" | |
768 }; | 729 }; |
769 return ConstructSpdyControlFrame(extra_headers, | 730 return ConstructSpdyControlFrame(extra_headers, |
770 extra_header_count, | 731 extra_header_count, |
771 false, | 732 false, |
772 1, | 733 1, |
773 LOWEST, | 734 LOWEST, |
774 SYN_REPLY, | 735 SYN_REPLY, |
775 CONTROL_FLAG_NONE, | 736 CONTROL_FLAG_NONE, |
776 kStandardGetHeaders, | 737 kStandardGetHeaders, |
777 arraysize(kStandardGetHeaders)); | 738 arraysize(kStandardGetHeaders)); |
778 } | 739 } |
779 | 740 |
780 // Constructs a single SPDY data frame with the default contents. | 741 // Constructs a single SPDY data frame with the default contents. |
781 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { | 742 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, bool fin) { |
782 BufferedSpdyFramer framer(3); | 743 BufferedSpdyFramer framer(3, false); |
783 return framer.CreateDataFrame( | 744 return framer.CreateDataFrame( |
784 stream_id, kUploadData, kUploadDataSize, | 745 stream_id, kUploadData, kUploadDataSize, |
785 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 746 fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
786 } | 747 } |
787 | 748 |
788 // Constructs a single SPDY data frame with the given content. | 749 // Constructs a single SPDY data frame with the given content. |
789 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, | 750 SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, |
790 uint32 len, bool fin) { | 751 uint32 len, bool fin) { |
791 BufferedSpdyFramer framer(3); | 752 BufferedSpdyFramer framer(3, false); |
792 return framer.CreateDataFrame( | 753 return framer.CreateDataFrame( |
793 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 754 stream_id, data, len, fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
794 } | 755 } |
795 | 756 |
796 // Wraps |frame| in the payload of a data frame in stream |stream_id|. | 757 // Wraps |frame| in the payload of a data frame in stream |stream_id|. |
797 SpdyFrame* ConstructWrappedSpdyFrame( | 758 SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, |
798 const scoped_ptr<SpdyFrame>& frame, | 759 int stream_id) { |
799 int stream_id) { | |
800 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 760 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
801 frame->length() + SpdyFrame::kHeaderSize, | 761 frame->length() + SpdyFrame::kHeaderSize, |
802 false); | 762 false); |
803 } | 763 } |
804 | 764 |
805 // Construct an expected SPDY reply string. | 765 // Construct an expected SPDY reply string. |
806 // |extra_headers| are the extra header-value pairs, which typically | 766 // |extra_headers| are the extra header-value pairs, which typically |
807 // will vary the most between calls. | 767 // will vary the most between calls. |
808 // |buffer| is the buffer we're filling in. | 768 // |buffer| is the buffer we're filling in. |
809 // Returns the number of bytes written into |buffer|. | 769 // Returns the number of bytes written into |buffer|. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 | 894 |
935 SpdySessionDependencies::SpdySessionDependencies() | 895 SpdySessionDependencies::SpdySessionDependencies() |
936 : host_resolver(new MockCachingHostResolver), | 896 : host_resolver(new MockCachingHostResolver), |
937 cert_verifier(new MockCertVerifier), | 897 cert_verifier(new MockCertVerifier), |
938 proxy_service(ProxyService::CreateDirect()), | 898 proxy_service(ProxyService::CreateDirect()), |
939 ssl_config_service(new SSLConfigServiceDefaults), | 899 ssl_config_service(new SSLConfigServiceDefaults), |
940 socket_factory(new MockClientSocketFactory), | 900 socket_factory(new MockClientSocketFactory), |
941 deterministic_socket_factory(new DeterministicMockClientSocketFactory), | 901 deterministic_socket_factory(new DeterministicMockClientSocketFactory), |
942 http_auth_handler_factory( | 902 http_auth_handler_factory( |
943 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 903 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
904 enable_ip_pooling(true), | |
905 enable_compression(false), | |
906 enable_ping(false), | |
907 initial_recv_window_size(kSpdyStreamInitialWindowSize), | |
908 time_func(&base::TimeTicks::Now), | |
944 net_log(NULL) { | 909 net_log(NULL) { |
945 // Note: The CancelledTransaction test does cleanup by running all | 910 // Note: The CancelledTransaction test does cleanup by running all |
946 // tasks in the message loop (RunAllPending). Unfortunately, that | 911 // tasks in the message loop (RunAllPending). Unfortunately, that |
947 // doesn't clean up tasks on the host resolver thread; and | 912 // doesn't clean up tasks on the host resolver thread; and |
948 // TCPConnectJob is currently not cancellable. Using synchronous | 913 // TCPConnectJob is currently not cancellable. Using synchronous |
949 // lookups allows the test to shutdown cleanly. Until we have | 914 // lookups allows the test to shutdown cleanly. Until we have |
950 // cancellable TCPConnectJobs, use synchronous lookups. | 915 // cancellable TCPConnectJobs, use synchronous lookups. |
951 host_resolver->set_synchronous_mode(true); | 916 host_resolver->set_synchronous_mode(true); |
952 } | 917 } |
953 | 918 |
954 SpdySessionDependencies::SpdySessionDependencies(ProxyService* proxy_service) | 919 SpdySessionDependencies::SpdySessionDependencies(ProxyService* proxy_service) |
955 : host_resolver(new MockHostResolver), | 920 : host_resolver(new MockHostResolver), |
956 cert_verifier(new MockCertVerifier), | 921 cert_verifier(new MockCertVerifier), |
957 proxy_service(proxy_service), | 922 proxy_service(proxy_service), |
958 ssl_config_service(new SSLConfigServiceDefaults), | 923 ssl_config_service(new SSLConfigServiceDefaults), |
959 socket_factory(new MockClientSocketFactory), | 924 socket_factory(new MockClientSocketFactory), |
960 deterministic_socket_factory(new DeterministicMockClientSocketFactory), | 925 deterministic_socket_factory(new DeterministicMockClientSocketFactory), |
961 http_auth_handler_factory( | 926 http_auth_handler_factory( |
962 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 927 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
928 enable_ip_pooling(true), | |
929 enable_compression(false), | |
930 enable_ping(false), | |
931 initial_recv_window_size(kSpdyStreamInitialWindowSize), | |
932 time_func(&base::TimeTicks::Now), | |
963 net_log(NULL) {} | 933 net_log(NULL) {} |
964 | 934 |
965 SpdySessionDependencies::~SpdySessionDependencies() {} | 935 SpdySessionDependencies::~SpdySessionDependencies() {} |
966 | 936 |
967 // static | 937 // static |
968 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( | 938 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( |
969 SpdySessionDependencies* session_deps) { | 939 SpdySessionDependencies* session_deps) { |
970 net::HttpNetworkSession::Params params = session_deps->CreateSessionParams(); | 940 net::HttpNetworkSession::Params params = session_deps->CreateSessionParams(); |
971 params.client_socket_factory = session_deps->socket_factory.get(); | 941 params.client_socket_factory = session_deps->socket_factory.get(); |
972 HttpNetworkSession* http_session = new HttpNetworkSession(params); | 942 HttpNetworkSession* http_session = new HttpNetworkSession(params); |
(...skipping 15 matching lines...) Expand all Loading... | |
988 } | 958 } |
989 | 959 |
990 net::HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams() { | 960 net::HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams() { |
991 net::HttpNetworkSession::Params params; | 961 net::HttpNetworkSession::Params params; |
992 params.host_resolver = host_resolver.get(); | 962 params.host_resolver = host_resolver.get(); |
993 params.cert_verifier = cert_verifier.get(); | 963 params.cert_verifier = cert_verifier.get(); |
994 params.proxy_service = proxy_service.get(); | 964 params.proxy_service = proxy_service.get(); |
995 params.ssl_config_service = ssl_config_service; | 965 params.ssl_config_service = ssl_config_service; |
996 params.http_auth_handler_factory = http_auth_handler_factory.get(); | 966 params.http_auth_handler_factory = http_auth_handler_factory.get(); |
997 params.http_server_properties = &http_server_properties; | 967 params.http_server_properties = &http_server_properties; |
968 params.enable_spdy_compression = enable_compression; | |
969 params.enable_spdy_ping_based_connection_checking = enable_ping; | |
970 params.spdy_default_protocol = kProtoSPDY3; | |
971 params.spdy_initial_recv_window_size = initial_recv_window_size; | |
972 params.time_func = time_func; | |
998 params.trusted_spdy_proxy = trusted_spdy_proxy; | 973 params.trusted_spdy_proxy = trusted_spdy_proxy; |
999 params.net_log = net_log; | 974 params.net_log = net_log; |
1000 return params; | 975 return params; |
1001 } | 976 } |
1002 | 977 |
1003 SpdyURLRequestContext::SpdyURLRequestContext() | 978 SpdyURLRequestContext::SpdyURLRequestContext() |
1004 : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { | 979 : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { |
1005 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); | 980 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); |
1006 storage_.set_cert_verifier(new MockCertVerifier); | 981 storage_.set_cert_verifier(new MockCertVerifier); |
1007 storage_.set_proxy_service(ProxyService::CreateDirect()); | 982 storage_.set_proxy_service(ProxyService::CreateDirect()); |
1008 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); | 983 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); |
1009 storage_.set_http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault( | 984 storage_.set_http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault( |
1010 host_resolver())); | 985 host_resolver())); |
1011 storage_.set_http_server_properties(new HttpServerPropertiesImpl); | 986 storage_.set_http_server_properties(new HttpServerPropertiesImpl); |
1012 net::HttpNetworkSession::Params params; | 987 net::HttpNetworkSession::Params params; |
1013 params.client_socket_factory = &socket_factory_; | 988 params.client_socket_factory = &socket_factory_; |
1014 params.host_resolver = host_resolver(); | 989 params.host_resolver = host_resolver(); |
1015 params.cert_verifier = cert_verifier(); | 990 params.cert_verifier = cert_verifier(); |
1016 params.proxy_service = proxy_service(); | 991 params.proxy_service = proxy_service(); |
1017 params.ssl_config_service = ssl_config_service(); | 992 params.ssl_config_service = ssl_config_service(); |
1018 params.http_auth_handler_factory = http_auth_handler_factory(); | 993 params.http_auth_handler_factory = http_auth_handler_factory(); |
1019 params.network_delegate = network_delegate(); | 994 params.network_delegate = network_delegate(); |
995 params.enable_spdy_compression = false; | |
996 params.enable_spdy_ping_based_connection_checking = false; | |
997 params.spdy_default_protocol = kProtoSPDY3; | |
1020 params.http_server_properties = http_server_properties(); | 998 params.http_server_properties = http_server_properties(); |
1021 scoped_refptr<HttpNetworkSession> network_session( | 999 scoped_refptr<HttpNetworkSession> network_session( |
1022 new HttpNetworkSession(params)); | 1000 new HttpNetworkSession(params)); |
1023 SpdySessionPoolPeer pool_peer(network_session->spdy_session_pool()); | 1001 SpdySessionPoolPeer pool_peer(network_session->spdy_session_pool()); |
1024 pool_peer.EnableSendingInitialSettings(false); | 1002 pool_peer.EnableSendingInitialSettings(false); |
1025 storage_.set_http_transaction_factory(new HttpCache( | 1003 storage_.set_http_transaction_factory(new HttpCache( |
1026 network_session, | 1004 network_session, |
1027 HttpCache::DefaultBackend::InMemory(0))); | 1005 HttpCache::DefaultBackend::InMemory(0))); |
1028 } | 1006 } |
1029 | 1007 |
(...skipping 10 matching lines...) Expand all Loading... | |
1040 CONTROL_FLAG_FIN, // Control Flags | 1018 CONTROL_FLAG_FIN, // Control Flags |
1041 false, // Compressed | 1019 false, // Compressed |
1042 INVALID, // Status | 1020 INVALID, // Status |
1043 NULL, // Data | 1021 NULL, // Data |
1044 0, // Length | 1022 0, // Length |
1045 DATA_FLAG_NONE // Data Flags | 1023 DATA_FLAG_NONE // Data Flags |
1046 }; | 1024 }; |
1047 return kHeader; | 1025 return kHeader; |
1048 } | 1026 } |
1049 | 1027 |
1050 SpdyTestStateHelper::SpdyTestStateHelper() | |
1051 : ec_signature_creator_factory_(new MockECSignatureCreatorFactory()) { | |
1052 // Use the mock signature creator. | |
1053 crypto::ECSignatureCreator::SetFactoryForTesting( | |
1054 ec_signature_creator_factory_.get()); | |
1055 // Pings can be non-deterministic, because they are sent via timer. | |
1056 SpdySession::set_enable_ping_based_connection_checking(false); | |
1057 // Avoid sending a non-default initial receive window size settings | |
1058 // frame on every test. | |
1059 SpdySession::set_default_initial_recv_window_size( | |
1060 kSpdyStreamInitialWindowSize); | |
1061 // Compression is per-session which makes it impossible to create | |
1062 // SPDY frames with static methods. | |
1063 BufferedSpdyFramer::set_enable_compression_default(false); | |
1064 } | |
1065 | |
1066 SpdyTestStateHelper::~SpdyTestStateHelper() { | |
1067 SpdySession::ResetStaticSettingsToInit(); | |
1068 // TODO(rch): save/restore this value | |
1069 BufferedSpdyFramer::set_enable_compression_default(true); | |
1070 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | |
1071 } | |
1072 | |
1073 } // namespace test_spdy3 | 1028 } // namespace test_spdy3 |
1074 | 1029 |
1075 } // namespace net | 1030 } // namespace net |
OLD | NEW |