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

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

Issue 2093553004: Reduce SpdyHeaderBlock copies with move semantics in shared code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove non-shared files (into a separate CL). 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/quic/quic_spdy_stream.cc ('k') | net/tools/quic/quic_simple_server_stream.h » ('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 #include <utility>
8 9
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "net/quic/quic_connection.h" 11 #include "net/quic/quic_connection.h"
11 #include "net/quic/quic_utils.h" 12 #include "net/quic/quic_utils.h"
12 #include "net/quic/quic_write_blocked_list.h" 13 #include "net/quic/quic_write_blocked_list.h"
13 #include "net/quic/spdy_utils.h" 14 #include "net/quic/spdy_utils.h"
14 #include "net/quic/test_tools/quic_flow_controller_peer.h" 15 #include "net/quic/test_tools/quic_flow_controller_peer.h"
15 #include "net/quic/test_tools/quic_session_peer.h" 16 #include "net/quic/test_tools/quic_session_peer.h"
16 #include "net/quic/test_tools/quic_test_utils.h" 17 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "net/quic/test_tools/reliable_quic_stream_peer.h" 18 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 888
888 // Write the initial headers, without a FIN. 889 // Write the initial headers, without a FIN.
889 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 890 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
890 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 891 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
891 892
892 // Writing trailers implicitly sends a FIN. 893 // Writing trailers implicitly sends a FIN.
893 SpdyHeaderBlock trailers; 894 SpdyHeaderBlock trailers;
894 trailers["trailer key"] = "trailer value"; 895 trailers["trailer key"] = "trailer value";
895 EXPECT_CALL(*session_, WriteHeaders(_, _, 896 EXPECT_CALL(*session_, WriteHeaders(_, _,
896 /*fin=*/true, _, _)); 897 /*fin=*/true, _, _));
897 stream_->WriteTrailers(trailers, nullptr); 898 stream_->WriteTrailers(std::move(trailers), nullptr);
898 EXPECT_TRUE(stream_->fin_sent()); 899 EXPECT_TRUE(stream_->fin_sent());
899 } 900 }
900 901
901 TEST_P(QuicSpdyStreamTest, WritingTrailersFinalOffset) { 902 TEST_P(QuicSpdyStreamTest, WritingTrailersFinalOffset) {
902 // Test that when writing trailers, the trailers that are actually sent to the 903 // Test that when writing trailers, the trailers that are actually sent to the
903 // peer contain the final offset field indicating last byte of data. 904 // peer contain the final offset field indicating last byte of data.
904 Initialize(kShouldProcessData); 905 Initialize(kShouldProcessData);
905 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 906 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
906 .Times(AnyNumber()) 907 .Times(AnyNumber())
907 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 908 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
908 909
909 // Write the initial headers. 910 // Write the initial headers.
910 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _)); 911 EXPECT_CALL(*session_, WriteHeaders(_, _, _, _, _));
911 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); 912 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr);
912 913
913 // Write non-zero body data to force a non-zero final offset. 914 // Write non-zero body data to force a non-zero final offset.
914 const int kBodySize = 1 * 1024; // 1 MB 915 const int kBodySize = 1 * 1024; // 1 MB
915 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); 916 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr);
916 917
917 // The final offset field in the trailing headers is populated with the 918 // The final offset field in the trailing headers is populated with the
918 // number of body bytes written (including queued bytes). 919 // number of body bytes written (including queued bytes).
919 SpdyHeaderBlock trailers; 920 SpdyHeaderBlock trailers;
920 trailers["trailer key"] = "trailer value"; 921 trailers["trailer key"] = "trailer value";
921 SpdyHeaderBlock trailers_with_offset = trailers; 922 SpdyHeaderBlock trailers_with_offset = trailers;
922 trailers_with_offset[kFinalOffsetHeaderKey] = base::IntToString(kBodySize); 923 trailers_with_offset[kFinalOffsetHeaderKey] = base::IntToString(kBodySize);
923 EXPECT_CALL(*session_, WriteHeaders(_, testing::Eq(trailers_with_offset), 924 EXPECT_CALL(*session_, WriteHeaders(_, testing::Eq(trailers_with_offset),
924 /*fin=*/true, _, _)); 925 /*fin=*/true, _, _));
925 stream_->WriteTrailers(trailers, nullptr); 926 stream_->WriteTrailers(std::move(trailers), nullptr);
926 } 927 }
927 928
928 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) { 929 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) {
929 // Test that if trailers are written after all other data has been written 930 // Test that if trailers are written after all other data has been written
930 // (headers and body), that this closes the stream for writing. 931 // (headers and body), that this closes the stream for writing.
931 Initialize(kShouldProcessData); 932 Initialize(kShouldProcessData);
932 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 933 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
933 .Times(AnyNumber()) 934 .Times(AnyNumber())
934 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 935 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
935 936
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 993
993 // Writing Trailers should fail, as the FIN has already been sent. 994 // Writing Trailers should fail, as the FIN has already been sent.
994 // populated with the number of body bytes written. 995 // populated with the number of body bytes written.
995 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), 996 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr),
996 "Trailers cannot be sent after a FIN"); 997 "Trailers cannot be sent after a FIN");
997 } 998 }
998 999
999 } // namespace 1000 } // namespace
1000 } // namespace test 1001 } // namespace test
1001 } // namespace net 1002 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_spdy_stream.cc ('k') | net/tools/quic/quic_simple_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698