| 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 | 1570 |
| 1571 // First send without any pause and check the result. | 1571 // First send without any pause and check the result. |
| 1572 QuicTime expected_recorded_send_time = clock_.Now(); | 1572 QuicTime expected_recorded_send_time = clock_.Now(); |
| 1573 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 1573 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
| 1574 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) | 1574 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1575 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() | 1575 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1576 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); | 1576 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1577 | 1577 |
| 1578 // Now pause during the write, and check the results. | 1578 // Now pause during the write, and check the results. |
| 1579 actual_recorded_send_time = QuicTime::Zero(); | 1579 actual_recorded_send_time = QuicTime::Zero(); |
| 1580 const QuicTime::Delta kWritePauseTimeDelta = | 1580 const QuicTime::Delta write_pause_time_delta = |
| 1581 QuicTime::Delta::FromMilliseconds(5000); | 1581 QuicTime::Delta::FromMilliseconds(5000); |
| 1582 SetWritePauseTimeDelta(kWritePauseTimeDelta); | 1582 SetWritePauseTimeDelta(write_pause_time_delta); |
| 1583 expected_recorded_send_time = clock_.Now(); | 1583 expected_recorded_send_time = clock_.Now(); |
| 1584 | 1584 |
| 1585 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 1585 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1586 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); | 1586 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
| 1587 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); | 1587 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); |
| 1588 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) | 1588 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1589 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() | 1589 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1590 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); | 1590 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1591 } | 1591 } |
| 1592 | 1592 |
| (...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3665 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 3665 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
| 3666 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3666 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3668 ProcessDataPacket(1, 1, kEntropyFlag); | 3668 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3669 ProcessDataPacket(5, 1, kEntropyFlag); | 3669 ProcessDataPacket(5, 1, kEntropyFlag); |
| 3670 ProcessDataPacket(4, 1, !kEntropyFlag); | 3670 ProcessDataPacket(4, 1, !kEntropyFlag); |
| 3671 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); | 3671 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); |
| 3672 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 3672 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
| 3673 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5); | 3673 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5); |
| 3674 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 3674 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
| 3675 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 3675 QuicPacketEntropyHash random_entropy_hash = 129u; |
| 3676 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3676 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3677 frame.entropy_hash = kRandomEntropyHash; | 3677 frame.entropy_hash = random_entropy_hash; |
| 3678 if (ProcessStopWaitingPacket(&frame)) { | 3678 if (ProcessStopWaitingPacket(&frame)) { |
| 3679 six_packet_entropy_hash = 1 << 6; | 3679 six_packet_entropy_hash = 1 << 6; |
| 3680 } | 3680 } |
| 3681 | 3681 |
| 3682 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 3682 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash), |
| 3683 outgoing_ack()->entropy_hash); | 3683 outgoing_ack()->entropy_hash); |
| 3684 } | 3684 } |
| 3685 | 3685 |
| 3686 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 3686 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
| 3687 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3687 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3689 ProcessDataPacket(1, 1, kEntropyFlag); | 3689 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3690 ProcessDataPacket(5, 1, !kEntropyFlag); | 3690 ProcessDataPacket(5, 1, !kEntropyFlag); |
| 3691 ProcessDataPacket(22, 1, kEntropyFlag); | 3691 ProcessDataPacket(22, 1, kEntropyFlag); |
| 3692 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); | 3692 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); |
| 3693 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22); | 3693 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22); |
| 3694 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 3694 QuicPacketEntropyHash random_entropy_hash = 85u; |
| 3695 // Current packet is the least unacked packet. | 3695 // Current packet is the least unacked packet. |
| 3696 QuicPacketEntropyHash ack_entropy_hash; | 3696 QuicPacketEntropyHash ack_entropy_hash; |
| 3697 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); | 3697 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); |
| 3698 frame.entropy_hash = kRandomEntropyHash; | 3698 frame.entropy_hash = random_entropy_hash; |
| 3699 ack_entropy_hash = ProcessStopWaitingPacket(&frame); | 3699 ack_entropy_hash = ProcessStopWaitingPacket(&frame); |
| 3700 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), | 3700 EXPECT_EQ((random_entropy_hash + ack_entropy_hash), |
| 3701 outgoing_ack()->entropy_hash); | 3701 outgoing_ack()->entropy_hash); |
| 3702 ProcessDataPacket(25, 1, kEntropyFlag); | 3702 ProcessDataPacket(25, 1, kEntropyFlag); |
| 3703 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), | 3703 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))), |
| 3704 outgoing_ack()->entropy_hash); | 3704 outgoing_ack()->entropy_hash); |
| 3705 } | 3705 } |
| 3706 | 3706 |
| 3707 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | 3707 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
| 3708 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3708 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3710 QuicPacketEntropyHash entropy[51]; | 3710 QuicPacketEntropyHash entropy[51]; |
| 3711 entropy[0] = 0; | 3711 entropy[0] = 0; |
| 3712 for (int i = 1; i < 51; ++i) { | 3712 for (int i = 1; i < 51; ++i) { |
| 3713 bool should_send = i % 10 != 1; | 3713 bool should_send = i % 10 != 1; |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4407 // Regression test for b/18594622 | 4407 // Regression test for b/18594622 |
| 4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 4409 EXPECT_DFATAL( | 4409 EXPECT_DFATAL( |
| 4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
| 4411 "Attempt to send empty stream frame"); | 4411 "Attempt to send empty stream frame"); |
| 4412 } | 4412 } |
| 4413 | 4413 |
| 4414 } // namespace | 4414 } // namespace |
| 4415 } // namespace test | 4415 } // namespace test |
| 4416 } // namespace net | 4416 } // namespace net |
| OLD | NEW |