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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 MockRandom* random_generator_; | 267 MockRandom* random_generator_; |
268 | 268 |
269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
270 }; | 270 }; |
271 | 271 |
272 class TestPacketWriter : public QuicPacketWriter { | 272 class TestPacketWriter : public QuicPacketWriter { |
273 public: | 273 public: |
274 TestPacketWriter() | 274 TestPacketWriter() |
275 : last_packet_size_(0), | 275 : last_packet_size_(0), |
276 write_blocked_(false), | 276 write_blocked_(false), |
| 277 block_next_write_(false), |
277 is_write_blocked_data_buffered_(false), | 278 is_write_blocked_data_buffered_(false), |
278 is_server_(true), | 279 is_server_(true), |
279 final_bytes_of_last_packet_(0), | 280 final_bytes_of_last_packet_(0), |
280 final_bytes_of_previous_packet_(0), | 281 final_bytes_of_previous_packet_(0), |
281 use_tagging_decrypter_(false), | 282 use_tagging_decrypter_(false), |
282 packets_write_attempts_(0) { | 283 packets_write_attempts_(0) { |
283 } | 284 } |
284 | 285 |
285 // QuicPacketWriter | 286 // QuicPacketWriter interface |
286 virtual WriteResult WritePacket( | 287 virtual WriteResult WritePacket( |
287 const char* buffer, size_t buf_len, | 288 const char* buffer, size_t buf_len, |
288 const IPAddressNumber& self_address, | 289 const IPAddressNumber& self_address, |
289 const IPEndPoint& peer_address, | 290 const IPEndPoint& peer_address, |
290 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { | 291 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { |
291 QuicEncryptedPacket packet(buffer, buf_len); | 292 QuicEncryptedPacket packet(buffer, buf_len); |
292 ++packets_write_attempts_; | 293 ++packets_write_attempts_; |
293 | 294 |
294 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { | 295 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { |
295 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; | 296 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; |
296 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, | 297 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, |
297 sizeof(final_bytes_of_last_packet_)); | 298 sizeof(final_bytes_of_last_packet_)); |
298 } | 299 } |
299 | 300 |
300 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); | 301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); |
301 if (use_tagging_decrypter_) { | 302 if (use_tagging_decrypter_) { |
302 framer.SetDecrypter(new TaggingDecrypter); | 303 framer.SetDecrypter(new TaggingDecrypter); |
303 } | 304 } |
304 visitor_.Reset(); | 305 visitor_.Reset(); |
305 framer.set_visitor(&visitor_); | 306 framer.set_visitor(&visitor_); |
306 EXPECT_TRUE(framer.ProcessPacket(packet)); | 307 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 308 if (block_next_write_) { |
| 309 write_blocked_ = true; |
| 310 block_next_write_ = false; |
| 311 } |
307 if (IsWriteBlocked()) { | 312 if (IsWriteBlocked()) { |
308 return WriteResult(WRITE_STATUS_BLOCKED, -1); | 313 return WriteResult(WRITE_STATUS_BLOCKED, -1); |
309 } | 314 } |
310 last_packet_size_ = packet.length(); | 315 last_packet_size_ = packet.length(); |
311 return WriteResult(WRITE_STATUS_OK, last_packet_size_); | 316 return WriteResult(WRITE_STATUS_OK, last_packet_size_); |
312 } | 317 } |
313 | 318 |
314 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 319 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
315 return is_write_blocked_data_buffered_; | 320 return is_write_blocked_data_buffered_; |
316 } | 321 } |
317 | 322 |
318 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } | 323 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } |
319 | 324 |
320 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } | 325 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } |
321 | 326 |
322 void SetWriteBlocked() { write_blocked_ = true; } | 327 void BlockNextWrite() { block_next_write_ = true; } |
323 | 328 |
324 // Resets the visitor's state by clearing out the headers and frames. | 329 // Resets the visitor's state by clearing out the headers and frames. |
325 void Reset() { | 330 void Reset() { |
326 visitor_.Reset(); | 331 visitor_.Reset(); |
327 } | 332 } |
328 | 333 |
329 QuicPacketHeader* header() { return visitor_.header(); } | 334 QuicPacketHeader* header() { return visitor_.header(); } |
330 | 335 |
331 size_t frame_count() const { return visitor_.frame_count(); } | 336 size_t frame_count() const { return visitor_.frame_count(); } |
332 | 337 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 void use_tagging_decrypter() { | 373 void use_tagging_decrypter() { |
369 use_tagging_decrypter_ = true; | 374 use_tagging_decrypter_ = true; |
370 } | 375 } |
371 | 376 |
372 uint32 packets_write_attempts() { return packets_write_attempts_; } | 377 uint32 packets_write_attempts() { return packets_write_attempts_; } |
373 | 378 |
374 private: | 379 private: |
375 FramerVisitorCapturingFrames visitor_; | 380 FramerVisitorCapturingFrames visitor_; |
376 size_t last_packet_size_; | 381 size_t last_packet_size_; |
377 bool write_blocked_; | 382 bool write_blocked_; |
| 383 bool block_next_write_; |
378 bool is_write_blocked_data_buffered_; | 384 bool is_write_blocked_data_buffered_; |
379 bool is_server_; | 385 bool is_server_; |
380 uint32 final_bytes_of_last_packet_; | 386 uint32 final_bytes_of_last_packet_; |
381 uint32 final_bytes_of_previous_packet_; | 387 uint32 final_bytes_of_previous_packet_; |
382 bool use_tagging_decrypter_; | 388 bool use_tagging_decrypter_; |
383 uint32 packets_write_attempts_; | 389 uint32 packets_write_attempts_; |
384 | 390 |
385 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
386 }; | 392 }; |
387 | 393 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); | 823 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); |
818 frame->received_info.missing_packets.erase(arrived); | 824 frame->received_info.missing_packets.erase(arrived); |
819 frame->received_info.entropy_hash ^= | 825 frame->received_info.entropy_hash ^= |
820 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); | 826 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); |
821 if (arrived > 1) { | 827 if (arrived > 1) { |
822 frame->received_info.entropy_hash ^= | 828 frame->received_info.entropy_hash ^= |
823 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); | 829 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); |
824 } | 830 } |
825 } | 831 } |
826 | 832 |
| 833 void TriggerConnectionClose() { |
| 834 // Send an erroneous packet to close the connection. |
| 835 EXPECT_CALL(visitor_, |
| 836 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 837 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 838 // packet call to the visitor. |
| 839 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 840 EXPECT_FALSE( |
| 841 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
| 842 } |
| 843 |
827 QuicGuid guid_; | 844 QuicGuid guid_; |
828 QuicFramer framer_; | 845 QuicFramer framer_; |
829 QuicPacketCreator creator_; | 846 QuicPacketCreator creator_; |
830 MockEntropyCalculator entropy_calculator_; | 847 MockEntropyCalculator entropy_calculator_; |
831 | 848 |
832 MockSendAlgorithm* send_algorithm_; | 849 MockSendAlgorithm* send_algorithm_; |
833 TestReceiveAlgorithm* receive_algorithm_; | 850 TestReceiveAlgorithm* receive_algorithm_; |
834 MockClock clock_; | 851 MockClock clock_; |
835 MockRandom random_generator_; | 852 MockRandom random_generator_; |
836 scoped_ptr<TestConnectionHelper> helper_; | 853 scoped_ptr<TestConnectionHelper> helper_; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 creator_.set_sequence_number(5); | 954 creator_.set_sequence_number(5); |
938 QuicAckFrame frame = InitAckFrame(0, 4); | 955 QuicAckFrame frame = InitAckFrame(0, 4); |
939 ProcessAckPacket(&frame); | 956 ProcessAckPacket(&frame); |
940 | 957 |
941 // Force an ack to be sent. | 958 // Force an ack to be sent. |
942 SendAckPacketToPeer(); | 959 SendAckPacketToPeer(); |
943 EXPECT_TRUE(IsMissing(4)); | 960 EXPECT_TRUE(IsMissing(4)); |
944 } | 961 } |
945 | 962 |
946 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 963 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { |
| 964 EXPECT_CALL(visitor_, |
| 965 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
947 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 966 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
948 // packet call to the visitor. | 967 // packet call to the visitor. |
949 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | |
950 ProcessDataPacket(6000, 0, !kEntropyFlag); | 968 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 969 EXPECT_FALSE( |
| 970 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
951 } | 971 } |
952 | 972 |
953 TEST_F(QuicConnectionTest, TruncatedAck) { | 973 TEST_F(QuicConnectionTest, TruncatedAck) { |
954 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 974 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
955 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; | 975 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; |
956 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { | 976 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { |
957 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); | 977 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); |
958 } | 978 } |
959 | 979 |
960 QuicAckFrame frame = InitAckFrame(num_packets, 1); | 980 QuicAckFrame frame = InitAckFrame(num_packets, 1); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 // All packets carry version info till version is negotiated. | 1334 // All packets carry version info till version is negotiated. |
1315 size_t payload_length; | 1335 size_t payload_length; |
1316 connection_.options()->max_packet_length = | 1336 connection_.options()->max_packet_length = |
1317 GetPacketLengthForOneStream( | 1337 GetPacketLengthForOneStream( |
1318 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1338 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
1319 IN_FEC_GROUP, &payload_length); | 1339 IN_FEC_GROUP, &payload_length); |
1320 // And send FEC every two packets. | 1340 // And send FEC every two packets. |
1321 connection_.options()->max_packets_per_fec_group = 2; | 1341 connection_.options()->max_packets_per_fec_group = 2; |
1322 | 1342 |
1323 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1343 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1324 writer_->SetWriteBlocked(); | 1344 writer_->BlockNextWrite(); |
1325 const string payload(payload_length, 'a'); | 1345 const string payload(payload_length, 'a'); |
1326 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1346 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1327 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1347 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
1328 // Expect the first data packet and the fec packet to be queued. | 1348 // Expect the first data packet and the fec packet to be queued. |
1329 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1349 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1330 } | 1350 } |
1331 | 1351 |
1332 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1352 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
1333 connection_.options()->max_packets_per_fec_group = 1; | 1353 connection_.options()->max_packets_per_fec_group = 1; |
1334 // 1 Data and 1 FEC packet. | 1354 // 1 Data and 1 FEC packet. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 EXPECT_EQ(1u, frame.stream_id); | 1604 EXPECT_EQ(1u, frame.stream_id); |
1585 EXPECT_EQ("ABCD", string(static_cast<char*> | 1605 EXPECT_EQ("ABCD", string(static_cast<char*> |
1586 (frame.data.iovec()[0].iov_base), | 1606 (frame.data.iovec()[0].iov_base), |
1587 (frame.data.iovec()[0].iov_len))); | 1607 (frame.data.iovec()[0].iov_len))); |
1588 } | 1608 } |
1589 | 1609 |
1590 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { | 1610 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { |
1591 // Try to send two stream frames in 1 packet by using writev. | 1611 // Try to send two stream frames in 1 packet by using writev. |
1592 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1612 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
1593 | 1613 |
1594 writer_->SetWriteBlocked(); | 1614 writer_->BlockNextWrite(); |
1595 char data[] = "ABCD"; | 1615 char data[] = "ABCD"; |
1596 IOVector data_iov; | 1616 IOVector data_iov; |
1597 data_iov.AppendNoCoalesce(data, 2); | 1617 data_iov.AppendNoCoalesce(data, 2); |
1598 data_iov.AppendNoCoalesce(data + 2, 2); | 1618 data_iov.AppendNoCoalesce(data + 2, 2); |
1599 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1619 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); |
1600 | 1620 |
1601 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1621 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
1602 EXPECT_TRUE(connection_.HasQueuedData()); | 1622 EXPECT_TRUE(connection_.HasQueuedData()); |
1603 | 1623 |
1604 // Attempt to send all packets, but since we're actually still | |
1605 // blocked, they should all remain queued. | |
1606 EXPECT_FALSE(connection_.OnCanWrite()); | |
1607 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | |
1608 | |
1609 // Unblock the writes and actually send. | 1624 // Unblock the writes and actually send. |
1610 writer_->SetWritable(); | 1625 writer_->SetWritable(); |
1611 EXPECT_TRUE(connection_.OnCanWrite()); | 1626 EXPECT_TRUE(connection_.OnCanWrite()); |
1612 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1627 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1613 | 1628 |
1614 // Parse the last packet and ensure it's one stream frame from one stream. | 1629 // Parse the last packet and ensure it's one stream frame from one stream. |
1615 EXPECT_EQ(1u, writer_->frame_count()); | 1630 EXPECT_EQ(1u, writer_->frame_count()); |
1616 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1631 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
1617 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); | 1632 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); |
1618 } | 1633 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 ProcessAckPacket(&ack_one); | 1723 ProcessAckPacket(&ack_one); |
1709 ProcessAckPacket(&ack_one); | 1724 ProcessAckPacket(&ack_one); |
1710 ProcessAckPacket(&ack_one); | 1725 ProcessAckPacket(&ack_one); |
1711 | 1726 |
1712 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no | 1727 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no |
1713 // change. | 1728 // change. |
1714 QuicAckFrame nack_two = InitAckFrame(3, 0); | 1729 QuicAckFrame nack_two = InitAckFrame(3, 0); |
1715 NackPacket(2, &nack_two); | 1730 NackPacket(2, &nack_two); |
1716 // The first nack should trigger a fast retransmission, but we'll be | 1731 // The first nack should trigger a fast retransmission, but we'll be |
1717 // write blocked, so the packet will be queued. | 1732 // write blocked, so the packet will be queued. |
1718 writer_->SetWriteBlocked(); | 1733 writer_->BlockNextWrite(); |
1719 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1734 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1720 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1735 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
1721 | 1736 |
1722 ProcessAckPacket(&nack_two); | 1737 ProcessAckPacket(&nack_two); |
1723 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1738 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
1724 | 1739 |
1725 // Now, ack the previous transmission. | 1740 // Now, ack the previous transmission. |
1726 QuicAckFrame ack_all = InitAckFrame(3, 0); | 1741 QuicAckFrame ack_all = InitAckFrame(3, 0); |
1727 ProcessAckPacket(&ack_all); | 1742 ProcessAckPacket(&ack_all); |
1728 | 1743 |
(...skipping 29 matching lines...) Expand all Loading... |
1758 ProcessAckPacket(&frame); | 1773 ProcessAckPacket(&frame); |
1759 } | 1774 } |
1760 | 1775 |
1761 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { | 1776 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { |
1762 for (int i = 0; i < 10; ++i) { | 1777 for (int i = 0; i < 10; ++i) { |
1763 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1778 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1764 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); | 1779 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); |
1765 } | 1780 } |
1766 | 1781 |
1767 // Block the congestion window and ensure they're queued. | 1782 // Block the congestion window and ensure they're queued. |
1768 writer_->SetWriteBlocked(); | 1783 writer_->BlockNextWrite(); |
1769 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1784 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1770 // Only one packet should be retransmitted. | 1785 // Only one packet should be retransmitted. |
1771 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1786 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1772 connection_.GetRetransmissionAlarm()->Fire(); | 1787 connection_.GetRetransmissionAlarm()->Fire(); |
1773 EXPECT_TRUE(connection_.HasQueuedData()); | 1788 EXPECT_TRUE(connection_.HasQueuedData()); |
1774 | 1789 |
1775 // Unblock the congestion window. | 1790 // Unblock the congestion window. |
1776 writer_->SetWritable(); | 1791 writer_->SetWritable(); |
1777 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1792 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
1778 2 * DefaultRetransmissionTime().ToMicroseconds())); | 1793 2 * DefaultRetransmissionTime().ToMicroseconds())); |
1779 // Retransmit already retransmitted packets event though the sequence number | 1794 // Retransmit already retransmitted packets event though the sequence number |
1780 // greater than the largest observed. | 1795 // greater than the largest observed. |
1781 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); | 1796 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); |
1782 connection_.GetRetransmissionAlarm()->Fire(); | 1797 connection_.GetRetransmissionAlarm()->Fire(); |
1783 connection_.OnCanWrite(); | 1798 connection_.OnCanWrite(); |
1784 } | 1799 } |
1785 | 1800 |
1786 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { | 1801 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { |
1787 writer_->SetWriteBlocked(); | 1802 writer_->BlockNextWrite(); |
| 1803 writer_->set_is_write_blocked_data_buffered(true); |
1788 | 1804 |
1789 writer_->set_is_write_blocked_data_buffered(true); | |
1790 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1805 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
1791 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1806 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1792 | 1807 |
1793 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1808 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1794 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1809 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1795 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1810 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1796 } | 1811 } |
1797 | 1812 |
1798 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { | 1813 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { |
1799 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1814 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1800 writer_->SetWriteBlocked(); | 1815 writer_->BlockNextWrite(); |
1801 | 1816 |
1802 writer_->set_is_write_blocked_data_buffered(true); | 1817 writer_->set_is_write_blocked_data_buffered(true); |
1803 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
1804 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1819 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1805 | 1820 |
1806 // Ack the sent packet before the callback returns, which happens in | 1821 // Ack the sent packet before the callback returns, which happens in |
1807 // rare circumstances with write blocked sockets. | 1822 // rare circumstances with write blocked sockets. |
1808 QuicAckFrame ack = InitAckFrame(1, 0); | 1823 QuicAckFrame ack = InitAckFrame(1, 0); |
1809 ProcessAckPacket(&ack); | 1824 ProcessAckPacket(&ack); |
1810 | 1825 |
1811 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 1826 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
1812 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1827 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1813 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1828 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1814 } | 1829 } |
1815 | 1830 |
1816 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { | 1831 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { |
1817 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1832 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1833 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
1819 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1834 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1820 | 1835 |
1821 writer_->SetWriteBlocked(); | 1836 writer_->BlockNextWrite(); |
1822 writer_->set_is_write_blocked_data_buffered(true); | 1837 writer_->set_is_write_blocked_data_buffered(true); |
1823 | 1838 |
1824 // Simulate the retransmission alarm firing. | 1839 // Simulate the retransmission alarm firing. |
1825 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); | 1840 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); |
1826 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1841 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1827 connection_.GetRetransmissionAlarm()->Fire(); | 1842 connection_.GetRetransmissionAlarm()->Fire(); |
1828 | 1843 |
1829 // Ack the sent packet before the callback returns, which happens in | 1844 // Ack the sent packet before the callback returns, which happens in |
1830 // rare circumstances with write blocked sockets. | 1845 // rare circumstances with write blocked sockets. |
1831 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1846 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1832 QuicAckFrame ack = InitAckFrame(1, 0); | 1847 QuicAckFrame ack = InitAckFrame(1, 0); |
1833 ProcessAckPacket(&ack); | 1848 ProcessAckPacket(&ack); |
1834 | 1849 |
1835 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1850 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1836 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1851 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1837 } | 1852 } |
1838 | 1853 |
1839 TEST_F(QuicConnectionTest, ResumptionAlarmThenWriteBlocked) { | 1854 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { |
1840 // Set the send and resumption alarm, then block the connection. | 1855 // Block the connection. |
| 1856 writer_->BlockNextWrite(); |
| 1857 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1858 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1859 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 1860 |
| 1861 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
| 1862 // attempt to write. |
1841 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); | 1863 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); |
1842 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); | 1864 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); |
1843 QuicConnectionPeer::SetIsWriteBlocked(&connection_, true); | |
1844 | |
1845 // Fire the alarms and ensure the connection is still write blocked. | |
1846 connection_.GetResumeWritesAlarm()->Fire(); | 1865 connection_.GetResumeWritesAlarm()->Fire(); |
1847 connection_.GetSendAlarm()->Fire(); | 1866 connection_.GetSendAlarm()->Fire(); |
1848 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); | 1867 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 1868 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
1849 } | 1869 } |
1850 | 1870 |
1851 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { | 1871 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { |
1852 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1872 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1853 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1873 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1854 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _)).Times(1); | 1874 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _)).Times(1); |
1855 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(4); | 1875 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(4); |
1856 int offset = 0; | 1876 int offset = 0; |
1857 // Send packets 1 to 15. | 1877 // Send packets 1 to 15. |
1858 for (int i = 0; i < 15; ++i) { | 1878 for (int i = 0; i < 15; ++i) { |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 ASSERT_NE(0u, nack_sequence_number); | 2253 ASSERT_NE(0u, nack_sequence_number); |
2234 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2254 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
2235 &connection_, rto_sequence_number)); | 2255 &connection_, rto_sequence_number)); |
2236 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2256 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
2237 &connection_, nack_sequence_number)); | 2257 &connection_, nack_sequence_number)); |
2238 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( | 2258 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( |
2239 &connection_, nack_sequence_number)); | 2259 &connection_, nack_sequence_number)); |
2240 } | 2260 } |
2241 | 2261 |
2242 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { | 2262 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { |
2243 writer_->SetWriteBlocked(); | 2263 writer_->BlockNextWrite(); |
2244 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2264 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
2245 // Make sure that RTO is not started when the packet is queued. | 2265 // Make sure that RTO is not started when the packet is queued. |
2246 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2266 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
2247 | 2267 |
2248 // Test that RTO is started once we write to the socket. | 2268 // Test that RTO is started once we write to the socket. |
2249 writer_->SetWritable(); | 2269 writer_->SetWritable(); |
2250 connection_.OnCanWrite(); | 2270 connection_.OnCanWrite(); |
2251 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2271 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
2252 } | 2272 } |
2253 | 2273 |
(...skipping 30 matching lines...) Expand all Loading... |
2284 // than previously. | 2304 // than previously. |
2285 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2305 EXPECT_TRUE(retransmission_alarm->IsSet()); |
2286 QuicTime next_rto_time = retransmission_alarm->deadline(); | 2306 QuicTime next_rto_time = retransmission_alarm->deadline(); |
2287 QuicTime expected_rto_time = | 2307 QuicTime expected_rto_time = |
2288 connection_.sent_packet_manager().GetRetransmissionTime(); | 2308 connection_.sent_packet_manager().GetRetransmissionTime(); |
2289 EXPECT_EQ(next_rto_time, expected_rto_time); | 2309 EXPECT_EQ(next_rto_time, expected_rto_time); |
2290 } | 2310 } |
2291 | 2311 |
2292 TEST_F(QuicConnectionTest, TestQueued) { | 2312 TEST_F(QuicConnectionTest, TestQueued) { |
2293 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2313 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2294 writer_->SetWriteBlocked(); | 2314 writer_->BlockNextWrite(); |
2295 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2315 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
2296 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2316 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2297 | 2317 |
2298 // Attempt to send all packets, but since we're actually still | |
2299 // blocked, they should all remain queued. | |
2300 EXPECT_FALSE(connection_.OnCanWrite()); | |
2301 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | |
2302 | |
2303 // Unblock the writes and actually send. | 2318 // Unblock the writes and actually send. |
2304 writer_->SetWritable(); | 2319 writer_->SetWritable(); |
2305 EXPECT_TRUE(connection_.OnCanWrite()); | 2320 EXPECT_TRUE(connection_.OnCanWrite()); |
2306 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2321 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2307 } | 2322 } |
2308 | 2323 |
2309 TEST_F(QuicConnectionTest, CloseFecGroup) { | 2324 TEST_F(QuicConnectionTest, CloseFecGroup) { |
2310 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2325 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2311 // Don't send missing packet 1. | 2326 // Don't send missing packet 1. |
2312 // Don't send missing packet 2. | 2327 // Don't send missing packet 2. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); | 2459 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); |
2445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2460 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2446 connection_.SendPacket( | 2461 connection_.SendPacket( |
2447 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2462 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
2448 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); | 2463 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); |
2449 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2464 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2450 } | 2465 } |
2451 | 2466 |
2452 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { | 2467 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { |
2453 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2468 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
2454 writer_->SetWriteBlocked(); | 2469 writer_->BlockNextWrite(); |
2455 EXPECT_CALL(*send_algorithm_, | 2470 EXPECT_CALL(*send_algorithm_, |
2456 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2471 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
2457 testing::Return(QuicTime::Delta::Zero())); | 2472 testing::Return(QuicTime::Delta::Zero())); |
2458 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2473 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
2459 connection_.SendPacket( | 2474 connection_.SendPacket( |
2460 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2475 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
2461 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2476 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2462 } | 2477 } |
2463 | 2478 |
2464 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 2479 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2919 QuicFrames frames; | 2934 QuicFrames frames; |
2920 QuicFrame frame(&frame1_); | 2935 QuicFrame frame(&frame1_); |
2921 frames.push_back(frame); | 2936 frames.push_back(frame); |
2922 scoped_ptr<QuicPacket> packet( | 2937 scoped_ptr<QuicPacket> packet( |
2923 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2938 framer_.BuildUnsizedDataPacket(header, frames).packet); |
2924 scoped_ptr<QuicEncryptedPacket> encrypted( | 2939 scoped_ptr<QuicEncryptedPacket> encrypted( |
2925 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2940 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
2926 | 2941 |
2927 framer_.set_version(QuicVersionMax()); | 2942 framer_.set_version(QuicVersionMax()); |
2928 connection_.set_is_server(true); | 2943 connection_.set_is_server(true); |
2929 writer_->SetWriteBlocked(); | 2944 writer_->BlockNextWrite(); |
2930 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2945 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
2931 EXPECT_EQ(0u, writer_->last_packet_size()); | 2946 EXPECT_EQ(0u, writer_->last_packet_size()); |
2932 EXPECT_TRUE(connection_.HasQueuedData()); | 2947 EXPECT_TRUE(connection_.HasQueuedData()); |
2933 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); | |
2934 | 2948 |
2935 writer_->SetWritable(); | 2949 writer_->SetWritable(); |
2936 connection_.OnCanWrite(); | 2950 connection_.OnCanWrite(); |
2937 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); | 2951 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); |
2938 | 2952 |
2939 size_t num_versions = arraysize(kSupportedQuicVersions); | 2953 size_t num_versions = arraysize(kSupportedQuicVersions); |
2940 EXPECT_EQ(num_versions, | 2954 EXPECT_EQ(num_versions, |
2941 writer_->version_negotiation_packet()->versions.size()); | 2955 writer_->version_negotiation_packet()->versions.size()); |
2942 | 2956 |
2943 // We expect all versions in kSupportedQuicVersions to be | 2957 // We expect all versions in kSupportedQuicVersions to be |
(...skipping 20 matching lines...) Expand all Loading... |
2964 QuicFrames frames; | 2978 QuicFrames frames; |
2965 QuicFrame frame(&frame1_); | 2979 QuicFrame frame(&frame1_); |
2966 frames.push_back(frame); | 2980 frames.push_back(frame); |
2967 scoped_ptr<QuicPacket> packet( | 2981 scoped_ptr<QuicPacket> packet( |
2968 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2982 framer_.BuildUnsizedDataPacket(header, frames).packet); |
2969 scoped_ptr<QuicEncryptedPacket> encrypted( | 2983 scoped_ptr<QuicEncryptedPacket> encrypted( |
2970 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2984 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
2971 | 2985 |
2972 framer_.set_version(QuicVersionMax()); | 2986 framer_.set_version(QuicVersionMax()); |
2973 connection_.set_is_server(true); | 2987 connection_.set_is_server(true); |
2974 writer_->SetWriteBlocked(); | 2988 writer_->BlockNextWrite(); |
2975 writer_->set_is_write_blocked_data_buffered(true); | 2989 writer_->set_is_write_blocked_data_buffered(true); |
2976 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2990 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
2977 EXPECT_EQ(0u, writer_->last_packet_size()); | 2991 EXPECT_EQ(0u, writer_->last_packet_size()); |
2978 EXPECT_FALSE(connection_.HasQueuedData()); | 2992 EXPECT_FALSE(connection_.HasQueuedData()); |
2979 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); | |
2980 } | 2993 } |
2981 | 2994 |
2982 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 2995 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
2983 // Start out with some unsupported version. | 2996 // Start out with some unsupported version. |
2984 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 2997 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
2985 QUIC_VERSION_UNSUPPORTED); | 2998 QUIC_VERSION_UNSUPPORTED); |
2986 | 2999 |
2987 QuicPacketHeader header; | 3000 QuicPacketHeader header; |
2988 header.public_header.guid = guid_; | 3001 header.public_header.guid = guid_; |
2989 header.public_header.reset_flag = false; | 3002 header.public_header.reset_flag = false; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3199 lowest_version_vector.push_back(QuicVersionMin()); | 3212 lowest_version_vector.push_back(QuicVersionMin()); |
3200 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); | 3213 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); |
3201 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 3214 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
3202 | 3215 |
3203 // Shouldn't be able to find a mutually supported version. | 3216 // Shouldn't be able to find a mutually supported version. |
3204 QuicVersionVector unsupported_version; | 3217 QuicVersionVector unsupported_version; |
3205 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); | 3218 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); |
3206 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); | 3219 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); |
3207 } | 3220 } |
3208 | 3221 |
3209 TEST_F(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) { | 3222 TEST_F(QuicConnectionTest, ConnectionCloseWhenWritable) { |
3210 writer_->SetWritable(); // Already default. | 3223 EXPECT_FALSE(writer_->IsWriteBlocked()); |
3211 | 3224 |
3212 // Send a packet (but write will not block). | 3225 // Send a packet. |
3213 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3226 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
3214 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3227 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3215 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3228 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3216 | 3229 |
3217 // Send an erroneous packet to close the connection. | 3230 TriggerConnectionClose(); |
3218 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | |
3219 ProcessDataPacket(6000, 0, !kEntropyFlag); | |
3220 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 3231 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
3221 } | 3232 } |
3222 | 3233 |
| 3234 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { |
| 3235 writer_->BlockNextWrite(); |
| 3236 TriggerConnectionClose(); |
| 3237 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3238 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 3239 } |
| 3240 |
3223 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { | 3241 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { |
3224 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3242 writer_->BlockNextWrite(); |
3225 writer_->SetWriteBlocked(); | |
3226 | |
3227 // Send a packet to so that write will really block. | |
3228 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3243 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
3229 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3244 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3230 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3245 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3231 | 3246 EXPECT_TRUE(writer_->IsWriteBlocked()); |
3232 // Send an erroneous packet to close the connection. | 3247 TriggerConnectionClose(); |
3233 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | |
3234 ProcessDataPacket(6000, 0, !kEntropyFlag); | |
3235 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3248 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3236 } | 3249 } |
3237 | 3250 |
3238 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) { | |
3239 writer_->SetWriteBlocked(); | |
3240 | |
3241 // Send an erroneous packet to close the connection. | |
3242 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | |
3243 ProcessDataPacket(6000, 0, !kEntropyFlag); | |
3244 EXPECT_EQ(1u, writer_->packets_write_attempts()); | |
3245 } | |
3246 | |
3247 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { | 3251 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { |
3248 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3249 | 3253 |
3250 // Create a delegate which we expect to be called. | 3254 // Create a delegate which we expect to be called. |
3251 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3255 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3252 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);; | 3256 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); |
3253 | 3257 |
3254 // Send some data, which will register the delegate to be notified. | 3258 // Send some data, which will register the delegate to be notified. |
3255 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3259 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3256 | 3260 |
3257 // Process an ACK from the server which should trigger the callback. | 3261 // Process an ACK from the server which should trigger the callback. |
3258 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3262 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
3259 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3263 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
3260 QuicAckFrame frame = InitAckFrame(1, 0); | 3264 QuicAckFrame frame = InitAckFrame(1, 0); |
3261 ProcessAckPacket(&frame); | 3265 ProcessAckPacket(&frame); |
3262 } | 3266 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3320 } | 3324 } |
3321 | 3325 |
3322 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting | 3326 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting |
3323 // ACK) triggers notification on our end. | 3327 // ACK) triggers notification on our end. |
3324 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3328 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
3325 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3329 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3326 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); | 3330 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); |
3327 | 3331 |
3328 // Create a delegate which we expect to be called. | 3332 // Create a delegate which we expect to be called. |
3329 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3333 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3330 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);; | 3334 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); |
3331 | 3335 |
3332 // Expect ACKs for 1 packet. | 3336 // Expect ACKs for 1 packet. |
3333 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3337 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
3334 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3338 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
3335 | 3339 |
3336 // Send one packet, and register to be notified on ACK. | 3340 // Send one packet, and register to be notified on ACK. |
3337 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3341 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3338 | 3342 |
3339 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 3343 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
3340 // Should recover the Ack packet and trigger the notification callback. | 3344 // Should recover the Ack packet and trigger the notification callback. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3433 true); | 3437 true); |
3434 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3438 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
3435 false); | 3439 false); |
3436 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3440 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
3437 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3441 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
3438 } | 3442 } |
3439 | 3443 |
3440 } // namespace | 3444 } // namespace |
3441 } // namespace test | 3445 } // namespace test |
3442 } // namespace net | 3446 } // namespace net |
OLD | NEW |