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

Side by Side Diff: net/quic/reliable_quic_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/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_sent_packet_manager_peer.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/reliable_quic_stream.h" 5 #include "net/quic/reliable_quic_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "net/quic/quic_connection.h" 9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_flags.h" 10 #include "net/quic/quic_flags.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void set_initial_flow_control_window_bytes(uint32_t val) { 132 void set_initial_flow_control_window_bytes(uint32_t val) {
133 initial_flow_control_window_bytes_ = val; 133 initial_flow_control_window_bytes_ = val;
134 } 134 }
135 135
136 bool HasWriteBlockedStreams() { 136 bool HasWriteBlockedStreams() {
137 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() || 137 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() ||
138 write_blocked_list_->HasWriteBlockedDataStreams(); 138 write_blocked_list_->HasWriteBlockedDataStreams();
139 } 139 }
140 140
141 QuicConsumedData CloseStreamOnWriteError( 141 QuicConsumedData CloseStreamOnWriteError(
142 ReliableQuicStream* /*stream*/,
142 QuicStreamId id, 143 QuicStreamId id,
143 QuicIOVector /*iov*/, 144 QuicIOVector /*iov*/,
144 QuicStreamOffset /*offset*/, 145 QuicStreamOffset /*offset*/,
145 bool /*fin*/, 146 bool /*fin*/,
146 QuicAckListenerInterface* /*ack_notifier_delegate*/) { 147 QuicAckListenerInterface* /*ack_notifier_delegate*/) {
147 session_->CloseStream(id); 148 session_->CloseStream(id);
148 return QuicConsumedData(1, false); 149 return QuicConsumedData(1, false);
149 } 150 }
150 151
151 protected: 152 protected:
(...skipping 13 matching lines...) Expand all
165 TEST_F(ReliableQuicStreamTest, WriteAllData) { 166 TEST_F(ReliableQuicStreamTest, WriteAllData) {
166 Initialize(kShouldProcessData); 167 Initialize(kShouldProcessData);
167 168
168 size_t length = 169 size_t length =
169 1 + QuicPacketCreator::StreamFramePacketOverhead( 170 1 + QuicPacketCreator::StreamFramePacketOverhead(
170 connection_->version(), PACKET_8BYTE_CONNECTION_ID, 171 connection_->version(), PACKET_8BYTE_CONNECTION_ID,
171 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, 172 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce,
172 PACKET_6BYTE_PACKET_NUMBER, 0u); 173 PACKET_6BYTE_PACKET_NUMBER, 0u);
173 connection_->SetMaxPacketLength(length); 174 connection_->SetMaxPacketLength(length);
174 175
175 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 176 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
176 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 177 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
177 stream_->WriteOrBufferData(kData1, false, nullptr); 178 stream_->WriteOrBufferData(kData1, false, nullptr);
178 EXPECT_FALSE(HasWriteBlockedStreams()); 179 EXPECT_FALSE(HasWriteBlockedStreams());
179 } 180 }
180 181
181 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { 182 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) {
182 Initialize(kShouldProcessData); 183 Initialize(kShouldProcessData);
183 184
184 // 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
185 // blocked. 186 // blocked.
186 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, nullptr), ""); 187 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, nullptr), "");
187 EXPECT_FALSE(HasWriteBlockedStreams()); 188 EXPECT_FALSE(HasWriteBlockedStreams());
188 } 189 }
189 190
190 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { 191 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) {
191 Initialize(kShouldProcessData); 192 Initialize(kShouldProcessData);
192 193
193 // Write some data and no fin. If we consume some but not all of the data, 194 // Write some data and no fin. If we consume some but not all of the data,
194 // we should be write blocked a not all the data was consumed. 195 // we should be write blocked a not all the data was consumed.
195 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 196 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
196 .WillOnce(Return(QuicConsumedData(1, false))); 197 .WillOnce(Return(QuicConsumedData(1, false)));
197 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 198 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
198 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 199 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
199 EXPECT_EQ(1u, stream_->queued_data_bytes()); 200 EXPECT_EQ(1u, stream_->queued_data_bytes());
200 } 201 }
201 202
202 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { 203 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) {
203 Initialize(kShouldProcessData); 204 Initialize(kShouldProcessData);
204 205
205 // Write some data and no fin. If we consume all the data but not the fin, 206 // Write some data and no fin. If we consume all the data but not the fin,
206 // we should be write blocked because the fin was not consumed. 207 // we should be write blocked because the fin was not consumed.
207 // (This should never actually happen as the fin should be sent out with the 208 // (This should never actually happen as the fin should be sent out with the
208 // last data) 209 // last data)
209 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 210 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
210 .WillOnce(Return(QuicConsumedData(2, false))); 211 .WillOnce(Return(QuicConsumedData(2, false)));
211 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 212 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
212 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 213 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
213 } 214 }
214 215
215 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { 216 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) {
216 Initialize(kShouldProcessData); 217 Initialize(kShouldProcessData);
217 218
218 // Write no data and a fin. If we consume nothing we should be write blocked, 219 // Write no data and a fin. If we consume nothing we should be write blocked,
219 // as the fin was not consumed. 220 // as the fin was not consumed.
220 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 221 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
221 .WillOnce(Return(QuicConsumedData(0, false))); 222 .WillOnce(Return(QuicConsumedData(0, false)));
222 stream_->WriteOrBufferData(StringPiece(), true, nullptr); 223 stream_->WriteOrBufferData(StringPiece(), true, nullptr);
223 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 224 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
224 } 225 }
225 226
226 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) { 227 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) {
227 Initialize(kShouldProcessData); 228 Initialize(kShouldProcessData);
228 229
229 // Write some data and no fin. However, while writing the data 230 // Write some data and no fin. However, while writing the data
230 // close the stream and verify that MarkConnectionLevelWriteBlocked does not 231 // close the stream and verify that MarkConnectionLevelWriteBlocked does not
231 // crash with an unknown stream. 232 // crash with an unknown stream.
232 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 233 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
233 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError)); 234 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError));
234 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 235 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
235 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams()); 236 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
236 } 237 }
237 238
238 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { 239 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) {
239 Initialize(kShouldProcessData); 240 Initialize(kShouldProcessData);
240 241
241 EXPECT_FALSE(HasWriteBlockedStreams()); 242 EXPECT_FALSE(HasWriteBlockedStreams());
242 size_t length = 243 size_t length =
243 1 + QuicPacketCreator::StreamFramePacketOverhead( 244 1 + QuicPacketCreator::StreamFramePacketOverhead(
244 connection_->version(), PACKET_8BYTE_CONNECTION_ID, 245 connection_->version(), PACKET_8BYTE_CONNECTION_ID,
245 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, 246 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce,
246 PACKET_6BYTE_PACKET_NUMBER, 0u); 247 PACKET_6BYTE_PACKET_NUMBER, 0u);
247 connection_->SetMaxPacketLength(length); 248 connection_->SetMaxPacketLength(length);
248 249
249 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 250 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
250 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false))); 251 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false)));
251 stream_->WriteOrBufferData(kData1, false, nullptr); 252 stream_->WriteOrBufferData(kData1, false, nullptr);
252 EXPECT_TRUE(HasWriteBlockedStreams()); 253 EXPECT_TRUE(HasWriteBlockedStreams());
253 254
254 // Queue a bytes_consumed write. 255 // Queue a bytes_consumed write.
255 stream_->WriteOrBufferData(kData2, false, nullptr); 256 stream_->WriteOrBufferData(kData2, false, nullptr);
256 257
257 // Make sure we get the tail of the first write followed by the bytes_consumed 258 // Make sure we get the tail of the first write followed by the bytes_consumed
258 InSequence s; 259 InSequence s;
259 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 260 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
260 .WillOnce(Return(QuicConsumedData(1, false))); 261 .WillOnce(Return(QuicConsumedData(1, false)));
261 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 262 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
262 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); 263 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false)));
263 stream_->OnCanWrite(); 264 stream_->OnCanWrite();
264 265
265 // And finally the end of the bytes_consumed. 266 // And finally the end of the bytes_consumed.
266 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 267 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
267 .WillOnce(Return(QuicConsumedData(2, true))); 268 .WillOnce(Return(QuicConsumedData(2, true)));
268 stream_->OnCanWrite(); 269 stream_->OnCanWrite();
269 } 270 }
270 271
271 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { 272 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) {
272 Initialize(kShouldProcessData); 273 Initialize(kShouldProcessData);
273 274
274 ReliableQuicStreamPeer::CloseReadSide(stream_); 275 ReliableQuicStreamPeer::CloseReadSide(stream_);
275 stream_->CloseWriteSide(); 276 stream_->CloseWriteSide();
276 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 277 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
277 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 278 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
278 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, 279 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
279 ConnectionCloseSource::FROM_SELF); 280 ConnectionCloseSource::FROM_SELF);
280 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 281 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
281 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 282 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
282 } 283 }
283 284
284 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { 285 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) {
285 // For flow control accounting, a stream must send either a FIN or a RST frame 286 // For flow control accounting, a stream must send either a FIN or a RST frame
286 // before termination. 287 // before termination.
287 // Test that if no FIN has been sent, we send a RST. 288 // Test that if no FIN has been sent, we send a RST.
288 289
289 Initialize(kShouldProcessData); 290 Initialize(kShouldProcessData);
290 EXPECT_FALSE(fin_sent()); 291 EXPECT_FALSE(fin_sent());
291 EXPECT_FALSE(rst_sent()); 292 EXPECT_FALSE(rst_sent());
292 293
293 // Write some data, with no FIN. 294 // Write some data, with no FIN.
294 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 295 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
295 .WillOnce(Return(QuicConsumedData(1, false))); 296 .WillOnce(Return(QuicConsumedData(1, false)));
296 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr); 297 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr);
297 EXPECT_FALSE(fin_sent()); 298 EXPECT_FALSE(fin_sent());
298 EXPECT_FALSE(rst_sent()); 299 EXPECT_FALSE(rst_sent());
299 300
300 // Now close the stream, and expect that we send a RST. 301 // Now close the stream, and expect that we send a RST.
301 EXPECT_CALL(*session_, SendRstStream(_, _, _)); 302 EXPECT_CALL(*session_, SendRstStream(_, _, _));
302 stream_->OnClose(); 303 stream_->OnClose();
303 EXPECT_FALSE(fin_sent()); 304 EXPECT_FALSE(fin_sent());
304 EXPECT_TRUE(rst_sent()); 305 EXPECT_TRUE(rst_sent());
305 } 306 }
306 307
307 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { 308 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) {
308 // For flow control accounting, a stream must send either a FIN or a RST frame 309 // For flow control accounting, a stream must send either a FIN or a RST frame
309 // before termination. 310 // before termination.
310 // Test that if a FIN has been sent, we don't also send a RST. 311 // Test that if a FIN has been sent, we don't also send a RST.
311 312
312 Initialize(kShouldProcessData); 313 Initialize(kShouldProcessData);
313 EXPECT_FALSE(fin_sent()); 314 EXPECT_FALSE(fin_sent());
314 EXPECT_FALSE(rst_sent()); 315 EXPECT_FALSE(rst_sent());
315 316
316 // Write some data, with FIN. 317 // Write some data, with FIN.
317 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 318 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
318 .WillOnce(Return(QuicConsumedData(1, true))); 319 .WillOnce(Return(QuicConsumedData(1, true)));
319 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr); 320 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr);
320 EXPECT_TRUE(fin_sent()); 321 EXPECT_TRUE(fin_sent());
321 EXPECT_FALSE(rst_sent()); 322 EXPECT_FALSE(rst_sent());
322 323
323 // Now close the stream, and expect that we do not send a RST. 324 // Now close the stream, and expect that we do not send a RST.
324 stream_->OnClose(); 325 stream_->OnClose();
325 EXPECT_TRUE(fin_sent()); 326 EXPECT_TRUE(fin_sent());
326 EXPECT_FALSE(rst_sent()); 327 EXPECT_FALSE(rst_sent());
327 } 328 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 const int kFirstWriteSize = 100; 402 const int kFirstWriteSize = 100;
402 const int kSecondWriteSize = 50; 403 const int kSecondWriteSize = 50;
403 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; 404 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize;
404 405
405 // Set a large flow control send window so this doesn't interfere with test. 406 // Set a large flow control send window so this doesn't interfere with test.
406 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 407 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
407 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 408 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
408 409
409 scoped_refptr<QuicAckListenerInterface> ack_listener; 410 scoped_refptr<QuicAckListenerInterface> ack_listener;
410 411
411 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 412 EXPECT_CALL(*session_, WritevData(_, kTestStreamId, _, _, _, _))
412 .WillOnce(DoAll( 413 .WillOnce(DoAll(
413 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &ack_listener))), 414 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &ack_listener))),
414 Return(QuicConsumedData(kFirstWriteSize, false)))); 415 Return(QuicConsumedData(kFirstWriteSize, false))));
415 stream_->WriteOrBufferData(kData, false, delegate.get()); 416 stream_->WriteOrBufferData(kData, false, delegate.get());
416 EXPECT_TRUE(HasWriteBlockedStreams()); 417 EXPECT_TRUE(HasWriteBlockedStreams());
417 418
418 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get())) 419 EXPECT_CALL(*session_,
420 WritevData(stream_, kTestStreamId, _, _, _, ack_listener.get()))
419 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false))); 421 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false)));
420 stream_->OnCanWrite(); 422 stream_->OnCanWrite();
421 423
422 // No ack expected for an empty write. 424 // No ack expected for an empty write.
423 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get())) 425 EXPECT_CALL(*session_,
426 WritevData(stream_, kTestStreamId, _, _, _, ack_listener.get()))
424 .WillOnce(Return(QuicConsumedData(0, false))); 427 .WillOnce(Return(QuicConsumedData(0, false)));
425 stream_->OnCanWrite(); 428 stream_->OnCanWrite();
426 429
427 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get())) 430 EXPECT_CALL(*session_,
431 WritevData(stream_, kTestStreamId, _, _, _, ack_listener.get()))
428 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); 432 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false)));
429 stream_->OnCanWrite(); 433 stream_->OnCanWrite();
430 } 434 }
431 435
432 // Verify delegate behavior when packets are acked before the WritevData call 436 // Verify delegate behavior when packets are acked before the WritevData call
433 // that sends out the last byte. 437 // that sends out the last byte.
434 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { 438 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) {
435 Initialize(kShouldProcessData); 439 Initialize(kShouldProcessData);
436 440
437 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>); 441 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>);
438 442
439 const int kDataSize = 16 * 1024; 443 const int kDataSize = 16 * 1024;
440 const string kData(kDataSize, 'a'); 444 const string kData(kDataSize, 'a');
441 445
442 const int kInitialWriteSize = 100; 446 const int kInitialWriteSize = 100;
443 447
444 // Set a large flow control send window so this doesn't interfere with test. 448 // Set a large flow control send window so this doesn't interfere with test.
445 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 449 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
446 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 450 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
447 451
448 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 452 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
449 453
450 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 454 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
451 .WillOnce(DoAll( 455 .WillOnce(DoAll(
452 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 456 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
453 Return(QuicConsumedData(kInitialWriteSize, false)))); 457 Return(QuicConsumedData(kInitialWriteSize, false))));
454 stream_->WriteOrBufferData(kData, false, ack_listener.get()); 458 stream_->WriteOrBufferData(kData, false, ack_listener.get());
455 EXPECT_TRUE(HasWriteBlockedStreams()); 459 EXPECT_TRUE(HasWriteBlockedStreams());
456 460
457 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 461 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
458 .WillOnce(DoAll( 462 .WillOnce(DoAll(
459 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 463 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
460 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); 464 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false))));
461 stream_->OnCanWrite(); 465 stream_->OnCanWrite();
462 } 466 }
463 467
464 // Verify delegate behavior when WriteOrBufferData does not buffer. 468 // Verify delegate behavior when WriteOrBufferData does not buffer.
465 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { 469 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) {
466 Initialize(kShouldProcessData); 470 Initialize(kShouldProcessData);
467 471
468 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 472 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
469 473
470 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 474 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
471 475
472 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 476 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
473 .WillOnce(DoAll( 477 .WillOnce(DoAll(
474 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 478 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
475 Return(QuicConsumedData(kDataLen, true)))); 479 Return(QuicConsumedData(kDataLen, true))));
476 stream_->WriteOrBufferData(kData1, true, delegate.get()); 480 stream_->WriteOrBufferData(kData1, true, delegate.get());
477 EXPECT_FALSE(HasWriteBlockedStreams()); 481 EXPECT_FALSE(HasWriteBlockedStreams());
478 } 482 }
479 483
480 // Verify delegate behavior when WriteOrBufferData buffers all the data. 484 // Verify delegate behavior when WriteOrBufferData buffers all the data.
481 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { 485 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) {
482 Initialize(kShouldProcessData); 486 Initialize(kShouldProcessData);
483 487
484 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 488 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
485 489
486 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 490 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
487 491
488 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 492 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
489 .WillOnce(Return(QuicConsumedData(0, false))); 493 .WillOnce(Return(QuicConsumedData(0, false)));
490 stream_->WriteOrBufferData(kData1, true, delegate.get()); 494 stream_->WriteOrBufferData(kData1, true, delegate.get());
491 EXPECT_TRUE(HasWriteBlockedStreams()); 495 EXPECT_TRUE(HasWriteBlockedStreams());
492 496
493 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 497 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
494 .WillOnce(DoAll( 498 .WillOnce(DoAll(
495 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 499 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
496 Return(QuicConsumedData(kDataLen, true)))); 500 Return(QuicConsumedData(kDataLen, true))));
497 stream_->OnCanWrite(); 501 stream_->OnCanWrite();
498 } 502 }
499 503
500 // Verify delegate behavior when WriteOrBufferData when the FIN is 504 // Verify delegate behavior when WriteOrBufferData when the FIN is
501 // sent out in a different packet. 505 // sent out in a different packet.
502 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { 506 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) {
503 Initialize(kShouldProcessData); 507 Initialize(kShouldProcessData);
504 508
505 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 509 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
506 510
507 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 511 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
508 512
509 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 513 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
510 .WillOnce(DoAll( 514 .WillOnce(DoAll(
511 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 515 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
512 Return(QuicConsumedData(kDataLen, false)))); 516 Return(QuicConsumedData(kDataLen, false))));
513 stream_->WriteOrBufferData(kData1, true, delegate.get()); 517 stream_->WriteOrBufferData(kData1, true, delegate.get());
514 EXPECT_TRUE(HasWriteBlockedStreams()); 518 EXPECT_TRUE(HasWriteBlockedStreams());
515 519
516 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 520 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
517 .WillOnce(DoAll( 521 .WillOnce(DoAll(
518 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 522 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
519 Return(QuicConsumedData(0, true)))); 523 Return(QuicConsumedData(0, true))));
520 stream_->OnCanWrite(); 524 stream_->OnCanWrite();
521 } 525 }
522 526
523 // Verify that when we receive a packet which violates flow control (i.e. sends 527 // Verify that when we receive a packet which violates flow control (i.e. sends
524 // too much data on the stream) that the stream sequencer never sees this frame, 528 // too much data on the stream) that the stream sequencer never sees this frame,
525 // as we check for violation and close the connection early. 529 // as we check for violation and close the connection early.
526 TEST_F(ReliableQuicStreamTest, 530 TEST_F(ReliableQuicStreamTest,
527 StreamSequencerNeverSeesPacketsViolatingFlowControl) { 531 StreamSequencerNeverSeesPacketsViolatingFlowControl) {
528 Initialize(kShouldProcessData); 532 Initialize(kShouldProcessData);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 StringPiece(".")); 604 StringPiece("."));
601 stream_->OnStreamFrame(stream_frame_with_fin); 605 stream_->OnStreamFrame(stream_frame_with_fin);
602 // The FIN has been received but not consumed. 606 // The FIN has been received but not consumed.
603 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 607 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
604 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 608 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_));
605 EXPECT_FALSE(stream_->reading_stopped()); 609 EXPECT_FALSE(stream_->reading_stopped());
606 610
607 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 611 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
608 612
609 // Outgoing data with FIN. 613 // Outgoing data with FIN.
610 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 614 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
611 .WillOnce(Return(QuicConsumedData(2, true))); 615 .WillOnce(Return(QuicConsumedData(2, true)));
612 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 616 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
613 EXPECT_TRUE(stream_->write_side_closed()); 617 EXPECT_TRUE(stream_->write_side_closed());
614 618
615 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 619 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
616 ->count(kTestStreamId)); 620 ->count(kTestStreamId));
617 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 621 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
618 } 622 }
619 623
620 TEST_F(ReliableQuicStreamTest, SetDrainingOutgoingIncoming) { 624 TEST_F(ReliableQuicStreamTest, SetDrainingOutgoingIncoming) {
621 // Don't have incoming data consumed. 625 // Don't have incoming data consumed.
622 Initialize(kShouldNotProcessData); 626 Initialize(kShouldNotProcessData);
623 627
624 // Outgoing data with FIN. 628 // Outgoing data with FIN.
625 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _)) 629 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
626 .WillOnce(Return(QuicConsumedData(2, true))); 630 .WillOnce(Return(QuicConsumedData(2, true)));
627 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 631 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
628 EXPECT_TRUE(stream_->write_side_closed()); 632 EXPECT_TRUE(stream_->write_side_closed());
629 633
630 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 634 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
631 635
632 // Incoming data with FIN. 636 // Incoming data with FIN.
633 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 637 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
634 StringPiece(".")); 638 StringPiece("."));
635 stream_->OnStreamFrame(stream_frame_with_fin); 639 stream_->OnStreamFrame(stream_frame_with_fin);
636 // The FIN has been received but not consumed. 640 // The FIN has been received but not consumed.
637 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 641 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
638 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 642 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_));
639 EXPECT_FALSE(stream_->reading_stopped()); 643 EXPECT_FALSE(stream_->reading_stopped());
640 644
641 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 645 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
642 ->count(kTestStreamId)); 646 ->count(kTestStreamId));
643 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 647 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
644 } 648 }
645 649
646 TEST_F(ReliableQuicStreamTest, EarlyResponseFinHandling) { 650 TEST_F(ReliableQuicStreamTest, EarlyResponseFinHandling) {
647 // Verify that if the server completes the response before reading the end of 651 // Verify that if the server completes the response before reading the end of
648 // the request, the received FIN is recorded. 652 // the request, the received FIN is recorded.
649 653
650 Initialize(kShouldProcessData); 654 Initialize(kShouldProcessData);
651 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 655 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
652 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)) 656 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
653 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 657 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
654 658
655 // Receive data for the request. 659 // Receive data for the request.
656 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start")); 660 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start"));
657 stream_->OnStreamFrame(frame1); 661 stream_->OnStreamFrame(frame1);
658 // When QuicSimpleServerStream sends the response, it calls 662 // When QuicSimpleServerStream sends the response, it calls
659 // ReliableQuicStream::CloseReadSide() first. 663 // ReliableQuicStream::CloseReadSide() first.
660 ReliableQuicStreamPeer::CloseReadSide(stream_); 664 ReliableQuicStreamPeer::CloseReadSide(stream_);
661 // Send data and FIN for the response. 665 // Send data and FIN for the response.
662 stream_->WriteOrBufferData(kData1, false, nullptr); 666 stream_->WriteOrBufferData(kData1, false, nullptr);
663 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream_)); 667 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream_));
664 // Receive remaining data and FIN for the request. 668 // Receive remaining data and FIN for the request.
665 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End")); 669 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End"));
666 stream_->OnStreamFrame(frame2); 670 stream_->OnStreamFrame(frame2);
667 EXPECT_TRUE(stream_->fin_received()); 671 EXPECT_TRUE(stream_->fin_received());
668 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 672 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
669 } 673 }
670 674
671 } // namespace 675 } // namespace
672 } // namespace test 676 } // namespace test
673 } // namespace net 677 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_sent_packet_manager_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698