Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(682)

Side by Side Diff: net/spdy/spdy_http_stream_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698