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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { | 569 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { |
570 EXPECT_EQ(kDefaultInitialTimeoutSecs, | 570 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
571 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 571 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
572 CryptoHandshakeMessage msg; | 572 CryptoHandshakeMessage msg; |
573 session_.GetCryptoStream()->OnHandshakeMessage(msg); | 573 session_.GetCryptoStream()->OnHandshakeMessage(msg); |
574 EXPECT_EQ(kDefaultTimeoutSecs, | 574 EXPECT_EQ(kDefaultTimeoutSecs, |
575 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 575 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
576 } | 576 } |
577 | 577 |
578 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { | 578 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { |
579 QuicStreamId stream_id1 = kClientDataStreamId1; | |
580 // Send two bytes of payload. | 579 // Send two bytes of payload. |
581 QuicStreamFrame data1(stream_id1, false, 0, MakeIOVector("HT")); | 580 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); |
582 vector<QuicStreamFrame> frames; | 581 vector<QuicStreamFrame> frames; |
583 frames.push_back(data1); | 582 frames.push_back(data1); |
584 session_.OnStreamFrames(frames); | 583 session_.OnStreamFrames(frames); |
585 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 584 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
586 | 585 |
587 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR, 0); | 586 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
588 session_.OnRstStream(rst1); | 587 session_.OnRstStream(rst1); |
589 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 588 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
590 // Connection should remain alive. | 589 // Connection should remain alive. |
591 EXPECT_TRUE(connection_->connected()); | 590 EXPECT_TRUE(connection_->connected()); |
592 } | 591 } |
593 | 592 |
594 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { | 593 TEST_P(QuicSessionTest, MultipleRstStreamsCauseSingleConnectionClose) { |
595 // If multiple invalid reset stream frames arrive in a single packet, this | 594 // If multiple invalid reset stream frames arrive in a single packet, this |
596 // should trigger a connection close. However there is no need to send | 595 // should trigger a connection close. However there is no need to send |
597 // multiple connection close frames. | 596 // multiple connection close frames. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 session_.config()->ToHandshakeMessage(&msg); | 661 session_.config()->ToHandshakeMessage(&msg); |
663 const QuicErrorCode error = | 662 const QuicErrorCode error = |
664 session_.config()->ProcessPeerHello(msg, CLIENT, &error_details); | 663 session_.config()->ProcessPeerHello(msg, CLIENT, &error_details); |
665 EXPECT_EQ(QUIC_NO_ERROR, error); | 664 EXPECT_EQ(QUIC_NO_ERROR, error); |
666 | 665 |
667 EXPECT_CALL(*connection_, | 666 EXPECT_CALL(*connection_, |
668 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 667 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); |
669 session_.OnConfigNegotiated(); | 668 session_.OnConfigNegotiated(); |
670 } | 669 } |
671 | 670 |
| 671 |
672 TEST_P(QuicSessionTest, InvalidFlowControlWindow) { | 672 TEST_P(QuicSessionTest, InvalidFlowControlWindow) { |
| 673 // Test that an attempt to create a QuicSession with an invalid (< default) |
| 674 // flow control window results in a QuicSession using the default. |
673 QuicConnection* connection = | 675 QuicConnection* connection = |
674 new MockConnection(true, SupportedVersions(GetParam())); | 676 new MockConnection(true, SupportedVersions(GetParam())); |
675 | 677 |
676 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; | 678 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; |
677 TestSession session(connection, kSmallerFlowControlWindow); | 679 TestSession session(connection, kSmallerFlowControlWindow); |
678 | 680 |
679 EXPECT_EQ(kDefaultFlowControlSendWindow, | 681 EXPECT_EQ(kDefaultFlowControlSendWindow, |
680 session.max_flow_control_receive_window_bytes()); | 682 session.max_flow_control_receive_window_bytes()); |
681 } | 683 } |
682 | 684 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 821 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
820 kByteOffset); | 822 kByteOffset); |
821 session_.OnRstStream(rst_frame); | 823 session_.OnRstStream(rst_frame); |
822 | 824 |
823 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, | 825 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, |
824 session_.flow_controller()->bytes_consumed()); | 826 session_.flow_controller()->bytes_consumed()); |
825 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, | 827 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, |
826 session_.flow_controller()->highest_received_byte_offset()); | 828 session_.flow_controller()->highest_received_byte_offset()); |
827 } | 829 } |
828 | 830 |
| 831 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
| 832 // Test that if we receive a stream RST with a highest byte offset that |
| 833 // violates flow control, that we close the connection. |
| 834 if (version() < QUIC_VERSION_17) { |
| 835 return; |
| 836 } |
| 837 FLAGS_enable_quic_stream_flow_control_2 = true; |
| 838 FLAGS_enable_quic_connection_flow_control = true; |
| 839 |
| 840 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; |
| 841 EXPECT_CALL(*connection_, |
| 842 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
| 843 .Times(2); |
| 844 |
| 845 // Check that stream frame + FIN results in connection close. |
| 846 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 847 stream->Reset(QUIC_STREAM_CANCELLED); |
| 848 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
| 849 session_.OnStreamFrames({frame}); |
| 850 |
| 851 // Check that RST results in connection close. |
| 852 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
| 853 kLargeOffset); |
| 854 session_.OnRstStream(rst_frame); |
| 855 } |
| 856 |
829 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 857 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
830 ValueRestore<bool> old_stream_flag( | 858 ValueRestore<bool> old_stream_flag( |
831 &FLAGS_enable_quic_stream_flow_control_2, true); | 859 &FLAGS_enable_quic_stream_flow_control_2, true); |
832 ValueRestore<bool> old_connection_flag( | 860 ValueRestore<bool> old_connection_flag( |
833 &FLAGS_enable_quic_connection_flow_control, true); | 861 &FLAGS_enable_quic_connection_flow_control, true); |
834 if (version() < QUIC_VERSION_19) { | 862 if (version() < QUIC_VERSION_19) { |
835 return; | 863 return; |
836 } | 864 } |
837 | 865 |
838 // Test that after successful version negotiation, flow control is disabled | 866 // Test that after successful version negotiation, flow control is disabled |
(...skipping 12 matching lines...) Expand all Loading... |
851 | 879 |
852 // Version 16 means all flow control is disabled. | 880 // Version 16 means all flow control is disabled. |
853 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 881 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
854 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 882 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
855 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 883 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
856 } | 884 } |
857 | 885 |
858 } // namespace | 886 } // namespace |
859 } // namespace test | 887 } // namespace test |
860 } // namespace net | 888 } // namespace net |
OLD | NEW |