Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 127633002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_ack_notifier_test.cc ('k') | net/quic/quic_default_packet_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 MockClock* clock_; 266 MockClock* clock_;
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 blocked_(false), 276 write_blocked_(false),
277 is_write_blocked_data_buffered_(false), 277 is_write_blocked_data_buffered_(false),
278 is_server_(true), 278 is_server_(true),
279 final_bytes_of_last_packet_(0), 279 final_bytes_of_last_packet_(0),
280 final_bytes_of_previous_packet_(0), 280 final_bytes_of_previous_packet_(0),
281 use_tagging_decrypter_(false), 281 use_tagging_decrypter_(false),
282 packets_write_attempts_(0) { 282 packets_write_attempts_(0) {
283 } 283 }
284 284
285 // QuicPacketWriter 285 // QuicPacketWriter
286 virtual WriteResult WritePacket( 286 virtual WriteResult WritePacket(
(...skipping 10 matching lines...) Expand all
297 sizeof(final_bytes_of_last_packet_)); 297 sizeof(final_bytes_of_last_packet_));
298 } 298 }
299 299
300 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); 300 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_);
301 if (use_tagging_decrypter_) { 301 if (use_tagging_decrypter_) {
302 framer.SetDecrypter(new TaggingDecrypter); 302 framer.SetDecrypter(new TaggingDecrypter);
303 } 303 }
304 visitor_.Reset(); 304 visitor_.Reset();
305 framer.set_visitor(&visitor_); 305 framer.set_visitor(&visitor_);
306 EXPECT_TRUE(framer.ProcessPacket(packet)); 306 EXPECT_TRUE(framer.ProcessPacket(packet));
307 if (blocked_) { 307 if (IsWriteBlocked()) {
308 return WriteResult(WRITE_STATUS_BLOCKED, -1); 308 return WriteResult(WRITE_STATUS_BLOCKED, -1);
309 } 309 }
310 last_packet_size_ = packet.length(); 310 last_packet_size_ = packet.length();
311 return WriteResult(WRITE_STATUS_OK, last_packet_size_); 311 return WriteResult(WRITE_STATUS_OK, last_packet_size_);
312 } 312 }
313 313
314 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { 314 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE {
315 return is_write_blocked_data_buffered_; 315 return is_write_blocked_data_buffered_;
316 } 316 }
317 317
318 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; }
319
320 virtual void SetWritable() OVERRIDE { write_blocked_ = false; }
321
322 void SetWriteBlocked() { write_blocked_ = true; }
323
318 // Resets the visitor's state by clearing out the headers and frames. 324 // Resets the visitor's state by clearing out the headers and frames.
319 void Reset() { 325 void Reset() {
320 visitor_.Reset(); 326 visitor_.Reset();
321 } 327 }
322 328
323 QuicPacketHeader* header() { return visitor_.header(); } 329 QuicPacketHeader* header() { return visitor_.header(); }
324 330
325 size_t frame_count() const { return visitor_.frame_count(); } 331 size_t frame_count() const { return visitor_.frame_count(); }
326 332
327 QuicAckFrame* ack() { return visitor_.ack(); } 333 QuicAckFrame* ack() { return visitor_.ack(); }
328 334
329 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); } 335 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); }
330 336
331 QuicConnectionCloseFrame* close() { return visitor_.close(); } 337 QuicConnectionCloseFrame* close() { return visitor_.close(); }
332 338
333 const vector<QuicStreamFrame>* stream_frames() const { 339 const vector<QuicStreamFrame>* stream_frames() const {
334 return visitor_.stream_frames(); 340 return visitor_.stream_frames();
335 } 341 }
336 342
337 size_t last_packet_size() { 343 size_t last_packet_size() {
338 return last_packet_size_; 344 return last_packet_size_;
339 } 345 }
340 346
341 QuicVersionNegotiationPacket* version_negotiation_packet() { 347 QuicVersionNegotiationPacket* version_negotiation_packet() {
342 return visitor_.version_negotiation_packet(); 348 return visitor_.version_negotiation_packet();
343 } 349 }
344 350
345 void set_blocked(bool blocked) { blocked_ = blocked; }
346
347 void set_is_write_blocked_data_buffered(bool buffered) { 351 void set_is_write_blocked_data_buffered(bool buffered) {
348 is_write_blocked_data_buffered_ = buffered; 352 is_write_blocked_data_buffered_ = buffered;
349 } 353 }
350 354
351 void set_is_server(bool is_server) { is_server_ = is_server; } 355 void set_is_server(bool is_server) { is_server_ = is_server; }
352 356
353 // final_bytes_of_last_packet_ returns the last four bytes of the previous 357 // final_bytes_of_last_packet_ returns the last four bytes of the previous
354 // packet as a little-endian, uint32. This is intended to be used with a 358 // packet as a little-endian, uint32. This is intended to be used with a
355 // TaggingEncrypter so that tests can determine which encrypter was used for 359 // TaggingEncrypter so that tests can determine which encrypter was used for
356 // a given packet. 360 // a given packet.
357 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; } 361 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; }
358 362
359 // Returns the final bytes of the second to last packet. 363 // Returns the final bytes of the second to last packet.
360 uint32 final_bytes_of_previous_packet() { 364 uint32 final_bytes_of_previous_packet() {
361 return final_bytes_of_previous_packet_; 365 return final_bytes_of_previous_packet_;
362 } 366 }
363 367
364 void use_tagging_decrypter() { 368 void use_tagging_decrypter() {
365 use_tagging_decrypter_ = true; 369 use_tagging_decrypter_ = true;
366 } 370 }
367 371
368 uint32 packets_write_attempts() { return packets_write_attempts_; } 372 uint32 packets_write_attempts() { return packets_write_attempts_; }
369 373
370 private: 374 private:
371 FramerVisitorCapturingFrames visitor_; 375 FramerVisitorCapturingFrames visitor_;
372 size_t last_packet_size_; 376 size_t last_packet_size_;
373 bool blocked_; 377 bool write_blocked_;
374 bool is_write_blocked_data_buffered_; 378 bool is_write_blocked_data_buffered_;
375 bool is_server_; 379 bool is_server_;
376 uint32 final_bytes_of_last_packet_; 380 uint32 final_bytes_of_last_packet_;
377 uint32 final_bytes_of_previous_packet_; 381 uint32 final_bytes_of_previous_packet_;
378 bool use_tagging_decrypter_; 382 bool use_tagging_decrypter_;
379 uint32 packets_write_attempts_; 383 uint32 packets_write_attempts_;
380 384
381 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); 385 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter);
382 }; 386 };
383 387
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 // All packets carry version info till version is negotiated. 1302 // All packets carry version info till version is negotiated.
1299 size_t payload_length; 1303 size_t payload_length;
1300 connection_.options()->max_packet_length = 1304 connection_.options()->max_packet_length =
1301 GetPacketLengthForOneStream( 1305 GetPacketLengthForOneStream(
1302 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1306 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1303 IN_FEC_GROUP, &payload_length); 1307 IN_FEC_GROUP, &payload_length);
1304 // And send FEC every two packets. 1308 // And send FEC every two packets.
1305 connection_.options()->max_packets_per_fec_group = 2; 1309 connection_.options()->max_packets_per_fec_group = 2;
1306 1310
1307 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1311 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1308 writer_->set_blocked(true); 1312 writer_->SetWriteBlocked();
1309 const string payload(payload_length, 'a'); 1313 const string payload(payload_length, 'a');
1310 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1314 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1311 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1315 EXPECT_FALSE(creator_.ShouldSendFec(true));
1312 // Expect the first data packet and the fec packet to be queued. 1316 // Expect the first data packet and the fec packet to be queued.
1313 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1317 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1314 } 1318 }
1315 1319
1316 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1320 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1317 connection_.options()->max_packets_per_fec_group = 1; 1321 connection_.options()->max_packets_per_fec_group = 1;
1318 // 1 Data and 1 FEC packet. 1322 // 1 Data and 1 FEC packet.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 EXPECT_EQ(1u, frame.stream_id); 1570 EXPECT_EQ(1u, frame.stream_id);
1567 EXPECT_EQ("ABCD", string(static_cast<char*> 1571 EXPECT_EQ("ABCD", string(static_cast<char*>
1568 (frame.data.iovec()[0].iov_base), 1572 (frame.data.iovec()[0].iov_base),
1569 (frame.data.iovec()[0].iov_len))); 1573 (frame.data.iovec()[0].iov_len)));
1570 } 1574 }
1571 1575
1572 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { 1576 TEST_F(QuicConnectionTest, FramePackingSendvQueued) {
1573 // Try to send two stream frames in 1 packet by using writev. 1577 // Try to send two stream frames in 1 packet by using writev.
1574 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1578 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1575 1579
1576 writer_->set_blocked(true); 1580 writer_->SetWriteBlocked();
1577 char data[] = "ABCD"; 1581 char data[] = "ABCD";
1578 IOVector data_iov; 1582 IOVector data_iov;
1579 data_iov.AppendNoCoalesce(data, 2); 1583 data_iov.AppendNoCoalesce(data, 2);
1580 data_iov.AppendNoCoalesce(data + 2, 2); 1584 data_iov.AppendNoCoalesce(data + 2, 2);
1581 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1585 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
1582 1586
1583 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1587 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1584 EXPECT_TRUE(connection_.HasQueuedData()); 1588 EXPECT_TRUE(connection_.HasQueuedData());
1585 1589
1586 // Attempt to send all packets, but since we're actually still 1590 // Attempt to send all packets, but since we're actually still
1587 // blocked, they should all remain queued. 1591 // blocked, they should all remain queued.
1588 EXPECT_FALSE(connection_.OnCanWrite()); 1592 EXPECT_FALSE(connection_.OnCanWrite());
1589 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1593 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1590 1594
1591 // Unblock the writes and actually send. 1595 // Unblock the writes and actually send.
1592 writer_->set_blocked(false); 1596 writer_->SetWritable();
1593 EXPECT_TRUE(connection_.OnCanWrite()); 1597 EXPECT_TRUE(connection_.OnCanWrite());
1594 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1598 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1595 1599
1596 // Parse the last packet and ensure it's one stream frame from one stream. 1600 // Parse the last packet and ensure it's one stream frame from one stream.
1597 EXPECT_EQ(1u, writer_->frame_count()); 1601 EXPECT_EQ(1u, writer_->frame_count());
1598 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1602 EXPECT_EQ(1u, writer_->stream_frames()->size());
1599 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); 1603 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id);
1600 } 1604 }
1601 1605
1602 TEST_F(QuicConnectionTest, SendingZeroBytes) { 1606 TEST_F(QuicConnectionTest, SendingZeroBytes) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 ProcessAckPacket(&ack_one); 1690 ProcessAckPacket(&ack_one);
1687 ProcessAckPacket(&ack_one); 1691 ProcessAckPacket(&ack_one);
1688 ProcessAckPacket(&ack_one); 1692 ProcessAckPacket(&ack_one);
1689 1693
1690 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no 1694 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no
1691 // change. 1695 // change.
1692 QuicAckFrame nack_two = InitAckFrame(3, 0); 1696 QuicAckFrame nack_two = InitAckFrame(3, 0);
1693 NackPacket(2, &nack_two); 1697 NackPacket(2, &nack_two);
1694 // The first nack should trigger a fast retransmission, but we'll be 1698 // The first nack should trigger a fast retransmission, but we'll be
1695 // write blocked, so the packet will be queued. 1699 // write blocked, so the packet will be queued.
1696 writer_->set_blocked(true); 1700 writer_->SetWriteBlocked();
1697 1701
1698 ProcessAckPacket(&nack_two); 1702 ProcessAckPacket(&nack_two);
1699 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1703 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1700 1704
1701 // Now, ack the previous transmission. 1705 // Now, ack the previous transmission.
1702 QuicAckFrame ack_all = InitAckFrame(3, 0); 1706 QuicAckFrame ack_all = InitAckFrame(3, 0);
1703 ProcessAckPacket(&ack_all); 1707 ProcessAckPacket(&ack_all);
1704 1708
1705 // Unblock the socket and attempt to send the queued packets. However, 1709 // Unblock the socket and attempt to send the queued packets. However,
1706 // since the previous transmission has been acked, we will not 1710 // since the previous transmission has been acked, we will not
1707 // send the retransmission. 1711 // send the retransmission.
1708 EXPECT_CALL(*send_algorithm_, 1712 EXPECT_CALL(*send_algorithm_,
1709 OnPacketSent(_, _, _, _, _)).Times(0); 1713 OnPacketSent(_, _, _, _, _)).Times(0);
1710 1714
1711 writer_->set_blocked(false); 1715 writer_->SetWritable();
1712 connection_.OnCanWrite(); 1716 connection_.OnCanWrite();
1713 1717
1714 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1718 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1715 } 1719 }
1716 1720
1717 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) { 1721 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) {
1718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1722 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1719 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 1723 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1);
1720 QuicPacketSequenceNumber largest_observed; 1724 QuicPacketSequenceNumber largest_observed;
1721 QuicByteCount packet_size; 1725 QuicByteCount packet_size;
(...skipping 11 matching lines...) Expand all
1733 ProcessAckPacket(&frame); 1737 ProcessAckPacket(&frame);
1734 } 1738 }
1735 1739
1736 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { 1740 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) {
1737 for (int i = 0; i < 10; ++i) { 1741 for (int i = 0; i < 10; ++i) {
1738 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1742 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1739 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); 1743 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL);
1740 } 1744 }
1741 1745
1742 // Block the congestion window and ensure they're queued. 1746 // Block the congestion window and ensure they're queued.
1743 writer_->set_blocked(true); 1747 writer_->SetWriteBlocked();
1744 clock_.AdvanceTime(DefaultRetransmissionTime()); 1748 clock_.AdvanceTime(DefaultRetransmissionTime());
1745 // Only one packet should be retransmitted. 1749 // Only one packet should be retransmitted.
1746 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1750 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1747 connection_.GetRetransmissionAlarm()->Fire(); 1751 connection_.GetRetransmissionAlarm()->Fire();
1748 EXPECT_TRUE(connection_.HasQueuedData()); 1752 EXPECT_TRUE(connection_.HasQueuedData());
1749 1753
1750 // Unblock the congestion window. 1754 // Unblock the congestion window.
1751 writer_->set_blocked(false); 1755 writer_->SetWritable();
1752 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 1756 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1753 2 * DefaultRetransmissionTime().ToMicroseconds())); 1757 2 * DefaultRetransmissionTime().ToMicroseconds()));
1754 // Retransmit already retransmitted packets event though the sequence number 1758 // Retransmit already retransmitted packets event though the sequence number
1755 // greater than the largest observed. 1759 // greater than the largest observed.
1756 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1760 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
1757 connection_.GetRetransmissionAlarm()->Fire(); 1761 connection_.GetRetransmissionAlarm()->Fire();
1758 connection_.OnCanWrite(); 1762 connection_.OnCanWrite();
1759 } 1763 }
1760 1764
1761 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { 1765 TEST_F(QuicConnectionTest, WriteBlockedThenSent) {
1762 writer_->set_blocked(true); 1766 writer_->SetWriteBlocked();
1763 1767
1764 writer_->set_is_write_blocked_data_buffered(true); 1768 writer_->set_is_write_blocked_data_buffered(true);
1765 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1769 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1766 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1770 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1767 1771
1768 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1772 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1769 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); 1773 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1770 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1774 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1771 } 1775 }
1772 1776
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 ASSERT_NE(0u, nack_sequence_number); 2165 ASSERT_NE(0u, nack_sequence_number);
2162 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2166 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2163 &connection_, rto_sequence_number)); 2167 &connection_, rto_sequence_number));
2164 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2168 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2165 &connection_, nack_sequence_number)); 2169 &connection_, nack_sequence_number));
2166 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2170 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2167 &connection_, nack_sequence_number)); 2171 &connection_, nack_sequence_number));
2168 } 2172 }
2169 2173
2170 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2174 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2171 writer_->set_blocked(true); 2175 writer_->SetWriteBlocked();
2172 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2176 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2173 // Make sure that RTO is not started when the packet is queued. 2177 // Make sure that RTO is not started when the packet is queued.
2174 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2178 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2175 2179
2176 // Test that RTO is started once we write to the socket. 2180 // Test that RTO is started once we write to the socket.
2177 writer_->set_blocked(false); 2181 writer_->SetWritable();
2178 connection_.OnCanWrite(); 2182 connection_.OnCanWrite();
2179 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2183 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2180 } 2184 }
2181 2185
2182 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) { 2186 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) {
2183 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2187 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2184 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2188 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2185 .Times(2); 2189 .Times(2);
2186 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL); 2190 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL);
2187 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); 2191 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL);
(...skipping 23 matching lines...) Expand all
2211 // than previously. 2215 // than previously.
2212 EXPECT_TRUE(retransmission_alarm->IsSet()); 2216 EXPECT_TRUE(retransmission_alarm->IsSet());
2213 QuicTime next_rto_time = retransmission_alarm->deadline(); 2217 QuicTime next_rto_time = retransmission_alarm->deadline();
2214 QuicTime expected_rto_time = 2218 QuicTime expected_rto_time =
2215 connection_.sent_packet_manager().GetRetransmissionTime(); 2219 connection_.sent_packet_manager().GetRetransmissionTime();
2216 EXPECT_EQ(next_rto_time, expected_rto_time); 2220 EXPECT_EQ(next_rto_time, expected_rto_time);
2217 } 2221 }
2218 2222
2219 TEST_F(QuicConnectionTest, TestQueued) { 2223 TEST_F(QuicConnectionTest, TestQueued) {
2220 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2224 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2221 writer_->set_blocked(true); 2225 writer_->SetWriteBlocked();
2222 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2226 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2223 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2227 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2224 2228
2225 // Attempt to send all packets, but since we're actually still 2229 // Attempt to send all packets, but since we're actually still
2226 // blocked, they should all remain queued. 2230 // blocked, they should all remain queued.
2227 EXPECT_FALSE(connection_.OnCanWrite()); 2231 EXPECT_FALSE(connection_.OnCanWrite());
2228 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2232 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2229 2233
2230 // Unblock the writes and actually send. 2234 // Unblock the writes and actually send.
2231 writer_->set_blocked(false); 2235 writer_->SetWritable();
2232 EXPECT_TRUE(connection_.OnCanWrite()); 2236 EXPECT_TRUE(connection_.OnCanWrite());
2233 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2237 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2234 } 2238 }
2235 2239
2236 TEST_F(QuicConnectionTest, CloseFecGroup) { 2240 TEST_F(QuicConnectionTest, CloseFecGroup) {
2237 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2241 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2238 // Don't send missing packet 1. 2242 // Don't send missing packet 1.
2239 // Don't send missing packet 2. 2243 // Don't send missing packet 2.
2240 ProcessFecProtectedPacket(3, false, !kEntropyFlag); 2244 ProcessFecProtectedPacket(3, false, !kEntropyFlag);
2241 // Don't send missing FEC packet 3. 2245 // Don't send missing FEC packet 3.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); 2375 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0);
2372 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2376 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2373 connection_.SendPacket( 2377 connection_.SendPacket(
2374 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2378 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2375 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); 2379 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce);
2376 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2380 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2377 } 2381 }
2378 2382
2379 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { 2383 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) {
2380 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2384 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2381 writer_->set_blocked(true); 2385 writer_->SetWriteBlocked();
2382 EXPECT_CALL(*send_algorithm_, 2386 EXPECT_CALL(*send_algorithm_,
2383 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2387 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2384 testing::Return(QuicTime::Delta::Zero())); 2388 testing::Return(QuicTime::Delta::Zero()));
2385 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); 2389 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0);
2386 connection_.SendPacket( 2390 connection_.SendPacket(
2387 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2391 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2388 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2392 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2389 } 2393 }
2390 2394
2391 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { 2395 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 QuicFrames frames; 2850 QuicFrames frames;
2847 QuicFrame frame(&frame1_); 2851 QuicFrame frame(&frame1_);
2848 frames.push_back(frame); 2852 frames.push_back(frame);
2849 scoped_ptr<QuicPacket> packet( 2853 scoped_ptr<QuicPacket> packet(
2850 framer_.BuildUnsizedDataPacket(header, frames).packet); 2854 framer_.BuildUnsizedDataPacket(header, frames).packet);
2851 scoped_ptr<QuicEncryptedPacket> encrypted( 2855 scoped_ptr<QuicEncryptedPacket> encrypted(
2852 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2856 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2853 2857
2854 framer_.set_version(QuicVersionMax()); 2858 framer_.set_version(QuicVersionMax());
2855 connection_.set_is_server(true); 2859 connection_.set_is_server(true);
2856 writer_->set_blocked(true); 2860 writer_->SetWriteBlocked();
2857 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2861 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2858 EXPECT_EQ(0u, writer_->last_packet_size()); 2862 EXPECT_EQ(0u, writer_->last_packet_size());
2859 EXPECT_TRUE(connection_.HasQueuedData()); 2863 EXPECT_TRUE(connection_.HasQueuedData());
2860 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); 2864 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
2861 2865
2862 writer_->set_blocked(false); 2866 writer_->SetWritable();
2863 connection_.OnCanWrite(); 2867 connection_.OnCanWrite();
2864 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); 2868 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL);
2865 2869
2866 size_t num_versions = arraysize(kSupportedQuicVersions); 2870 size_t num_versions = arraysize(kSupportedQuicVersions);
2867 EXPECT_EQ(num_versions, 2871 EXPECT_EQ(num_versions,
2868 writer_->version_negotiation_packet()->versions.size()); 2872 writer_->version_negotiation_packet()->versions.size());
2869 2873
2870 // We expect all versions in kSupportedQuicVersions to be 2874 // We expect all versions in kSupportedQuicVersions to be
2871 // included in the packet. 2875 // included in the packet.
2872 for (size_t i = 0; i < num_versions; ++i) { 2876 for (size_t i = 0; i < num_versions; ++i) {
(...skipping 18 matching lines...) Expand all
2891 QuicFrames frames; 2895 QuicFrames frames;
2892 QuicFrame frame(&frame1_); 2896 QuicFrame frame(&frame1_);
2893 frames.push_back(frame); 2897 frames.push_back(frame);
2894 scoped_ptr<QuicPacket> packet( 2898 scoped_ptr<QuicPacket> packet(
2895 framer_.BuildUnsizedDataPacket(header, frames).packet); 2899 framer_.BuildUnsizedDataPacket(header, frames).packet);
2896 scoped_ptr<QuicEncryptedPacket> encrypted( 2900 scoped_ptr<QuicEncryptedPacket> encrypted(
2897 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2901 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2898 2902
2899 framer_.set_version(QuicVersionMax()); 2903 framer_.set_version(QuicVersionMax());
2900 connection_.set_is_server(true); 2904 connection_.set_is_server(true);
2901 writer_->set_blocked(true); 2905 writer_->SetWriteBlocked();
2902 writer_->set_is_write_blocked_data_buffered(true); 2906 writer_->set_is_write_blocked_data_buffered(true);
2903 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2907 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2904 EXPECT_EQ(0u, writer_->last_packet_size()); 2908 EXPECT_EQ(0u, writer_->last_packet_size());
2905 EXPECT_FALSE(connection_.HasQueuedData()); 2909 EXPECT_FALSE(connection_.HasQueuedData());
2906 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); 2910 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
2907 } 2911 }
2908 2912
2909 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { 2913 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) {
2910 // Start out with some unsupported version. 2914 // Start out with some unsupported version.
2911 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( 2915 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); 3130 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector));
3127 EXPECT_EQ(QuicVersionMin(), connection_.version()); 3131 EXPECT_EQ(QuicVersionMin(), connection_.version());
3128 3132
3129 // Shouldn't be able to find a mutually supported version. 3133 // Shouldn't be able to find a mutually supported version.
3130 QuicVersionVector unsupported_version; 3134 QuicVersionVector unsupported_version;
3131 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); 3135 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED);
3132 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); 3136 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version));
3133 } 3137 }
3134 3138
3135 TEST_F(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) { 3139 TEST_F(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) {
3136 writer_->set_blocked(false); // Already default. 3140 writer_->SetWritable(); // Already default.
3137 3141
3138 // Send a packet (but write will not block). 3142 // Send a packet (but write will not block).
3139 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3143 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3140 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3144 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3141 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3145 EXPECT_EQ(1u, writer_->packets_write_attempts());
3142 3146
3143 // Send an erroneous packet to close the connection. 3147 // Send an erroneous packet to close the connection.
3144 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3148 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3145 ProcessDataPacket(6000, 0, !kEntropyFlag); 3149 ProcessDataPacket(6000, 0, !kEntropyFlag);
3146 EXPECT_EQ(2u, writer_->packets_write_attempts()); 3150 EXPECT_EQ(2u, writer_->packets_write_attempts());
3147 } 3151 }
3148 3152
3149 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { 3153 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) {
3150 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3154 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3151 writer_->set_blocked(true); 3155 writer_->SetWriteBlocked();
3152 3156
3153 // Send a packet to so that write will really block. 3157 // Send a packet to so that write will really block.
3154 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3158 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3155 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3159 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3156 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3160 EXPECT_EQ(1u, writer_->packets_write_attempts());
3157 3161
3158 // Send an erroneous packet to close the connection. 3162 // Send an erroneous packet to close the connection.
3159 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3163 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3160 ProcessDataPacket(6000, 0, !kEntropyFlag); 3164 ProcessDataPacket(6000, 0, !kEntropyFlag);
3161 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3165 EXPECT_EQ(1u, writer_->packets_write_attempts());
3162 } 3166 }
3163 3167
3164 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) { 3168 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) {
3165 writer_->set_blocked(true); 3169 writer_->SetWriteBlocked();
3166 3170
3167 // Send an erroneous packet to close the connection. 3171 // Send an erroneous packet to close the connection.
3168 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3172 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3169 ProcessDataPacket(6000, 0, !kEntropyFlag); 3173 ProcessDataPacket(6000, 0, !kEntropyFlag);
3170 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3174 EXPECT_EQ(1u, writer_->packets_write_attempts());
3171 } 3175 }
3172 3176
3173 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { 3177 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) {
3174 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3178 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3175 3179
3176 // Create a delegate which we expect to be called. 3180 // Create a delegate which we expect to be called.
3177 MockAckNotifierDelegate delegate; 3181 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3178 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3182 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);;
3179 3183
3180 // Send some data, which will register the delegate to be notified. 3184 // Send some data, which will register the delegate to be notified.
3181 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); 3185 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3182 3186
3183 // Process an ACK from the server which should trigger the callback. 3187 // Process an ACK from the server which should trigger the callback.
3184 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 3188 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1);
3185 QuicAckFrame frame = InitAckFrame(1, 0); 3189 QuicAckFrame frame = InitAckFrame(1, 0);
3186 ProcessAckPacket(&frame); 3190 ProcessAckPacket(&frame);
3187 } 3191 }
3188 3192
3189 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 3193 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3190 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3194 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3191 3195
3192 // Create a delegate which we don't expect to be called. 3196 // Create a delegate which we don't expect to be called.
3193 MockAckNotifierDelegate delegate; 3197 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3194 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; 3198 EXPECT_CALL(*delegate, OnAckNotification()).Times(0);;
3195 3199
3196 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 3200 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2);
3197 3201
3198 // Send some data, which will register the delegate to be notified. This will 3202 // Send some data, which will register the delegate to be notified. This will
3199 // not be ACKed and so the delegate should never be called. 3203 // not be ACKed and so the delegate should never be called.
3200 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); 3204 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3201 3205
3202 // Send some other data which we will ACK. 3206 // Send some other data which we will ACK.
3203 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3207 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3204 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); 3208 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL);
3205 3209
3206 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 3210 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
3207 // which we registered to be notified about. 3211 // which we registered to be notified about.
3208 QuicAckFrame frame = InitAckFrame(3, 0); 3212 QuicAckFrame frame = InitAckFrame(3, 0);
3209 NackPacket(1, &frame); 3213 NackPacket(1, &frame);
3210 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); 3214 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _));
3211 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); 3215 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _));
3212 ProcessAckPacket(&frame); 3216 ProcessAckPacket(&frame);
3213 } 3217 }
3214 3218
3215 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 3219 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3216 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3220 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3217 3221
3218 // Create a delegate which we expect to be called. 3222 // Create a delegate which we expect to be called.
3219 MockAckNotifierDelegate delegate; 3223 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3220 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3224 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);;
3221 3225
3222 // In total expect ACKs for all 4 packets. 3226 // In total expect ACKs for all 4 packets.
3223 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(4); 3227 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(4);
3224 3228
3225 // Send four packets, and register to be notified on ACK of packet 2. 3229 // Send four packets, and register to be notified on ACK of packet 2.
3226 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3230 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3227 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, &delegate); 3231 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, delegate.get());
3228 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL); 3232 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL);
3229 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL); 3233 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL);
3230 3234
3231 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit. 3235 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit.
3232 QuicAckFrame frame = InitAckFrame(4, 0); 3236 QuicAckFrame frame = InitAckFrame(4, 0);
3233 NackPacket(2, &frame); 3237 NackPacket(2, &frame);
3234 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); 3238 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _));
3235 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); 3239 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
3236 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3240 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3237 ProcessAckPacket(&frame); 3241 ProcessAckPacket(&frame);
3238 3242
3239 // Now we get an ACK for packet 5 (retransmitted packet 2), which should 3243 // Now we get an ACK for packet 5 (retransmitted packet 2), which should
3240 // trigger the callback. 3244 // trigger the callback.
3241 QuicAckFrame second_ack_frame = InitAckFrame(5, 0); 3245 QuicAckFrame second_ack_frame = InitAckFrame(5, 0);
3242 ProcessAckPacket(&second_ack_frame); 3246 ProcessAckPacket(&second_ack_frame);
3243 } 3247 }
3244 3248
3245 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting 3249 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting
3246 // ACK) triggers notification on our end. 3250 // ACK) triggers notification on our end.
3247 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 3251 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
3248 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3249 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 3253 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
3250 3254
3251 // Create a delegate which we expect to be called. 3255 // Create a delegate which we expect to be called.
3252 MockAckNotifierDelegate delegate; 3256 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3253 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3257 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);;
3254 3258
3255 // Expect ACKs for 1 packet. 3259 // Expect ACKs for 1 packet.
3256 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 3260 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1);
3257 3261
3258 // Send one packet, and register to be notified on ACK. 3262 // Send one packet, and register to be notified on ACK.
3259 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); 3263 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3260 3264
3261 // Ack packet gets dropped, but we receive an FEC packet that covers it. 3265 // Ack packet gets dropped, but we receive an FEC packet that covers it.
3262 // Should recover the Ack packet and trigger the notification callback. 3266 // Should recover the Ack packet and trigger the notification callback.
3263 QuicFrames frames; 3267 QuicFrames frames;
3264 3268
3265 QuicAckFrame ack_frame = InitAckFrame(1, 0); 3269 QuicAckFrame ack_frame = InitAckFrame(1, 0);
3266 frames.push_back(QuicFrame(&ack_frame)); 3270 frames.push_back(QuicFrame(&ack_frame));
3267 3271
3268 // Dummy stream frame to satisfy expectations set elsewhere. 3272 // Dummy stream frame to satisfy expectations set elsewhere.
3269 frames.push_back(QuicFrame(&frame1_)); 3273 frames.push_back(QuicFrame(&frame1_));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3355 true); 3359 true);
3356 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), 3360 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(),
3357 false); 3361 false);
3358 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); 3362 EXPECT_TRUE(client.sent_packet_manager().using_pacing());
3359 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 3363 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
3360 } 3364 }
3361 3365
3362 } // namespace 3366 } // namespace
3363 } // namespace test 3367 } // namespace test
3364 } // namespace net 3368 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_ack_notifier_test.cc ('k') | net/quic/quic_default_packet_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698