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

Side by Side Diff: net/quic/quic_spdy_stream_test.cc

Issue 1983183002: Landing Recent QUIC changes until 5/14/2016 02:25:25 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "first try to fix link error for win_clang build" Created 4 years, 7 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/quic/quic_session_test.cc ('k') | net/quic/quic_stream_sequencer.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/quic/quic_spdy_stream.h" 5 #include "net/quic/quic_spdy_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/quic/quic_connection.h" 10 #include "net/quic/quic_connection.h"
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( 436 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset(
437 stream_->flow_controller())); 437 stream_->flow_controller()));
438 438
439 // Try to send more data than the flow control limit allows. 439 // Try to send more data than the flow control limit allows.
440 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); 440 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
441 string body; 441 string body;
442 const uint64_t kOverflow = 15; 442 const uint64_t kOverflow = 15;
443 GenerateBody(&body, kWindow + kOverflow); 443 GenerateBody(&body, kWindow + kOverflow);
444 444
445 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); 445 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1));
446 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _)) 446 EXPECT_CALL(*session_, WritevData(stream_, kClientDataStreamId1, _, _, _, _))
447 .WillOnce(Return(QuicConsumedData(kWindow, true))); 447 .WillOnce(Return(QuicConsumedData(kWindow, true)));
448 stream_->WriteOrBufferData(body, false, nullptr); 448 stream_->WriteOrBufferData(body, false, nullptr);
449 449
450 // Should have sent as much as possible, resulting in no send window left. 450 // Should have sent as much as possible, resulting in no send window left.
451 EXPECT_EQ(0u, 451 EXPECT_EQ(0u,
452 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); 452 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller()));
453 453
454 // And we should have queued the overflowed data. 454 // And we should have queued the overflowed data.
455 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); 455 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_));
456 } 456 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // Set a flow control limit of zero. 682 // Set a flow control limit of zero.
683 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0); 683 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0);
684 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset( 684 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset(
685 stream_->flow_controller())); 685 stream_->flow_controller()));
686 686
687 // Send a frame with a FIN but no data. This should not be blocked. 687 // Send a frame with a FIN but no data. This should not be blocked.
688 string body = ""; 688 string body = "";
689 bool fin = true; 689 bool fin = true;
690 690
691 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); 691 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0);
692 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _)) 692 EXPECT_CALL(*session_, WritevData(stream_, kClientDataStreamId1, _, _, _, _))
693 .WillOnce(Return(QuicConsumedData(0, fin))); 693 .WillOnce(Return(QuicConsumedData(0, fin)));
694 694
695 stream_->WriteOrBufferData(body, fin, nullptr); 695 stream_->WriteOrBufferData(body, fin, nullptr);
696 } 696 }
697 697
698 TEST_P(QuicSpdyStreamTest, ReceivingTrailers) { 698 TEST_P(QuicSpdyStreamTest, ReceivingTrailers) {
699 // Test that receiving trailing headers from the peer works, and can be read 699 // Test that receiving trailing headers from the peer works, and can be read
700 // from the stream and consumed. 700 // from the stream and consumed.
701 Initialize(kShouldProcessData); 701 Initialize(kShouldProcessData);
702 702
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, kBody); 873 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, kBody);
874 stream_->OnStreamFrame(frame); 874 stream_->OnStreamFrame(frame);
875 875
876 EXPECT_TRUE(stream_->IsDoneReading()); 876 EXPECT_TRUE(stream_->IsDoneReading());
877 } 877 }
878 878
879 TEST_P(QuicSpdyStreamTest, WritingTrailersSendsAFin) { 879 TEST_P(QuicSpdyStreamTest, WritingTrailersSendsAFin) {
880 // Test that writing trailers will send a FIN, as Trailers are the last thing 880 // Test that writing trailers will send a FIN, as Trailers are the last thing
881 // to be sent on a stream. 881 // to be sent on a stream.
882 Initialize(kShouldProcessData); 882 Initialize(kShouldProcessData);
883 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 883 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
884 .Times(AnyNumber()) 884 .Times(AnyNumber())
885 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 885 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
886 886
887 // Write the initial headers, without a FIN. 887 // Write the initial headers, without a FIN.
888 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 888 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
889 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 889 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
890 890
891 // Writing trailers implicitly sends a FIN. 891 // Writing trailers implicitly sends a FIN.
892 SpdyHeaderBlock trailers; 892 SpdyHeaderBlock trailers;
893 trailers["trailer key"] = "trailer value"; 893 trailers["trailer key"] = "trailer value";
894 EXPECT_CALL(*session_, WriteHeaders(_, _, 894 EXPECT_CALL(*session_, WriteHeaders(_, _,
895 /*fin=*/true, _, _)); 895 /*fin=*/true, _, _));
896 stream_->WriteTrailers(trailers, nullptr); 896 stream_->WriteTrailers(trailers, nullptr);
897 EXPECT_TRUE(stream_->fin_sent()); 897 EXPECT_TRUE(stream_->fin_sent());
898 } 898 }
899 899
900 TEST_P(QuicSpdyStreamTest, WritingTrailersFinalOffset) { 900 TEST_P(QuicSpdyStreamTest, WritingTrailersFinalOffset) {
901 // Test that when writing trailers, the trailers that are actually sent to the 901 // Test that when writing trailers, the trailers that are actually sent to the
902 // peer contain the final offset field indicating last byte of data. 902 // peer contain the final offset field indicating last byte of data.
903 Initialize(kShouldProcessData); 903 Initialize(kShouldProcessData);
904 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 904 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
905 .Times(AnyNumber()) 905 .Times(AnyNumber())
906 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 906 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
907 907
908 // Write the initial headers. 908 // Write the initial headers.
909 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 909 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
910 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 910 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
911 911
912 // Write non-zero body data to force a non-zero final offset. 912 // Write non-zero body data to force a non-zero final offset.
913 const int kBodySize = 1 * 1024; // 1 MB 913 const int kBodySize = 1 * 1024; // 1 MB
914 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); 914 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr);
915 915
916 // The final offset field in the trailing headers is populated with the 916 // The final offset field in the trailing headers is populated with the
917 // number of body bytes written (including queued bytes). 917 // number of body bytes written (including queued bytes).
918 SpdyHeaderBlock trailers; 918 SpdyHeaderBlock trailers;
919 trailers["trailer key"] = "trailer value"; 919 trailers["trailer key"] = "trailer value";
920 SpdyHeaderBlock trailers_with_offset = trailers; 920 SpdyHeaderBlock trailers_with_offset = trailers;
921 trailers_with_offset[kFinalOffsetHeaderKey] = base::IntToString(kBodySize); 921 trailers_with_offset[kFinalOffsetHeaderKey] = base::IntToString(kBodySize);
922 EXPECT_CALL(*session_, WriteHeaders(_, testing::Eq(trailers_with_offset), 922 EXPECT_CALL(*session_, WriteHeaders(_, testing::Eq(trailers_with_offset),
923 /*fin=*/true, _, _)); 923 /*fin=*/true, _, _));
924 stream_->WriteTrailers(trailers, nullptr); 924 stream_->WriteTrailers(trailers, nullptr);
925 } 925 }
926 926
927 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) { 927 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) {
928 // Test that if trailers are written after all other data has been written 928 // Test that if trailers are written after all other data has been written
929 // (headers and body), that this closes the stream for writing. 929 // (headers and body), that this closes the stream for writing.
930 Initialize(kShouldProcessData); 930 Initialize(kShouldProcessData);
931 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 931 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
932 .Times(AnyNumber()) 932 .Times(AnyNumber())
933 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 933 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
934 934
935 // Write the initial headers. 935 // Write the initial headers.
936 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 936 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
937 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 937 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
938 938
939 // Write non-zero body data. 939 // Write non-zero body data.
940 const int kBodySize = 1 * 1024; // 1 MB 940 const int kBodySize = 1 * 1024; // 1 MB
941 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); 941 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr);
942 EXPECT_EQ(0u, stream_->queued_data_bytes()); 942 EXPECT_EQ(0u, stream_->queued_data_bytes());
943 943
944 // Headers and body have been fully written, there is no queued data. Writing 944 // Headers and body have been fully written, there is no queued data. Writing
945 // trailers marks the end of this stream, and thus the write side is closed. 945 // trailers marks the end of this stream, and thus the write side is closed.
946 EXPECT_CALL(*session_, WriteHeaders(_, _, 946 EXPECT_CALL(*session_, WriteHeaders(_, _,
947 /*fin=*/true, _, _)); 947 /*fin=*/true, _, _));
948 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr); 948 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr);
949 EXPECT_TRUE(stream_->write_side_closed()); 949 EXPECT_TRUE(stream_->write_side_closed());
950 } 950 }
951 951
952 TEST_P(QuicSpdyStreamTest, WritingTrailersWithQueuedBytes) { 952 TEST_P(QuicSpdyStreamTest, WritingTrailersWithQueuedBytes) {
953 // Test that the stream is not closed for writing when trailers are sent 953 // Test that the stream is not closed for writing when trailers are sent
954 // while there are still body bytes queued. 954 // while there are still body bytes queued.
955 Initialize(kShouldProcessData); 955 Initialize(kShouldProcessData);
956 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 956 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
957 .Times(AnyNumber()) 957 .Times(AnyNumber())
958 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 958 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
959 959
960 // Write the initial headers. 960 // Write the initial headers.
961 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 961 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
962 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 962 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
963 963
964 // Write non-zero body data, but only consume partially, ensuring queueing. 964 // Write non-zero body data, but only consume partially, ensuring queueing.
965 const int kBodySize = 1 * 1024; // 1 MB 965 const int kBodySize = 1 * 1024; // 1 MB
966 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 966 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
967 .WillOnce(Return(QuicConsumedData(kBodySize - 1, false))); 967 .WillOnce(Return(QuicConsumedData(kBodySize - 1, false)));
968 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); 968 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr);
969 EXPECT_EQ(1u, stream_->queued_data_bytes()); 969 EXPECT_EQ(1u, stream_->queued_data_bytes());
970 970
971 // Writing trailers will send a FIN, but not close the write side of the 971 // Writing trailers will send a FIN, but not close the write side of the
972 // stream as there are queued bytes. 972 // stream as there are queued bytes.
973 EXPECT_CALL(*session_, WriteHeaders(_, _, 973 EXPECT_CALL(*session_, WriteHeaders(_, _,
974 /*fin=*/true, _, _)); 974 /*fin=*/true, _, _));
975 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr); 975 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr);
976 EXPECT_TRUE(stream_->fin_sent()); 976 EXPECT_TRUE(stream_->fin_sent());
977 EXPECT_FALSE(stream_->write_side_closed()); 977 EXPECT_FALSE(stream_->write_side_closed());
978 } 978 }
979 979
980 TEST_P(QuicSpdyStreamTest, WritingTrailersAfterFIN) { 980 TEST_P(QuicSpdyStreamTest, WritingTrailersAfterFIN) {
981 // Test that it is not possible to write Trailers after a FIN has been sent. 981 // Test that it is not possible to write Trailers after a FIN has been sent.
982 Initialize(kShouldProcessData); 982 Initialize(kShouldProcessData);
983 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 983 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
984 .Times(AnyNumber()) 984 .Times(AnyNumber())
985 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 985 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
986 986
987 // Write the initial headers, with a FIN. 987 // Write the initial headers, with a FIN.
988 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 988 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
989 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/true, nullptr); 989 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/true, nullptr);
990 EXPECT_TRUE(stream_->fin_sent()); 990 EXPECT_TRUE(stream_->fin_sent());
991 991
992 // Writing Trailers should fail, as the FIN has already been sent. 992 // Writing Trailers should fail, as the FIN has already been sent.
993 // populated with the number of body bytes written. 993 // populated with the number of body bytes written.
994 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), 994 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr),
995 "Trailers cannot be sent after a FIN"); 995 "Trailers cannot be sent after a FIN");
996 } 996 }
997 997
998 } // namespace 998 } // namespace
999 } // namespace test 999 } // namespace test
1000 } // namespace net 1000 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_session_test.cc ('k') | net/quic/quic_stream_sequencer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698