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_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 HttpRequestHeaders headers; | 430 HttpRequestHeaders headers; |
431 BoundNetLog net_log; | 431 BoundNetLog net_log; |
432 SpdyHttpStream http_stream(session_, true); | 432 SpdyHttpStream http_stream(session_, true); |
433 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 433 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
434 net_log, CompletionCallback())); | 434 net_log, CompletionCallback())); |
435 | 435 |
436 EXPECT_EQ(ERR_IO_PENDING, | 436 EXPECT_EQ(ERR_IO_PENDING, |
437 http_stream.SendRequest(headers, &response, callback.callback())); | 437 http_stream.SendRequest(headers, &response, callback.callback())); |
438 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 438 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
439 | 439 |
440 EXPECT_EQ(OK, callback.WaitForResult()); | 440 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
441 | 441 |
442 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 442 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
443 http_stream.GetTotalSentBytes()); | 443 http_stream.GetTotalSentBytes()); |
444 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 444 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
445 | 445 |
446 // Because the server closed the connection, we there shouldn't be a session | 446 // Because the server closed the connection, we there shouldn't be a session |
447 // in the pool anymore. | 447 // in the pool anymore. |
448 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 448 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
449 | 449 |
450 // Appending a second chunk now should not result in a crash. | 450 // Appending a second chunk now should not result in a crash. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 HttpRequestHeaders headers; | 513 HttpRequestHeaders headers; |
514 HttpResponseInfo response; | 514 HttpResponseInfo response; |
515 // This will attempt to Write() the initial request and headers, which will | 515 // This will attempt to Write() the initial request and headers, which will |
516 // complete asynchronously. | 516 // complete asynchronously. |
517 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 517 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
518 callback.callback())); | 518 callback.callback())); |
519 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 519 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
520 | 520 |
521 // Complete the initial request write and the first chunk. | 521 // Complete the initial request write and the first chunk. |
522 base::RunLoop().RunUntilIdle(); | 522 base::RunLoop().RunUntilIdle(); |
523 ASSERT_TRUE(callback.have_result()); | 523 ASSERT_FALSE(callback.have_result()); |
524 EXPECT_EQ(OK, callback.WaitForResult()); | |
525 | 524 |
526 // Now append the final two chunks which will enqueue two more writes. | 525 // Now append the final two chunks which will enqueue two more writes. |
527 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); | 526 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); |
528 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 527 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
529 | 528 |
530 // Finish writing all the chunks and do all reads. | 529 // Finish writing all the chunks and do all reads. |
531 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 531 ASSERT_TRUE(callback.have_result()); |
| 532 EXPECT_EQ(OK, callback.WaitForResult()); |
532 | 533 |
533 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + | 534 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + |
534 chunk3->size()), | 535 chunk3->size()), |
535 http_stream->GetTotalSentBytes()); | 536 http_stream->GetTotalSentBytes()); |
536 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + | 537 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + |
537 chunk2->size() + chunk3->size()), | 538 chunk2->size() + chunk3->size()), |
538 http_stream->GetTotalReceivedBytes()); | 539 http_stream->GetTotalReceivedBytes()); |
539 | 540 |
540 // Check response headers. | 541 // Check response headers. |
541 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 542 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 HttpRequestHeaders headers; | 614 HttpRequestHeaders headers; |
614 HttpResponseInfo response; | 615 HttpResponseInfo response; |
615 // This will attempt to Write() the initial request and headers, which will | 616 // This will attempt to Write() the initial request and headers, which will |
616 // complete asynchronously. | 617 // complete asynchronously. |
617 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 618 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
618 callback.callback())); | 619 callback.callback())); |
619 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 620 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
620 | 621 |
621 // Complete the initial request write and the first chunk. | 622 // Complete the initial request write and the first chunk. |
622 base::RunLoop().RunUntilIdle(); | 623 base::RunLoop().RunUntilIdle(); |
623 ASSERT_TRUE(callback.have_result()); | 624 ASSERT_FALSE(callback.have_result()); |
624 EXPECT_EQ(OK, callback.WaitForResult()); | |
625 | 625 |
626 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 626 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
627 http_stream->GetTotalSentBytes()); | 627 http_stream->GetTotalSentBytes()); |
628 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 628 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
629 | 629 |
630 // Now end the stream with an empty data frame and the FIN set. | 630 // Now end the stream with an empty data frame and the FIN set. |
631 upload_stream.AppendData(NULL, 0, true); | 631 upload_stream.AppendData(NULL, 0, true); |
632 | 632 |
633 // Finish writing the final frame, and perform all reads. | 633 // Finish writing the final frame, and perform all reads. |
634 base::RunLoop().RunUntilIdle(); | 634 base::RunLoop().RunUntilIdle(); |
| 635 ASSERT_TRUE(callback.have_result()); |
| 636 EXPECT_EQ(OK, callback.WaitForResult()); |
635 | 637 |
636 // Check response headers. | 638 // Check response headers. |
637 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 639 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
638 | 640 |
639 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), | 641 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), |
640 http_stream->GetTotalSentBytes()); | 642 http_stream->GetTotalSentBytes()); |
641 EXPECT_EQ( | 643 EXPECT_EQ( |
642 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), | 644 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), |
643 http_stream->GetTotalReceivedBytes()); | 645 http_stream->GetTotalReceivedBytes()); |
644 | 646 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 HttpResponseInfo response; | 830 HttpResponseInfo response; |
829 // This will attempt to Write() the initial request and headers, which will | 831 // This will attempt to Write() the initial request and headers, which will |
830 // complete asynchronously. | 832 // complete asynchronously. |
831 TestCompletionCallback callback; | 833 TestCompletionCallback callback; |
832 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 834 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
833 callback.callback())); | 835 callback.callback())); |
834 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 836 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
835 | 837 |
836 // Complete the initial request write and first chunk. | 838 // Complete the initial request write and first chunk. |
837 base::RunLoop().RunUntilIdle(); | 839 base::RunLoop().RunUntilIdle(); |
838 ASSERT_TRUE(callback.have_result()); | 840 ASSERT_FALSE(callback.have_result()); |
839 EXPECT_EQ(OK, callback.WaitForResult()); | |
840 | 841 |
841 EXPECT_EQ(static_cast<int64_t>(req->size()), | 842 EXPECT_EQ(static_cast<int64_t>(req->size()), |
842 http_stream->GetTotalSentBytes()); | 843 http_stream->GetTotalSentBytes()); |
843 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 844 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
844 | 845 |
845 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 846 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
846 | 847 |
| 848 ASSERT_TRUE(callback.have_result()); |
| 849 EXPECT_EQ(OK, callback.WaitForResult()); |
| 850 |
847 // Verify that the window size has decreased. | 851 // Verify that the window size has decreased. |
848 ASSERT_TRUE(http_stream->stream() != NULL); | 852 ASSERT_TRUE(http_stream->stream() != NULL); |
849 EXPECT_NE(static_cast<int>( | 853 EXPECT_NE(static_cast<int>( |
850 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 854 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
851 http_stream->stream()->send_window_size()); | 855 http_stream->stream()->send_window_size()); |
852 | 856 |
853 // Read window update. | 857 // Read window update. |
854 base::RunLoop().RunUntilIdle(); | 858 base::RunLoop().RunUntilIdle(); |
855 | 859 |
856 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 860 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
(...skipping 27 matching lines...) Expand all Loading... |
884 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 888 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
885 | 889 |
886 ASSERT_TRUE(response.headers.get()); | 890 ASSERT_TRUE(response.headers.get()); |
887 ASSERT_EQ(200, response.headers->response_code()); | 891 ASSERT_EQ(200, response.headers->response_code()); |
888 } | 892 } |
889 | 893 |
890 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 894 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
891 // methods. | 895 // methods. |
892 | 896 |
893 } // namespace net | 897 } // namespace net |
OLD | NEW |