| 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 13 matching lines...) Expand all Loading... |
| 24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 25 #include "net/quic/test_tools/quic_test_utils.h" | 25 #include "net/quic/test_tools/quic_test_utils.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using base::StringPiece; | 29 using base::StringPiece; |
| 30 using std::map; | 30 using std::map; |
| 31 using std::vector; | 31 using std::vector; |
| 32 using testing::_; | 32 using testing::_; |
| 33 using testing::AnyNumber; | 33 using testing::AnyNumber; |
| 34 using testing::AtLeast; |
| 34 using testing::ContainerEq; | 35 using testing::ContainerEq; |
| 35 using testing::Contains; | 36 using testing::Contains; |
| 36 using testing::DoAll; | 37 using testing::DoAll; |
| 37 using testing::InSequence; | 38 using testing::InSequence; |
| 38 using testing::InvokeWithoutArgs; | 39 using testing::InvokeWithoutArgs; |
| 39 using testing::Ref; | 40 using testing::Ref; |
| 40 using testing::Return; | 41 using testing::Return; |
| 41 using testing::SaveArg; | 42 using testing::SaveArg; |
| 42 using testing::StrictMock; | 43 using testing::StrictMock; |
| 43 | 44 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 MockRandom* random_generator_; | 268 MockRandom* random_generator_; |
| 268 | 269 |
| 269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 270 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
| 270 }; | 271 }; |
| 271 | 272 |
| 272 class TestPacketWriter : public QuicPacketWriter { | 273 class TestPacketWriter : public QuicPacketWriter { |
| 273 public: | 274 public: |
| 274 TestPacketWriter() | 275 TestPacketWriter() |
| 275 : last_packet_size_(0), | 276 : last_packet_size_(0), |
| 276 write_blocked_(false), | 277 write_blocked_(false), |
| 277 block_next_write_(false), | 278 block_on_next_write_(false), |
| 278 is_write_blocked_data_buffered_(false), | 279 is_write_blocked_data_buffered_(false), |
| 279 is_server_(true), | 280 is_server_(true), |
| 280 final_bytes_of_last_packet_(0), | 281 final_bytes_of_last_packet_(0), |
| 281 final_bytes_of_previous_packet_(0), | 282 final_bytes_of_previous_packet_(0), |
| 282 use_tagging_decrypter_(false), | 283 use_tagging_decrypter_(false), |
| 283 packets_write_attempts_(0) { | 284 packets_write_attempts_(0) { |
| 284 } | 285 } |
| 285 | 286 |
| 286 // QuicPacketWriter interface | 287 // QuicPacketWriter interface |
| 287 virtual WriteResult WritePacket( | 288 virtual WriteResult WritePacket( |
| 288 const char* buffer, size_t buf_len, | 289 const char* buffer, size_t buf_len, |
| 289 const IPAddressNumber& self_address, | 290 const IPAddressNumber& self_address, |
| 290 const IPEndPoint& peer_address, | 291 const IPEndPoint& peer_address) OVERRIDE { |
| 291 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { | |
| 292 QuicEncryptedPacket packet(buffer, buf_len); | 292 QuicEncryptedPacket packet(buffer, buf_len); |
| 293 ++packets_write_attempts_; | 293 ++packets_write_attempts_; |
| 294 | 294 |
| 295 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { | 295 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { |
| 296 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; | 296 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; |
| 297 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, | 297 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, |
| 298 sizeof(final_bytes_of_last_packet_)); | 298 sizeof(final_bytes_of_last_packet_)); |
| 299 } | 299 } |
| 300 | 300 |
| 301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); | 301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); |
| 302 if (use_tagging_decrypter_) { | 302 if (use_tagging_decrypter_) { |
| 303 framer.SetDecrypter(new TaggingDecrypter); | 303 framer.SetDecrypter(new TaggingDecrypter); |
| 304 } | 304 } |
| 305 visitor_.Reset(); | 305 visitor_.Reset(); |
| 306 framer.set_visitor(&visitor_); | 306 framer.set_visitor(&visitor_); |
| 307 EXPECT_TRUE(framer.ProcessPacket(packet)); | 307 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 308 if (block_next_write_) { | 308 if (block_on_next_write_) { |
| 309 write_blocked_ = true; | 309 write_blocked_ = true; |
| 310 block_next_write_ = false; | 310 block_on_next_write_ = false; |
| 311 } | 311 } |
| 312 if (IsWriteBlocked()) { | 312 if (IsWriteBlocked()) { |
| 313 return WriteResult(WRITE_STATUS_BLOCKED, -1); | 313 return WriteResult(WRITE_STATUS_BLOCKED, -1); |
| 314 } | 314 } |
| 315 last_packet_size_ = packet.length(); | 315 last_packet_size_ = packet.length(); |
| 316 return WriteResult(WRITE_STATUS_OK, last_packet_size_); | 316 return WriteResult(WRITE_STATUS_OK, last_packet_size_); |
| 317 } | 317 } |
| 318 | 318 |
| 319 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 319 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
| 320 return is_write_blocked_data_buffered_; | 320 return is_write_blocked_data_buffered_; |
| 321 } | 321 } |
| 322 | 322 |
| 323 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } | 323 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } |
| 324 | 324 |
| 325 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } | 325 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } |
| 326 | 326 |
| 327 void BlockNextWrite() { block_next_write_ = true; } | 327 void BlockOnNextWrite() { block_on_next_write_ = true; } |
| 328 | 328 |
| 329 // 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. |
| 330 void Reset() { | 330 void Reset() { |
| 331 visitor_.Reset(); | 331 visitor_.Reset(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 QuicPacketHeader* header() { return visitor_.header(); } | 334 QuicPacketHeader* header() { return visitor_.header(); } |
| 335 | 335 |
| 336 size_t frame_count() const { return visitor_.frame_count(); } | 336 size_t frame_count() const { return visitor_.frame_count(); } |
| 337 | 337 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 void use_tagging_decrypter() { | 373 void use_tagging_decrypter() { |
| 374 use_tagging_decrypter_ = true; | 374 use_tagging_decrypter_ = true; |
| 375 } | 375 } |
| 376 | 376 |
| 377 uint32 packets_write_attempts() { return packets_write_attempts_; } | 377 uint32 packets_write_attempts() { return packets_write_attempts_; } |
| 378 | 378 |
| 379 private: | 379 private: |
| 380 FramerVisitorCapturingFrames visitor_; | 380 FramerVisitorCapturingFrames visitor_; |
| 381 size_t last_packet_size_; | 381 size_t last_packet_size_; |
| 382 bool write_blocked_; | 382 bool write_blocked_; |
| 383 bool block_next_write_; | 383 bool block_on_next_write_; |
| 384 bool is_write_blocked_data_buffered_; | 384 bool is_write_blocked_data_buffered_; |
| 385 bool is_server_; | 385 bool is_server_; |
| 386 uint32 final_bytes_of_last_packet_; | 386 uint32 final_bytes_of_last_packet_; |
| 387 uint32 final_bytes_of_previous_packet_; | 387 uint32 final_bytes_of_previous_packet_; |
| 388 bool use_tagging_decrypter_; | 388 bool use_tagging_decrypter_; |
| 389 uint32 packets_write_attempts_; | 389 uint32 packets_write_attempts_; |
| 390 | 390 |
| 391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
| 392 }; | 392 }; |
| 393 | 393 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL); | 465 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL); |
| 466 this->Flush(); | 466 this->Flush(); |
| 467 return consumed; | 467 return consumed; |
| 468 } | 468 } |
| 469 | 469 |
| 470 bool is_server() { | 470 bool is_server() { |
| 471 return QuicConnectionPeer::IsServer(this); | 471 return QuicConnectionPeer::IsServer(this); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void set_version(QuicVersion version) { | 474 void set_version(QuicVersion version) { |
| 475 framer_.set_version(version); | 475 QuicConnectionPeer::GetFramer(this)->set_version(version); |
| 476 } | 476 } |
| 477 | 477 |
| 478 void set_is_server(bool is_server) { | 478 void set_is_server(bool is_server) { |
| 479 writer_->set_is_server(is_server); | 479 writer_->set_is_server(is_server); |
| 480 QuicPacketCreatorPeer::SetIsServer( | 480 QuicPacketCreatorPeer::SetIsServer( |
| 481 QuicConnectionPeer::GetPacketCreator(this), is_server); | 481 QuicConnectionPeer::GetPacketCreator(this), is_server); |
| 482 QuicConnectionPeer::SetIsServer(this, is_server); | 482 QuicConnectionPeer::SetIsServer(this, is_server); |
| 483 } | 483 } |
| 484 | 484 |
| 485 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 485 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 // Send an erroneous packet to close the connection. | 834 // Send an erroneous packet to close the connection. |
| 835 EXPECT_CALL(visitor_, | 835 EXPECT_CALL(visitor_, |
| 836 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 836 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 837 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 837 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 838 // packet call to the visitor. | 838 // packet call to the visitor. |
| 839 ProcessDataPacket(6000, 0, !kEntropyFlag); | 839 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 840 EXPECT_FALSE( | 840 EXPECT_FALSE( |
| 841 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); | 841 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
| 842 } | 842 } |
| 843 | 843 |
| 844 void BlockOnNextWrite() { |
| 845 writer_->BlockOnNextWrite(); |
| 846 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
| 847 } |
| 848 |
| 844 QuicGuid guid_; | 849 QuicGuid guid_; |
| 845 QuicFramer framer_; | 850 QuicFramer framer_; |
| 846 QuicPacketCreator creator_; | 851 QuicPacketCreator creator_; |
| 847 MockEntropyCalculator entropy_calculator_; | 852 MockEntropyCalculator entropy_calculator_; |
| 848 | 853 |
| 849 MockSendAlgorithm* send_algorithm_; | 854 MockSendAlgorithm* send_algorithm_; |
| 850 TestReceiveAlgorithm* receive_algorithm_; | 855 TestReceiveAlgorithm* receive_algorithm_; |
| 851 MockClock clock_; | 856 MockClock clock_; |
| 852 MockRandom random_generator_; | 857 MockRandom random_generator_; |
| 853 scoped_ptr<TestConnectionHelper> helper_; | 858 scoped_ptr<TestConnectionHelper> helper_; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 | 1102 |
| 1098 // Start out saying the least unacked is 2. | 1103 // Start out saying the least unacked is 2. |
| 1099 creator_.set_sequence_number(5); | 1104 creator_.set_sequence_number(5); |
| 1100 QuicAckFrame frame = InitAckFrame(0, 2); | 1105 QuicAckFrame frame = InitAckFrame(0, 2); |
| 1101 ProcessAckPacket(&frame); | 1106 ProcessAckPacket(&frame); |
| 1102 | 1107 |
| 1103 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 1108 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
| 1104 // This should be fine. | 1109 // This should be fine. |
| 1105 creator_.set_sequence_number(1); | 1110 creator_.set_sequence_number(1); |
| 1106 QuicAckFrame frame2 = InitAckFrame(0, 1); | 1111 QuicAckFrame frame2 = InitAckFrame(0, 1); |
| 1107 // The scheduler will not process out of order acks. | 1112 // The scheduler will not process out of order acks, but all packet processing |
| 1108 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1113 // causes the connection to try to write. |
| 1114 EXPECT_CALL(visitor_, OnCanWrite()).Times(1); |
| 1109 ProcessAckPacket(&frame2); | 1115 ProcessAckPacket(&frame2); |
| 1110 | 1116 |
| 1111 // Now claim it's one, but set the ordering so it was sent "after" the first | 1117 // Now claim it's one, but set the ordering so it was sent "after" the first |
| 1112 // one. This should cause a connection error. | 1118 // one. This should cause a connection error. |
| 1113 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1119 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1114 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1120 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1115 creator_.set_sequence_number(7); | 1121 creator_.set_sequence_number(7); |
| 1116 ProcessAckPacket(&frame2); | 1122 ProcessAckPacket(&frame2); |
| 1117 } | 1123 } |
| 1118 | 1124 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1256 |
| 1251 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); | 1257 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); |
| 1252 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, | 1258 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, |
| 1253 connection_.options()->send_sequence_number_length); | 1259 connection_.options()->send_sequence_number_length); |
| 1254 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1260 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
| 1255 last_header()->public_header.sequence_number_length); | 1261 last_header()->public_header.sequence_number_length); |
| 1256 } | 1262 } |
| 1257 | 1263 |
| 1258 TEST_F(QuicConnectionTest, BasicSending) { | 1264 TEST_F(QuicConnectionTest, BasicSending) { |
| 1259 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1265 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1260 // EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | |
| 1261 // EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(6); | |
| 1262 QuicPacketSequenceNumber last_packet; | 1266 QuicPacketSequenceNumber last_packet; |
| 1263 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1267 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1264 EXPECT_EQ(1u, last_packet); | 1268 EXPECT_EQ(1u, last_packet); |
| 1265 SendAckPacketToPeer(); // Packet 2 | 1269 SendAckPacketToPeer(); // Packet 2 |
| 1266 | 1270 |
| 1267 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1271 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 1268 | 1272 |
| 1269 SendAckPacketToPeer(); // Packet 3 | 1273 SendAckPacketToPeer(); // Packet 3 |
| 1270 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1274 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 1271 | 1275 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 // All packets carry version info till version is negotiated. | 1337 // All packets carry version info till version is negotiated. |
| 1334 size_t payload_length; | 1338 size_t payload_length; |
| 1335 connection_.options()->max_packet_length = | 1339 connection_.options()->max_packet_length = |
| 1336 GetPacketLengthForOneStream( | 1340 GetPacketLengthForOneStream( |
| 1337 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1341 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1338 IN_FEC_GROUP, &payload_length); | 1342 IN_FEC_GROUP, &payload_length); |
| 1339 // And send FEC every two packets. | 1343 // And send FEC every two packets. |
| 1340 connection_.options()->max_packets_per_fec_group = 2; | 1344 connection_.options()->max_packets_per_fec_group = 2; |
| 1341 | 1345 |
| 1342 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1346 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1343 writer_->BlockNextWrite(); | 1347 BlockOnNextWrite(); |
| 1344 const string payload(payload_length, 'a'); | 1348 const string payload(payload_length, 'a'); |
| 1345 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1349 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
| 1346 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1350 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 1347 // Expect the first data packet and the fec packet to be queued. | 1351 // Expect the first data packet and the fec packet to be queued. |
| 1348 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1352 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 1349 } | 1353 } |
| 1350 | 1354 |
| 1351 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1355 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
| 1352 connection_.options()->max_packets_per_fec_group = 1; | 1356 connection_.options()->max_packets_per_fec_group = 1; |
| 1353 // 1 Data and 1 FEC packet. | 1357 // 1 Data and 1 FEC packet. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 EXPECT_EQ(1u, frame.stream_id); | 1607 EXPECT_EQ(1u, frame.stream_id); |
| 1604 EXPECT_EQ("ABCD", string(static_cast<char*> | 1608 EXPECT_EQ("ABCD", string(static_cast<char*> |
| 1605 (frame.data.iovec()[0].iov_base), | 1609 (frame.data.iovec()[0].iov_base), |
| 1606 (frame.data.iovec()[0].iov_len))); | 1610 (frame.data.iovec()[0].iov_len))); |
| 1607 } | 1611 } |
| 1608 | 1612 |
| 1609 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { | 1613 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { |
| 1610 // Try to send two stream frames in 1 packet by using writev. | 1614 // Try to send two stream frames in 1 packet by using writev. |
| 1611 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1615 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 1612 | 1616 |
| 1613 writer_->BlockNextWrite(); | 1617 BlockOnNextWrite(); |
| 1614 char data[] = "ABCD"; | 1618 char data[] = "ABCD"; |
| 1615 IOVector data_iov; | 1619 IOVector data_iov; |
| 1616 data_iov.AppendNoCoalesce(data, 2); | 1620 data_iov.AppendNoCoalesce(data, 2); |
| 1617 data_iov.AppendNoCoalesce(data + 2, 2); | 1621 data_iov.AppendNoCoalesce(data + 2, 2); |
| 1618 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1622 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); |
| 1619 | 1623 |
| 1620 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1624 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1621 EXPECT_TRUE(connection_.HasQueuedData()); | 1625 EXPECT_TRUE(connection_.HasQueuedData()); |
| 1622 | 1626 |
| 1623 // Unblock the writes and actually send. | 1627 // Unblock the writes and actually send. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 ProcessAckPacket(&ack_one); | 1726 ProcessAckPacket(&ack_one); |
| 1723 ProcessAckPacket(&ack_one); | 1727 ProcessAckPacket(&ack_one); |
| 1724 ProcessAckPacket(&ack_one); | 1728 ProcessAckPacket(&ack_one); |
| 1725 | 1729 |
| 1726 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no | 1730 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no |
| 1727 // change. | 1731 // change. |
| 1728 QuicAckFrame nack_two = InitAckFrame(3, 0); | 1732 QuicAckFrame nack_two = InitAckFrame(3, 0); |
| 1729 NackPacket(2, &nack_two); | 1733 NackPacket(2, &nack_two); |
| 1730 // The first nack should trigger a fast retransmission, but we'll be | 1734 // The first nack should trigger a fast retransmission, but we'll be |
| 1731 // write blocked, so the packet will be queued. | 1735 // write blocked, so the packet will be queued. |
| 1732 writer_->BlockNextWrite(); | 1736 BlockOnNextWrite(); |
| 1733 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1737 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1734 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1738 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
| 1735 | |
| 1736 ProcessAckPacket(&nack_two); | 1739 ProcessAckPacket(&nack_two); |
| 1737 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1740 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1738 | 1741 |
| 1739 // Now, ack the previous transmission. | 1742 // Now, ack the previous transmission. |
| 1740 QuicAckFrame ack_all = InitAckFrame(3, 0); | 1743 QuicAckFrame ack_all = InitAckFrame(3, 0); |
| 1741 ProcessAckPacket(&ack_all); | 1744 ProcessAckPacket(&ack_all); |
| 1742 | 1745 |
| 1743 // Unblock the socket and attempt to send the queued packets. However, | 1746 // Unblock the socket and attempt to send the queued packets. However, |
| 1744 // since the previous transmission has been acked, we will not | 1747 // since the previous transmission has been acked, we will not |
| 1745 // send the retransmission. | 1748 // send the retransmission. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1772 ProcessAckPacket(&frame); | 1775 ProcessAckPacket(&frame); |
| 1773 } | 1776 } |
| 1774 | 1777 |
| 1775 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { | 1778 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { |
| 1776 for (int i = 0; i < 10; ++i) { | 1779 for (int i = 0; i < 10; ++i) { |
| 1777 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1780 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1778 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); | 1781 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); |
| 1779 } | 1782 } |
| 1780 | 1783 |
| 1781 // Block the congestion window and ensure they're queued. | 1784 // Block the congestion window and ensure they're queued. |
| 1782 writer_->BlockNextWrite(); | 1785 BlockOnNextWrite(); |
| 1783 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1786 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1784 // Only one packet should be retransmitted. | 1787 // Only one packet should be retransmitted. |
| 1785 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1788 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1786 connection_.GetRetransmissionAlarm()->Fire(); | 1789 connection_.GetRetransmissionAlarm()->Fire(); |
| 1787 EXPECT_TRUE(connection_.HasQueuedData()); | 1790 EXPECT_TRUE(connection_.HasQueuedData()); |
| 1788 | 1791 |
| 1789 // Unblock the congestion window. | 1792 // Unblock the congestion window. |
| 1790 writer_->SetWritable(); | 1793 writer_->SetWritable(); |
| 1791 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1794 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 1792 2 * DefaultRetransmissionTime().ToMicroseconds())); | 1795 2 * DefaultRetransmissionTime().ToMicroseconds())); |
| 1793 // Retransmit already retransmitted packets event though the sequence number | 1796 // Retransmit already retransmitted packets event though the sequence number |
| 1794 // greater than the largest observed. | 1797 // greater than the largest observed. |
| 1795 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); | 1798 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); |
| 1796 connection_.GetRetransmissionAlarm()->Fire(); | 1799 connection_.GetRetransmissionAlarm()->Fire(); |
| 1797 connection_.OnCanWrite(); | 1800 connection_.OnCanWrite(); |
| 1798 } | 1801 } |
| 1799 | 1802 |
| 1800 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { | 1803 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { |
| 1801 writer_->BlockNextWrite(); | 1804 BlockOnNextWrite(); |
| 1802 writer_->set_is_write_blocked_data_buffered(true); | 1805 writer_->set_is_write_blocked_data_buffered(true); |
| 1803 | |
| 1804 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1806 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 1805 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1807 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1806 | 1808 |
| 1807 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1809 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1808 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1810 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1809 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1811 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1810 } | 1812 } |
| 1811 | 1813 |
| 1812 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { | 1814 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { |
| 1813 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1815 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1814 writer_->BlockNextWrite(); | 1816 BlockOnNextWrite(); |
| 1815 | |
| 1816 writer_->set_is_write_blocked_data_buffered(true); | 1817 writer_->set_is_write_blocked_data_buffered(true); |
| 1817 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 1818 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1819 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1819 | 1820 |
| 1820 // Ack the sent packet before the callback returns, which happens in | 1821 // Ack the sent packet before the callback returns, which happens in |
| 1821 // rare circumstances with write blocked sockets. | 1822 // rare circumstances with write blocked sockets. |
| 1822 QuicAckFrame ack = InitAckFrame(1, 0); | 1823 QuicAckFrame ack = InitAckFrame(1, 0); |
| 1823 ProcessAckPacket(&ack); | 1824 ProcessAckPacket(&ack); |
| 1824 | 1825 |
| 1825 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 1826 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 1826 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1827 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1827 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1828 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1828 } | 1829 } |
| 1829 | 1830 |
| 1830 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { | 1831 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { |
| 1831 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1832 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1832 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1833 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1833 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1834 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1834 | 1835 |
| 1835 writer_->BlockNextWrite(); | 1836 BlockOnNextWrite(); |
| 1836 writer_->set_is_write_blocked_data_buffered(true); | 1837 writer_->set_is_write_blocked_data_buffered(true); |
| 1837 | |
| 1838 // Simulate the retransmission alarm firing. | 1838 // Simulate the retransmission alarm firing. |
| 1839 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); | 1839 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); |
| 1840 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1840 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1841 connection_.GetRetransmissionAlarm()->Fire(); | 1841 connection_.GetRetransmissionAlarm()->Fire(); |
| 1842 | 1842 |
| 1843 // Ack the sent packet before the callback returns, which happens in | 1843 // Ack the sent packet before the callback returns, which happens in |
| 1844 // rare circumstances with write blocked sockets. | 1844 // rare circumstances with write blocked sockets. |
| 1845 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1845 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1846 QuicAckFrame ack = InitAckFrame(1, 0); | 1846 QuicAckFrame ack = InitAckFrame(1, 0); |
| 1847 ProcessAckPacket(&ack); | 1847 ProcessAckPacket(&ack); |
| 1848 | 1848 |
| 1849 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1849 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1850 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1850 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1851 } | 1851 } |
| 1852 | 1852 |
| 1853 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { | 1853 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { |
| 1854 // Block the connection. | 1854 // Block the connection. |
| 1855 writer_->BlockNextWrite(); | 1855 BlockOnNextWrite(); |
| 1856 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1856 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1857 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1857 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1858 EXPECT_TRUE(writer_->IsWriteBlocked()); | 1858 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 1859 | 1859 |
| 1860 // Set the send and resumption alarms. Fire the alarms and ensure they don't | 1860 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
| 1861 // attempt to write. | 1861 // attempt to write. |
| 1862 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); | 1862 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); |
| 1863 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); | 1863 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); |
| 1864 connection_.GetResumeWritesAlarm()->Fire(); | 1864 connection_.GetResumeWritesAlarm()->Fire(); |
| 1865 connection_.GetSendAlarm()->Fire(); | 1865 connection_.GetSendAlarm()->Fire(); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2248 ASSERT_NE(0u, nack_sequence_number); | 2248 ASSERT_NE(0u, nack_sequence_number); |
| 2249 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2249 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2250 &connection_, rto_sequence_number)); | 2250 &connection_, rto_sequence_number)); |
| 2251 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2251 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2252 &connection_, nack_sequence_number)); | 2252 &connection_, nack_sequence_number)); |
| 2253 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( | 2253 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( |
| 2254 &connection_, nack_sequence_number)); | 2254 &connection_, nack_sequence_number)); |
| 2255 } | 2255 } |
| 2256 | 2256 |
| 2257 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { | 2257 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { |
| 2258 writer_->BlockNextWrite(); | 2258 BlockOnNextWrite(); |
| 2259 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2259 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 2260 // Make sure that RTO is not started when the packet is queued. | 2260 // Make sure that RTO is not started when the packet is queued. |
| 2261 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2261 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2262 | 2262 |
| 2263 // Test that RTO is started once we write to the socket. | 2263 // Test that RTO is started once we write to the socket. |
| 2264 writer_->SetWritable(); | 2264 writer_->SetWritable(); |
| 2265 connection_.OnCanWrite(); | 2265 connection_.OnCanWrite(); |
| 2266 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2266 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2267 } | 2267 } |
| 2268 | 2268 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2299 // than previously. | 2299 // than previously. |
| 2300 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2300 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2301 QuicTime next_rto_time = retransmission_alarm->deadline(); | 2301 QuicTime next_rto_time = retransmission_alarm->deadline(); |
| 2302 QuicTime expected_rto_time = | 2302 QuicTime expected_rto_time = |
| 2303 connection_.sent_packet_manager().GetRetransmissionTime(); | 2303 connection_.sent_packet_manager().GetRetransmissionTime(); |
| 2304 EXPECT_EQ(next_rto_time, expected_rto_time); | 2304 EXPECT_EQ(next_rto_time, expected_rto_time); |
| 2305 } | 2305 } |
| 2306 | 2306 |
| 2307 TEST_F(QuicConnectionTest, TestQueued) { | 2307 TEST_F(QuicConnectionTest, TestQueued) { |
| 2308 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2308 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2309 writer_->BlockNextWrite(); | 2309 BlockOnNextWrite(); |
| 2310 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2310 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 2311 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2311 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2312 | 2312 |
| 2313 // Unblock the writes and actually send. | 2313 // Unblock the writes and actually send. |
| 2314 writer_->SetWritable(); | 2314 writer_->SetWritable(); |
| 2315 EXPECT_TRUE(connection_.OnCanWrite()); | 2315 EXPECT_TRUE(connection_.OnCanWrite()); |
| 2316 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2316 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2317 } | 2317 } |
| 2318 | 2318 |
| 2319 TEST_F(QuicConnectionTest, CloseFecGroup) { | 2319 TEST_F(QuicConnectionTest, CloseFecGroup) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2454 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); | 2454 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); |
| 2455 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2455 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2456 connection_.SendPacket( | 2456 connection_.SendPacket( |
| 2457 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2457 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2458 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); | 2458 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); |
| 2459 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2459 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2460 } | 2460 } |
| 2461 | 2461 |
| 2462 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { | 2462 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { |
| 2463 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2463 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2464 writer_->BlockNextWrite(); | 2464 BlockOnNextWrite(); |
| 2465 EXPECT_CALL(*send_algorithm_, | 2465 EXPECT_CALL(*send_algorithm_, |
| 2466 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2466 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2467 testing::Return(QuicTime::Delta::Zero())); | 2467 testing::Return(QuicTime::Delta::Zero())); |
| 2468 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2468 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
| 2469 connection_.SendPacket( | 2469 connection_.SendPacket( |
| 2470 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2470 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2471 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2471 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2472 } | 2472 } |
| 2473 | 2473 |
| 2474 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 2474 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 QuicFrames frames; | 2929 QuicFrames frames; |
| 2930 QuicFrame frame(&frame1_); | 2930 QuicFrame frame(&frame1_); |
| 2931 frames.push_back(frame); | 2931 frames.push_back(frame); |
| 2932 scoped_ptr<QuicPacket> packet( | 2932 scoped_ptr<QuicPacket> packet( |
| 2933 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2933 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 2934 scoped_ptr<QuicEncryptedPacket> encrypted( | 2934 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 2935 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2935 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 2936 | 2936 |
| 2937 framer_.set_version(QuicVersionMax()); | 2937 framer_.set_version(QuicVersionMax()); |
| 2938 connection_.set_is_server(true); | 2938 connection_.set_is_server(true); |
| 2939 writer_->BlockNextWrite(); | 2939 BlockOnNextWrite(); |
| 2940 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2940 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2941 EXPECT_EQ(0u, writer_->last_packet_size()); | 2941 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 2942 EXPECT_TRUE(connection_.HasQueuedData()); | 2942 EXPECT_TRUE(connection_.HasQueuedData()); |
| 2943 | 2943 |
| 2944 writer_->SetWritable(); | 2944 writer_->SetWritable(); |
| 2945 connection_.OnCanWrite(); | 2945 connection_.OnCanWrite(); |
| 2946 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); | 2946 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); |
| 2947 | 2947 |
| 2948 size_t num_versions = arraysize(kSupportedQuicVersions); | 2948 size_t num_versions = arraysize(kSupportedQuicVersions); |
| 2949 EXPECT_EQ(num_versions, | 2949 EXPECT_EQ(num_versions, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2973 QuicFrames frames; | 2973 QuicFrames frames; |
| 2974 QuicFrame frame(&frame1_); | 2974 QuicFrame frame(&frame1_); |
| 2975 frames.push_back(frame); | 2975 frames.push_back(frame); |
| 2976 scoped_ptr<QuicPacket> packet( | 2976 scoped_ptr<QuicPacket> packet( |
| 2977 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2977 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 2978 scoped_ptr<QuicEncryptedPacket> encrypted( | 2978 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 2979 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2979 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 2980 | 2980 |
| 2981 framer_.set_version(QuicVersionMax()); | 2981 framer_.set_version(QuicVersionMax()); |
| 2982 connection_.set_is_server(true); | 2982 connection_.set_is_server(true); |
| 2983 writer_->BlockNextWrite(); | 2983 BlockOnNextWrite(); |
| 2984 writer_->set_is_write_blocked_data_buffered(true); | 2984 writer_->set_is_write_blocked_data_buffered(true); |
| 2985 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2985 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2986 EXPECT_EQ(0u, writer_->last_packet_size()); | 2986 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 2987 EXPECT_FALSE(connection_.HasQueuedData()); | 2987 EXPECT_FALSE(connection_.HasQueuedData()); |
| 2988 } | 2988 } |
| 2989 | 2989 |
| 2990 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 2990 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 2991 // Start out with some unsupported version. | 2991 // Start out with some unsupported version. |
| 2992 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 2992 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
| 2993 QUIC_VERSION_UNSUPPORTED); | 2993 QUIC_VERSION_UNSUPPORTED); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3251 // Send a packet. | 3251 // Send a packet. |
| 3252 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3252 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3253 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3253 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3254 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3254 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3255 | 3255 |
| 3256 TriggerConnectionClose(); | 3256 TriggerConnectionClose(); |
| 3257 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 3257 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
| 3258 } | 3258 } |
| 3259 | 3259 |
| 3260 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { | 3260 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { |
| 3261 writer_->BlockNextWrite(); | 3261 BlockOnNextWrite(); |
| 3262 TriggerConnectionClose(); | 3262 TriggerConnectionClose(); |
| 3263 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3263 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3264 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3264 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 3265 } | 3265 } |
| 3266 | 3266 |
| 3267 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { | 3267 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { |
| 3268 writer_->BlockNextWrite(); | 3268 BlockOnNextWrite(); |
| 3269 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3269 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3270 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3270 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 3271 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3271 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3272 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3272 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 3273 TriggerConnectionClose(); | 3273 TriggerConnectionClose(); |
| 3274 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3274 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3275 } | 3275 } |
| 3276 | 3276 |
| 3277 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { | 3277 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { |
| 3278 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3278 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3463 true); | 3463 true); |
| 3464 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3464 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 3465 false); | 3465 false); |
| 3466 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3466 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
| 3467 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3467 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3468 } | 3468 } |
| 3469 | 3469 |
| 3470 } // namespace | 3470 } // namespace |
| 3471 } // namespace test | 3471 } // namespace test |
| 3472 } // namespace net | 3472 } // namespace net |
| OLD | NEW |