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_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 // Parse the last packet and ensure it's one stream frame from one stream. | 1937 // Parse the last packet and ensure it's one stream frame from one stream. |
1938 EXPECT_EQ(1u, writer_->frame_count()); | 1938 EXPECT_EQ(1u, writer_->frame_count()); |
1939 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1939 EXPECT_EQ(1u, writer_->stream_frames().size()); |
1940 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 1940 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); |
1941 } | 1941 } |
1942 | 1942 |
1943 TEST_P(QuicConnectionTest, SendingZeroBytes) { | 1943 TEST_P(QuicConnectionTest, SendingZeroBytes) { |
1944 // Send a zero byte write with a fin using writev. | 1944 // Send a zero byte write with a fin using writev. |
1945 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1945 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
1946 QuicIOVector empty_iov(nullptr, 0, 0); | 1946 QuicIOVector empty_iov(nullptr, 0, 0); |
1947 connection_.SendStreamData(1, empty_iov, 0, kFin, nullptr); | 1947 connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, kFin, nullptr); |
1948 | 1948 |
1949 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1949 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1950 EXPECT_FALSE(connection_.HasQueuedData()); | 1950 EXPECT_FALSE(connection_.HasQueuedData()); |
1951 | 1951 |
1952 // Parse the last packet and ensure it's one stream frame from one stream. | 1952 // Parse the last packet and ensure it's one stream frame from one stream. |
1953 EXPECT_EQ(1u, writer_->frame_count()); | 1953 EXPECT_EQ(1u, writer_->frame_count()); |
1954 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1954 EXPECT_EQ(1u, writer_->stream_frames().size()); |
1955 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 1955 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id); |
1956 EXPECT_TRUE(writer_->stream_frames()[0]->fin); | 1956 EXPECT_TRUE(writer_->stream_frames()[0]->fin); |
1957 } | 1957 } |
1958 | 1958 |
1959 TEST_P(QuicConnectionTest, OnCanWrite) { | 1959 TEST_P(QuicConnectionTest, OnCanWrite) { |
1960 // Visitor's OnCanWrite will send data, but will have more pending writes. | 1960 // Visitor's OnCanWrite will send data, but will have more pending writes. |
1961 EXPECT_CALL(visitor_, OnCanWrite()) | 1961 EXPECT_CALL(visitor_, OnCanWrite()) |
1962 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( | 1962 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( |
1963 &connection_, &TestConnection::SendStreamData3)), | 1963 &connection_, &TestConnection::SendStreamData3)), |
1964 IgnoreResult(InvokeWithoutArgs( | 1964 IgnoreResult(InvokeWithoutArgs( |
1965 &connection_, &TestConnection::SendStreamData5)))); | 1965 &connection_, &TestConnection::SendStreamData5)))); |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 connection_.SetNetworkTimeouts(timeout, timeout); | 2890 connection_.SetNetworkTimeouts(timeout, timeout); |
2891 EXPECT_TRUE(connection_.connected()); | 2891 EXPECT_TRUE(connection_.connected()); |
2892 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 2892 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
2893 | 2893 |
2894 QuicTime handshake_timeout = clock_.ApproximateNow().Add(timeout).Subtract( | 2894 QuicTime handshake_timeout = clock_.ApproximateNow().Add(timeout).Subtract( |
2895 QuicTime::Delta::FromSeconds(1)); | 2895 QuicTime::Delta::FromSeconds(1)); |
2896 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline()); | 2896 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline()); |
2897 EXPECT_TRUE(connection_.connected()); | 2897 EXPECT_TRUE(connection_.connected()); |
2898 | 2898 |
2899 // Send and ack new data 3 seconds later to lengthen the idle timeout. | 2899 // Send and ack new data 3 seconds later to lengthen the idle timeout. |
2900 SendStreamDataToPeer(1, "GET /", 0, kFin, nullptr); | 2900 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); |
2901 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3)); | 2901 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3)); |
2902 QuicAckFrame frame = InitAckFrame(1); | 2902 QuicAckFrame frame = InitAckFrame(1); |
2903 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2903 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2904 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2904 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
2905 ProcessAckPacket(&frame); | 2905 ProcessAckPacket(&frame); |
2906 | 2906 |
2907 // Fire early to verify it wouldn't timeout yet. | 2907 // Fire early to verify it wouldn't timeout yet. |
2908 connection_.GetTimeoutAlarm()->Fire(); | 2908 connection_.GetTimeoutAlarm()->Fire(); |
2909 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); | 2909 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
2910 EXPECT_TRUE(connection_.connected()); | 2910 EXPECT_TRUE(connection_.connected()); |
(...skipping 17 matching lines...) Expand all Loading... |
2928 | 2928 |
2929 TEST_P(QuicConnectionTest, PingAfterSend) { | 2929 TEST_P(QuicConnectionTest, PingAfterSend) { |
2930 EXPECT_TRUE(connection_.connected()); | 2930 EXPECT_TRUE(connection_.connected()); |
2931 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); | 2931 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); |
2932 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 2932 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
2933 | 2933 |
2934 // Advance to 5ms, and send a packet to the peer, which will set | 2934 // Advance to 5ms, and send a packet to the peer, which will set |
2935 // the ping alarm. | 2935 // the ping alarm. |
2936 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2936 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
2937 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2937 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
2938 SendStreamDataToPeer(1, "GET /", 0, kFin, nullptr); | 2938 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); |
2939 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); | 2939 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); |
2940 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), | 2940 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), |
2941 connection_.GetPingAlarm()->deadline()); | 2941 connection_.GetPingAlarm()->deadline()); |
2942 | 2942 |
2943 // Now recevie and ACK of the previous packet, which will move the | 2943 // Now recevie and ACK of the previous packet, which will move the |
2944 // ping alarm forward. | 2944 // ping alarm forward. |
2945 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2945 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
2946 QuicAckFrame frame = InitAckFrame(1); | 2946 QuicAckFrame frame = InitAckFrame(1); |
2947 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2947 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2948 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2948 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4959 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); | 4959 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); |
4960 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", | 4960 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", |
4961 ConnectionCloseBehavior::SILENT_CLOSE); | 4961 ConnectionCloseBehavior::SILENT_CLOSE); |
4962 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", | 4962 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", |
4963 ConnectionCloseBehavior::SILENT_CLOSE); | 4963 ConnectionCloseBehavior::SILENT_CLOSE); |
4964 } | 4964 } |
4965 | 4965 |
4966 } // namespace | 4966 } // namespace |
4967 } // namespace test | 4967 } // namespace test |
4968 } // namespace net | 4968 } // namespace net |
OLD | NEW |