OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_data_stream.h" | 5 #include "net/quic/quic_data_stream.h" |
6 | 6 |
7 #include "net/quic/quic_ack_notifier.h" | 7 #include "net/quic/quic_ack_notifier.h" |
8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
9 #include "net/quic/quic_utils.h" | 9 #include "net/quic/quic_utils.h" |
10 #include "net/quic/quic_write_blocked_list.h" | 10 #include "net/quic/quic_write_blocked_list.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 size_t bytes_read = stream_->Readv(vec, 2); | 274 size_t bytes_read = stream_->Readv(vec, 2); |
275 ASSERT_EQ(2u, bytes_read) << i; | 275 ASSERT_EQ(2u, bytes_read) << i; |
276 ASSERT_EQ(data.data()[i], buffer1[0]) << i; | 276 ASSERT_EQ(data.data()[i], buffer1[0]) << i; |
277 ASSERT_EQ(data.data()[i + 1], buffer2[0]) << i; | 277 ASSERT_EQ(data.data()[i + 1], buffer2[0]) << i; |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 TEST_P(QuicDataStreamTest, StreamFlowControlBlocked) { | 281 TEST_P(QuicDataStreamTest, StreamFlowControlBlocked) { |
282 // Tests that we send a BLOCKED frame to the peer when we attempt to write, | 282 // Tests that we send a BLOCKED frame to the peer when we attempt to write, |
283 // but are flow control blocked. | 283 // but are flow control blocked. |
284 if (GetParam() <= QUIC_VERSION_16) { | |
285 return; | |
286 } | |
287 | |
288 Initialize(kShouldProcessData); | 284 Initialize(kShouldProcessData); |
289 | 285 |
290 // Set a small flow control limit. | 286 // Set a small flow control limit. |
291 const uint64 kWindow = 36; | 287 const uint64 kWindow = 36; |
292 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), | 288 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), |
293 kWindow); | 289 kWindow); |
294 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( | 290 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( |
295 stream_->flow_controller())); | 291 stream_->flow_controller())); |
296 | 292 |
297 // Try to send more data than the flow control limit allows. | 293 // Try to send more data than the flow control limit allows. |
(...skipping 14 matching lines...) Expand all Loading... |
312 // And we should have queued the overflowed data. | 308 // And we should have queued the overflowed data. |
313 EXPECT_EQ(kOverflow, | 309 EXPECT_EQ(kOverflow, |
314 ReliableQuicStreamPeer::SizeOfQueuedData(stream_.get())); | 310 ReliableQuicStreamPeer::SizeOfQueuedData(stream_.get())); |
315 } | 311 } |
316 | 312 |
317 TEST_P(QuicDataStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { | 313 TEST_P(QuicDataStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { |
318 // The flow control receive window decreases whenever we add new bytes to the | 314 // The flow control receive window decreases whenever we add new bytes to the |
319 // sequencer, whether they are consumed immediately or buffered. However we | 315 // sequencer, whether they are consumed immediately or buffered. However we |
320 // only send WINDOW_UPDATE frames based on increasing number of bytes | 316 // only send WINDOW_UPDATE frames based on increasing number of bytes |
321 // consumed. | 317 // consumed. |
322 if (GetParam() <= QUIC_VERSION_16) { | |
323 return; | |
324 } | |
325 | 318 |
326 // Don't process data - it will be buffered instead. | 319 // Don't process data - it will be buffered instead. |
327 Initialize(!kShouldProcessData); | 320 Initialize(!kShouldProcessData); |
328 | 321 |
329 // Expect no WINDOW_UPDATE frames to be sent. | 322 // Expect no WINDOW_UPDATE frames to be sent. |
330 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0); | 323 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0); |
331 | 324 |
332 // Set a small flow control receive window. | 325 // Set a small flow control receive window. |
333 const uint64 kWindow = 36; | 326 const uint64 kWindow = 36; |
334 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 327 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
(...skipping 24 matching lines...) Expand all Loading... |
359 stream_->OnStreamFrame(frame2); | 352 stream_->OnStreamFrame(frame2); |
360 EXPECT_EQ( | 353 EXPECT_EQ( |
361 kWindow - (2 * kWindow / 3), | 354 kWindow - (2 * kWindow / 3), |
362 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller())); | 355 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller())); |
363 } | 356 } |
364 | 357 |
365 TEST_P(QuicDataStreamTest, StreamFlowControlWindowUpdate) { | 358 TEST_P(QuicDataStreamTest, StreamFlowControlWindowUpdate) { |
366 // Tests that on receipt of data, the stream updates its receive window offset | 359 // Tests that on receipt of data, the stream updates its receive window offset |
367 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops | 360 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops |
368 // too low. | 361 // too low. |
369 if (GetParam() <= QUIC_VERSION_16) { | |
370 return; | |
371 } | |
372 | |
373 Initialize(kShouldProcessData); | 362 Initialize(kShouldProcessData); |
374 | 363 |
375 // Set a small flow control limit. | 364 // Set a small flow control limit. |
376 const uint64 kWindow = 36; | 365 const uint64 kWindow = 36; |
377 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 366 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
378 kWindow); | 367 kWindow); |
379 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 368 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
380 kWindow); | 369 kWindow); |
381 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( | 370 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( |
382 stream_->flow_controller())); | 371 stream_->flow_controller())); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 session_->flow_controller()) + | 449 session_->flow_controller()) + |
461 1 + kWindow / 2)); | 450 1 + kWindow / 2)); |
462 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4), | 451 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4), |
463 MakeIOVector("a")); | 452 MakeIOVector("a")); |
464 stream_->OnStreamFrame(frame3); | 453 stream_->OnStreamFrame(frame3); |
465 } | 454 } |
466 | 455 |
467 TEST_P(QuicDataStreamTest, StreamFlowControlViolation) { | 456 TEST_P(QuicDataStreamTest, StreamFlowControlViolation) { |
468 // Tests that on if the peer sends too much data (i.e. violates the flow | 457 // Tests that on if the peer sends too much data (i.e. violates the flow |
469 // control protocol), then we terminate the connection. | 458 // control protocol), then we terminate the connection. |
470 if (GetParam() <= QUIC_VERSION_16) { | |
471 return; | |
472 } | |
473 | 459 |
474 // Stream should not process data, so that data gets buffered in the | 460 // Stream should not process data, so that data gets buffered in the |
475 // sequencer, triggering flow control limits. | 461 // sequencer, triggering flow control limits. |
476 Initialize(!kShouldProcessData); | 462 Initialize(!kShouldProcessData); |
477 | 463 |
478 // Set a small flow control limit. | 464 // Set a small flow control limit. |
479 const uint64 kWindow = 50; | 465 const uint64 kWindow = 50; |
480 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 466 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
481 kWindow); | 467 kWindow); |
482 | 468 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body)); | 512 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body)); |
527 | 513 |
528 EXPECT_CALL(*connection_, | 514 EXPECT_CALL(*connection_, |
529 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)); | 515 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)); |
530 stream_->OnStreamFrame(frame); | 516 stream_->OnStreamFrame(frame); |
531 } | 517 } |
532 | 518 |
533 TEST_P(QuicDataStreamTest, StreamFlowControlFinNotBlocked) { | 519 TEST_P(QuicDataStreamTest, StreamFlowControlFinNotBlocked) { |
534 // An attempt to write a FIN with no data should not be flow control blocked, | 520 // An attempt to write a FIN with no data should not be flow control blocked, |
535 // even if the send window is 0. | 521 // even if the send window is 0. |
536 if (GetParam() <= QUIC_VERSION_16) { | |
537 return; | |
538 } | |
539 | 522 |
540 Initialize(kShouldProcessData); | 523 Initialize(kShouldProcessData); |
541 | 524 |
542 // Set a flow control limit of zero. | 525 // Set a flow control limit of zero. |
543 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0); | 526 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0); |
544 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset( | 527 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset( |
545 stream_->flow_controller())); | 528 stream_->flow_controller())); |
546 | 529 |
547 // Send a frame with a FIN but no data. This should not be blocked. | 530 // Send a frame with a FIN but no data. This should not be blocked. |
548 string body = ""; | 531 string body = ""; |
549 bool fin = true; | 532 bool fin = true; |
550 | 533 |
551 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); | 534 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); |
552 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) | 535 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) |
553 .WillOnce(Return(QuicConsumedData(0, fin))); | 536 .WillOnce(Return(QuicConsumedData(0, fin))); |
554 | 537 |
555 stream_->WriteOrBufferData(body, fin, NULL); | 538 stream_->WriteOrBufferData(body, fin, NULL); |
556 } | 539 } |
557 | 540 |
558 } // namespace | 541 } // namespace |
559 } // namespace test | 542 } // namespace test |
560 } // namespace net | 543 } // namespace net |
OLD | NEW |