OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_network_transaction.h" | 5 #include "net/spdy/spdy_network_transaction.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/load_log_unittest.h" | 10 #include "net/base/load_log_unittest.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 &session_deps->socket_factory, | 77 &session_deps->socket_factory, |
78 session_deps->ssl_config_service, | 78 session_deps->ssl_config_service, |
79 session_deps->flip_session_pool); | 79 session_deps->flip_session_pool); |
80 } | 80 } |
81 | 81 |
82 // Chop a frame into an array of MockWrites. | 82 // Chop a frame into an array of MockWrites. |
83 // |data| is the frame to chop. | 83 // |data| is the frame to chop. |
84 // |length| is the length of the frame to chop. | 84 // |length| is the length of the frame to chop. |
85 // |num_chunks| is the number of chunks to create. | 85 // |num_chunks| is the number of chunks to create. |
86 MockWrite* ChopFrame(const char* data, int length, int num_chunks) { | 86 MockWrite* ChopFrame(const char* data, int length, int num_chunks) { |
87 MockWrite* chunks = new MockWrite[num_chunks + 1]; | 87 MockWrite* chunks = new MockWrite[num_chunks]; |
88 int chunk_size = length / num_chunks; | 88 int chunk_size = length / num_chunks; |
89 for (int index = 0; index < num_chunks; index++) { | 89 for (int index = 0; index < num_chunks; index++) { |
90 const char* ptr = data + (index * chunk_size); | 90 const char* ptr = data + (index * chunk_size); |
91 if (index == num_chunks - 1) | 91 if (index == num_chunks - 1) |
92 chunk_size += length % chunk_size; // The last chunk takes the remainder. | 92 chunk_size += length % chunk_size; // The last chunk takes the remainder. |
93 chunks[index] = MockWrite(true, ptr, chunk_size); | 93 chunks[index] = MockWrite(true, ptr, chunk_size); |
94 } | 94 } |
95 chunks[num_chunks] = MockWrite(true, 0, 0); | |
96 return chunks; | 95 return chunks; |
97 } | 96 } |
98 | 97 |
99 // ---------------------------------------------------------------------------- | 98 // ---------------------------------------------------------------------------- |
100 | 99 |
101 static const unsigned char kGetSyn[] = { | 100 static const unsigned char kGetSyn[] = { |
102 0x80, 0x01, 0x00, 0x01, // header | 101 0x80, 0x01, 0x00, 0x01, // header |
103 0x01, 0x00, 0x00, 0x45, // FIN, len | 102 0x01, 0x00, 0x00, 0x45, // FIN, len |
104 0x00, 0x00, 0x00, 0x01, // stream id | 103 0x00, 0x00, 0x00, 0x01, // stream id |
105 0xc0, 0x00, 0x00, 0x03, // 4 headers | 104 0xc0, 0x00, 0x00, 0x03, // 4 headers |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 'h', 'e', 'l', 'l', 'o', '!', // "hello" | 190 'h', 'e', 'l', 'l', 'o', '!', // "hello" |
192 }; | 191 }; |
193 | 192 |
194 } // namespace | 193 } // namespace |
195 | 194 |
196 // A DataProvider where the client must write a request before the reads (e.g. | 195 // A DataProvider where the client must write a request before the reads (e.g. |
197 // the response) will complete. | 196 // the response) will complete. |
198 class DelayedSocketData : public StaticSocketDataProvider, | 197 class DelayedSocketData : public StaticSocketDataProvider, |
199 public base::RefCounted<DelayedSocketData> { | 198 public base::RefCounted<DelayedSocketData> { |
200 public: | 199 public: |
201 // |reads| the list of MockRead completions. | |
202 // |write_delay| the number of MockWrites to complete before allowing | 200 // |write_delay| the number of MockWrites to complete before allowing |
203 // a MockRead to complete. | 201 // a MockRead to complete. |
| 202 // |reads| the list of MockRead completions. |
204 // |writes| the list of MockWrite completions. | 203 // |writes| the list of MockWrite completions. |
205 // Note: All MockReads and MockWrites must be async. | 204 // Note: All MockReads and MockWrites must be async. |
206 // Note: The MockRead and MockWrite lists musts end with a EOF | 205 // Note: The MockRead and MockWrite lists musts end with a EOF |
207 // e.g. a MockRead(true, 0, 0); | 206 // e.g. a MockRead(true, 0, 0); |
208 DelayedSocketData(MockRead* reads, int write_delay, MockWrite* writes) | 207 DelayedSocketData(int write_delay, |
209 : StaticSocketDataProvider(reads, writes), | 208 MockRead* reads, size_t reads_count, |
| 209 MockWrite* writes, size_t writes_count) |
| 210 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), |
210 write_delay_(write_delay), | 211 write_delay_(write_delay), |
211 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { | 212 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { |
212 DCHECK_GE(write_delay_, 0); | 213 DCHECK_GE(write_delay_, 0); |
213 } | 214 } |
214 | 215 |
215 // |connect| the result for the connect phase. | 216 // |connect| the result for the connect phase. |
216 // |reads| the list of MockRead completions. | 217 // |reads| the list of MockRead completions. |
217 // |write_delay| the number of MockWrites to complete before allowing | 218 // |write_delay| the number of MockWrites to complete before allowing |
218 // a MockRead to complete. | 219 // a MockRead to complete. |
219 // |writes| the list of MockWrite completions. | 220 // |writes| the list of MockWrite completions. |
220 // Note: All MockReads and MockWrites must be async. | 221 // Note: All MockReads and MockWrites must be async. |
221 // Note: The MockRead and MockWrite lists musts end with a EOF | 222 // Note: The MockRead and MockWrite lists musts end with a EOF |
222 // e.g. a MockRead(true, 0, 0); | 223 // e.g. a MockRead(true, 0, 0); |
223 DelayedSocketData(const MockConnect& connect, MockRead* reads, | 224 DelayedSocketData(const MockConnect& connect, int write_delay, |
224 int write_delay, MockWrite* writes) | 225 MockRead* reads, size_t reads_count, |
225 : StaticSocketDataProvider(reads, writes), | 226 MockWrite* writes, size_t writes_count) |
| 227 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), |
226 write_delay_(write_delay), | 228 write_delay_(write_delay), |
227 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { | 229 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { |
228 DCHECK_GE(write_delay_, 0); | 230 DCHECK_GE(write_delay_, 0); |
229 set_connect_data(connect); | 231 set_connect_data(connect); |
230 } | 232 } |
231 | 233 |
232 virtual MockRead GetNextRead() { | 234 virtual MockRead GetNextRead() { |
233 if (write_delay_) | 235 if (write_delay_) |
234 return MockRead(true, ERR_IO_PENDING); | 236 return MockRead(true, ERR_IO_PENDING); |
235 return StaticSocketDataProvider::GetNextRead(); | 237 return StaticSocketDataProvider::GetNextRead(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 SessionDependencies session_deps; | 340 SessionDependencies session_deps; |
339 scoped_refptr<HttpNetworkSession> session = | 341 scoped_refptr<HttpNetworkSession> session = |
340 CreateSession(&session_deps); | 342 CreateSession(&session_deps); |
341 scoped_ptr<HttpTransaction> trans(new FlipNetworkTransaction(session)); | 343 scoped_ptr<HttpTransaction> trans(new FlipNetworkTransaction(session)); |
342 } | 344 } |
343 | 345 |
344 TEST_F(FlipNetworkTransactionTest, Get) { | 346 TEST_F(FlipNetworkTransactionTest, Get) { |
345 MockWrite writes[] = { | 347 MockWrite writes[] = { |
346 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 348 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
347 arraysize(kGetSyn)), | 349 arraysize(kGetSyn)), |
348 MockWrite(true, 0, 0) // EOF | |
349 }; | 350 }; |
350 | 351 |
351 MockRead reads[] = { | 352 MockRead reads[] = { |
352 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 353 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
353 arraysize(kGetSynReply)), | 354 arraysize(kGetSynReply)), |
354 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 355 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
355 arraysize(kGetBodyFrame)), | 356 arraysize(kGetBodyFrame)), |
356 MockRead(true, 0, 0) // EOF | 357 MockRead(true, 0, 0) // EOF |
357 }; | 358 }; |
358 | 359 |
359 HttpRequestInfo request; | 360 HttpRequestInfo request; |
360 request.method = "GET"; | 361 request.method = "GET"; |
361 request.url = GURL("http://www.google.com/"); | 362 request.url = GURL("http://www.google.com/"); |
362 request.load_flags = 0; | 363 request.load_flags = 0; |
363 scoped_refptr<DelayedSocketData> data( | 364 scoped_refptr<DelayedSocketData> data( |
364 new DelayedSocketData(reads, 1, writes)); | 365 new DelayedSocketData(1, reads, arraysize(reads), |
| 366 writes, arraysize(writes))); |
365 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 367 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
366 EXPECT_EQ(OK, out.rv); | 368 EXPECT_EQ(OK, out.rv); |
367 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 369 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
368 EXPECT_EQ("hello!", out.response_data); | 370 EXPECT_EQ("hello!", out.response_data); |
369 } | 371 } |
370 | 372 |
371 // Test that a simple POST works. | 373 // Test that a simple POST works. |
372 TEST_F(FlipNetworkTransactionTest, Post) { | 374 TEST_F(FlipNetworkTransactionTest, Post) { |
373 static const char upload[] = { "hello world" }; | 375 static const char upload[] = { "hello world" }; |
374 | 376 |
375 // Setup the request | 377 // Setup the request |
376 HttpRequestInfo request; | 378 HttpRequestInfo request; |
377 request.method = "POST"; | 379 request.method = "POST"; |
378 request.url = GURL("http://www.google.com/"); | 380 request.url = GURL("http://www.google.com/"); |
379 request.upload_data = new UploadData(); | 381 request.upload_data = new UploadData(); |
380 request.upload_data->AppendBytes(upload, sizeof(upload)); | 382 request.upload_data->AppendBytes(upload, sizeof(upload)); |
381 | 383 |
382 MockWrite writes[] = { | 384 MockWrite writes[] = { |
383 MockWrite(true, reinterpret_cast<const char*>(kPostSyn), | 385 MockWrite(true, reinterpret_cast<const char*>(kPostSyn), |
384 arraysize(kPostSyn)), | 386 arraysize(kPostSyn)), |
385 MockWrite(true, reinterpret_cast<const char*>(kPostUploadFrame), | 387 MockWrite(true, reinterpret_cast<const char*>(kPostUploadFrame), |
386 arraysize(kPostUploadFrame)), | 388 arraysize(kPostUploadFrame)), |
387 MockWrite(true, 0, 0) // EOF | |
388 }; | 389 }; |
389 | 390 |
390 MockRead reads[] = { | 391 MockRead reads[] = { |
391 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), | 392 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), |
392 arraysize(kPostSynReply)), | 393 arraysize(kPostSynReply)), |
393 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 394 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
394 arraysize(kPostBodyFrame)), | 395 arraysize(kPostBodyFrame)), |
395 MockRead(true, 0, 0) // EOF | 396 MockRead(true, 0, 0) // EOF |
396 }; | 397 }; |
397 | 398 |
398 scoped_refptr<DelayedSocketData> data( | 399 scoped_refptr<DelayedSocketData> data( |
399 new DelayedSocketData(reads, 2, writes)); | 400 new DelayedSocketData(2, reads, arraysize(reads), |
| 401 writes, arraysize(writes))); |
400 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 402 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
401 EXPECT_EQ(OK, out.rv); | 403 EXPECT_EQ(OK, out.rv); |
402 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 404 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
403 EXPECT_EQ("hello!", out.response_data); | 405 EXPECT_EQ("hello!", out.response_data); |
404 } | 406 } |
405 | 407 |
406 // Test that a simple POST works. | 408 // Test that a simple POST works. |
407 TEST_F(FlipNetworkTransactionTest, EmptyPost) { | 409 TEST_F(FlipNetworkTransactionTest, EmptyPost) { |
408 static const unsigned char kEmptyPostSyn[] = { | 410 static const unsigned char kEmptyPostSyn[] = { |
409 0x80, 0x01, 0x00, 0x01, // header | 411 0x80, 0x01, 0x00, 0x01, // header |
(...skipping 13 matching lines...) Expand all Loading... |
423 // Setup the request | 425 // Setup the request |
424 HttpRequestInfo request; | 426 HttpRequestInfo request; |
425 request.method = "POST"; | 427 request.method = "POST"; |
426 request.url = GURL("http://www.google.com/"); | 428 request.url = GURL("http://www.google.com/"); |
427 // Create an empty UploadData. | 429 // Create an empty UploadData. |
428 request.upload_data = new UploadData(); | 430 request.upload_data = new UploadData(); |
429 | 431 |
430 MockWrite writes[] = { | 432 MockWrite writes[] = { |
431 MockWrite(true, reinterpret_cast<const char*>(kEmptyPostSyn), | 433 MockWrite(true, reinterpret_cast<const char*>(kEmptyPostSyn), |
432 arraysize(kEmptyPostSyn)), | 434 arraysize(kEmptyPostSyn)), |
433 MockWrite(true, 0, 0) // EOF | |
434 }; | 435 }; |
435 | 436 |
436 MockRead reads[] = { | 437 MockRead reads[] = { |
437 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), | 438 MockRead(true, reinterpret_cast<const char*>(kPostSynReply), |
438 arraysize(kPostSynReply)), | 439 arraysize(kPostSynReply)), |
439 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 440 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
440 arraysize(kGetBodyFrame)), | 441 arraysize(kGetBodyFrame)), |
441 MockRead(true, 0, 0) // EOF | 442 MockRead(true, 0, 0) // EOF |
442 }; | 443 }; |
443 | 444 |
444 scoped_refptr<DelayedSocketData> data( | 445 scoped_refptr<DelayedSocketData> data( |
445 new DelayedSocketData(reads, 1, writes)); | 446 new DelayedSocketData(1, reads, arraysize(reads), |
| 447 writes, arraysize(writes))); |
446 | 448 |
447 TransactionHelperResult out = TransactionHelper(request, data, NULL); | 449 TransactionHelperResult out = TransactionHelper(request, data, NULL); |
448 EXPECT_EQ(OK, out.rv); | 450 EXPECT_EQ(OK, out.rv); |
449 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 451 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
450 EXPECT_EQ("hello!", out.response_data); | 452 EXPECT_EQ("hello!", out.response_data); |
451 } | 453 } |
452 | 454 |
453 // Test that the transaction doesn't crash when we don't have a reply. | 455 // Test that the transaction doesn't crash when we don't have a reply. |
454 TEST_F(FlipNetworkTransactionTest, ResponseWithoutSynReply) { | 456 TEST_F(FlipNetworkTransactionTest, ResponseWithoutSynReply) { |
455 MockRead reads[] = { | 457 MockRead reads[] = { |
456 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), | 458 MockRead(true, reinterpret_cast<const char*>(kPostBodyFrame), |
457 arraysize(kPostBodyFrame)), | 459 arraysize(kPostBodyFrame)), |
458 MockRead(true, 0, 0) // EOF | 460 MockRead(true, 0, 0) // EOF |
459 }; | 461 }; |
460 | 462 |
461 HttpRequestInfo request; | 463 HttpRequestInfo request; |
462 request.method = "GET"; | 464 request.method = "GET"; |
463 request.url = GURL("http://www.google.com/"); | 465 request.url = GURL("http://www.google.com/"); |
464 request.load_flags = 0; | 466 request.load_flags = 0; |
465 scoped_refptr<DelayedSocketData> data( | 467 scoped_refptr<DelayedSocketData> data( |
466 new DelayedSocketData(reads, 1, NULL)); | 468 new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); |
467 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 469 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
468 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 470 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
469 } | 471 } |
470 | 472 |
471 TEST_F(FlipNetworkTransactionTest, CancelledTransaction) { | 473 TEST_F(FlipNetworkTransactionTest, CancelledTransaction) { |
472 MockWrite writes[] = { | 474 MockWrite writes[] = { |
473 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 475 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
474 arraysize(kGetSyn)), | 476 arraysize(kGetSyn)), |
475 MockRead(true, 0, 0) // EOF | 477 MockRead(true, 0, 0) // EOF |
476 }; | 478 }; |
(...skipping 13 matching lines...) Expand all Loading... |
490 request.url = GURL("http://www.google.com/"); | 492 request.url = GURL("http://www.google.com/"); |
491 request.load_flags = 0; | 493 request.load_flags = 0; |
492 | 494 |
493 // We disable SSL for this test. | 495 // We disable SSL for this test. |
494 FlipSession::SetSSLMode(false); | 496 FlipSession::SetSSLMode(false); |
495 | 497 |
496 SessionDependencies session_deps; | 498 SessionDependencies session_deps; |
497 scoped_ptr<FlipNetworkTransaction> trans( | 499 scoped_ptr<FlipNetworkTransaction> trans( |
498 new FlipNetworkTransaction(CreateSession(&session_deps))); | 500 new FlipNetworkTransaction(CreateSession(&session_deps))); |
499 | 501 |
500 StaticSocketDataProvider data(reads, writes); | 502 StaticSocketDataProvider data(reads, arraysize(reads), |
| 503 writes, arraysize(writes)); |
501 session_deps.socket_factory.AddSocketDataProvider(&data); | 504 session_deps.socket_factory.AddSocketDataProvider(&data); |
502 | 505 |
503 TestCompletionCallback callback; | 506 TestCompletionCallback callback; |
504 | 507 |
505 int rv = trans->Start(&request, &callback, NULL); | 508 int rv = trans->Start(&request, &callback, NULL); |
506 EXPECT_EQ(ERR_IO_PENDING, rv); | 509 EXPECT_EQ(ERR_IO_PENDING, rv); |
507 trans.reset(); // Cancel the transaction. | 510 trans.reset(); // Cancel the transaction. |
508 | 511 |
509 // Flush the MessageLoop while the SessionDependencies (in particular, the | 512 // Flush the MessageLoop while the SessionDependencies (in particular, the |
510 // MockClientSocketFactory) are still alive. | 513 // MockClientSocketFactory) are still alive. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 "status: 200\n" | 591 "status: 200\n" |
589 "url: /index.php\n" | 592 "url: /index.php\n" |
590 "version: HTTP/1.1\n" | 593 "version: HTTP/1.1\n" |
591 } | 594 } |
592 }; | 595 }; |
593 | 596 |
594 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 597 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
595 MockWrite writes[] = { | 598 MockWrite writes[] = { |
596 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 599 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
597 arraysize(kGetSyn)), | 600 arraysize(kGetSyn)), |
598 MockWrite(true, 0, 0) // EOF | |
599 }; | 601 }; |
600 | 602 |
601 MockRead reads[] = { | 603 MockRead reads[] = { |
602 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), | 604 MockRead(true, reinterpret_cast<const char*>(test_cases[i].syn_reply), |
603 test_cases[i].syn_reply_length), | 605 test_cases[i].syn_reply_length), |
604 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 606 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
605 arraysize(kGetBodyFrame)), | 607 arraysize(kGetBodyFrame)), |
606 MockRead(true, 0, 0) // EOF | 608 MockRead(true, 0, 0) // EOF |
607 }; | 609 }; |
608 | 610 |
609 HttpRequestInfo request; | 611 HttpRequestInfo request; |
610 request.method = "GET"; | 612 request.method = "GET"; |
611 request.url = GURL("http://www.google.com/"); | 613 request.url = GURL("http://www.google.com/"); |
612 request.load_flags = 0; | 614 request.load_flags = 0; |
613 scoped_refptr<DelayedSocketData> data( | 615 scoped_refptr<DelayedSocketData> data( |
614 new DelayedSocketData(reads, 1, writes)); | 616 new DelayedSocketData(1, reads, arraysize(reads), |
| 617 writes, arraysize(writes))); |
615 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 618 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
616 EXPECT_EQ(OK, out.rv); | 619 EXPECT_EQ(OK, out.rv); |
617 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 620 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
618 EXPECT_EQ("hello!", out.response_data); | 621 EXPECT_EQ("hello!", out.response_data); |
619 | 622 |
620 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; | 623 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
621 EXPECT_TRUE(headers.get() != NULL); | 624 EXPECT_TRUE(headers.get() != NULL); |
622 void* iter = NULL; | 625 void* iter = NULL; |
623 std::string name, value, lines; | 626 std::string name, value, lines; |
624 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 627 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 682 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
680 arraysize(kGetBodyFrame)), | 683 arraysize(kGetBodyFrame)), |
681 MockRead(true, 0, 0) // EOF | 684 MockRead(true, 0, 0) // EOF |
682 }; | 685 }; |
683 | 686 |
684 HttpRequestInfo request; | 687 HttpRequestInfo request; |
685 request.method = "GET"; | 688 request.method = "GET"; |
686 request.url = GURL("http://www.google.com/"); | 689 request.url = GURL("http://www.google.com/"); |
687 request.load_flags = 0; | 690 request.load_flags = 0; |
688 scoped_refptr<DelayedSocketData> data( | 691 scoped_refptr<DelayedSocketData> data( |
689 new DelayedSocketData(reads, 1, writes)); | 692 new DelayedSocketData(1, reads, arraysize(reads), |
| 693 writes, arraysize(writes))); |
690 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 694 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
691 EXPECT_EQ(ERR_INVALID_RESPONSE, out.rv); | 695 EXPECT_EQ(ERR_INVALID_RESPONSE, out.rv); |
692 } | 696 } |
693 } | 697 } |
694 | 698 |
695 // Verify that we don't crash on some corrupt frames. | 699 // Verify that we don't crash on some corrupt frames. |
696 TEST_F(FlipNetworkTransactionTest, CorruptFrameSessionError) { | 700 TEST_F(FlipNetworkTransactionTest, CorruptFrameSessionError) { |
697 static const unsigned char kSynReplyMassiveLength[] = { | 701 static const unsigned char kSynReplyMassiveLength[] = { |
698 0x80, 0x01, 0x00, 0x02, | 702 0x80, 0x01, 0x00, 0x02, |
699 0x0f, 0x11, 0x11, 0x26, // This is the length field with a big number | 703 0x0f, 0x11, 0x11, 0x26, // This is the length field with a big number |
(...skipping 25 matching lines...) Expand all Loading... |
725 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 729 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
726 arraysize(kGetBodyFrame)), | 730 arraysize(kGetBodyFrame)), |
727 MockRead(true, 0, 0) // EOF | 731 MockRead(true, 0, 0) // EOF |
728 }; | 732 }; |
729 | 733 |
730 HttpRequestInfo request; | 734 HttpRequestInfo request; |
731 request.method = "GET"; | 735 request.method = "GET"; |
732 request.url = GURL("http://www.google.com/"); | 736 request.url = GURL("http://www.google.com/"); |
733 request.load_flags = 0; | 737 request.load_flags = 0; |
734 scoped_refptr<DelayedSocketData> data( | 738 scoped_refptr<DelayedSocketData> data( |
735 new DelayedSocketData(reads, 1, writes)); | 739 new DelayedSocketData(1, reads, arraysize(reads), |
| 740 writes, arraysize(writes))); |
736 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 741 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
737 EXPECT_EQ(ERR_FLIP_PROTOCOL_ERROR, out.rv); | 742 EXPECT_EQ(ERR_FLIP_PROTOCOL_ERROR, out.rv); |
738 } | 743 } |
739 } | 744 } |
740 | 745 |
741 TEST_F(FlipNetworkTransactionTest, ServerPush) { | 746 TEST_F(FlipNetworkTransactionTest, ServerPush) { |
742 // Reply with the X-Associated-Content header. | 747 // Reply with the X-Associated-Content header. |
743 static const unsigned char syn_reply[] = { | 748 static const unsigned char syn_reply[] = { |
744 0x80, 0x01, 0x00, 0x02, | 749 0x80, 0x01, 0x00, 0x02, |
745 0x00, 0x00, 0x00, 0x71, | 750 0x00, 0x00, 0x00, 0x71, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // Body for stream 2 | 782 // Body for stream 2 |
778 static const unsigned char body_frame_2[] = { | 783 static const unsigned char body_frame_2[] = { |
779 0x00, 0x00, 0x00, 0x02, | 784 0x00, 0x00, 0x00, 0x02, |
780 0x01, 0x00, 0x00, 0x07, | 785 0x01, 0x00, 0x00, 0x07, |
781 'g', 'o', 'o', 'd', 'b', 'y', 'e', | 786 'g', 'o', 'o', 'd', 'b', 'y', 'e', |
782 }; | 787 }; |
783 | 788 |
784 MockWrite writes[] = { | 789 MockWrite writes[] = { |
785 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 790 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
786 arraysize(kGetSyn)), | 791 arraysize(kGetSyn)), |
787 MockWrite(true, 0, 0) // EOF | |
788 }; | 792 }; |
789 | 793 |
790 MockRead reads[] = { | 794 MockRead reads[] = { |
791 MockRead(true, reinterpret_cast<const char*>(syn_reply), | 795 MockRead(true, reinterpret_cast<const char*>(syn_reply), |
792 arraysize(syn_reply)), | 796 arraysize(syn_reply)), |
793 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 797 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
794 arraysize(kGetBodyFrame)), | 798 arraysize(kGetBodyFrame)), |
795 MockRead(true, ERR_IO_PENDING), // Force a pause | 799 MockRead(true, ERR_IO_PENDING), // Force a pause |
796 MockRead(true, reinterpret_cast<const char*>(syn_push), | 800 MockRead(true, reinterpret_cast<const char*>(syn_push), |
797 arraysize(syn_push)), | 801 arraysize(syn_push)), |
(...skipping 16 matching lines...) Expand all Loading... |
814 // deliver the data when the client does make the request. | 818 // deliver the data when the client does make the request. |
815 PUSH_BEFORE_REQUEST, | 819 PUSH_BEFORE_REQUEST, |
816 DONE | 820 DONE |
817 }; | 821 }; |
818 | 822 |
819 for (int test_type = PUSH_AFTER_REQUEST; test_type != DONE; ++test_type) { | 823 for (int test_type = PUSH_AFTER_REQUEST; test_type != DONE; ++test_type) { |
820 // Setup a mock session. | 824 // Setup a mock session. |
821 SessionDependencies session_deps; | 825 SessionDependencies session_deps; |
822 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 826 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
823 scoped_refptr<DelayedSocketData> data( | 827 scoped_refptr<DelayedSocketData> data( |
824 new DelayedSocketData(reads, 1, writes)); | 828 new DelayedSocketData(1, reads, arraysize(reads), |
| 829 writes, arraysize(writes))); |
825 session_deps.socket_factory.AddSocketDataProvider(data.get()); | 830 session_deps.socket_factory.AddSocketDataProvider(data.get()); |
826 | 831 |
827 // Issue the first request | 832 // Issue the first request |
828 { | 833 { |
829 FlipNetworkTransaction trans(session.get()); | 834 FlipNetworkTransaction trans(session.get()); |
830 | 835 |
831 // Issue the first request. | 836 // Issue the first request. |
832 HttpRequestInfo request; | 837 HttpRequestInfo request; |
833 request.method = "GET"; | 838 request.method = "GET"; |
834 request.url = GURL("http://www.google.com/"); | 839 request.url = GURL("http://www.google.com/"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 916 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
912 arraysize(kGetBodyFrame)), | 917 arraysize(kGetBodyFrame)), |
913 MockRead(true, 0, 0) // EOF | 918 MockRead(true, 0, 0) // EOF |
914 }; | 919 }; |
915 | 920 |
916 HttpRequestInfo request; | 921 HttpRequestInfo request; |
917 request.method = "GET"; | 922 request.method = "GET"; |
918 request.url = GURL("http://www.google.com/"); | 923 request.url = GURL("http://www.google.com/"); |
919 request.load_flags = 0; | 924 request.load_flags = 0; |
920 scoped_refptr<DelayedSocketData> data( | 925 scoped_refptr<DelayedSocketData> data( |
921 new DelayedSocketData(reads, 2, writes)); | 926 new DelayedSocketData(2, reads, arraysize(reads), |
| 927 writes, arraysize(writes))); |
922 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 928 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
923 EXPECT_EQ(ERR_FAILED, out.rv); | 929 EXPECT_EQ(ERR_FAILED, out.rv); |
924 data->Reset(); | 930 data->Reset(); |
925 } | 931 } |
926 | 932 |
927 // Test that partial writes work. | 933 // Test that partial writes work. |
928 TEST_F(FlipNetworkTransactionTest, PartialWrite) { | 934 TEST_F(FlipNetworkTransactionTest, PartialWrite) { |
929 // Chop the SYN_STREAM frame into 5 chunks. | 935 // Chop the SYN_STREAM frame into 5 chunks. |
930 const int kChunks = 5; | 936 const int kChunks = 5; |
931 scoped_array<MockWrite> writes(ChopFrame( | 937 scoped_array<MockWrite> writes(ChopFrame( |
932 reinterpret_cast<const char*>(kGetSyn), arraysize(kGetSyn), kChunks)); | 938 reinterpret_cast<const char*>(kGetSyn), arraysize(kGetSyn), kChunks)); |
933 | 939 |
934 MockRead reads[] = { | 940 MockRead reads[] = { |
935 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 941 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
936 arraysize(kGetSynReply)), | 942 arraysize(kGetSynReply)), |
937 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 943 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
938 arraysize(kGetBodyFrame)), | 944 arraysize(kGetBodyFrame)), |
939 MockRead(true, 0, 0) // EOF | 945 MockRead(true, 0, 0) // EOF |
940 }; | 946 }; |
941 | 947 |
942 HttpRequestInfo request; | 948 HttpRequestInfo request; |
943 request.method = "GET"; | 949 request.method = "GET"; |
944 request.url = GURL("http://www.google.com/"); | 950 request.url = GURL("http://www.google.com/"); |
945 request.load_flags = 0; | 951 request.load_flags = 0; |
946 scoped_refptr<DelayedSocketData> data( | 952 scoped_refptr<DelayedSocketData> data( |
947 new DelayedSocketData(reads, kChunks, writes.get())); | 953 new DelayedSocketData(kChunks, reads, arraysize(reads), |
| 954 writes.get(), kChunks)); |
948 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 955 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
949 EXPECT_EQ(OK, out.rv); | 956 EXPECT_EQ(OK, out.rv); |
950 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 957 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
951 EXPECT_EQ("hello!", out.response_data); | 958 EXPECT_EQ("hello!", out.response_data); |
952 } | 959 } |
953 | 960 |
954 TEST_F(FlipNetworkTransactionTest, DISABLED_ConnectFailure) { | 961 TEST_F(FlipNetworkTransactionTest, DISABLED_ConnectFailure) { |
955 MockConnect connects[] = { | 962 MockConnect connects[] = { |
956 MockConnect(true, ERR_NAME_NOT_RESOLVED), | 963 MockConnect(true, ERR_NAME_NOT_RESOLVED), |
957 MockConnect(false, ERR_NAME_NOT_RESOLVED), | 964 MockConnect(false, ERR_NAME_NOT_RESOLVED), |
(...skipping 14 matching lines...) Expand all Loading... |
972 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 979 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
973 arraysize(kGetBodyFrame)), | 980 arraysize(kGetBodyFrame)), |
974 MockRead(true, 0, 0) // EOF | 981 MockRead(true, 0, 0) // EOF |
975 }; | 982 }; |
976 | 983 |
977 HttpRequestInfo request; | 984 HttpRequestInfo request; |
978 request.method = "GET"; | 985 request.method = "GET"; |
979 request.url = GURL("http://www.google.com/"); | 986 request.url = GURL("http://www.google.com/"); |
980 request.load_flags = 0; | 987 request.load_flags = 0; |
981 scoped_refptr<DelayedSocketData> data( | 988 scoped_refptr<DelayedSocketData> data( |
982 new DelayedSocketData(connects[index], reads, 1, writes)); | 989 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), |
| 990 writes, arraysize(writes))); |
983 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 991 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
984 EXPECT_EQ(connects[index].result, out.rv); | 992 EXPECT_EQ(connects[index].result, out.rv); |
985 } | 993 } |
986 } | 994 } |
987 | 995 |
988 // In this test, we enable compression, but get a uncompressed SynReply from | 996 // In this test, we enable compression, but get a uncompressed SynReply from |
989 // the server. Verify that teardown is all clean. | 997 // the server. Verify that teardown is all clean. |
990 TEST_F(FlipNetworkTransactionTest, DecompressFailureOnSynReply) { | 998 TEST_F(FlipNetworkTransactionTest, DecompressFailureOnSynReply) { |
991 MockWrite writes[] = { | 999 MockWrite writes[] = { |
992 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), | 1000 MockWrite(true, reinterpret_cast<const char*>(kGetSynCompressed), |
(...skipping 10 matching lines...) Expand all Loading... |
1003 }; | 1011 }; |
1004 | 1012 |
1005 // For this test, we turn on the normal compression. | 1013 // For this test, we turn on the normal compression. |
1006 EnableCompression(true); | 1014 EnableCompression(true); |
1007 | 1015 |
1008 HttpRequestInfo request; | 1016 HttpRequestInfo request; |
1009 request.method = "GET"; | 1017 request.method = "GET"; |
1010 request.url = GURL("http://www.google.com/"); | 1018 request.url = GURL("http://www.google.com/"); |
1011 request.load_flags = 0; | 1019 request.load_flags = 0; |
1012 scoped_refptr<DelayedSocketData> data( | 1020 scoped_refptr<DelayedSocketData> data( |
1013 new DelayedSocketData(reads, 1, writes)); | 1021 new DelayedSocketData(1, reads, arraysize(reads), |
| 1022 writes, arraysize(writes))); |
1014 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); | 1023 TransactionHelperResult out = TransactionHelper(request, data.get(), NULL); |
1015 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); | 1024 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); |
1016 data->Reset(); | 1025 data->Reset(); |
1017 | 1026 |
1018 EnableCompression(false); | 1027 EnableCompression(false); |
1019 } | 1028 } |
1020 | 1029 |
1021 // Test that the LoadLog contains good data for a simple GET request. | 1030 // Test that the LoadLog contains good data for a simple GET request. |
1022 TEST_F(FlipNetworkTransactionTest, LoadLog) { | 1031 TEST_F(FlipNetworkTransactionTest, LoadLog) { |
1023 MockWrite writes[] = { | 1032 MockWrite writes[] = { |
1024 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), | 1033 MockWrite(true, reinterpret_cast<const char*>(kGetSyn), |
1025 arraysize(kGetSyn)), | 1034 arraysize(kGetSyn)), |
1026 MockWrite(true, 0, 0) // EOF | |
1027 }; | 1035 }; |
1028 | 1036 |
1029 MockRead reads[] = { | 1037 MockRead reads[] = { |
1030 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), | 1038 MockRead(true, reinterpret_cast<const char*>(kGetSynReply), |
1031 arraysize(kGetSynReply)), | 1039 arraysize(kGetSynReply)), |
1032 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), | 1040 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame), |
1033 arraysize(kGetBodyFrame)), | 1041 arraysize(kGetBodyFrame)), |
1034 MockRead(true, 0, 0) // EOF | 1042 MockRead(true, 0, 0) // EOF |
1035 }; | 1043 }; |
1036 | 1044 |
1037 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); | 1045 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); |
1038 | 1046 |
1039 HttpRequestInfo request; | 1047 HttpRequestInfo request; |
1040 request.method = "GET"; | 1048 request.method = "GET"; |
1041 request.url = GURL("http://www.google.com/"); | 1049 request.url = GURL("http://www.google.com/"); |
1042 request.load_flags = 0; | 1050 request.load_flags = 0; |
1043 scoped_refptr<DelayedSocketData> data( | 1051 scoped_refptr<DelayedSocketData> data( |
1044 new DelayedSocketData(reads, 1, writes)); | 1052 new DelayedSocketData(1, reads, arraysize(reads), |
| 1053 writes, arraysize(writes))); |
1045 TransactionHelperResult out = TransactionHelper(request, data.get(), | 1054 TransactionHelperResult out = TransactionHelper(request, data.get(), |
1046 log); | 1055 log); |
1047 EXPECT_EQ(OK, out.rv); | 1056 EXPECT_EQ(OK, out.rv); |
1048 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1057 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
1049 EXPECT_EQ("hello!", out.response_data); | 1058 EXPECT_EQ("hello!", out.response_data); |
1050 | 1059 |
1051 // Check that the LoadLog was filled reasonably. | 1060 // Check that the LoadLog was filled reasonably. |
1052 // This test is intentionally non-specific about the exact ordering of | 1061 // This test is intentionally non-specific about the exact ordering of |
1053 // the log; instead we just check to make sure that certain events exist. | 1062 // the log; instead we just check to make sure that certain events exist. |
1054 EXPECT_LT(0u, log->entries().size()); | 1063 EXPECT_LT(0u, log->entries().size()); |
(...skipping 20 matching lines...) Expand all Loading... |
1075 net::LoadLog::PHASE_END); | 1084 net::LoadLog::PHASE_END); |
1076 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1085 pos = net::ExpectLogContainsSomewhere(log, pos + 1, |
1077 net::LoadLog::TYPE_FLIP_TRANSACTION_READ_BODY, | 1086 net::LoadLog::TYPE_FLIP_TRANSACTION_READ_BODY, |
1078 net::LoadLog::PHASE_BEGIN); | 1087 net::LoadLog::PHASE_BEGIN); |
1079 pos = net::ExpectLogContainsSomewhere(log, pos + 1, | 1088 pos = net::ExpectLogContainsSomewhere(log, pos + 1, |
1080 net::LoadLog::TYPE_FLIP_TRANSACTION_READ_BODY, | 1089 net::LoadLog::TYPE_FLIP_TRANSACTION_READ_BODY, |
1081 net::LoadLog::PHASE_END); | 1090 net::LoadLog::PHASE_END); |
1082 } | 1091 } |
1083 | 1092 |
1084 } // namespace net | 1093 } // namespace net |
OLD | NEW |