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

Side by Side Diff: net/quic/core/quic_session_test.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 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/core/quic_session.cc ('k') | net/quic/core/quic_spdy_session.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 (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/quic/core/quic_session.h" 5 #include "net/quic/core/quic_session.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "net/quic/core/crypto/crypto_protocol.h" 13 #include "net/quic/core/crypto/crypto_protocol.h"
14 #include "net/quic/core/crypto/null_encrypter.h" 14 #include "net/quic/core/crypto/null_encrypter.h"
15 #include "net/quic/core/quic_crypto_stream.h" 15 #include "net/quic/core/quic_crypto_stream.h"
16 #include "net/quic/core/quic_flags.h" 16 #include "net/quic/core/quic_flags.h"
17 #include "net/quic/core/quic_packets.h" 17 #include "net/quic/core/quic_packets.h"
18 #include "net/quic/core/quic_stream.h" 18 #include "net/quic/core/quic_stream.h"
19 #include "net/quic/core/quic_utils.h" 19 #include "net/quic/core/quic_utils.h"
20 #include "net/quic/platform/api/quic_map_util.h" 20 #include "net/quic/platform/api/quic_map_util.h"
21 #include "net/quic/platform/api/quic_ptr_util.h" 21 #include "net/quic/platform/api/quic_ptr_util.h"
22 #include "net/quic/platform/api/quic_str_cat.h" 22 #include "net/quic/platform/api/quic_str_cat.h"
23 #include "net/quic/platform/api/quic_string_piece.h"
23 #include "net/quic/test_tools/quic_config_peer.h" 24 #include "net/quic/test_tools/quic_config_peer.h"
24 #include "net/quic/test_tools/quic_connection_peer.h" 25 #include "net/quic/test_tools/quic_connection_peer.h"
25 #include "net/quic/test_tools/quic_flow_controller_peer.h" 26 #include "net/quic/test_tools/quic_flow_controller_peer.h"
26 #include "net/quic/test_tools/quic_session_peer.h" 27 #include "net/quic/test_tools/quic_session_peer.h"
27 #include "net/quic/test_tools/quic_spdy_session_peer.h" 28 #include "net/quic/test_tools/quic_spdy_session_peer.h"
28 #include "net/quic/test_tools/quic_spdy_stream_peer.h" 29 #include "net/quic/test_tools/quic_spdy_stream_peer.h"
29 #include "net/quic/test_tools/quic_stream_peer.h" 30 #include "net/quic/test_tools/quic_stream_peer.h"
30 #include "net/quic/test_tools/quic_test_utils.h" 31 #include "net/quic/test_tools/quic_test_utils.h"
31 #include "net/spdy/spdy_framer.h" 32 #include "net/spdy/spdy_framer.h"
32 #include "net/test/gtest_util.h" 33 #include "net/test/gtest_util.h"
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 EXPECT_EQ(kInitialIdleTimeoutSecs + 3, 789 EXPECT_EQ(kInitialIdleTimeoutSecs + 3,
789 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 790 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
790 CryptoHandshakeMessage msg; 791 CryptoHandshakeMessage msg;
791 session_.GetCryptoStream()->OnHandshakeMessage(msg); 792 session_.GetCryptoStream()->OnHandshakeMessage(msg);
792 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3, 793 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3,
793 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 794 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
794 } 795 }
795 796
796 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) { 797 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) {
797 // Send two bytes of payload. 798 // Send two bytes of payload.
798 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); 799 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT"));
799 session_.OnStreamFrame(data1); 800 session_.OnStreamFrame(data1);
800 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); 801 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams());
801 802
802 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _)); 803 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _));
803 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 804 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM,
804 0); 805 0);
805 session_.OnRstStream(rst1); 806 session_.OnRstStream(rst1);
806 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams()); 807 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams());
807 // Connection should remain alive. 808 // Connection should remain alive.
808 EXPECT_TRUE(connection_->connected()); 809 EXPECT_TRUE(connection_->connected());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 // Reset our stream: this results in the stream being closed locally. 1014 // Reset our stream: this results in the stream being closed locally.
1014 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); 1015 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority);
1015 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 1016 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
1016 stream->Reset(QUIC_STREAM_CANCELLED); 1017 stream->Reset(QUIC_STREAM_CANCELLED);
1017 1018
1018 // Now receive a response from the peer with a FIN. We should handle this by 1019 // Now receive a response from the peer with a FIN. We should handle this by
1019 // adjusting the connection level flow control receive window to take into 1020 // adjusting the connection level flow control receive window to take into
1020 // account the total number of bytes sent by the peer. 1021 // account the total number of bytes sent by the peer.
1021 const QuicStreamOffset kByteOffset = 5678; 1022 const QuicStreamOffset kByteOffset = 5678;
1022 string body = "hello"; 1023 string body = "hello";
1023 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece(body)); 1024 QuicStreamFrame frame(stream->id(), true, kByteOffset, QuicStringPiece(body));
1024 session_.OnStreamFrame(frame); 1025 session_.OnStreamFrame(frame);
1025 1026
1026 QuicStreamOffset total_stream_bytes_sent_by_peer = 1027 QuicStreamOffset total_stream_bytes_sent_by_peer =
1027 kByteOffset + body.length(); 1028 kByteOffset + body.length();
1028 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer, 1029 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer,
1029 session_.flow_controller()->bytes_consumed()); 1030 session_.flow_controller()->bytes_consumed());
1030 EXPECT_EQ( 1031 EXPECT_EQ(
1031 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer, 1032 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer,
1032 session_.flow_controller()->highest_received_byte_offset()); 1033 session_.flow_controller()->highest_received_byte_offset());
1033 } 1034 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 // violates flow control, that we close the connection. 1109 // violates flow control, that we close the connection.
1109 const uint64_t kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; 1110 const uint64_t kLargeOffset = kInitialSessionFlowControlWindowForTest + 1;
1110 EXPECT_CALL(*connection_, 1111 EXPECT_CALL(*connection_,
1111 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)) 1112 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _))
1112 .Times(2); 1113 .Times(2);
1113 1114
1114 // Check that stream frame + FIN results in connection close. 1115 // Check that stream frame + FIN results in connection close.
1115 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); 1116 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority);
1116 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 1117 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
1117 stream->Reset(QUIC_STREAM_CANCELLED); 1118 stream->Reset(QUIC_STREAM_CANCELLED);
1118 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); 1119 QuicStreamFrame frame(stream->id(), true, kLargeOffset, QuicStringPiece());
1119 session_.OnStreamFrame(frame); 1120 session_.OnStreamFrame(frame);
1120 1121
1121 // Check that RST results in connection close. 1122 // Check that RST results in connection close.
1122 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, 1123 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
1123 kLargeOffset); 1124 kLargeOffset);
1124 session_.OnRstStream(rst_frame); 1125 session_.OnRstStream(rst_frame);
1125 } 1126 }
1126 1127
1127 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) { 1128 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) {
1128 // Test that a flow control blocked headers stream gets unblocked on recipt of 1129 // Test that a flow control blocked headers stream gets unblocked on recipt of
(...skipping 21 matching lines...) Expand all
1150 // If a buggy/malicious peer creates too many streams that are not ended 1151 // If a buggy/malicious peer creates too many streams that are not ended
1151 // with a FIN or RST then we send an RST to refuse streams. 1152 // with a FIN or RST then we send an RST to refuse streams.
1152 const QuicStreamId kMaxStreams = 5; 1153 const QuicStreamId kMaxStreams = 5;
1153 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams); 1154 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1154 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1155 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
1155 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams; 1156 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams;
1156 1157
1157 // Create kMaxStreams data streams, and close them all without receiving a 1158 // Create kMaxStreams data streams, and close them all without receiving a
1158 // FIN or a RST_STREAM from the client. 1159 // FIN or a RST_STREAM from the client.
1159 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1160 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
1160 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); 1161 QuicStreamFrame data1(i, false, 0, QuicStringPiece("HT"));
1161 session_.OnStreamFrame(data1); 1162 session_.OnStreamFrame(data1);
1162 // EXPECT_EQ(1u, session_.GetNumOpenStreams()); 1163 // EXPECT_EQ(1u, session_.GetNumOpenStreams());
1163 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); 1164 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
1164 session_.CloseStream(i); 1165 session_.CloseStream(i);
1165 } 1166 }
1166 1167
1167 EXPECT_CALL(*connection_, 1168 EXPECT_CALL(*connection_,
1168 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _)) 1169 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _))
1169 .Times(1); 1170 .Times(1);
1170 // Create one more data streams to exceed limit of open stream. 1171 // Create one more data streams to exceed limit of open stream.
1171 QuicStreamFrame data1(kFinalStreamId, false, 0, StringPiece("HT")); 1172 QuicStreamFrame data1(kFinalStreamId, false, 0, QuicStringPiece("HT"));
1172 session_.OnStreamFrame(data1); 1173 session_.OnStreamFrame(data1);
1173 1174
1174 // Called after any new data is received by the session, and triggers the 1175 // Called after any new data is received by the session, and triggers the
1175 // call to close the connection. 1176 // call to close the connection.
1176 session_.PostProcessAfterData(); 1177 session_.PostProcessAfterData();
1177 } 1178 }
1178 1179
1179 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { 1180 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) {
1180 // Verify that a draining stream (which has received a FIN but not consumed 1181 // Verify that a draining stream (which has received a FIN but not consumed
1181 // it) does not count against the open quota (because it is closed from the 1182 // it) does not count against the open quota (because it is closed from the
1182 // protocol point of view). 1183 // protocol point of view).
1183 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)).Times(0); 1184 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)).Times(0);
1184 const QuicStreamId kMaxStreams = 5; 1185 const QuicStreamId kMaxStreams = 5;
1185 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams); 1186 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1186 1187
1187 // Create kMaxStreams + 1 data streams, and mark them draining. 1188 // Create kMaxStreams + 1 data streams, and mark them draining.
1188 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1189 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
1189 const QuicStreamId kFinalStreamId = 1190 const QuicStreamId kFinalStreamId =
1190 kClientDataStreamId1 + 2 * kMaxStreams + 1; 1191 kClientDataStreamId1 + 2 * kMaxStreams + 1;
1191 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1192 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
1192 QuicStreamFrame data1(i, true, 0, StringPiece("HT")); 1193 QuicStreamFrame data1(i, true, 0, QuicStringPiece("HT"));
1193 session_.OnStreamFrame(data1); 1194 session_.OnStreamFrame(data1);
1194 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); 1195 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams());
1195 session_.StreamDraining(i); 1196 session_.StreamDraining(i);
1196 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams()); 1197 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams());
1197 } 1198 }
1198 1199
1199 // Called after any new data is received by the session, and triggers the call 1200 // Called after any new data is received by the session, and triggers the call
1200 // to close the connection. 1201 // to close the connection.
1201 session_.PostProcessAfterData(); 1202 session_.PostProcessAfterData();
1202 } 1203 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 // Verify that an incoming FIN is recorded in a stream object even if the read 1252 // Verify that an incoming FIN is recorded in a stream object even if the read
1252 // side has been closed. This prevents an entry from being made in 1253 // side has been closed. This prevents an entry from being made in
1253 // locally_closed_streams_highest_offset_ (which will never be deleted). 1254 // locally_closed_streams_highest_offset_ (which will never be deleted).
1254 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); 1255 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority);
1255 QuicStreamId stream_id = stream->id(); 1256 QuicStreamId stream_id = stream->id();
1256 1257
1257 // Close the read side manually. 1258 // Close the read side manually.
1258 QuicStreamPeer::CloseReadSide(stream); 1259 QuicStreamPeer::CloseReadSide(stream);
1259 1260
1260 // Receive a stream data frame with FIN. 1261 // Receive a stream data frame with FIN.
1261 QuicStreamFrame frame(stream_id, true, 0, StringPiece()); 1262 QuicStreamFrame frame(stream_id, true, 0, QuicStringPiece());
1262 session_.OnStreamFrame(frame); 1263 session_.OnStreamFrame(frame);
1263 EXPECT_TRUE(stream->fin_received()); 1264 EXPECT_TRUE(stream->fin_received());
1264 1265
1265 // Reset stream locally. 1266 // Reset stream locally.
1266 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 1267 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
1267 stream->Reset(QUIC_STREAM_CANCELLED); 1268 stream->Reset(QUIC_STREAM_CANCELLED);
1268 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream)); 1269 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream));
1269 1270
1270 // Allow the session to delete the stream object. 1271 // Allow the session to delete the stream object.
1271 session_.PostProcessAfterData(); 1272 session_.PostProcessAfterData();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 if (version() != QUIC_VERSION_36) { 1309 if (version() != QUIC_VERSION_36) {
1309 EXPECT_FALSE(session_.force_hol_blocking()); 1310 EXPECT_FALSE(session_.force_hol_blocking());
1310 } else { 1311 } else {
1311 EXPECT_TRUE(session_.force_hol_blocking()); 1312 EXPECT_TRUE(session_.force_hol_blocking());
1312 } 1313 }
1313 } 1314 }
1314 1315
1315 } // namespace 1316 } // namespace
1316 } // namespace test 1317 } // namespace test
1317 } // namespace net 1318 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_session.cc ('k') | net/quic/core/quic_spdy_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698