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 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); | 2404 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); |
2405 | 2405 |
2406 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 2406 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
2407 | 2407 |
2408 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2408 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
2409 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2409 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2410 | 2410 |
2411 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); | 2411 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); |
2412 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2412 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2413 | 2413 |
2414 connection_.RetransmitUnackedPackets(INITIAL_ENCRYPTION_ONLY); | 2414 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
2415 } | 2415 } |
2416 | 2416 |
2417 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2417 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
2418 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2418 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2419 use_tagging_decrypter(); | 2419 use_tagging_decrypter(); |
2420 | 2420 |
2421 const uint8 tag = 0x07; | 2421 const uint8 tag = 0x07; |
2422 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2422 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2423 | 2423 |
2424 // Process an encrypted packet which can not yet be decrypted | 2424 // Process an encrypted packet which can not yet be decrypted |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2645 SendAckPacketToPeer(); | 2645 SendAckPacketToPeer(); |
2646 // Process an FEC packet, and revive the missing data packet | 2646 // Process an FEC packet, and revive the missing data packet |
2647 // but only contact the receive_algorithm once. | 2647 // but only contact the receive_algorithm once. |
2648 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2648 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
2649 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2649 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
2650 } | 2650 } |
2651 | 2651 |
2652 TEST_P(QuicConnectionTest, InitialTimeout) { | 2652 TEST_P(QuicConnectionTest, InitialTimeout) { |
2653 EXPECT_TRUE(connection_.connected()); | 2653 EXPECT_TRUE(connection_.connected()); |
2654 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 2654 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
2655 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2655 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
2656 | 2656 |
2657 QuicTime default_timeout = clock_.ApproximateNow().Add( | 2657 QuicTime default_timeout = clock_.ApproximateNow().Add( |
2658 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 2658 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
2659 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 2659 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
2660 | 2660 |
| 2661 if (FLAGS_quic_timeouts_require_activity) { |
| 2662 // Simulate the timeout alarm firing. |
| 2663 clock_.AdvanceTime( |
| 2664 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
| 2665 connection_.GetTimeoutAlarm()->Fire(); |
| 2666 // We should not actually timeout until a packet is sent. |
| 2667 EXPECT_TRUE(connection_.connected()); |
| 2668 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL); |
| 2669 } |
| 2670 |
2661 // Simulate the timeout alarm firing. | 2671 // Simulate the timeout alarm firing. |
2662 clock_.AdvanceTime( | 2672 clock_.AdvanceTime( |
2663 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 2673 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
2664 connection_.GetTimeoutAlarm()->Fire(); | 2674 connection_.GetTimeoutAlarm()->Fire(); |
| 2675 |
2665 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2676 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
2666 EXPECT_FALSE(connection_.connected()); | 2677 EXPECT_FALSE(connection_.connected()); |
2667 | 2678 |
2668 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2679 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
2669 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 2680 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
2670 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); | 2681 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); |
2671 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2682 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
2672 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 2683 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
| 2684 } |
| 2685 |
| 2686 TEST_P(QuicConnectionTest, OverallTimeout) { |
| 2687 connection_.SetOverallConnectionTimeout( |
| 2688 QuicTime::Delta::FromSeconds(kDefaultMaxTimeForCryptoHandshakeSecs)); |
| 2689 EXPECT_TRUE(connection_.connected()); |
| 2690 EXPECT_CALL(visitor_, |
| 2691 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false)); |
| 2692 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
| 2693 |
| 2694 QuicTime overall_timeout = clock_.ApproximateNow().Add( |
| 2695 QuicTime::Delta::FromSeconds(kDefaultMaxTimeForCryptoHandshakeSecs)); |
| 2696 EXPECT_EQ(overall_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 2697 |
| 2698 EXPECT_TRUE(connection_.connected()); |
| 2699 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL); |
| 2700 |
| 2701 clock_.AdvanceTime( |
| 2702 QuicTime::Delta::FromSeconds(2 * kDefaultInitialTimeoutSecs)); |
| 2703 |
| 2704 // Process an ack and see that the connection still times out. |
| 2705 QuicAckFrame frame = InitAckFrame(1); |
| 2706 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2707 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2708 ProcessAckPacket(&frame); |
| 2709 |
| 2710 // Simulate the timeout alarm firing. |
| 2711 connection_.GetTimeoutAlarm()->Fire(); |
| 2712 |
2673 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2713 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 2714 EXPECT_FALSE(connection_.connected()); |
| 2715 |
| 2716 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2717 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
| 2718 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); |
| 2719 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2720 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
2674 } | 2721 } |
2675 | 2722 |
2676 TEST_P(QuicConnectionTest, PingAfterSend) { | 2723 TEST_P(QuicConnectionTest, PingAfterSend) { |
2677 EXPECT_TRUE(connection_.connected()); | 2724 EXPECT_TRUE(connection_.connected()); |
2678 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true)); | 2725 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true)); |
2679 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 2726 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
2680 | 2727 |
2681 // Advance to 5ms, and send a packet to the peer, which will set | 2728 // Advance to 5ms, and send a packet to the peer, which will set |
2682 // the ping alarm. | 2729 // the ping alarm. |
2683 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2730 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3895 QuicBlockedFrame blocked; | 3942 QuicBlockedFrame blocked; |
3896 blocked.stream_id = 3; | 3943 blocked.stream_id = 3; |
3897 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3944 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3898 ProcessFramePacket(QuicFrame(&blocked)); | 3945 ProcessFramePacket(QuicFrame(&blocked)); |
3899 EXPECT_TRUE(ack_alarm->IsSet()); | 3946 EXPECT_TRUE(ack_alarm->IsSet()); |
3900 } | 3947 } |
3901 | 3948 |
3902 } // namespace | 3949 } // namespace |
3903 } // namespace test | 3950 } // namespace test |
3904 } // namespace net | 3951 } // namespace net |
OLD | NEW |