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/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 private: | 178 private: |
179 StrictMock<TestCryptoStream> crypto_stream_; | 179 StrictMock<TestCryptoStream> crypto_stream_; |
180 | 180 |
181 bool writev_consumes_all_data_; | 181 bool writev_consumes_all_data_; |
182 }; | 182 }; |
183 | 183 |
184 class QuicSessionTest : public ::testing::TestWithParam<QuicVersion> { | 184 class QuicSessionTest : public ::testing::TestWithParam<QuicVersion> { |
185 protected: | 185 protected: |
186 QuicSessionTest() | 186 QuicSessionTest() |
187 : connection_(new MockConnection(true, SupportedVersions(GetParam()))), | 187 : connection_( |
| 188 new StrictMock<MockConnection>(true, |
| 189 SupportedVersions(GetParam()))), |
188 session_(connection_) { | 190 session_(connection_) { |
189 session_.config()->SetInitialStreamFlowControlWindowToSend( | 191 session_.config()->SetInitialStreamFlowControlWindowToSend( |
190 kInitialStreamFlowControlWindowForTest); | 192 kInitialStreamFlowControlWindowForTest); |
191 session_.config()->SetInitialSessionFlowControlWindowToSend( | 193 session_.config()->SetInitialSessionFlowControlWindowToSend( |
192 kInitialSessionFlowControlWindowForTest); | 194 kInitialSessionFlowControlWindowForTest); |
193 headers_[":host"] = "www.google.com"; | 195 headers_[":host"] = "www.google.com"; |
194 headers_[":path"] = "/index.hml"; | 196 headers_[":path"] = "/index.hml"; |
195 headers_[":scheme"] = "http"; | 197 headers_[":scheme"] = "http"; |
196 headers_["cookie"] = | 198 headers_["cookie"] = |
197 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 199 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
(...skipping 26 matching lines...) Expand all Loading... |
224 for (int i = kCryptoStreamId; i < 100; i++) { | 226 for (int i = kCryptoStreamId; i < 100; i++) { |
225 if (!ContainsKey(closed_streams_, i)) { | 227 if (!ContainsKey(closed_streams_, i)) { |
226 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i; | 228 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i; |
227 } else { | 229 } else { |
228 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; | 230 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; |
229 } | 231 } |
230 } | 232 } |
231 } | 233 } |
232 | 234 |
233 void CloseStream(QuicStreamId id) { | 235 void CloseStream(QuicStreamId id) { |
| 236 EXPECT_CALL(*connection_, SendRstStream(id, _, _)); |
234 session_.CloseStream(id); | 237 session_.CloseStream(id); |
235 closed_streams_.insert(id); | 238 closed_streams_.insert(id); |
236 } | 239 } |
237 | 240 |
238 QuicVersion version() const { return connection_->version(); } | 241 QuicVersion version() const { return connection_->version(); } |
239 | 242 |
240 MockConnection* connection_; | 243 StrictMock<MockConnection>* connection_; |
241 TestSession session_; | 244 TestSession session_; |
242 set<QuicStreamId> closed_streams_; | 245 set<QuicStreamId> closed_streams_; |
243 SpdyHeaderBlock headers_; | 246 SpdyHeaderBlock headers_; |
244 }; | 247 }; |
245 | 248 |
246 INSTANTIATE_TEST_CASE_P(Tests, QuicSessionTest, | 249 INSTANTIATE_TEST_CASE_P(Tests, QuicSessionTest, |
247 ::testing::ValuesIn(QuicSupportedVersions())); | 250 ::testing::ValuesIn(QuicSupportedVersions())); |
248 | 251 |
249 TEST_P(QuicSessionTest, PeerAddress) { | 252 TEST_P(QuicSessionTest, PeerAddress) { |
250 EXPECT_EQ(IPEndPoint(Loopback4(), kTestPort), session_.peer_address()); | 253 EXPECT_EQ(IPEndPoint(Loopback4(), kTestPort), session_.peer_address()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 }; | 329 }; |
327 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | 330 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
328 QUIC_INVALID_HEADERS_STREAM_DATA, | 331 QUIC_INVALID_HEADERS_STREAM_DATA, |
329 "SPDY framing error: DECOMPRESS_FAILURE")); | 332 "SPDY framing error: DECOMPRESS_FAILURE")); |
330 stream->ProcessRawData(reinterpret_cast<const char*>(data), | 333 stream->ProcessRawData(reinterpret_cast<const char*>(data), |
331 arraysize(data)); | 334 arraysize(data)); |
332 } | 335 } |
333 | 336 |
334 TEST_P(QuicSessionTest, DebugDFatalIfMarkingClosedStreamWriteBlocked) { | 337 TEST_P(QuicSessionTest, DebugDFatalIfMarkingClosedStreamWriteBlocked) { |
335 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 338 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
| 339 QuicStreamId kClosedStreamId = stream2->id(); |
336 // Close the stream. | 340 // Close the stream. |
| 341 EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _)); |
337 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 342 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
338 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL. | 343 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL. |
339 /* | 344 /* |
340 QuicStreamId kClosedStreamId = stream2->id(); | |
341 EXPECT_DEBUG_DFATAL( | 345 EXPECT_DEBUG_DFATAL( |
342 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority), | 346 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority), |
343 "Marking unknown stream 2 blocked."); | 347 "Marking unknown stream 2 blocked."); |
344 */ | 348 */ |
345 } | 349 } |
346 | 350 |
347 TEST_P(QuicSessionTest, DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) { | 351 TEST_P(QuicSessionTest, DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) { |
348 const QuicPriority kDifferentPriority = 0; | 352 const QuicPriority kDifferentPriority = 0; |
349 | 353 |
350 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 354 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 586 } |
583 | 587 |
584 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { | 588 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { |
585 // Send two bytes of payload. | 589 // Send two bytes of payload. |
586 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); | 590 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); |
587 vector<QuicStreamFrame> frames; | 591 vector<QuicStreamFrame> frames; |
588 frames.push_back(data1); | 592 frames.push_back(data1); |
589 session_.OnStreamFrames(frames); | 593 session_.OnStreamFrames(frames); |
590 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 594 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
591 | 595 |
| 596 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _)); |
592 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); | 597 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
593 session_.OnRstStream(rst1); | 598 session_.OnRstStream(rst1); |
594 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 599 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
595 // Connection should remain alive. | 600 // Connection should remain alive. |
596 EXPECT_TRUE(connection_->connected()); | 601 EXPECT_TRUE(connection_->connected()); |
597 } | 602 } |
598 | 603 |
599 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { | 604 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { |
600 // If multiple invalid reset stream frames arrive in a single packet, this | 605 // If multiple invalid reset stream frames arrive in a single packet, this |
601 // should trigger a connection close. However there is no need to send | 606 // should trigger a connection close. However there is no need to send |
(...skipping 28 matching lines...) Expand all Loading... |
630 // Ensure that Writev consumes all the data it is given (simulate no socket | 635 // Ensure that Writev consumes all the data it is given (simulate no socket |
631 // blocking). | 636 // blocking). |
632 session_.set_writev_consumes_all_data(true); | 637 session_.set_writev_consumes_all_data(true); |
633 | 638 |
634 // Create a stream, and send enough data to make it flow control blocked. | 639 // Create a stream, and send enough data to make it flow control blocked. |
635 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 640 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
636 string body(kMinimumFlowControlSendWindow, '.'); | 641 string body(kMinimumFlowControlSendWindow, '.'); |
637 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); | 642 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); |
638 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 643 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
639 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 644 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
| 645 EXPECT_CALL(*connection_, SendBlocked(stream2->id())); |
| 646 EXPECT_CALL(*connection_, SendBlocked(0)); |
640 stream2->SendBody(body, false); | 647 stream2->SendBody(body, false); |
641 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); | 648 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); |
642 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked()); | 649 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked()); |
643 EXPECT_TRUE(session_.IsStreamFlowControlBlocked()); | 650 EXPECT_TRUE(session_.IsStreamFlowControlBlocked()); |
644 | 651 |
645 // The handshake message will call OnCanWrite, so the stream can resume | 652 // The handshake message will call OnCanWrite, so the stream can resume |
646 // writing. | 653 // writing. |
647 EXPECT_CALL(*stream2, OnCanWrite()); | 654 EXPECT_CALL(*stream2, OnCanWrite()); |
648 // Now complete the crypto handshake, resulting in an increased flow control | 655 // Now complete the crypto handshake, resulting in an increased flow control |
649 // send window. | 656 // send window. |
(...skipping 13 matching lines...) Expand all Loading... |
663 TestCryptoStream* crypto_stream = session_.GetCryptoStream(); | 670 TestCryptoStream* crypto_stream = session_.GetCryptoStream(); |
664 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked()); | 671 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked()); |
665 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 672 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
666 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 673 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
667 QuicHeadersStream* headers_stream = | 674 QuicHeadersStream* headers_stream = |
668 QuicSessionPeer::GetHeadersStream(&session_); | 675 QuicSessionPeer::GetHeadersStream(&session_); |
669 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); | 676 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); |
670 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 677 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
671 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 678 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
672 // Write until the crypto stream is flow control blocked. | 679 // Write until the crypto stream is flow control blocked. |
| 680 EXPECT_CALL(*connection_, SendBlocked(kCryptoStreamId)); |
673 int i = 0; | 681 int i = 0; |
674 while (!crypto_stream->flow_controller()->IsBlocked() && i < 1000) { | 682 while (!crypto_stream->flow_controller()->IsBlocked() && i < 1000) { |
675 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 683 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
676 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 684 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
677 QuicConfig config; | 685 QuicConfig config; |
678 CryptoHandshakeMessage crypto_message; | 686 CryptoHandshakeMessage crypto_message; |
679 config.ToHandshakeMessage(&crypto_message); | 687 config.ToHandshakeMessage(&crypto_message); |
680 crypto_stream->SendHandshakeMessage(crypto_message); | 688 crypto_stream->SendHandshakeMessage(crypto_message); |
681 ++i; | 689 ++i; |
682 } | 690 } |
(...skipping 26 matching lines...) Expand all Loading... |
709 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked()); | 717 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked()); |
710 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 718 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
711 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 719 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
712 QuicHeadersStream* headers_stream = | 720 QuicHeadersStream* headers_stream = |
713 QuicSessionPeer::GetHeadersStream(&session_); | 721 QuicSessionPeer::GetHeadersStream(&session_); |
714 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); | 722 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); |
715 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 723 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
716 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 724 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
717 QuicStreamId stream_id = 5; | 725 QuicStreamId stream_id = 5; |
718 // Write until the header stream is flow control blocked. | 726 // Write until the header stream is flow control blocked. |
| 727 EXPECT_CALL(*connection_, SendBlocked(kHeadersStreamId)); |
719 SpdyHeaderBlock headers; | 728 SpdyHeaderBlock headers; |
720 while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) { | 729 while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) { |
721 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 730 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
722 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 731 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
723 headers["header"] = base::Uint64ToString(base::RandUint64()) + | 732 headers["header"] = base::Uint64ToString(base::RandUint64()) + |
724 base::Uint64ToString(base::RandUint64()) + | 733 base::Uint64ToString(base::RandUint64()) + |
725 base::Uint64ToString(base::RandUint64()); | 734 base::Uint64ToString(base::RandUint64()); |
726 headers_stream->WriteHeaders(stream_id, headers, true, nullptr); | 735 headers_stream->WriteHeaders(stream_id, headers, true, nullptr); |
727 stream_id += 2; | 736 stream_id += 2; |
728 } | 737 } |
(...skipping 30 matching lines...) Expand all Loading... |
759 const QuicStreamOffset kByteOffset = | 768 const QuicStreamOffset kByteOffset = |
760 1 + kInitialSessionFlowControlWindowForTest / 2; | 769 1 + kInitialSessionFlowControlWindowForTest / 2; |
761 | 770 |
762 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. | 771 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. |
763 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); | 772 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); |
764 // We do expect a connection level WINDOW_UPDATE when the stream is reset. | 773 // We do expect a connection level WINDOW_UPDATE when the stream is reset. |
765 EXPECT_CALL(*connection_, | 774 EXPECT_CALL(*connection_, |
766 SendWindowUpdate(0, kInitialSessionFlowControlWindowForTest + | 775 SendWindowUpdate(0, kInitialSessionFlowControlWindowForTest + |
767 kByteOffset)).Times(1); | 776 kByteOffset)).Times(1); |
768 | 777 |
| 778 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
769 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 779 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
770 kByteOffset); | 780 kByteOffset); |
771 session_.OnRstStream(rst_frame); | 781 session_.OnRstStream(rst_frame); |
772 session_.PostProcessAfterData(); | 782 session_.PostProcessAfterData(); |
773 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 783 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
774 } | 784 } |
775 | 785 |
776 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { | 786 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { |
777 // Test the situation where we receive a FIN on a stream, and before we fully | 787 // Test the situation where we receive a FIN on a stream, and before we fully |
778 // consume all the data from the sequencer buffer we locally RST the stream. | 788 // consume all the data from the sequencer buffer we locally RST the stream. |
779 // The bytes between highest consumed byte, and the final byte offset that we | 789 // The bytes between highest consumed byte, and the final byte offset that we |
780 // determined when the FIN arrived, should be marked as consumed at the | 790 // determined when the FIN arrived, should be marked as consumed at the |
781 // connection level flow controller when the stream is reset. | 791 // connection level flow controller when the stream is reset. |
782 TestStream* stream = session_.CreateOutgoingDataStream(); | 792 TestStream* stream = session_.CreateOutgoingDataStream(); |
783 | 793 |
784 const QuicStreamOffset kByteOffset = | 794 const QuicStreamOffset kByteOffset = |
785 1 + kInitialSessionFlowControlWindowForTest / 2; | 795 kInitialSessionFlowControlWindowForTest / 2; |
786 QuicStreamFrame frame(stream->id(), true, kByteOffset, IOVector()); | 796 QuicStreamFrame frame(stream->id(), true, kByteOffset, IOVector()); |
787 vector<QuicStreamFrame> frames; | 797 vector<QuicStreamFrame> frames; |
788 frames.push_back(frame); | 798 frames.push_back(frame); |
789 session_.OnStreamFrames(frames); | 799 session_.OnStreamFrames(frames); |
790 session_.PostProcessAfterData(); | 800 session_.PostProcessAfterData(); |
| 801 EXPECT_TRUE(connection_->connected()); |
791 | 802 |
792 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed()); | 803 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed()); |
793 EXPECT_EQ(kByteOffset, | 804 EXPECT_EQ(kByteOffset, |
794 stream->flow_controller()->highest_received_byte_offset()); | 805 stream->flow_controller()->highest_received_byte_offset()); |
795 | 806 |
796 // Reset stream locally. | 807 // Reset stream locally. |
| 808 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
797 stream->Reset(QUIC_STREAM_CANCELLED); | 809 stream->Reset(QUIC_STREAM_CANCELLED); |
798 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 810 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
799 } | 811 } |
800 | 812 |
801 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { | 813 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { |
802 // Test that when we RST the stream (and tear down stream state), and then | 814 // Test that when we RST the stream (and tear down stream state), and then |
803 // receive a FIN from the peer, we correctly adjust our connection level flow | 815 // receive a FIN from the peer, we correctly adjust our connection level flow |
804 // control receive window. | 816 // control receive window. |
805 | 817 |
806 // Connection starts with some non-zero highest received byte offset, | 818 // Connection starts with some non-zero highest received byte offset, |
807 // due to other active streams. | 819 // due to other active streams. |
808 const uint64 kInitialConnectionBytesConsumed = 567; | 820 const uint64 kInitialConnectionBytesConsumed = 567; |
809 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 821 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
810 EXPECT_LT(kInitialConnectionBytesConsumed, | 822 EXPECT_LT(kInitialConnectionBytesConsumed, |
811 kInitialConnectionHighestReceivedOffset); | 823 kInitialConnectionHighestReceivedOffset); |
812 session_.flow_controller()->UpdateHighestReceivedOffset( | 824 session_.flow_controller()->UpdateHighestReceivedOffset( |
813 kInitialConnectionHighestReceivedOffset); | 825 kInitialConnectionHighestReceivedOffset); |
814 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 826 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
815 | 827 |
816 // Reset our stream: this results in the stream being closed locally. | 828 // Reset our stream: this results in the stream being closed locally. |
817 TestStream* stream = session_.CreateOutgoingDataStream(); | 829 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 830 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
818 stream->Reset(QUIC_STREAM_CANCELLED); | 831 stream->Reset(QUIC_STREAM_CANCELLED); |
819 | 832 |
820 // Now receive a response from the peer with a FIN. We should handle this by | 833 // Now receive a response from the peer with a FIN. We should handle this by |
821 // adjusting the connection level flow control receive window to take into | 834 // adjusting the connection level flow control receive window to take into |
822 // account the total number of bytes sent by the peer. | 835 // account the total number of bytes sent by the peer. |
823 const QuicStreamOffset kByteOffset = 5678; | 836 const QuicStreamOffset kByteOffset = 5678; |
824 string body = "hello"; | 837 string body = "hello"; |
825 IOVector data = MakeIOVector(body); | 838 IOVector data = MakeIOVector(body); |
826 QuicStreamFrame frame(stream->id(), true, kByteOffset, data); | 839 QuicStreamFrame frame(stream->id(), true, kByteOffset, data); |
827 vector<QuicStreamFrame> frames; | 840 vector<QuicStreamFrame> frames; |
(...skipping 19 matching lines...) Expand all Loading... |
847 const uint64 kInitialConnectionBytesConsumed = 567; | 860 const uint64 kInitialConnectionBytesConsumed = 567; |
848 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 861 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
849 EXPECT_LT(kInitialConnectionBytesConsumed, | 862 EXPECT_LT(kInitialConnectionBytesConsumed, |
850 kInitialConnectionHighestReceivedOffset); | 863 kInitialConnectionHighestReceivedOffset); |
851 session_.flow_controller()->UpdateHighestReceivedOffset( | 864 session_.flow_controller()->UpdateHighestReceivedOffset( |
852 kInitialConnectionHighestReceivedOffset); | 865 kInitialConnectionHighestReceivedOffset); |
853 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 866 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
854 | 867 |
855 // Reset our stream: this results in the stream being closed locally. | 868 // Reset our stream: this results in the stream being closed locally. |
856 TestStream* stream = session_.CreateOutgoingDataStream(); | 869 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 870 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
857 stream->Reset(QUIC_STREAM_CANCELLED); | 871 stream->Reset(QUIC_STREAM_CANCELLED); |
858 | 872 |
859 // Now receive a RST from the peer. We should handle this by adjusting the | 873 // Now receive a RST from the peer. We should handle this by adjusting the |
860 // connection level flow control receive window to take into account the total | 874 // connection level flow control receive window to take into account the total |
861 // number of bytes sent by the peer. | 875 // number of bytes sent by the peer. |
862 const QuicStreamOffset kByteOffset = 5678; | 876 const QuicStreamOffset kByteOffset = 5678; |
863 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 877 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
864 kByteOffset); | 878 kByteOffset); |
865 session_.OnRstStream(rst_frame); | 879 session_.OnRstStream(rst_frame); |
866 | 880 |
(...skipping 30 matching lines...) Expand all Loading... |
897 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { | 911 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
898 // Test that if we receive a stream RST with a highest byte offset that | 912 // Test that if we receive a stream RST with a highest byte offset that |
899 // violates flow control, that we close the connection. | 913 // violates flow control, that we close the connection. |
900 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; | 914 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; |
901 EXPECT_CALL(*connection_, | 915 EXPECT_CALL(*connection_, |
902 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 916 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
903 .Times(2); | 917 .Times(2); |
904 | 918 |
905 // Check that stream frame + FIN results in connection close. | 919 // Check that stream frame + FIN results in connection close. |
906 TestStream* stream = session_.CreateOutgoingDataStream(); | 920 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 921 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
907 stream->Reset(QUIC_STREAM_CANCELLED); | 922 stream->Reset(QUIC_STREAM_CANCELLED); |
908 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); | 923 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
909 vector<QuicStreamFrame> frames; | 924 vector<QuicStreamFrame> frames; |
910 frames.push_back(frame); | 925 frames.push_back(frame); |
911 session_.OnStreamFrames(frames); | 926 session_.OnStreamFrames(frames); |
912 | 927 |
913 // Check that RST results in connection close. | 928 // Check that RST results in connection close. |
914 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 929 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
915 kLargeOffset); | 930 kLargeOffset); |
916 session_.OnRstStream(rst_frame); | 931 session_.OnRstStream(rst_frame); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 // Create kMaxStreams + 1 data streams, and close them all without receiving a | 967 // Create kMaxStreams + 1 data streams, and close them all without receiving a |
953 // FIN or a RST from the client. | 968 // FIN or a RST from the client. |
954 const int kFirstStreamId = kClientDataStreamId1; | 969 const int kFirstStreamId = kClientDataStreamId1; |
955 const int kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams + 1; | 970 const int kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams + 1; |
956 for (int i = kFirstStreamId; i < kFinalStreamId; i += 2) { | 971 for (int i = kFirstStreamId; i < kFinalStreamId; i += 2) { |
957 QuicStreamFrame data1(i, false, 0, MakeIOVector("HT")); | 972 QuicStreamFrame data1(i, false, 0, MakeIOVector("HT")); |
958 vector<QuicStreamFrame> frames; | 973 vector<QuicStreamFrame> frames; |
959 frames.push_back(data1); | 974 frames.push_back(data1); |
960 session_.OnStreamFrames(frames); | 975 session_.OnStreamFrames(frames); |
961 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 976 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
| 977 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); |
962 session_.CloseStream(i); | 978 session_.CloseStream(i); |
963 } | 979 } |
964 | 980 |
965 // Called after any new data is received by the session, and triggers the call | 981 // Called after any new data is received by the session, and triggers the call |
966 // to close the connection. | 982 // to close the connection. |
967 session_.PostProcessAfterData(); | 983 session_.PostProcessAfterData(); |
968 } | 984 } |
969 | 985 |
970 } // namespace | 986 } // namespace |
971 } // namespace test | 987 } // namespace test |
972 } // namespace net | 988 } // namespace net |
OLD | NEW |