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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/quic/test_tools/quic_framer_peer.h" | 24 #include "net/quic/test_tools/quic_framer_peer.h" |
25 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 25 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
27 #include "net/quic/test_tools/quic_test_utils.h" | 27 #include "net/quic/test_tools/quic_test_utils.h" |
28 #include "net/quic/test_tools/simple_quic_framer.h" | 28 #include "net/quic/test_tools/simple_quic_framer.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 | 31 |
32 using base::StringPiece; | 32 using base::StringPiece; |
33 using std::map; | 33 using std::map; |
| 34 using std::string; |
34 using std::vector; | 35 using std::vector; |
35 using testing::AnyNumber; | 36 using testing::AnyNumber; |
36 using testing::AtLeast; | 37 using testing::AtLeast; |
37 using testing::ContainerEq; | 38 using testing::ContainerEq; |
38 using testing::Contains; | 39 using testing::Contains; |
39 using testing::DoAll; | 40 using testing::DoAll; |
40 using testing::InSequence; | 41 using testing::InSequence; |
41 using testing::InvokeWithoutArgs; | 42 using testing::InvokeWithoutArgs; |
42 using testing::NiceMock; | 43 using testing::NiceMock; |
43 using testing::Ref; | 44 using testing::Ref; |
(...skipping 2936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2980 SendAckPacketToPeer(); | 2981 SendAckPacketToPeer(); |
2981 | 2982 |
2982 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 2983 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
2983 } | 2984 } |
2984 | 2985 |
2985 TEST_P(QuicConnectionTest, TimeoutAfterSend) { | 2986 TEST_P(QuicConnectionTest, TimeoutAfterSend) { |
2986 EXPECT_TRUE(connection_.connected()); | 2987 EXPECT_TRUE(connection_.connected()); |
2987 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 2988 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); |
2988 QuicConfig config; | 2989 QuicConfig config; |
2989 connection_.SetFromConfig(config); | 2990 connection_.SetFromConfig(config); |
| 2991 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
2990 | 2992 |
2991 const QuicTime::Delta initial_idle_timeout = | 2993 const QuicTime::Delta initial_idle_timeout = |
2992 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 2994 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
2993 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); | 2995 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
2994 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); | 2996 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); |
2995 | 2997 |
2996 // When we send a packet, the timeout will change to 5ms + | 2998 // When we send a packet, the timeout will change to 5ms + |
2997 // kInitialIdleTimeoutSecs. | 2999 // kInitialIdleTimeoutSecs. |
2998 clock_.AdvanceTime(five_ms); | 3000 clock_.AdvanceTime(five_ms); |
2999 | 3001 |
(...skipping 14 matching lines...) Expand all Loading... |
3014 // This time, we should time out. | 3016 // This time, we should time out. |
3015 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 3017 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
3016 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3018 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3017 clock_.AdvanceTime(five_ms); | 3019 clock_.AdvanceTime(five_ms); |
3018 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); | 3020 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); |
3019 connection_.GetTimeoutAlarm()->Fire(); | 3021 connection_.GetTimeoutAlarm()->Fire(); |
3020 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3022 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3021 EXPECT_FALSE(connection_.connected()); | 3023 EXPECT_FALSE(connection_.connected()); |
3022 } | 3024 } |
3023 | 3025 |
| 3026 TEST_P(QuicConnectionTest, TimeoutAfterSendSilentClose) { |
| 3027 // Same test as above, but complete a handshake which enables silent close, |
| 3028 // causing no connection close packet to be sent. |
| 3029 ValueRestore<bool> old_flag(&FLAGS_quic_allow_silent_close, true); |
| 3030 EXPECT_TRUE(connection_.connected()); |
| 3031 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); |
| 3032 QuicConfig config; |
| 3033 |
| 3034 // Create a handshake message that also enables silent close. |
| 3035 CryptoHandshakeMessage msg; |
| 3036 string error_details; |
| 3037 QuicConfig client_config; |
| 3038 client_config.SetInitialFlowControlWindowToSend( |
| 3039 kInitialSessionFlowControlWindowForTest); |
| 3040 client_config.SetInitialStreamFlowControlWindowToSend( |
| 3041 kInitialStreamFlowControlWindowForTest); |
| 3042 client_config.SetInitialSessionFlowControlWindowToSend( |
| 3043 kInitialSessionFlowControlWindowForTest); |
| 3044 client_config.SetIdleConnectionStateLifetime( |
| 3045 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs), |
| 3046 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs)); |
| 3047 client_config.ToHandshakeMessage(&msg); |
| 3048 const QuicErrorCode error = |
| 3049 config.ProcessPeerHello(msg, CLIENT, &error_details); |
| 3050 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 3051 |
| 3052 connection_.SetFromConfig(config); |
| 3053 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3054 |
| 3055 const QuicTime::Delta default_idle_timeout = |
| 3056 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1); |
| 3057 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
| 3058 QuicTime default_timeout = clock_.ApproximateNow().Add(default_idle_timeout); |
| 3059 |
| 3060 // When we send a packet, the timeout will change to 5ms + |
| 3061 // kInitialIdleTimeoutSecs. |
| 3062 clock_.AdvanceTime(five_ms); |
| 3063 |
| 3064 // Send an ack so we don't set the retransmission alarm. |
| 3065 SendAckPacketToPeer(); |
| 3066 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 3067 |
| 3068 // The original alarm will fire. We should not time out because we had a |
| 3069 // network event at t=5ms. The alarm will reregister. |
| 3070 clock_.AdvanceTime(default_idle_timeout.Subtract(five_ms)); |
| 3071 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); |
| 3072 connection_.GetTimeoutAlarm()->Fire(); |
| 3073 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3074 EXPECT_TRUE(connection_.connected()); |
| 3075 EXPECT_EQ(default_timeout.Add(five_ms), |
| 3076 connection_.GetTimeoutAlarm()->deadline()); |
| 3077 |
| 3078 // This time, we should time out. |
| 3079 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
| 3080 clock_.AdvanceTime(five_ms); |
| 3081 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); |
| 3082 connection_.GetTimeoutAlarm()->Fire(); |
| 3083 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3084 EXPECT_FALSE(connection_.connected()); |
| 3085 } |
| 3086 |
3024 TEST_P(QuicConnectionTest, SendScheduler) { | 3087 TEST_P(QuicConnectionTest, SendScheduler) { |
3025 // Test that if we send a packet without delay, it is not queued. | 3088 // Test that if we send a packet without delay, it is not queued. |
3026 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 3089 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
3027 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3090 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3028 connection_.SendPacket( | 3091 connection_.SendPacket( |
3029 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 3092 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
3030 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3093 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3031 } | 3094 } |
3032 | 3095 |
3033 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { | 3096 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4192 QuicBlockedFrame blocked; | 4255 QuicBlockedFrame blocked; |
4193 blocked.stream_id = 3; | 4256 blocked.stream_id = 3; |
4194 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4257 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4195 ProcessFramePacket(QuicFrame(&blocked)); | 4258 ProcessFramePacket(QuicFrame(&blocked)); |
4196 EXPECT_TRUE(ack_alarm->IsSet()); | 4259 EXPECT_TRUE(ack_alarm->IsSet()); |
4197 } | 4260 } |
4198 | 4261 |
4199 } // namespace | 4262 } // namespace |
4200 } // namespace test | 4263 } // namespace test |
4201 } // namespace net | 4264 } // namespace net |
OLD | NEW |