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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 383 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
384 http_stream.GetTotalSentBytes()); | 384 http_stream.GetTotalSentBytes()); |
385 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), | 385 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), |
386 http_stream.GetTotalReceivedBytes()); | 386 http_stream.GetTotalReceivedBytes()); |
387 | 387 |
388 // Because the server closed the connection, we there shouldn't be a session | 388 // Because the server closed the connection, we there shouldn't be a session |
389 // in the pool anymore. | 389 // in the pool anymore. |
390 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 390 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
391 } | 391 } |
392 | 392 |
393 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { | |
394 std::unique_ptr<SpdySerializedFrame> req( | |
395 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | |
396 std::unique_ptr<SpdySerializedFrame> chunk1( | |
397 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); | |
398 MockWrite writes[] = { | |
399 CreateMockWrite(*req, 0), // request | |
400 CreateMockWrite(*chunk1, 1), | |
401 //CreateMockWrite(*chunk2, 2), | |
402 // CreateMockWrite(*chunk3, 3), | |
mmenke
2016/06/17 15:30:08
Remove commented out code.
| |
403 }; | |
404 | |
405 std::unique_ptr<SpdySerializedFrame> resp( | |
406 spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | |
407 MockRead reads[] = { | |
408 CreateMockRead(*resp, 2), | |
409 CreateMockRead(*chunk1, 3), | |
410 MockRead(SYNCHRONOUS, 0, 4) // EOF | |
411 }; | |
412 | |
413 HostPortPair host_port_pair("www.example.org", 80); | |
414 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
415 PRIVACY_MODE_DISABLED); | |
416 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
417 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | |
418 | |
419 ChunkedUploadDataStream upload_stream(0); | |
420 upload_stream.AppendData(nullptr, 0, true); | |
421 | |
422 HttpRequestInfo request; | |
423 request.method = "POST"; | |
424 request.url = GURL("http://www.example.org/"); | |
425 request.upload_data_stream = &upload_stream; | |
426 | |
427 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | |
428 | |
429 TestCompletionCallback callback; | |
430 HttpResponseInfo response; | |
431 HttpRequestHeaders headers; | |
432 BoundNetLog net_log; | |
433 SpdyHttpStream http_stream(session_, true); | |
434 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | |
435 net_log, CompletionCallback())); | |
436 EXPECT_EQ(ERR_IO_PENDING, | |
437 http_stream.SendRequest(headers, &response, callback.callback())); | |
438 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | |
439 | |
440 base::RunLoop().RunUntilIdle(); | |
mmenke
2016/06/17 15:30:08
This isn't needed.
| |
441 EXPECT_EQ(OK, callback.WaitForResult()); | |
442 | |
443 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | |
444 http_stream.GetTotalSentBytes()); | |
445 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), | |
446 http_stream.GetTotalReceivedBytes()); | |
447 | |
448 // Because the server closed the connection, we there shouldn't be a session | |
449 // in the pool anymore. | |
mmenke
2016/06/17 15:30:08
remove "we"
| |
450 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | |
451 } | |
452 | |
393 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { | 453 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { |
394 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 454 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
395 | 455 |
396 std::unique_ptr<SpdySerializedFrame> req( | 456 std::unique_ptr<SpdySerializedFrame> req( |
397 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 457 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
398 std::unique_ptr<SpdySerializedFrame> body( | 458 std::unique_ptr<SpdySerializedFrame> body( |
399 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); | 459 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); |
400 MockWrite writes[] = { | 460 MockWrite writes[] = { |
401 CreateMockWrite(*req, 0), // Request | 461 CreateMockWrite(*req, 0), // Request |
402 CreateMockWrite(*body, 1) // First POST upload frame | 462 CreateMockWrite(*body, 1) // First POST upload frame |
(...skipping 27 matching lines...) Expand all Loading... | |
430 HttpRequestHeaders headers; | 490 HttpRequestHeaders headers; |
431 BoundNetLog net_log; | 491 BoundNetLog net_log; |
432 SpdyHttpStream http_stream(session_, true); | 492 SpdyHttpStream http_stream(session_, true); |
433 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 493 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
434 net_log, CompletionCallback())); | 494 net_log, CompletionCallback())); |
435 | 495 |
436 EXPECT_EQ(ERR_IO_PENDING, | 496 EXPECT_EQ(ERR_IO_PENDING, |
437 http_stream.SendRequest(headers, &response, callback.callback())); | 497 http_stream.SendRequest(headers, &response, callback.callback())); |
438 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 498 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
439 | 499 |
440 EXPECT_EQ(OK, callback.WaitForResult()); | 500 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
441 | 501 |
442 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 502 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
443 http_stream.GetTotalSentBytes()); | 503 http_stream.GetTotalSentBytes()); |
444 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 504 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
445 | 505 |
446 // Because the server closed the connection, we there shouldn't be a session | 506 // Because the server closed the connection, we there shouldn't be a session |
447 // in the pool anymore. | 507 // in the pool anymore. |
448 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 508 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
449 | 509 |
450 // Appending a second chunk now should not result in a crash. | 510 // 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; | 573 HttpRequestHeaders headers; |
514 HttpResponseInfo response; | 574 HttpResponseInfo response; |
515 // This will attempt to Write() the initial request and headers, which will | 575 // This will attempt to Write() the initial request and headers, which will |
516 // complete asynchronously. | 576 // complete asynchronously. |
517 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 577 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
518 callback.callback())); | 578 callback.callback())); |
519 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 579 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
520 | 580 |
521 // Complete the initial request write and the first chunk. | 581 // Complete the initial request write and the first chunk. |
522 base::RunLoop().RunUntilIdle(); | 582 base::RunLoop().RunUntilIdle(); |
523 ASSERT_TRUE(callback.have_result()); | 583 ASSERT_FALSE(callback.have_result()); |
524 EXPECT_EQ(OK, callback.WaitForResult()); | |
525 | 584 |
526 // Now append the final two chunks which will enqueue two more writes. | 585 // Now append the final two chunks which will enqueue two more writes. |
527 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); | 586 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); |
528 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 587 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
529 | 588 |
530 // Finish writing all the chunks and do all reads. | 589 // Finish writing all the chunks and do all reads. |
531 base::RunLoop().RunUntilIdle(); | 590 base::RunLoop().RunUntilIdle(); |
591 ASSERT_TRUE(callback.have_result()); | |
592 EXPECT_EQ(OK, callback.WaitForResult()); | |
532 | 593 |
533 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + | 594 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + |
534 chunk3->size()), | 595 chunk3->size()), |
535 http_stream->GetTotalSentBytes()); | 596 http_stream->GetTotalSentBytes()); |
536 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + | 597 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + |
537 chunk2->size() + chunk3->size()), | 598 chunk2->size() + chunk3->size()), |
538 http_stream->GetTotalReceivedBytes()); | 599 http_stream->GetTotalReceivedBytes()); |
539 | 600 |
540 // Check response headers. | 601 // Check response headers. |
541 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 602 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 HttpRequestHeaders headers; | 674 HttpRequestHeaders headers; |
614 HttpResponseInfo response; | 675 HttpResponseInfo response; |
615 // This will attempt to Write() the initial request and headers, which will | 676 // This will attempt to Write() the initial request and headers, which will |
616 // complete asynchronously. | 677 // complete asynchronously. |
617 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 678 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
618 callback.callback())); | 679 callback.callback())); |
619 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 680 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
620 | 681 |
621 // Complete the initial request write and the first chunk. | 682 // Complete the initial request write and the first chunk. |
622 base::RunLoop().RunUntilIdle(); | 683 base::RunLoop().RunUntilIdle(); |
623 ASSERT_TRUE(callback.have_result()); | 684 ASSERT_FALSE(callback.have_result()); |
624 EXPECT_EQ(OK, callback.WaitForResult()); | |
625 | 685 |
626 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 686 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
627 http_stream->GetTotalSentBytes()); | 687 http_stream->GetTotalSentBytes()); |
628 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 688 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
629 | 689 |
630 // Now end the stream with an empty data frame and the FIN set. | 690 // Now end the stream with an empty data frame and the FIN set. |
631 upload_stream.AppendData(NULL, 0, true); | 691 upload_stream.AppendData(NULL, 0, true); |
632 | 692 |
633 // Finish writing the final frame, and perform all reads. | 693 // Finish writing the final frame, and perform all reads. |
634 base::RunLoop().RunUntilIdle(); | 694 base::RunLoop().RunUntilIdle(); |
695 ASSERT_TRUE(callback.have_result()); | |
696 EXPECT_EQ(OK, callback.WaitForResult()); | |
635 | 697 |
636 // Check response headers. | 698 // Check response headers. |
637 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); | 699 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); |
638 | 700 |
639 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), | 701 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), |
640 http_stream->GetTotalSentBytes()); | 702 http_stream->GetTotalSentBytes()); |
641 EXPECT_EQ( | 703 EXPECT_EQ( |
642 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), | 704 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), |
643 http_stream->GetTotalReceivedBytes()); | 705 http_stream->GetTotalReceivedBytes()); |
644 | 706 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 HttpResponseInfo response; | 890 HttpResponseInfo response; |
829 // This will attempt to Write() the initial request and headers, which will | 891 // This will attempt to Write() the initial request and headers, which will |
830 // complete asynchronously. | 892 // complete asynchronously. |
831 TestCompletionCallback callback; | 893 TestCompletionCallback callback; |
832 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 894 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
833 callback.callback())); | 895 callback.callback())); |
834 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 896 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
835 | 897 |
836 // Complete the initial request write and first chunk. | 898 // Complete the initial request write and first chunk. |
837 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
838 ASSERT_TRUE(callback.have_result()); | 900 ASSERT_FALSE(callback.have_result()); |
839 EXPECT_EQ(OK, callback.WaitForResult()); | |
840 | 901 |
841 EXPECT_EQ(static_cast<int64_t>(req->size()), | 902 EXPECT_EQ(static_cast<int64_t>(req->size()), |
842 http_stream->GetTotalSentBytes()); | 903 http_stream->GetTotalSentBytes()); |
843 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 904 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
844 | 905 |
845 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 906 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
846 | 907 |
908 ASSERT_TRUE(callback.have_result()); | |
909 EXPECT_EQ(OK, callback.WaitForResult()); | |
910 | |
847 // Verify that the window size has decreased. | 911 // Verify that the window size has decreased. |
848 ASSERT_TRUE(http_stream->stream() != NULL); | 912 ASSERT_TRUE(http_stream->stream() != NULL); |
849 EXPECT_NE(static_cast<int>( | 913 EXPECT_NE(static_cast<int>( |
850 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), | 914 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), |
851 http_stream->stream()->send_window_size()); | 915 http_stream->stream()->send_window_size()); |
852 | 916 |
853 // Read window update. | 917 // Read window update. |
854 base::RunLoop().RunUntilIdle(); | 918 base::RunLoop().RunUntilIdle(); |
855 | 919 |
856 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 920 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)); | 948 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
885 | 949 |
886 ASSERT_TRUE(response.headers.get()); | 950 ASSERT_TRUE(response.headers.get()); |
887 ASSERT_EQ(200, response.headers->response_code()); | 951 ASSERT_EQ(200, response.headers->response_code()); |
888 } | 952 } |
889 | 953 |
890 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 954 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
891 // methods. | 955 // methods. |
892 | 956 |
893 } // namespace net | 957 } // namespace net |
OLD | NEW |