| 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 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 // But if we send more data it should. | 1426 // But if we send more data it should. |
| 1427 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 | 1427 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 |
| 1428 EXPECT_EQ(8u, last_packet); | 1428 EXPECT_EQ(8u, last_packet); |
| 1429 SendAckPacketToPeer(); // Packet 9 | 1429 SendAckPacketToPeer(); // Packet 9 |
| 1430 EXPECT_EQ(7u, least_unacked()); | 1430 EXPECT_EQ(7u, least_unacked()); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 TEST_P(QuicConnectionTest, FECSending) { | 1433 TEST_P(QuicConnectionTest, FECSending) { |
| 1434 // All packets carry version info till version is negotiated. | 1434 // All packets carry version info till version is negotiated. |
| 1435 size_t payload_length; | 1435 size_t payload_length; |
| 1436 connection_.options()->max_packet_length = | 1436 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
| 1437 GetPacketLengthForOneStream( | 1437 // packet length. The size of the offset field in a stream frame is 0 for |
| 1438 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
| 1439 // max_packet_length by 2 so that subsequent packets containing subsequent |
| 1440 // stream frames with non-zero offets will fit within the packet length. |
| 1441 connection_.options()->max_packet_length = 2 + GetPacketLengthForOneStream( |
| 1438 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1442 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1439 IN_FEC_GROUP, &payload_length); | 1443 IN_FEC_GROUP, &payload_length); |
| 1440 // And send FEC every two packets. | 1444 // And send FEC every two packets. |
| 1441 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( | 1445 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1442 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); | 1446 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); |
| 1443 | 1447 |
| 1444 // Send 4 data packets and 2 FEC packets. | 1448 // Send 4 data packets and 2 FEC packets. |
| 1445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1449 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1446 // The first stream frame will consume 2 fewer bytes than the other three. | 1450 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
| 1447 const string payload(payload_length * 4 - 6, 'a'); | 1451 const string payload(payload_length * 4 + 2, 'a'); |
| 1448 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1452 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
| 1449 // Expect the FEC group to be closed after SendStreamDataWithString. | 1453 // Expect the FEC group to be closed after SendStreamDataWithString. |
| 1450 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1454 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 1451 } | 1455 } |
| 1452 | 1456 |
| 1453 TEST_P(QuicConnectionTest, FECQueueing) { | 1457 TEST_P(QuicConnectionTest, FECQueueing) { |
| 1454 // All packets carry version info till version is negotiated. | 1458 // All packets carry version info till version is negotiated. |
| 1455 size_t payload_length; | 1459 size_t payload_length; |
| 1456 connection_.options()->max_packet_length = | 1460 connection_.options()->max_packet_length = |
| 1457 GetPacketLengthForOneStream( | 1461 GetPacketLengthForOneStream( |
| (...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 const string payload(payload_length, 'a'); | 2882 const string payload(payload_length, 'a'); |
| 2879 EXPECT_EQ(0u, | 2883 EXPECT_EQ(0u, |
| 2880 connection_.SendStreamDataWithString(3, payload, 0, | 2884 connection_.SendStreamDataWithString(3, payload, 0, |
| 2881 !kFin, NULL).bytes_consumed); | 2885 !kFin, NULL).bytes_consumed); |
| 2882 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2886 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2883 } | 2887 } |
| 2884 | 2888 |
| 2885 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 2889 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
| 2886 // All packets carry version info till version is negotiated. | 2890 // All packets carry version info till version is negotiated. |
| 2887 size_t payload_length; | 2891 size_t payload_length; |
| 2888 connection_.options()->max_packet_length = | 2892 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
| 2889 GetPacketLengthForOneStream( | 2893 // packet length. The size of the offset field in a stream frame is 0 for |
| 2894 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
| 2895 // max_packet_length by 2 so that subsequent packets containing subsequent |
| 2896 // stream frames with non-zero offets will fit within the packet length. |
| 2897 connection_.options()->max_packet_length = 2 + GetPacketLengthForOneStream( |
| 2890 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 2898 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 2891 NOT_IN_FEC_GROUP, &payload_length); | 2899 NOT_IN_FEC_GROUP, &payload_length); |
| 2892 | 2900 |
| 2893 // Queue the first packet. | 2901 // Queue the first packet. |
| 2894 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 2902 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
| 2895 // The first stream frame will consume 2 fewer bytes than the other six. | 2903 // The first stream frame will have 2 fewer overhead bytes than the other six. |
| 2896 const string payload(payload_length * 7 - 12, 'a'); | 2904 const string payload(payload_length * 7 + 2, 'a'); |
| 2897 EXPECT_EQ(payload.size(), | 2905 EXPECT_EQ(payload.size(), |
| 2898 connection_.SendStreamDataWithString(1, payload, 0, | 2906 connection_.SendStreamDataWithString(1, payload, 0, |
| 2899 !kFin, NULL).bytes_consumed); | 2907 !kFin, NULL).bytes_consumed); |
| 2900 } | 2908 } |
| 2901 | 2909 |
| 2902 TEST_P(QuicConnectionTest, SendDelayedAck) { | 2910 TEST_P(QuicConnectionTest, SendDelayedAck) { |
| 2903 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); | 2911 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); |
| 2904 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2912 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2905 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2913 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2906 const uint8 tag = 0x07; | 2914 const uint8 tag = 0x07; |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3981 QuicBlockedFrame blocked; | 3989 QuicBlockedFrame blocked; |
| 3982 blocked.stream_id = 3; | 3990 blocked.stream_id = 3; |
| 3983 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3991 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3984 ProcessFramePacket(QuicFrame(&blocked)); | 3992 ProcessFramePacket(QuicFrame(&blocked)); |
| 3985 EXPECT_TRUE(ack_alarm->IsSet()); | 3993 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3986 } | 3994 } |
| 3987 | 3995 |
| 3988 } // namespace | 3996 } // namespace |
| 3989 } // namespace test | 3997 } // namespace test |
| 3990 } // namespace net | 3998 } // namespace net |
| OLD | NEW |