OLD | NEW |
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 "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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 .WillOnce(Return(QuicConsumedData(0, false))); | 468 .WillOnce(Return(QuicConsumedData(0, false))); |
469 stream_->OnCanWrite(); | 469 stream_->OnCanWrite(); |
470 | 470 |
471 EXPECT_CALL(*session_, | 471 EXPECT_CALL(*session_, |
472 WritevData(kHeadersStreamId, _, _, _, _, proxy_delegate.get())) | 472 WritevData(kHeadersStreamId, _, _, _, _, proxy_delegate.get())) |
473 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); | 473 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); |
474 stream_->OnCanWrite(); | 474 stream_->OnCanWrite(); |
475 | 475 |
476 // There were two writes, so OnAckNotification is not propagated | 476 // There were two writes, so OnAckNotification is not propagated |
477 // until the third Ack arrives. | 477 // until the third Ack arrives. |
478 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 478 proxy_delegate->OnAckNotification(3, 4, zero_); |
479 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); | 479 proxy_delegate->OnAckNotification(30, 40, zero_); |
480 | 480 |
481 // The arguments to delegate->OnAckNotification are the sum of the | 481 // The arguments to delegate->OnAckNotification are the sum of the |
482 // arguments to proxy_delegate OnAckNotification calls. | 482 // arguments to proxy_delegate OnAckNotification calls. |
483 EXPECT_CALL(*delegate.get(), OnAckNotification(111, 222, 333, 444, zero_)); | 483 EXPECT_CALL(*delegate.get(), OnAckNotification(333, 444, zero_)); |
484 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); | 484 proxy_delegate->OnAckNotification(300, 400, zero_); |
485 } | 485 } |
486 | 486 |
487 // Verify delegate behavior when packets are acked before the | 487 // Verify delegate behavior when packets are acked before the |
488 // WritevData call that sends out the last byte. | 488 // WritevData call that sends out the last byte. |
489 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { | 489 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { |
490 Initialize(kShouldProcessData); | 490 Initialize(kShouldProcessData); |
491 | 491 |
492 scoped_refptr<MockAckNotifierDelegate> delegate( | 492 scoped_refptr<MockAckNotifierDelegate> delegate( |
493 new StrictMock<MockAckNotifierDelegate>); | 493 new StrictMock<MockAckNotifierDelegate>); |
494 | 494 |
495 const int kDataSize = 16 * 1024; | 495 const int kDataSize = 16 * 1024; |
496 const string kData(kDataSize, 'a'); | 496 const string kData(kDataSize, 'a'); |
497 | 497 |
498 const int kInitialWriteSize = 100; | 498 const int kInitialWriteSize = 100; |
499 | 499 |
500 // Set a large flow control send window so this doesn't interfere with test. | 500 // Set a large flow control send window so this doesn't interfere with test. |
501 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 501 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
502 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 502 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
503 | 503 |
504 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 504 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
505 | 505 |
506 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 506 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
507 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( | 507 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
508 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 508 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
509 Return(QuicConsumedData(kInitialWriteSize, false)))); | 509 Return(QuicConsumedData(kInitialWriteSize, false)))); |
510 stream_->WriteOrBufferData(kData, false, delegate.get()); | 510 stream_->WriteOrBufferData(kData, false, delegate.get()); |
511 EXPECT_TRUE(HasWriteBlockedStreams()); | 511 EXPECT_TRUE(HasWriteBlockedStreams()); |
512 | 512 |
513 // Handle the ack of the first write. | 513 // Handle the ack of the first write. |
514 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 514 proxy_delegate->OnAckNotification(3, 4, zero_); |
515 proxy_delegate = nullptr; | 515 proxy_delegate = nullptr; |
516 | 516 |
517 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)).WillOnce( | 517 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)).WillOnce( |
518 DoAll(WithArgs<5>(Invoke(CreateFunctor( | 518 DoAll(WithArgs<5>(Invoke(CreateFunctor( |
519 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 519 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
520 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); | 520 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); |
521 stream_->OnCanWrite(); | 521 stream_->OnCanWrite(); |
522 | 522 |
523 // Handle the ack for the second write. | 523 // Handle the ack for the second write. |
524 EXPECT_CALL(*delegate.get(), OnAckNotification(101, 202, 303, 404, zero_)); | 524 EXPECT_CALL(*delegate.get(), OnAckNotification(303, 404, zero_)); |
525 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); | 525 proxy_delegate->OnAckNotification(300, 400, zero_); |
526 } | 526 } |
527 | 527 |
528 // Verify delegate behavior when WriteOrBufferData does not buffer. | 528 // Verify delegate behavior when WriteOrBufferData does not buffer. |
529 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { | 529 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { |
530 Initialize(kShouldProcessData); | 530 Initialize(kShouldProcessData); |
531 | 531 |
532 scoped_refptr<MockAckNotifierDelegate> delegate( | 532 scoped_refptr<MockAckNotifierDelegate> delegate( |
533 new StrictMock<MockAckNotifierDelegate>); | 533 new StrictMock<MockAckNotifierDelegate>); |
534 | 534 |
535 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 535 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
536 | 536 |
537 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 537 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
538 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( | 538 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
539 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 539 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
540 Return(QuicConsumedData(kDataLen, true)))); | 540 Return(QuicConsumedData(kDataLen, true)))); |
541 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 541 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
542 EXPECT_FALSE(HasWriteBlockedStreams()); | 542 EXPECT_FALSE(HasWriteBlockedStreams()); |
543 | 543 |
544 // Handle the ack. | 544 // Handle the ack. |
545 EXPECT_CALL(*delegate.get(), OnAckNotification(1, 2, 3, 4, zero_)); | 545 EXPECT_CALL(*delegate.get(), OnAckNotification(3, 4, zero_)); |
546 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 546 proxy_delegate->OnAckNotification(3, 4, zero_); |
547 } | 547 } |
548 | 548 |
549 // Verify delegate behavior when WriteOrBufferData buffers all the data. | 549 // Verify delegate behavior when WriteOrBufferData buffers all the data. |
550 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { | 550 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { |
551 Initialize(kShouldProcessData); | 551 Initialize(kShouldProcessData); |
552 | 552 |
553 scoped_refptr<MockAckNotifierDelegate> delegate( | 553 scoped_refptr<MockAckNotifierDelegate> delegate( |
554 new StrictMock<MockAckNotifierDelegate>); | 554 new StrictMock<MockAckNotifierDelegate>); |
555 | 555 |
556 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 556 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
557 | 557 |
558 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 558 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
559 .WillOnce(Return(QuicConsumedData(0, false))); | 559 .WillOnce(Return(QuicConsumedData(0, false))); |
560 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 560 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
561 EXPECT_TRUE(HasWriteBlockedStreams()); | 561 EXPECT_TRUE(HasWriteBlockedStreams()); |
562 | 562 |
563 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 563 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
564 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( | 564 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
565 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 565 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
566 Return(QuicConsumedData(kDataLen, true)))); | 566 Return(QuicConsumedData(kDataLen, true)))); |
567 stream_->OnCanWrite(); | 567 stream_->OnCanWrite(); |
568 | 568 |
569 // Handle the ack. | 569 // Handle the ack. |
570 EXPECT_CALL(*delegate.get(), OnAckNotification(1, 2, 3, 4, zero_)); | 570 EXPECT_CALL(*delegate.get(), OnAckNotification(3, 4, zero_)); |
571 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 571 proxy_delegate->OnAckNotification(3, 4, zero_); |
572 } | 572 } |
573 | 573 |
574 // Verify delegate behavior when WriteOrBufferData when the FIN is | 574 // Verify delegate behavior when WriteOrBufferData when the FIN is |
575 // sent out in a different packet. | 575 // sent out in a different packet. |
576 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { | 576 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { |
577 Initialize(kShouldProcessData); | 577 Initialize(kShouldProcessData); |
578 | 578 |
579 scoped_refptr<MockAckNotifierDelegate> delegate( | 579 scoped_refptr<MockAckNotifierDelegate> delegate( |
580 new StrictMock<MockAckNotifierDelegate>); | 580 new StrictMock<MockAckNotifierDelegate>); |
581 | 581 |
582 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 582 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
583 | 583 |
584 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 584 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
585 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( | 585 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
586 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 586 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
587 Return(QuicConsumedData(kDataLen, false)))); | 587 Return(QuicConsumedData(kDataLen, false)))); |
588 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 588 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
589 EXPECT_TRUE(HasWriteBlockedStreams()); | 589 EXPECT_TRUE(HasWriteBlockedStreams()); |
590 | 590 |
591 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) | 591 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
592 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( | 592 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
593 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 593 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
594 Return(QuicConsumedData(0, true)))); | 594 Return(QuicConsumedData(0, true)))); |
595 stream_->OnCanWrite(); | 595 stream_->OnCanWrite(); |
596 | 596 |
597 // Handle the acks. | 597 // Handle the acks. |
598 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 598 proxy_delegate->OnAckNotification(3, 4, zero_); |
599 EXPECT_CALL(*delegate.get(), OnAckNotification(11, 22, 33, 44, zero_)); | 599 EXPECT_CALL(*delegate.get(), OnAckNotification(33, 44, zero_)); |
600 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); | 600 proxy_delegate->OnAckNotification(30, 40, zero_); |
601 } | 601 } |
602 | 602 |
603 // Verify that when we receive a packet which violates flow control (i.e. sends | 603 // Verify that when we receive a packet which violates flow control (i.e. sends |
604 // too much data on the stream) that the stream sequencer never sees this frame, | 604 // too much data on the stream) that the stream sequencer never sees this frame, |
605 // as we check for violation and close the connection early. | 605 // as we check for violation and close the connection early. |
606 TEST_F(ReliableQuicStreamTest, | 606 TEST_F(ReliableQuicStreamTest, |
607 StreamSequencerNeverSeesPacketsViolatingFlowControl) { | 607 StreamSequencerNeverSeesPacketsViolatingFlowControl) { |
608 Initialize(kShouldProcessData); | 608 Initialize(kShouldProcessData); |
609 | 609 |
610 // Receive a stream frame that violates flow control: the byte offset is | 610 // Receive a stream frame that violates flow control: the byte offset is |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 642 |
643 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); | 643 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); |
644 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); | 644 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
645 stream_->OnStreamReset(rst_frame); | 645 stream_->OnStreamReset(rst_frame); |
646 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); | 646 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); |
647 } | 647 } |
648 | 648 |
649 } // namespace | 649 } // namespace |
650 } // namespace test | 650 } // namespace test |
651 } // namespace net | 651 } // namespace net |
OLD | NEW |