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

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

Issue 2487613002: Landing Recent QUIC changes until 12:43 PM, Nov 5, 2016 UTC+8 (Closed)
Patch Set: Created 4 years, 1 month 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_stream_sequencer_test.cc ('k') | net/quic/core/reliable_quic_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 (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/reliable_quic_stream.h" 5 #include "net/quic/core/quic_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "net/quic/core/quic_connection.h" 10 #include "net/quic/core/quic_connection.h"
11 #include "net/quic/core/quic_flags.h" 11 #include "net/quic/core/quic_flags.h"
12 #include "net/quic/core/quic_utils.h" 12 #include "net/quic/core/quic_utils.h"
13 #include "net/quic/core/quic_write_blocked_list.h" 13 #include "net/quic/core/quic_write_blocked_list.h"
14 #include "net/quic/core/spdy_utils.h" 14 #include "net/quic/core/spdy_utils.h"
15 #include "net/quic/test_tools/quic_config_peer.h" 15 #include "net/quic/test_tools/quic_config_peer.h"
16 #include "net/quic/test_tools/quic_connection_peer.h" 16 #include "net/quic/test_tools/quic_connection_peer.h"
17 #include "net/quic/test_tools/quic_flow_controller_peer.h" 17 #include "net/quic/test_tools/quic_flow_controller_peer.h"
18 #include "net/quic/test_tools/quic_session_peer.h" 18 #include "net/quic/test_tools/quic_session_peer.h"
19 #include "net/quic/test_tools/quic_stream_peer.h"
19 #include "net/quic/test_tools/quic_test_utils.h" 20 #include "net/quic/test_tools/quic_test_utils.h"
20 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
21 #include "net/test/gtest_util.h" 21 #include "net/test/gtest_util.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gmock_mutant.h" 23 #include "testing/gmock_mutant.h"
24 24
25 using base::StringPiece; 25 using base::StringPiece;
26 using std::min; 26 using std::min;
27 using std::string; 27 using std::string;
28 using testing::AnyNumber; 28 using testing::AnyNumber;
29 using testing::AtLeast; 29 using testing::AtLeast;
30 using testing::CreateFunctor; 30 using testing::CreateFunctor;
31 using testing::InSequence; 31 using testing::InSequence;
32 using testing::Invoke; 32 using testing::Invoke;
33 using testing::DoAll; 33 using testing::DoAll;
34 using testing::Return; 34 using testing::Return;
35 using testing::StrictMock; 35 using testing::StrictMock;
36 using testing::WithArgs; 36 using testing::WithArgs;
37 using testing::_; 37 using testing::_;
38 38
39 namespace net { 39 namespace net {
40 namespace test { 40 namespace test {
41 namespace { 41 namespace {
42 42
43 const char kData1[] = "FooAndBar"; 43 const char kData1[] = "FooAndBar";
44 const char kData2[] = "EepAndBaz"; 44 const char kData2[] = "EepAndBaz";
45 const size_t kDataLen = 9; 45 const size_t kDataLen = 9;
46 const bool kShouldProcessData = true; 46 const bool kShouldProcessData = true;
47 const bool kShouldNotProcessData = false; 47 const bool kShouldNotProcessData = false;
48 48
49 class TestStream : public ReliableQuicStream { 49 class TestStream : public QuicStream {
50 public: 50 public:
51 TestStream(QuicStreamId id, QuicSession* session, bool should_process_data) 51 TestStream(QuicStreamId id, QuicSession* session, bool should_process_data)
52 : ReliableQuicStream(id, session), 52 : QuicStream(id, session), should_process_data_(should_process_data) {}
53 should_process_data_(should_process_data) {}
54 53
55 void OnDataAvailable() override {} 54 void OnDataAvailable() override {}
56 55
57 uint32_t ProcessRawData(const char* data, uint32_t data_len) { 56 uint32_t ProcessRawData(const char* data, uint32_t data_len) {
58 EXPECT_NE(0u, data_len); 57 EXPECT_NE(0u, data_len);
59 DVLOG(1) << "ProcessData data_len: " << data_len; 58 DVLOG(1) << "ProcessData data_len: " << data_len;
60 data_ += string(data, data_len); 59 data_ += string(data, data_len);
61 return should_process_data_ ? data_len : 0; 60 return should_process_data_ ? data_len : 0;
62 } 61 }
63 62
64 using ReliableQuicStream::WriteOrBufferData; 63 using QuicStream::WriteOrBufferData;
65 using ReliableQuicStream::CloseWriteSide; 64 using QuicStream::CloseWriteSide;
66 using ReliableQuicStream::OnClose; 65 using QuicStream::OnClose;
67 66
68 private: 67 private:
69 bool should_process_data_; 68 bool should_process_data_;
70 string data_; 69 string data_;
71 }; 70 };
72 71
73 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { 72 class QuicStreamTest : public ::testing::TestWithParam<bool> {
74 public: 73 public:
75 ReliableQuicStreamTest() 74 QuicStreamTest()
76 : initial_flow_control_window_bytes_(kMaxPacketSize), 75 : initial_flow_control_window_bytes_(kMaxPacketSize),
77 zero_(QuicTime::Delta::Zero()), 76 zero_(QuicTime::Delta::Zero()),
78 supported_versions_(AllSupportedVersions()) { 77 supported_versions_(AllSupportedVersions()) {
79 headers_[":host"] = "www.google.com"; 78 headers_[":host"] = "www.google.com";
80 headers_[":path"] = "/index.hml"; 79 headers_[":path"] = "/index.hml";
81 headers_[":scheme"] = "https"; 80 headers_[":scheme"] = "https";
82 headers_["cookie"] = 81 headers_["cookie"] =
83 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " 82 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
84 "__utmc=160408618; " 83 "__utmc=160408618; "
85 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" 84 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // session_ now owns stream_. 119 // session_ now owns stream_.
121 session_->ActivateStream(base::WrapUnique(stream_)); 120 session_->ActivateStream(base::WrapUnique(stream_));
122 // Ignore resetting when session_ is terminated. 121 // Ignore resetting when session_ is terminated.
123 EXPECT_CALL(*session_, SendRstStream(kTestStreamId, _, _)) 122 EXPECT_CALL(*session_, SendRstStream(kTestStreamId, _, _))
124 .Times(AnyNumber()); 123 .Times(AnyNumber());
125 write_blocked_list_ = 124 write_blocked_list_ =
126 QuicSessionPeer::GetWriteBlockedStreams(session_.get()); 125 QuicSessionPeer::GetWriteBlockedStreams(session_.get());
127 write_blocked_list_->RegisterStream(kTestStreamId, kV3HighestPriority); 126 write_blocked_list_->RegisterStream(kTestStreamId, kV3HighestPriority);
128 } 127 }
129 128
130 bool fin_sent() { return ReliableQuicStreamPeer::FinSent(stream_); } 129 bool fin_sent() { return QuicStreamPeer::FinSent(stream_); }
131 bool rst_sent() { return ReliableQuicStreamPeer::RstSent(stream_); } 130 bool rst_sent() { return QuicStreamPeer::RstSent(stream_); }
132 131
133 void set_initial_flow_control_window_bytes(uint32_t val) { 132 void set_initial_flow_control_window_bytes(uint32_t val) {
134 initial_flow_control_window_bytes_ = val; 133 initial_flow_control_window_bytes_ = val;
135 } 134 }
136 135
137 bool HasWriteBlockedStreams() { 136 bool HasWriteBlockedStreams() {
138 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() || 137 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() ||
139 write_blocked_list_->HasWriteBlockedDataStreams(); 138 write_blocked_list_->HasWriteBlockedDataStreams();
140 } 139 }
141 140
142 QuicConsumedData CloseStreamOnWriteError( 141 QuicConsumedData CloseStreamOnWriteError(
143 ReliableQuicStream* /*stream*/, 142 QuicStream* /*stream*/,
144 QuicStreamId id, 143 QuicStreamId id,
145 QuicIOVector /*iov*/, 144 QuicIOVector /*iov*/,
146 QuicStreamOffset /*offset*/, 145 QuicStreamOffset /*offset*/,
147 bool /*fin*/, 146 bool /*fin*/,
148 QuicAckListenerInterface* /*ack_notifier_delegate*/) { 147 QuicAckListenerInterface* /*ack_notifier_delegate*/) {
149 session_->CloseStream(id); 148 session_->CloseStream(id);
150 return QuicConsumedData(1, false); 149 return QuicConsumedData(1, false);
151 } 150 }
152 151
153 protected: 152 protected:
154 MockQuicConnectionHelper helper_; 153 MockQuicConnectionHelper helper_;
155 MockAlarmFactory alarm_factory_; 154 MockAlarmFactory alarm_factory_;
156 MockQuicConnection* connection_; 155 MockQuicConnection* connection_;
157 std::unique_ptr<MockQuicSession> session_; 156 std::unique_ptr<MockQuicSession> session_;
158 TestStream* stream_; 157 TestStream* stream_;
159 SpdyHeaderBlock headers_; 158 SpdyHeaderBlock headers_;
160 QuicWriteBlockedList* write_blocked_list_; 159 QuicWriteBlockedList* write_blocked_list_;
161 uint32_t initial_flow_control_window_bytes_; 160 uint32_t initial_flow_control_window_bytes_;
162 QuicTime::Delta zero_; 161 QuicTime::Delta zero_;
163 QuicVersionVector supported_versions_; 162 QuicVersionVector supported_versions_;
164 const QuicStreamId kTestStreamId = 5u; 163 const QuicStreamId kTestStreamId = 5u;
165 }; 164 };
166 165
167 TEST_F(ReliableQuicStreamTest, WriteAllData) { 166 TEST_F(QuicStreamTest, WriteAllData) {
168 Initialize(kShouldProcessData); 167 Initialize(kShouldProcessData);
169 168
170 size_t length = 169 size_t length =
171 1 + QuicPacketCreator::StreamFramePacketOverhead( 170 1 + QuicPacketCreator::StreamFramePacketOverhead(
172 connection_->version(), PACKET_8BYTE_CONNECTION_ID, 171 connection_->version(), PACKET_8BYTE_CONNECTION_ID,
173 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, 172 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce,
174 PACKET_6BYTE_PACKET_NUMBER, 0u); 173 PACKET_6BYTE_PACKET_NUMBER, 0u);
175 connection_->SetMaxPacketLength(length); 174 connection_->SetMaxPacketLength(length);
176 175
177 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 176 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
178 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 177 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
179 stream_->WriteOrBufferData(kData1, false, nullptr); 178 stream_->WriteOrBufferData(kData1, false, nullptr);
180 EXPECT_FALSE(HasWriteBlockedStreams()); 179 EXPECT_FALSE(HasWriteBlockedStreams());
181 } 180 }
182 181
183 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { 182 TEST_F(QuicStreamTest, NoBlockingIfNoDataOrFin) {
184 Initialize(kShouldProcessData); 183 Initialize(kShouldProcessData);
185 184
186 // Write no data and no fin. If we consume nothing we should not be write 185 // Write no data and no fin. If we consume nothing we should not be write
187 // blocked. 186 // blocked.
188 EXPECT_QUIC_BUG(stream_->WriteOrBufferData(StringPiece(), false, nullptr), 187 EXPECT_QUIC_BUG(stream_->WriteOrBufferData(StringPiece(), false, nullptr),
189 ""); 188 "");
190 EXPECT_FALSE(HasWriteBlockedStreams()); 189 EXPECT_FALSE(HasWriteBlockedStreams());
191 } 190 }
192 191
193 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { 192 TEST_F(QuicStreamTest, BlockIfOnlySomeDataConsumed) {
194 Initialize(kShouldProcessData); 193 Initialize(kShouldProcessData);
195 194
196 // Write some data and no fin. If we consume some but not all of the data, 195 // Write some data and no fin. If we consume some but not all of the data,
197 // we should be write blocked a not all the data was consumed. 196 // we should be write blocked a not all the data was consumed.
198 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 197 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
199 .WillOnce(Return(QuicConsumedData(1, false))); 198 .WillOnce(Return(QuicConsumedData(1, false)));
200 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 199 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
201 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 200 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
202 EXPECT_EQ(1u, stream_->queued_data_bytes()); 201 EXPECT_EQ(1u, stream_->queued_data_bytes());
203 } 202 }
204 203
205 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { 204 TEST_F(QuicStreamTest, BlockIfFinNotConsumedWithData) {
206 Initialize(kShouldProcessData); 205 Initialize(kShouldProcessData);
207 206
208 // Write some data and no fin. If we consume all the data but not the fin, 207 // Write some data and no fin. If we consume all the data but not the fin,
209 // we should be write blocked because the fin was not consumed. 208 // we should be write blocked because the fin was not consumed.
210 // (This should never actually happen as the fin should be sent out with the 209 // (This should never actually happen as the fin should be sent out with the
211 // last data) 210 // last data)
212 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 211 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
213 .WillOnce(Return(QuicConsumedData(2, false))); 212 .WillOnce(Return(QuicConsumedData(2, false)));
214 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 213 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
215 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 214 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
216 } 215 }
217 216
218 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { 217 TEST_F(QuicStreamTest, BlockIfSoloFinNotConsumed) {
219 Initialize(kShouldProcessData); 218 Initialize(kShouldProcessData);
220 219
221 // Write no data and a fin. If we consume nothing we should be write blocked, 220 // Write no data and a fin. If we consume nothing we should be write blocked,
222 // as the fin was not consumed. 221 // as the fin was not consumed.
223 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 222 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
224 .WillOnce(Return(QuicConsumedData(0, false))); 223 .WillOnce(Return(QuicConsumedData(0, false)));
225 stream_->WriteOrBufferData(StringPiece(), true, nullptr); 224 stream_->WriteOrBufferData(StringPiece(), true, nullptr);
226 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 225 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
227 } 226 }
228 227
229 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) { 228 TEST_F(QuicStreamTest, CloseOnPartialWrite) {
230 Initialize(kShouldProcessData); 229 Initialize(kShouldProcessData);
231 230
232 // Write some data and no fin. However, while writing the data 231 // Write some data and no fin. However, while writing the data
233 // close the stream and verify that MarkConnectionLevelWriteBlocked does not 232 // close the stream and verify that MarkConnectionLevelWriteBlocked does not
234 // crash with an unknown stream. 233 // crash with an unknown stream.
235 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 234 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
236 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError)); 235 .WillOnce(Invoke(this, &QuicStreamTest::CloseStreamOnWriteError));
237 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 236 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
238 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams()); 237 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
239 } 238 }
240 239
241 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { 240 TEST_F(QuicStreamTest, WriteOrBufferData) {
242 Initialize(kShouldProcessData); 241 Initialize(kShouldProcessData);
243 242
244 EXPECT_FALSE(HasWriteBlockedStreams()); 243 EXPECT_FALSE(HasWriteBlockedStreams());
245 size_t length = 244 size_t length =
246 1 + QuicPacketCreator::StreamFramePacketOverhead( 245 1 + QuicPacketCreator::StreamFramePacketOverhead(
247 connection_->version(), PACKET_8BYTE_CONNECTION_ID, 246 connection_->version(), PACKET_8BYTE_CONNECTION_ID,
248 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, 247 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce,
249 PACKET_6BYTE_PACKET_NUMBER, 0u); 248 PACKET_6BYTE_PACKET_NUMBER, 0u);
250 connection_->SetMaxPacketLength(length); 249 connection_->SetMaxPacketLength(length);
251 250
(...skipping 12 matching lines...) Expand all
264 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 263 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
265 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); 264 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false)));
266 stream_->OnCanWrite(); 265 stream_->OnCanWrite();
267 266
268 // And finally the end of the bytes_consumed. 267 // And finally the end of the bytes_consumed.
269 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 268 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
270 .WillOnce(Return(QuicConsumedData(2, true))); 269 .WillOnce(Return(QuicConsumedData(2, true)));
271 stream_->OnCanWrite(); 270 stream_->OnCanWrite();
272 } 271 }
273 272
274 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { 273 TEST_F(QuicStreamTest, ConnectionCloseAfterStreamClose) {
275 Initialize(kShouldProcessData); 274 Initialize(kShouldProcessData);
276 275
277 ReliableQuicStreamPeer::CloseReadSide(stream_); 276 QuicStreamPeer::CloseReadSide(stream_);
278 stream_->CloseWriteSide(); 277 stream_->CloseWriteSide();
279 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 278 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
280 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 279 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
281 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, 280 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
282 ConnectionCloseSource::FROM_SELF); 281 ConnectionCloseSource::FROM_SELF);
283 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 282 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
284 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 283 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
285 } 284 }
286 285
287 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { 286 TEST_F(QuicStreamTest, RstAlwaysSentIfNoFinSent) {
288 // For flow control accounting, a stream must send either a FIN or a RST frame 287 // For flow control accounting, a stream must send either a FIN or a RST frame
289 // before termination. 288 // before termination.
290 // Test that if no FIN has been sent, we send a RST. 289 // Test that if no FIN has been sent, we send a RST.
291 290
292 Initialize(kShouldProcessData); 291 Initialize(kShouldProcessData);
293 EXPECT_FALSE(fin_sent()); 292 EXPECT_FALSE(fin_sent());
294 EXPECT_FALSE(rst_sent()); 293 EXPECT_FALSE(rst_sent());
295 294
296 // Write some data, with no FIN. 295 // Write some data, with no FIN.
297 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 296 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
298 .WillOnce(Return(QuicConsumedData(1, false))); 297 .WillOnce(Return(QuicConsumedData(1, false)));
299 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr); 298 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr);
300 EXPECT_FALSE(fin_sent()); 299 EXPECT_FALSE(fin_sent());
301 EXPECT_FALSE(rst_sent()); 300 EXPECT_FALSE(rst_sent());
302 301
303 // Now close the stream, and expect that we send a RST. 302 // Now close the stream, and expect that we send a RST.
304 EXPECT_CALL(*session_, SendRstStream(_, _, _)); 303 EXPECT_CALL(*session_, SendRstStream(_, _, _));
305 stream_->OnClose(); 304 stream_->OnClose();
306 EXPECT_FALSE(fin_sent()); 305 EXPECT_FALSE(fin_sent());
307 EXPECT_TRUE(rst_sent()); 306 EXPECT_TRUE(rst_sent());
308 } 307 }
309 308
310 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { 309 TEST_F(QuicStreamTest, RstNotSentIfFinSent) {
311 // For flow control accounting, a stream must send either a FIN or a RST frame 310 // For flow control accounting, a stream must send either a FIN or a RST frame
312 // before termination. 311 // before termination.
313 // Test that if a FIN has been sent, we don't also send a RST. 312 // Test that if a FIN has been sent, we don't also send a RST.
314 313
315 Initialize(kShouldProcessData); 314 Initialize(kShouldProcessData);
316 EXPECT_FALSE(fin_sent()); 315 EXPECT_FALSE(fin_sent());
317 EXPECT_FALSE(rst_sent()); 316 EXPECT_FALSE(rst_sent());
318 317
319 // Write some data, with FIN. 318 // Write some data, with FIN.
320 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 319 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
321 .WillOnce(Return(QuicConsumedData(1, true))); 320 .WillOnce(Return(QuicConsumedData(1, true)));
322 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr); 321 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr);
323 EXPECT_TRUE(fin_sent()); 322 EXPECT_TRUE(fin_sent());
324 EXPECT_FALSE(rst_sent()); 323 EXPECT_FALSE(rst_sent());
325 324
326 // Now close the stream, and expect that we do not send a RST. 325 // Now close the stream, and expect that we do not send a RST.
327 stream_->OnClose(); 326 stream_->OnClose();
328 EXPECT_TRUE(fin_sent()); 327 EXPECT_TRUE(fin_sent());
329 EXPECT_FALSE(rst_sent()); 328 EXPECT_FALSE(rst_sent());
330 } 329 }
331 330
332 TEST_F(ReliableQuicStreamTest, OnlySendOneRst) { 331 TEST_F(QuicStreamTest, OnlySendOneRst) {
333 // For flow control accounting, a stream must send either a FIN or a RST frame 332 // For flow control accounting, a stream must send either a FIN or a RST frame
334 // before termination. 333 // before termination.
335 // Test that if a stream sends a RST, it doesn't send an additional RST during 334 // Test that if a stream sends a RST, it doesn't send an additional RST during
336 // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...) 335 // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...)
337 336
338 Initialize(kShouldProcessData); 337 Initialize(kShouldProcessData);
339 EXPECT_FALSE(fin_sent()); 338 EXPECT_FALSE(fin_sent());
340 EXPECT_FALSE(rst_sent()); 339 EXPECT_FALSE(rst_sent());
341 340
342 // Reset the stream. 341 // Reset the stream.
343 const int expected_resets = 1; 342 const int expected_resets = 1;
344 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(expected_resets); 343 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(expected_resets);
345 stream_->Reset(QUIC_STREAM_CANCELLED); 344 stream_->Reset(QUIC_STREAM_CANCELLED);
346 EXPECT_FALSE(fin_sent()); 345 EXPECT_FALSE(fin_sent());
347 EXPECT_TRUE(rst_sent()); 346 EXPECT_TRUE(rst_sent());
348 347
349 // Now close the stream (any further resets being sent would break the 348 // Now close the stream (any further resets being sent would break the
350 // expectation above). 349 // expectation above).
351 stream_->OnClose(); 350 stream_->OnClose();
352 EXPECT_FALSE(fin_sent()); 351 EXPECT_FALSE(fin_sent());
353 EXPECT_TRUE(rst_sent()); 352 EXPECT_TRUE(rst_sent());
354 } 353 }
355 354
356 TEST_F(ReliableQuicStreamTest, StreamFlowControlMultipleWindowUpdates) { 355 TEST_F(QuicStreamTest, StreamFlowControlMultipleWindowUpdates) {
357 set_initial_flow_control_window_bytes(1000); 356 set_initial_flow_control_window_bytes(1000);
358 357
359 Initialize(kShouldProcessData); 358 Initialize(kShouldProcessData);
360 359
361 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we 360 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we
362 // want to make sure we latch the largest offset we see. 361 // want to make sure we latch the largest offset we see.
363 362
364 // Initially should be default. 363 // Initially should be default.
365 EXPECT_EQ( 364 EXPECT_EQ(
366 initial_flow_control_window_bytes_, 365 initial_flow_control_window_bytes_,
(...skipping 19 matching lines...) Expand all
386 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller())); 385 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller()));
387 } 386 }
388 387
389 // TODO(ianswett): It's not clear this method is still needed now that 388 // TODO(ianswett): It's not clear this method is still needed now that
390 // ProxyAckNotifierDelegate has been removed. 389 // ProxyAckNotifierDelegate has been removed.
391 void SaveAckListener(scoped_refptr<QuicAckListenerInterface>* listener_out, 390 void SaveAckListener(scoped_refptr<QuicAckListenerInterface>* listener_out,
392 QuicAckListenerInterface* listener) { 391 QuicAckListenerInterface* listener) {
393 *listener_out = (listener); 392 *listener_out = (listener);
394 } 393 }
395 394
396 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) { 395 TEST_F(QuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) {
397 Initialize(kShouldProcessData); 396 Initialize(kShouldProcessData);
398 397
399 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 398 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
400 399
401 const int kDataSize = 16 * 1024; 400 const int kDataSize = 16 * 1024;
402 const string kData(kDataSize, 'a'); 401 const string kData(kDataSize, 'a');
403 402
404 const int kFirstWriteSize = 100; 403 const int kFirstWriteSize = 100;
405 const int kSecondWriteSize = 50; 404 const int kSecondWriteSize = 50;
406 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; 405 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize;
(...skipping 23 matching lines...) Expand all
430 stream_->OnCanWrite(); 429 stream_->OnCanWrite();
431 430
432 EXPECT_CALL(*session_, 431 EXPECT_CALL(*session_,
433 WritevData(stream_, kTestStreamId, _, _, _, ack_listener.get())) 432 WritevData(stream_, kTestStreamId, _, _, _, ack_listener.get()))
434 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); 433 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false)));
435 stream_->OnCanWrite(); 434 stream_->OnCanWrite();
436 } 435 }
437 436
438 // Verify delegate behavior when packets are acked before the WritevData call 437 // Verify delegate behavior when packets are acked before the WritevData call
439 // that sends out the last byte. 438 // that sends out the last byte.
440 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { 439 TEST_F(QuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) {
441 Initialize(kShouldProcessData); 440 Initialize(kShouldProcessData);
442 441
443 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>); 442 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>);
444 443
445 const int kDataSize = 16 * 1024; 444 const int kDataSize = 16 * 1024;
446 const string kData(kDataSize, 'a'); 445 const string kData(kDataSize, 'a');
447 446
448 const int kInitialWriteSize = 100; 447 const int kInitialWriteSize = 100;
449 448
450 // Set a large flow control send window so this doesn't interfere with test. 449 // Set a large flow control send window so this doesn't interfere with test.
(...skipping 10 matching lines...) Expand all
461 EXPECT_TRUE(HasWriteBlockedStreams()); 460 EXPECT_TRUE(HasWriteBlockedStreams());
462 461
463 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 462 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
464 .WillOnce(DoAll( 463 .WillOnce(DoAll(
465 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 464 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
466 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); 465 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false))));
467 stream_->OnCanWrite(); 466 stream_->OnCanWrite();
468 } 467 }
469 468
470 // Verify delegate behavior when WriteOrBufferData does not buffer. 469 // Verify delegate behavior when WriteOrBufferData does not buffer.
471 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { 470 TEST_F(QuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) {
472 Initialize(kShouldProcessData); 471 Initialize(kShouldProcessData);
473 472
474 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 473 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
475 474
476 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 475 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
477 476
478 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 477 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
479 .WillOnce(DoAll( 478 .WillOnce(DoAll(
480 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 479 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
481 Return(QuicConsumedData(kDataLen, true)))); 480 Return(QuicConsumedData(kDataLen, true))));
482 stream_->WriteOrBufferData(kData1, true, delegate.get()); 481 stream_->WriteOrBufferData(kData1, true, delegate.get());
483 EXPECT_FALSE(HasWriteBlockedStreams()); 482 EXPECT_FALSE(HasWriteBlockedStreams());
484 } 483 }
485 484
486 // Verify delegate behavior when WriteOrBufferData buffers all the data. 485 // Verify delegate behavior when WriteOrBufferData buffers all the data.
487 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { 486 TEST_F(QuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) {
488 Initialize(kShouldProcessData); 487 Initialize(kShouldProcessData);
489 488
490 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 489 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
491 490
492 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 491 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
493 492
494 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 493 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
495 .WillOnce(Return(QuicConsumedData(0, false))); 494 .WillOnce(Return(QuicConsumedData(0, false)));
496 stream_->WriteOrBufferData(kData1, true, delegate.get()); 495 stream_->WriteOrBufferData(kData1, true, delegate.get());
497 EXPECT_TRUE(HasWriteBlockedStreams()); 496 EXPECT_TRUE(HasWriteBlockedStreams());
498 497
499 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 498 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
500 .WillOnce(DoAll( 499 .WillOnce(DoAll(
501 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 500 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
502 Return(QuicConsumedData(kDataLen, true)))); 501 Return(QuicConsumedData(kDataLen, true))));
503 stream_->OnCanWrite(); 502 stream_->OnCanWrite();
504 } 503 }
505 504
506 // Verify delegate behavior when WriteOrBufferData when the FIN is 505 // Verify delegate behavior when WriteOrBufferData when the FIN is
507 // sent out in a different packet. 506 // sent out in a different packet.
508 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { 507 TEST_F(QuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) {
509 Initialize(kShouldProcessData); 508 Initialize(kShouldProcessData);
510 509
511 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 510 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
512 511
513 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 512 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
514 513
515 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 514 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
516 .WillOnce(DoAll( 515 .WillOnce(DoAll(
517 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 516 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
518 Return(QuicConsumedData(kDataLen, false)))); 517 Return(QuicConsumedData(kDataLen, false))));
519 stream_->WriteOrBufferData(kData1, true, delegate.get()); 518 stream_->WriteOrBufferData(kData1, true, delegate.get());
520 EXPECT_TRUE(HasWriteBlockedStreams()); 519 EXPECT_TRUE(HasWriteBlockedStreams());
521 520
522 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 521 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
523 .WillOnce(DoAll( 522 .WillOnce(DoAll(
524 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 523 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
525 Return(QuicConsumedData(0, true)))); 524 Return(QuicConsumedData(0, true))));
526 stream_->OnCanWrite(); 525 stream_->OnCanWrite();
527 } 526 }
528 527
529 // Verify that when we receive a packet which violates flow control (i.e. sends 528 // Verify that when we receive a packet which violates flow control (i.e. sends
530 // too much data on the stream) that the stream sequencer never sees this frame, 529 // too much data on the stream) that the stream sequencer never sees this frame,
531 // as we check for violation and close the connection early. 530 // as we check for violation and close the connection early.
532 TEST_F(ReliableQuicStreamTest, 531 TEST_F(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) {
533 StreamSequencerNeverSeesPacketsViolatingFlowControl) {
534 Initialize(kShouldProcessData); 532 Initialize(kShouldProcessData);
535 533
536 // Receive a stream frame that violates flow control: the byte offset is 534 // Receive a stream frame that violates flow control: the byte offset is
537 // higher than the receive window offset. 535 // higher than the receive window offset.
538 QuicStreamFrame frame(stream_->id(), false, 536 QuicStreamFrame frame(stream_->id(), false,
539 kInitialSessionFlowControlWindowForTest + 1, 537 kInitialSessionFlowControlWindowForTest + 1,
540 StringPiece(".")); 538 StringPiece("."));
541 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset( 539 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset(
542 stream_->flow_controller())); 540 stream_->flow_controller()));
543 541
544 // Stream should not accept the frame, and the connection should be closed. 542 // Stream should not accept the frame, and the connection should be closed.
545 EXPECT_CALL(*connection_, 543 EXPECT_CALL(*connection_,
546 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); 544 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
547 stream_->OnStreamFrame(frame); 545 stream_->OnStreamFrame(frame);
548 } 546 }
549 547
550 // Verify that after the consumer calls StopReading(), the stream still sends 548 // Verify that after the consumer calls StopReading(), the stream still sends
551 // flow control updates. 549 // flow control updates.
552 TEST_F(ReliableQuicStreamTest, StopReadingSendsFlowControl) { 550 TEST_F(QuicStreamTest, StopReadingSendsFlowControl) {
553 Initialize(kShouldProcessData); 551 Initialize(kShouldProcessData);
554 552
555 stream_->StopReading(); 553 stream_->StopReading();
556 554
557 // Connection should not get terminated due to flow control errors. 555 // Connection should not get terminated due to flow control errors.
558 EXPECT_CALL(*connection_, 556 EXPECT_CALL(*connection_,
559 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)) 557 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _))
560 .Times(0); 558 .Times(0);
561 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(AtLeast(1)); 559 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(AtLeast(1));
562 560
563 string data(1000, 'x'); 561 string data(1000, 'x');
564 for (QuicStreamOffset offset = 0; 562 for (QuicStreamOffset offset = 0;
565 offset < 2 * kInitialStreamFlowControlWindowForTest; 563 offset < 2 * kInitialStreamFlowControlWindowForTest;
566 offset += data.length()) { 564 offset += data.length()) {
567 QuicStreamFrame frame(stream_->id(), false, offset, data); 565 QuicStreamFrame frame(stream_->id(), false, offset, data);
568 stream_->OnStreamFrame(frame); 566 stream_->OnStreamFrame(frame);
569 } 567 }
570 EXPECT_LT( 568 EXPECT_LT(
571 kInitialStreamFlowControlWindowForTest, 569 kInitialStreamFlowControlWindowForTest,
572 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); 570 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
573 } 571 }
574 572
575 TEST_F(ReliableQuicStreamTest, FinalByteOffsetFromFin) { 573 TEST_F(QuicStreamTest, FinalByteOffsetFromFin) {
576 Initialize(kShouldProcessData); 574 Initialize(kShouldProcessData);
577 575
578 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 576 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
579 577
580 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234, 578 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234,
581 StringPiece(".")); 579 StringPiece("."));
582 stream_->OnStreamFrame(stream_frame_no_fin); 580 stream_->OnStreamFrame(stream_frame_no_fin);
583 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 581 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
584 582
585 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 583 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
586 StringPiece(".")); 584 StringPiece("."));
587 stream_->OnStreamFrame(stream_frame_with_fin); 585 stream_->OnStreamFrame(stream_frame_with_fin);
588 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 586 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
589 } 587 }
590 588
591 TEST_F(ReliableQuicStreamTest, FinalByteOffsetFromRst) { 589 TEST_F(QuicStreamTest, FinalByteOffsetFromRst) {
592 Initialize(kShouldProcessData); 590 Initialize(kShouldProcessData);
593 591
594 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 592 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
595 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); 593 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234);
596 stream_->OnStreamReset(rst_frame); 594 stream_->OnStreamReset(rst_frame);
597 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 595 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
598 } 596 }
599 597
600 TEST_F(ReliableQuicStreamTest, FinalByteOffsetFromZeroLengthStreamFrame) { 598 TEST_F(QuicStreamTest, FinalByteOffsetFromZeroLengthStreamFrame) {
601 // When receiving Trailers, an empty stream frame is created with the FIN set, 599 // When receiving Trailers, an empty stream frame is created with the FIN set,
602 // and is passed to OnStreamFrame. The Trailers may be sent in advance of 600 // and is passed to OnStreamFrame. The Trailers may be sent in advance of
603 // queued body bytes being sent, and thus the final byte offset may exceed 601 // queued body bytes being sent, and thus the final byte offset may exceed
604 // current flow control limits. Flow control should only be concerned with 602 // current flow control limits. Flow control should only be concerned with
605 // data that has actually been sent/received, so verify that flow control 603 // data that has actually been sent/received, so verify that flow control
606 // ignores such a stream frame. 604 // ignores such a stream frame.
607 Initialize(kShouldProcessData); 605 Initialize(kShouldProcessData);
608 606
609 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 607 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
610 const QuicStreamOffset kByteOffsetExceedingFlowControlWindow = 608 const QuicStreamOffset kByteOffsetExceedingFlowControlWindow =
(...skipping 17 matching lines...) Expand all
628 626
629 // The flow control receive offset values should not have changed. 627 // The flow control receive offset values should not have changed.
630 EXPECT_EQ( 628 EXPECT_EQ(
631 current_stream_flow_control_offset, 629 current_stream_flow_control_offset,
632 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); 630 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
633 EXPECT_EQ( 631 EXPECT_EQ(
634 current_connection_flow_control_offset, 632 current_connection_flow_control_offset,
635 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller())); 633 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()));
636 } 634 }
637 635
638 TEST_F(ReliableQuicStreamTest, SetDrainingIncomingOutgoing) { 636 TEST_F(QuicStreamTest, SetDrainingIncomingOutgoing) {
639 // Don't have incoming data consumed. 637 // Don't have incoming data consumed.
640 Initialize(kShouldNotProcessData); 638 Initialize(kShouldNotProcessData);
641 639
642 // Incoming data with FIN. 640 // Incoming data with FIN.
643 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 641 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
644 StringPiece(".")); 642 StringPiece("."));
645 stream_->OnStreamFrame(stream_frame_with_fin); 643 stream_->OnStreamFrame(stream_frame_with_fin);
646 // The FIN has been received but not consumed. 644 // The FIN has been received but not consumed.
647 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 645 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
648 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 646 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
649 EXPECT_FALSE(stream_->reading_stopped()); 647 EXPECT_FALSE(stream_->reading_stopped());
650 648
651 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 649 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
652 650
653 // Outgoing data with FIN. 651 // Outgoing data with FIN.
654 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 652 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
655 .WillOnce(Return(QuicConsumedData(2, true))); 653 .WillOnce(Return(QuicConsumedData(2, true)));
656 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 654 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
657 EXPECT_TRUE(stream_->write_side_closed()); 655 EXPECT_TRUE(stream_->write_side_closed());
658 656
659 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 657 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
660 ->count(kTestStreamId)); 658 ->count(kTestStreamId));
661 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 659 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
662 } 660 }
663 661
664 TEST_F(ReliableQuicStreamTest, SetDrainingOutgoingIncoming) { 662 TEST_F(QuicStreamTest, SetDrainingOutgoingIncoming) {
665 // Don't have incoming data consumed. 663 // Don't have incoming data consumed.
666 Initialize(kShouldNotProcessData); 664 Initialize(kShouldNotProcessData);
667 665
668 // Outgoing data with FIN. 666 // Outgoing data with FIN.
669 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 667 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
670 .WillOnce(Return(QuicConsumedData(2, true))); 668 .WillOnce(Return(QuicConsumedData(2, true)));
671 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 669 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
672 EXPECT_TRUE(stream_->write_side_closed()); 670 EXPECT_TRUE(stream_->write_side_closed());
673 671
674 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 672 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
675 673
676 // Incoming data with FIN. 674 // Incoming data with FIN.
677 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 675 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
678 StringPiece(".")); 676 StringPiece("."));
679 stream_->OnStreamFrame(stream_frame_with_fin); 677 stream_->OnStreamFrame(stream_frame_with_fin);
680 // The FIN has been received but not consumed. 678 // The FIN has been received but not consumed.
681 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 679 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
682 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 680 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
683 EXPECT_FALSE(stream_->reading_stopped()); 681 EXPECT_FALSE(stream_->reading_stopped());
684 682
685 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 683 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
686 ->count(kTestStreamId)); 684 ->count(kTestStreamId));
687 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 685 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
688 } 686 }
689 687
690 TEST_F(ReliableQuicStreamTest, EarlyResponseFinHandling) { 688 TEST_F(QuicStreamTest, EarlyResponseFinHandling) {
691 // Verify that if the server completes the response before reading the end of 689 // Verify that if the server completes the response before reading the end of
692 // the request, the received FIN is recorded. 690 // the request, the received FIN is recorded.
693 691
694 Initialize(kShouldProcessData); 692 Initialize(kShouldProcessData);
695 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 693 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
696 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 694 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
697 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 695 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
698 696
699 // Receive data for the request. 697 // Receive data for the request.
700 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start")); 698 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start"));
701 stream_->OnStreamFrame(frame1); 699 stream_->OnStreamFrame(frame1);
702 // When QuicSimpleServerStream sends the response, it calls 700 // When QuicSimpleServerStream sends the response, it calls
703 // ReliableQuicStream::CloseReadSide() first. 701 // QuicStream::CloseReadSide() first.
704 ReliableQuicStreamPeer::CloseReadSide(stream_); 702 QuicStreamPeer::CloseReadSide(stream_);
705 // Send data and FIN for the response. 703 // Send data and FIN for the response.
706 stream_->WriteOrBufferData(kData1, false, nullptr); 704 stream_->WriteOrBufferData(kData1, false, nullptr);
707 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream_)); 705 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
708 // Receive remaining data and FIN for the request. 706 // Receive remaining data and FIN for the request.
709 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End")); 707 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End"));
710 stream_->OnStreamFrame(frame2); 708 stream_->OnStreamFrame(frame2);
711 EXPECT_TRUE(stream_->fin_received()); 709 EXPECT_TRUE(stream_->fin_received());
712 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 710 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
713 } 711 }
714 712
715 } // namespace 713 } // namespace
716 } // namespace test 714 } // namespace test
717 } // namespace net 715 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_stream_sequencer_test.cc ('k') | net/quic/core/reliable_quic_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698