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

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

Issue 76723002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation error Created 7 years, 1 month 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_connection_helper_test.cc ('k') | net/quic/quic_framer.cc » ('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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 public: 271 public:
272 TestPacketWriter() 272 TestPacketWriter()
273 : last_packet_size_(0), 273 : last_packet_size_(0),
274 blocked_(false), 274 blocked_(false),
275 is_write_blocked_data_buffered_(false), 275 is_write_blocked_data_buffered_(false),
276 is_server_(true), 276 is_server_(true),
277 use_tagging_decrypter_(false), 277 use_tagging_decrypter_(false),
278 packets_write_attempts_(0) { 278 packets_write_attempts_(0) {
279 } 279 }
280 280
281 virtual ~TestPacketWriter() {
282 STLDeleteElements(&stream_data_);
283 }
284
285 // QuicPacketWriter 281 // QuicPacketWriter
286 virtual WriteResult WritePacket( 282 virtual WriteResult WritePacket(
287 const char* buffer, size_t buf_len, 283 const char* buffer, size_t buf_len,
288 const IPAddressNumber& self_address, 284 const IPAddressNumber& self_address,
289 const IPEndPoint& peer_address, 285 const IPEndPoint& peer_address,
290 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { 286 QuicBlockedWriterInterface* blocked_writer) OVERRIDE {
291 QuicEncryptedPacket packet(buffer, buf_len); 287 QuicEncryptedPacket packet(buffer, buf_len);
292 ++packets_write_attempts_; 288 ++packets_write_attempts_;
293 289
294 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { 290 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) {
295 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, 291 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4,
296 sizeof(final_bytes_of_last_packet_)); 292 sizeof(final_bytes_of_last_packet_));
297 } 293 }
298 294
299 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); 295 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_);
300 if (use_tagging_decrypter_) { 296 if (use_tagging_decrypter_) {
301 framer.SetDecrypter(new TaggingDecrypter); 297 framer.SetDecrypter(new TaggingDecrypter);
302 } 298 }
303 FramerVisitorCapturingFrames visitor; 299 visitor_.Reset();
304 framer.set_visitor(&visitor); 300 framer.set_visitor(&visitor_);
305 EXPECT_TRUE(framer.ProcessPacket(packet)); 301 EXPECT_TRUE(framer.ProcessPacket(packet));
306 header_ = *visitor.header();
307 frame_count_ = visitor.frame_count();
308 if (visitor.ack()) {
309 ack_.reset(new QuicAckFrame(*visitor.ack()));
310 }
311 if (visitor.feedback()) {
312 feedback_.reset(new QuicCongestionFeedbackFrame(*visitor.feedback()));
313 }
314 if (visitor.stream_frames() != NULL && !visitor.stream_frames()->empty()) {
315 stream_frames_ = *visitor.stream_frames();
316 // Also make a copy of underlying data, since the data that the frames in
317 // |stream_frames_| point to is bound to the |visitor|'s scope.
318 for (size_t i = 0; i < stream_frames_.size(); ++i) {
319 stream_data_.push_back(new string(*visitor.stream_data()[i]));
320 IOVector data;
321 data.Append(const_cast<char*>(stream_data_.back()->data()),
322 stream_data_.back()->size());
323 stream_frames_[i].data = data;
324 }
325 }
326 if (visitor.version_negotiation_packet() != NULL) {
327 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(
328 *visitor.version_negotiation_packet()));
329 }
330 if (blocked_) { 302 if (blocked_) {
331 return WriteResult(WRITE_STATUS_BLOCKED, -1); 303 return WriteResult(WRITE_STATUS_BLOCKED, -1);
332 } 304 }
333 last_packet_size_ = packet.length(); 305 last_packet_size_ = packet.length();
334 return WriteResult(WRITE_STATUS_OK, last_packet_size_); 306 return WriteResult(WRITE_STATUS_OK, last_packet_size_);
335 } 307 }
336 308
337 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { 309 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE {
338 return is_write_blocked_data_buffered_; 310 return is_write_blocked_data_buffered_;
339 } 311 }
340 312
341 QuicPacketHeader* header() { return &header_; } 313 QuicPacketHeader* header() { return visitor_.header(); }
342 314
343 size_t frame_count() const { return frame_count_; } 315 size_t frame_count() const { return visitor_.frame_count(); }
344 316
345 QuicAckFrame* ack() { return ack_.get(); } 317 QuicAckFrame* ack() { return visitor_.ack(); }
346 318
347 QuicCongestionFeedbackFrame* feedback() { return feedback_.get(); } 319 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); }
320
321 QuicConnectionCloseFrame* close() { return visitor_.close(); }
348 322
349 const vector<QuicStreamFrame>* stream_frames() const { 323 const vector<QuicStreamFrame>* stream_frames() const {
350 return &stream_frames_; 324 return visitor_.stream_frames();
351 } 325 }
352 326
353 size_t last_packet_size() { 327 size_t last_packet_size() {
354 return last_packet_size_; 328 return last_packet_size_;
355 } 329 }
356 330
357 QuicVersionNegotiationPacket* version_negotiation_packet() { 331 QuicVersionNegotiationPacket* version_negotiation_packet() {
358 return version_negotiation_packet_.get(); 332 return visitor_.version_negotiation_packet();
359 } 333 }
360 334
361 void set_blocked(bool blocked) { blocked_ = blocked; } 335 void set_blocked(bool blocked) { blocked_ = blocked; }
362 336
363 void set_is_write_blocked_data_buffered(bool buffered) { 337 void set_is_write_blocked_data_buffered(bool buffered) {
364 is_write_blocked_data_buffered_ = buffered; 338 is_write_blocked_data_buffered_ = buffered;
365 } 339 }
366 340
367 void set_is_server(bool is_server) { is_server_ = is_server; } 341 void set_is_server(bool is_server) { is_server_ = is_server; }
368 342
369 // final_bytes_of_last_packet_ returns the last four bytes of the previous 343 // final_bytes_of_last_packet_ returns the last four bytes of the previous
370 // packet as a little-endian, uint32. This is intended to be used with a 344 // packet as a little-endian, uint32. This is intended to be used with a
371 // TaggingEncrypter so that tests can determine which encrypter was used for 345 // TaggingEncrypter so that tests can determine which encrypter was used for
372 // a given packet. 346 // a given packet.
373 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; } 347 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; }
374 348
375 void use_tagging_decrypter() { 349 void use_tagging_decrypter() {
376 use_tagging_decrypter_ = true; 350 use_tagging_decrypter_ = true;
377 } 351 }
378 352
379 uint32 packets_write_attempts() { return packets_write_attempts_; } 353 uint32 packets_write_attempts() { return packets_write_attempts_; }
380 354
381 private: 355 private:
382 QuicPacketHeader header_; 356 FramerVisitorCapturingFrames visitor_;
383 size_t frame_count_;
384 scoped_ptr<QuicAckFrame> ack_;
385 scoped_ptr<QuicCongestionFeedbackFrame> feedback_;
386 vector<QuicStreamFrame> stream_frames_;
387 vector<string*> stream_data_;
388 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_;
389 size_t last_packet_size_; 357 size_t last_packet_size_;
390 bool blocked_; 358 bool blocked_;
391 bool is_write_blocked_data_buffered_; 359 bool is_write_blocked_data_buffered_;
392 bool is_server_; 360 bool is_server_;
393 uint32 final_bytes_of_last_packet_; 361 uint32 final_bytes_of_last_packet_;
394 bool use_tagging_decrypter_; 362 bool use_tagging_decrypter_;
395 uint32 packets_write_attempts_; 363 uint32 packets_write_attempts_;
396 364
397 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); 365 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter);
398 }; 366 };
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 : guid_(42), 493 : guid_(42),
526 framer_(QuicSupportedVersions(), QuicTime::Zero(), false), 494 framer_(QuicSupportedVersions(), QuicTime::Zero(), false),
527 creator_(guid_, &framer_, QuicRandom::GetInstance(), false), 495 creator_(guid_, &framer_, QuicRandom::GetInstance(), false),
528 send_algorithm_(new StrictMock<MockSendAlgorithm>), 496 send_algorithm_(new StrictMock<MockSendAlgorithm>),
529 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 497 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
530 writer_(new TestPacketWriter()), 498 writer_(new TestPacketWriter()),
531 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), false), 499 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), false),
532 frame1_(1, false, 0, MakeIOVector(data1)), 500 frame1_(1, false, 0, MakeIOVector(data1)),
533 frame2_(1, false, 3, MakeIOVector(data2)), 501 frame2_(1, false, 3, MakeIOVector(data2)),
534 accept_packet_(true) { 502 accept_packet_(true) {
535 // TODO(rtenneti): remove g_* flags.
536 FLAGS_track_retransmission_history = true;
537 connection_.set_visitor(&visitor_); 503 connection_.set_visitor(&visitor_);
538 connection_.SetSendAlgorithm(send_algorithm_); 504 connection_.SetSendAlgorithm(send_algorithm_);
539 framer_.set_received_entropy_calculator(&entropy_calculator_); 505 framer_.set_received_entropy_calculator(&entropy_calculator_);
540 // Simplify tests by not sending feedback unless specifically configured. 506 // Simplify tests by not sending feedback unless specifically configured.
541 SetFeedback(NULL); 507 SetFeedback(NULL);
542 EXPECT_CALL( 508 EXPECT_CALL(
543 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return( 509 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return(
544 QuicTime::Delta::Zero())); 510 QuicTime::Delta::Zero()));
545 EXPECT_CALL(*receive_algorithm_, 511 EXPECT_CALL(*receive_algorithm_,
546 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); 512 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber());
547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 513 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
548 .Times(AnyNumber()); 514 .Times(AnyNumber());
549 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 515 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
550 Return(QuicTime::Delta::Zero())); 516 Return(QuicTime::Delta::Zero()));
551 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( 517 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return(
552 QuicBandwidth::FromKBitsPerSecond(100))); 518 QuicBandwidth::FromKBitsPerSecond(100)));
553 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( 519 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return(
554 QuicTime::Delta::FromMilliseconds(100))); 520 QuicTime::Delta::FromMilliseconds(100)));
555 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 521 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
556 .WillByDefault(Return(true)); 522 .WillByDefault(Return(true));
557 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 523 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
558 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()).WillRepeatedly( 524 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()).WillRepeatedly(
559 Return(true)); 525 Return(true));
560 } 526 }
561 527
562 void SetUp() {
563 FLAGS_bundle_ack_with_outgoing_packet = GetParam();
564 }
565
566 QuicAckFrame* outgoing_ack() { 528 QuicAckFrame* outgoing_ack() {
567 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); 529 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_));
568 return outgoing_ack_.get(); 530 return outgoing_ack_.get();
569 } 531 }
570 532
571 QuicAckFrame* last_ack() { 533 QuicAckFrame* last_ack() {
572 return writer_->ack(); 534 return writer_->ack();
573 } 535 }
574 536
575 QuicCongestionFeedbackFrame* last_feedback() { 537 QuicCongestionFeedbackFrame* last_feedback() {
576 return writer_->feedback(); 538 return writer_->feedback();
577 } 539 }
578 540
541 QuicConnectionCloseFrame* last_close() {
542 return writer_->close();
543 }
544
579 QuicPacketHeader* last_header() { 545 QuicPacketHeader* last_header() {
580 return writer_->header(); 546 return writer_->header();
581 } 547 }
582 548
583 size_t last_sent_packet_size() { 549 size_t last_sent_packet_size() {
584 return writer_->last_packet_size(); 550 return writer_->last_packet_size();
585 } 551 }
586 552
587 uint32 final_bytes_of_last_packet() { 553 uint32 final_bytes_of_last_packet() {
588 return writer_->final_bytes_of_last_packet(); 554 return writer_->final_bytes_of_last_packet();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 QuicPacketHeader header_; 781 QuicPacketHeader header_;
816 QuicStreamFrame frame1_; 782 QuicStreamFrame frame1_;
817 QuicStreamFrame frame2_; 783 QuicStreamFrame frame2_;
818 scoped_ptr<QuicAckFrame> outgoing_ack_; 784 scoped_ptr<QuicAckFrame> outgoing_ack_;
819 bool accept_packet_; 785 bool accept_packet_;
820 786
821 private: 787 private:
822 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); 788 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest);
823 }; 789 };
824 790
825 INSTANTIATE_TEST_CASE_P(BundleAckWithPacket, 791 TEST_F(QuicConnectionTest, PacketsInOrder) {
826 QuicConnectionTest,
827 ::testing::Values(false, true));
828
829 TEST_P(QuicConnectionTest, PacketsInOrder) {
830 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 792 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
831 793
832 ProcessPacket(1); 794 ProcessPacket(1);
833 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 795 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
834 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 796 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
835 797
836 ProcessPacket(2); 798 ProcessPacket(2);
837 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); 799 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed);
838 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 800 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
839 801
840 ProcessPacket(3); 802 ProcessPacket(3);
841 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 803 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
842 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 804 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
843 } 805 }
844 806
845 TEST_P(QuicConnectionTest, PacketsRejected) { 807 TEST_F(QuicConnectionTest, PacketsRejected) {
846 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 808 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
847 809
848 ProcessPacket(1); 810 ProcessPacket(1);
849 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 811 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
850 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 812 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
851 813
852 accept_packet_ = false; 814 accept_packet_ = false;
853 ProcessPacket(2); 815 ProcessPacket(2);
854 // We should not have an ack for two. 816 // We should not have an ack for two.
855 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 817 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
856 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 818 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
857 } 819 }
858 820
859 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { 821 TEST_F(QuicConnectionTest, PacketsOutOfOrder) {
860 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 822 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
861 823
862 ProcessPacket(3); 824 ProcessPacket(3);
863 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 825 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
864 EXPECT_TRUE(IsMissing(2)); 826 EXPECT_TRUE(IsMissing(2));
865 EXPECT_TRUE(IsMissing(1)); 827 EXPECT_TRUE(IsMissing(1));
866 828
867 ProcessPacket(2); 829 ProcessPacket(2);
868 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 830 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
869 EXPECT_FALSE(IsMissing(2)); 831 EXPECT_FALSE(IsMissing(2));
870 EXPECT_TRUE(IsMissing(1)); 832 EXPECT_TRUE(IsMissing(1));
871 833
872 ProcessPacket(1); 834 ProcessPacket(1);
873 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 835 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
874 EXPECT_FALSE(IsMissing(2)); 836 EXPECT_FALSE(IsMissing(2));
875 EXPECT_FALSE(IsMissing(1)); 837 EXPECT_FALSE(IsMissing(1));
876 } 838 }
877 839
878 TEST_P(QuicConnectionTest, DuplicatePacket) { 840 TEST_F(QuicConnectionTest, DuplicatePacket) {
879 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 841 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
880 842
881 ProcessPacket(3); 843 ProcessPacket(3);
882 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 844 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
883 EXPECT_TRUE(IsMissing(2)); 845 EXPECT_TRUE(IsMissing(2));
884 EXPECT_TRUE(IsMissing(1)); 846 EXPECT_TRUE(IsMissing(1));
885 847
886 // Send packet 3 again, but do not set the expectation that 848 // Send packet 3 again, but do not set the expectation that
887 // the visitor OnStreamFrames() will be called. 849 // the visitor OnStreamFrames() will be called.
888 ProcessDataPacket(3, 0, !kEntropyFlag); 850 ProcessDataPacket(3, 0, !kEntropyFlag);
889 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 851 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
890 EXPECT_TRUE(IsMissing(2)); 852 EXPECT_TRUE(IsMissing(2));
891 EXPECT_TRUE(IsMissing(1)); 853 EXPECT_TRUE(IsMissing(1));
892 } 854 }
893 855
894 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { 856 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) {
895 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 857 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
896 858
897 ProcessPacket(3); 859 ProcessPacket(3);
898 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 860 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
899 EXPECT_TRUE(IsMissing(2)); 861 EXPECT_TRUE(IsMissing(2));
900 EXPECT_TRUE(IsMissing(1)); 862 EXPECT_TRUE(IsMissing(1));
901 863
902 ProcessPacket(2); 864 ProcessPacket(2);
903 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 865 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
904 EXPECT_TRUE(IsMissing(1)); 866 EXPECT_TRUE(IsMissing(1));
905 867
906 ProcessPacket(5); 868 ProcessPacket(5);
907 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); 869 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed);
908 EXPECT_TRUE(IsMissing(1)); 870 EXPECT_TRUE(IsMissing(1));
909 EXPECT_TRUE(IsMissing(4)); 871 EXPECT_TRUE(IsMissing(4));
910 872
911 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a 873 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a
912 // packet the peer will not retransmit. It indicates this by sending 'least 874 // packet the peer will not retransmit. It indicates this by sending 'least
913 // awaiting' is 4. The connection should then realize 1 will not be 875 // awaiting' is 4. The connection should then realize 1 will not be
914 // retransmitted, and will remove it from the missing list. 876 // retransmitted, and will remove it from the missing list.
915 creator_.set_sequence_number(5); 877 creator_.set_sequence_number(5);
916 QuicAckFrame frame(0, QuicTime::Zero(), 4); 878 QuicAckFrame frame(0, QuicTime::Zero(), 4);
917 ProcessAckPacket(&frame); 879 ProcessAckPacket(&frame);
918 880
919 // Force an ack to be sent. 881 // Force an ack to be sent.
920 SendAckPacketToPeer(); 882 SendAckPacketToPeer();
921 EXPECT_TRUE(IsMissing(4)); 883 EXPECT_TRUE(IsMissing(4));
922 } 884 }
923 885
924 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { 886 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) {
925 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 887 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
926 // packet call to the visitor. 888 // packet call to the visitor.
927 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 889 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
928 ProcessDataPacket(6000, 0, !kEntropyFlag); 890 ProcessDataPacket(6000, 0, !kEntropyFlag);
929 } 891 }
930 892
931 // TODO(rtenneti): Delete this when QUIC_VERSION_11 is deprecated. 893 // TODO(rtenneti): Delete this when QUIC_VERSION_11 is deprecated.
932 TEST_P(QuicConnectionTest, TruncatedAck11) { 894 TEST_F(QuicConnectionTest, TruncatedAck11) {
933 if (QuicVersionMax() > QUIC_VERSION_11) { 895 if (QuicVersionMax() > QUIC_VERSION_11) {
934 return; 896 return;
935 } 897 }
936 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 898 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
937 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 899 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
938 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 900 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
939 for (int i = 0; i < 200; ++i) { 901 for (int i = 0; i < 200; ++i) {
940 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); 902 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL);
941 } 903 }
942 904
(...skipping 10 matching lines...) Expand all
953 915
954 frame.received_info.missing_packets.erase(192); 916 frame.received_info.missing_packets.erase(192);
955 frame.received_info.entropy_hash = 917 frame.received_info.entropy_hash =
956 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ 918 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^
957 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191); 919 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191);
958 920
959 ProcessAckPacket(&frame); 921 ProcessAckPacket(&frame);
960 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 922 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
961 } 923 }
962 924
963 TEST_P(QuicConnectionTest, TruncatedAck) { 925 TEST_F(QuicConnectionTest, TruncatedAck) {
964 // TODO(rtenneti): Delete this when QUIC_VERSION_11 is deprecated. 926 // TODO(rtenneti): Delete this when QUIC_VERSION_11 is deprecated.
965 if (QuicVersionMax() <= QUIC_VERSION_11) { 927 if (QuicVersionMax() <= QUIC_VERSION_11) {
966 return; 928 return;
967 } 929 }
968 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 930 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
969 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(256); 931 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(256);
970 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(2); 932 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(2);
971 int num_packets = 256 * 2 + 1; 933 int num_packets = 256 * 2 + 1;
972 for (int i = 0; i < num_packets; ++i) { 934 for (int i = 0; i < num_packets; ++i) {
973 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); 935 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL);
(...skipping 11 matching lines...) Expand all
985 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 947 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
986 948
987 frame.received_info.missing_packets.erase(192); 949 frame.received_info.missing_packets.erase(192);
988 950
989 // Removing one missing packet allows us to ack 192 and one more range. 951 // Removing one missing packet allows us to ack 192 and one more range.
990 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 952 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
991 ProcessAckPacket(&frame); 953 ProcessAckPacket(&frame);
992 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 954 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
993 } 955 }
994 956
995 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 957 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
996 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 958 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
997 959
998 ProcessPacket(1); 960 ProcessPacket(1);
999 // Delay sending, then queue up an ack. 961 // Delay sending, then queue up an ack.
1000 EXPECT_CALL(*send_algorithm_, 962 EXPECT_CALL(*send_algorithm_,
1001 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 963 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
1002 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 964 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
1003 QuicConnectionPeer::SendAck(&connection_); 965 QuicConnectionPeer::SendAck(&connection_);
1004 966
1005 // Process an ack with a least unacked of the received ack. 967 // Process an ack with a least unacked of the received ack.
1006 // This causes an ack to be sent when TimeUntilSend returns 0. 968 // This causes an ack to be sent when TimeUntilSend returns 0.
1007 EXPECT_CALL(*send_algorithm_, 969 EXPECT_CALL(*send_algorithm_,
1008 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 970 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
1009 testing::Return(QuicTime::Delta::Zero())); 971 testing::Return(QuicTime::Delta::Zero()));
1010 // Skip a packet and then record an ack. 972 // Skip a packet and then record an ack.
1011 creator_.set_sequence_number(2); 973 creator_.set_sequence_number(2);
1012 QuicAckFrame frame(0, QuicTime::Zero(), 3); 974 QuicAckFrame frame(0, QuicTime::Zero(), 3);
1013 ProcessAckPacket(&frame); 975 ProcessAckPacket(&frame);
1014 } 976 }
1015 977
1016 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { 978 TEST_F(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) {
1017 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 979 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1018 980
1019 ProcessPacket(3); 981 ProcessPacket(3);
1020 // Should ack immediately since we have missing packets. 982 // Should ack immediately since we have missing packets.
1021 EXPECT_EQ(1u, writer_->packets_write_attempts()); 983 EXPECT_EQ(1u, writer_->packets_write_attempts());
1022 984
1023 ProcessPacket(2); 985 ProcessPacket(2);
1024 // Should ack immediately since we have missing packets. 986 // Should ack immediately since we have missing packets.
1025 EXPECT_EQ(2u, writer_->packets_write_attempts()); 987 EXPECT_EQ(2u, writer_->packets_write_attempts());
1026 988
1027 ProcessPacket(1); 989 ProcessPacket(1);
1028 // Should ack immediately, since this fills the last hole. 990 // Should ack immediately, since this fills the last hole.
1029 EXPECT_EQ(3u, writer_->packets_write_attempts()); 991 EXPECT_EQ(3u, writer_->packets_write_attempts());
1030 992
1031 ProcessPacket(4); 993 ProcessPacket(4);
1032 // Should not cause an ack. 994 // Should not cause an ack.
1033 EXPECT_EQ(3u, writer_->packets_write_attempts()); 995 EXPECT_EQ(3u, writer_->packets_write_attempts());
1034 } 996 }
1035 997
1036 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { 998 TEST_F(QuicConnectionTest, AckReceiptCausesAckSend) {
1037 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 999 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1038 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1000 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1039 QuicPacketSequenceNumber original; 1001 QuicPacketSequenceNumber original;
1040 QuicByteCount packet_size; 1002 QuicByteCount packet_size;
1041 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1003 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1042 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), 1004 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size),
1043 Return(true))); 1005 Return(true)));
1044 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1006 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1045 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1007 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1046 QuicAckFrame frame(original, QuicTime::Zero(), 1); 1008 QuicAckFrame frame(original, QuicTime::Zero(), 1);
(...skipping 24 matching lines...) Expand all
1071 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1033 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1072 ProcessAckPacket(&frame2); 1034 ProcessAckPacket(&frame2);
1073 ProcessAckPacket(&frame2); 1035 ProcessAckPacket(&frame2);
1074 1036
1075 // But an ack with no missing packets will not send an ack. 1037 // But an ack with no missing packets will not send an ack.
1076 frame2.received_info.missing_packets.clear(); 1038 frame2.received_info.missing_packets.clear();
1077 ProcessAckPacket(&frame2); 1039 ProcessAckPacket(&frame2);
1078 ProcessAckPacket(&frame2); 1040 ProcessAckPacket(&frame2);
1079 } 1041 }
1080 1042
1081 TEST_P(QuicConnectionTest, LeastUnackedLower) { 1043 TEST_F(QuicConnectionTest, LeastUnackedLower) {
1082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1044 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1083 1045
1084 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1046 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1085 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 1047 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
1086 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 1048 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
1087 1049
1088 // Start out saying the least unacked is 2. 1050 // Start out saying the least unacked is 2.
1089 creator_.set_sequence_number(5); 1051 creator_.set_sequence_number(5);
1090 QuicAckFrame frame(0, QuicTime::Zero(), 2); 1052 QuicAckFrame frame(0, QuicTime::Zero(), 2);
1091 ProcessAckPacket(&frame); 1053 ProcessAckPacket(&frame);
1092 1054
1093 // Change it to 1, but lower the sequence number to fake out-of-order packets. 1055 // Change it to 1, but lower the sequence number to fake out-of-order packets.
1094 // This should be fine. 1056 // This should be fine.
1095 creator_.set_sequence_number(1); 1057 creator_.set_sequence_number(1);
1096 QuicAckFrame frame2(0, QuicTime::Zero(), 1); 1058 QuicAckFrame frame2(0, QuicTime::Zero(), 1);
1097 // The scheduler will not process out of order acks. 1059 // The scheduler will not process out of order acks.
1098 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); 1060 EXPECT_CALL(visitor_, OnCanWrite()).Times(0);
1099 ProcessAckPacket(&frame2); 1061 ProcessAckPacket(&frame2);
1100 1062
1101 // Now claim it's one, but set the ordering so it was sent "after" the first 1063 // Now claim it's one, but set the ordering so it was sent "after" the first
1102 // one. This should cause a connection error. 1064 // one. This should cause a connection error.
1103 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); 1065 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false));
1104 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1066 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1105 creator_.set_sequence_number(7); 1067 creator_.set_sequence_number(7);
1106 ProcessAckPacket(&frame2); 1068 ProcessAckPacket(&frame2);
1107 } 1069 }
1108 1070
1109 TEST_P(QuicConnectionTest, LargestObservedLower) { 1071 TEST_F(QuicConnectionTest, LargestObservedLower) {
1110 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1072 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1111 1073
1112 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1074 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1113 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 1075 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
1114 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 1076 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
1115 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 1077 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
1116 1078
1117 // Start out saying the largest observed is 2. 1079 // Start out saying the largest observed is 2.
1118 QuicAckFrame frame(2, QuicTime::Zero(), 0); 1080 QuicAckFrame frame(2, QuicTime::Zero(), 0);
1119 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1081 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1120 &connection_, 2); 1082 &connection_, 2);
1121 ProcessAckPacket(&frame); 1083 ProcessAckPacket(&frame);
1122 1084
1123 // Now change it to 1, and it should cause a connection error. 1085 // Now change it to 1, and it should cause a connection error.
1124 QuicAckFrame frame2(1, QuicTime::Zero(), 0); 1086 QuicAckFrame frame2(1, QuicTime::Zero(), 0);
1125 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); 1087 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false));
1126 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); 1088 EXPECT_CALL(visitor_, OnCanWrite()).Times(0);
1127 ProcessAckPacket(&frame2); 1089 ProcessAckPacket(&frame2);
1128 } 1090 }
1129 1091
1130 TEST_P(QuicConnectionTest, AckUnsentData) { 1092 TEST_F(QuicConnectionTest, AckUnsentData) {
1131 // Ack a packet which has not been sent. 1093 // Ack a packet which has not been sent.
1132 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); 1094 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false));
1133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1095 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1134 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1096 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1135 QuicAckFrame frame(1, QuicTime::Zero(), 0); 1097 QuicAckFrame frame(1, QuicTime::Zero(), 0);
1136 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); 1098 EXPECT_CALL(visitor_, OnCanWrite()).Times(0);
1137 ProcessAckPacket(&frame); 1099 ProcessAckPacket(&frame);
1138 } 1100 }
1139 1101
1140 TEST_P(QuicConnectionTest, AckAll) { 1102 TEST_F(QuicConnectionTest, AckAll) {
1141 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1103 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1142 ProcessPacket(1); 1104 ProcessPacket(1);
1143 1105
1144 creator_.set_sequence_number(1); 1106 creator_.set_sequence_number(1);
1145 QuicAckFrame frame1(0, QuicTime::Zero(), 1); 1107 QuicAckFrame frame1(0, QuicTime::Zero(), 1);
1146 ProcessAckPacket(&frame1); 1108 ProcessAckPacket(&frame1);
1147 } 1109 }
1148 1110
1149 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { 1111 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) {
1150 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return( 1112 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return(
1151 QuicBandwidth::FromKBitsPerSecond(1000))); 1113 QuicBandwidth::FromKBitsPerSecond(1000)));
1152 1114
1153 QuicPacketSequenceNumber last_packet; 1115 QuicPacketSequenceNumber last_packet;
1154 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1116 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1155 EXPECT_EQ(1u, last_packet); 1117 EXPECT_EQ(1u, last_packet);
1156 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1118 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1157 connection_.options()->send_sequence_number_length); 1119 connection_.options()->send_sequence_number_length);
1158 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1120 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1159 last_header()->public_header.sequence_number_length); 1121 last_header()->public_header.sequence_number_length);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 QuicBandwidth::FromKBitsPerSecond(1000ll * 256 * 256 * 256 * 256))); 1156 QuicBandwidth::FromKBitsPerSecond(1000ll * 256 * 256 * 256 * 256)));
1195 1157
1196 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1158 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1197 EXPECT_EQ(5u, last_packet); 1159 EXPECT_EQ(5u, last_packet);
1198 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1160 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1199 connection_.options()->send_sequence_number_length); 1161 connection_.options()->send_sequence_number_length);
1200 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1162 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1201 last_header()->public_header.sequence_number_length); 1163 last_header()->public_header.sequence_number_length);
1202 } 1164 }
1203 1165
1204 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { 1166 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) {
1205 QuicPacketSequenceNumber last_packet; 1167 QuicPacketSequenceNumber last_packet;
1206 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1168 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1207 EXPECT_EQ(1u, last_packet); 1169 EXPECT_EQ(1u, last_packet);
1208 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1170 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1209 connection_.options()->send_sequence_number_length); 1171 connection_.options()->send_sequence_number_length);
1210 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1172 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1211 last_header()->public_header.sequence_number_length); 1173 last_header()->public_header.sequence_number_length);
1212 1174
1213 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100); 1175 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100);
1214 1176
(...skipping 24 matching lines...) Expand all
1239 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( 1201 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(
1240 100 * 256 * 256 * 256); 1202 100 * 256 * 256 * 256);
1241 1203
1242 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1204 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1243 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1205 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1244 connection_.options()->send_sequence_number_length); 1206 connection_.options()->send_sequence_number_length);
1245 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1207 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1246 last_header()->public_header.sequence_number_length); 1208 last_header()->public_header.sequence_number_length);
1247 } 1209 }
1248 1210
1249 TEST_P(QuicConnectionTest, BasicSending) { 1211 TEST_F(QuicConnectionTest, BasicSending) {
1250 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1212 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1251 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); 1213 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6);
1252 QuicPacketSequenceNumber last_packet; 1214 QuicPacketSequenceNumber last_packet;
1253 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1215 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1254 EXPECT_EQ(1u, last_packet); 1216 EXPECT_EQ(1u, last_packet);
1255 SendAckPacketToPeer(); // Packet 2 1217 SendAckPacketToPeer(); // Packet 2
1256 1218
1257 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1219 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
1258 1220
1259 SendAckPacketToPeer(); // Packet 3 1221 SendAckPacketToPeer(); // Packet 3
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 SendAckPacketToPeer(); // Packet 7 1253 SendAckPacketToPeer(); // Packet 7
1292 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked); 1254 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked);
1293 1255
1294 // But if we send more data it should. 1256 // But if we send more data it should.
1295 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 1257 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8
1296 EXPECT_EQ(8u, last_packet); 1258 EXPECT_EQ(8u, last_packet);
1297 SendAckPacketToPeer(); // Packet 9 1259 SendAckPacketToPeer(); // Packet 9
1298 EXPECT_EQ(8u, last_ack()->sent_info.least_unacked); 1260 EXPECT_EQ(8u, last_ack()->sent_info.least_unacked);
1299 } 1261 }
1300 1262
1301 TEST_P(QuicConnectionTest, FECSending) { 1263 TEST_F(QuicConnectionTest, FECSending) {
1302 // All packets carry version info till version is negotiated. 1264 // All packets carry version info till version is negotiated.
1303 size_t payload_length; 1265 size_t payload_length;
1304 connection_.options()->max_packet_length = 1266 connection_.options()->max_packet_length =
1305 GetPacketLengthForOneStream( 1267 GetPacketLengthForOneStream(
1306 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1268 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1307 IN_FEC_GROUP, &payload_length); 1269 IN_FEC_GROUP, &payload_length);
1308 // And send FEC every two packets. 1270 // And send FEC every two packets.
1309 connection_.options()->max_packets_per_fec_group = 2; 1271 connection_.options()->max_packets_per_fec_group = 2;
1310 1272
1311 // Send 4 data packets and 2 FEC packets. 1273 // Send 4 data packets and 2 FEC packets.
1312 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1274 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1313 // The first stream frame will consume 2 fewer bytes than the other three. 1275 // The first stream frame will consume 2 fewer bytes than the other three.
1314 const string payload(payload_length * 4 - 6, 'a'); 1276 const string payload(payload_length * 4 - 6, 'a');
1315 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1277 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1316 // Expect the FEC group to be closed after SendStreamDataWithString. 1278 // Expect the FEC group to be closed after SendStreamDataWithString.
1317 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1279 EXPECT_FALSE(creator_.ShouldSendFec(true));
1318 } 1280 }
1319 1281
1320 TEST_P(QuicConnectionTest, FECQueueing) { 1282 TEST_F(QuicConnectionTest, FECQueueing) {
1321 // All packets carry version info till version is negotiated. 1283 // All packets carry version info till version is negotiated.
1322 size_t payload_length; 1284 size_t payload_length;
1323 connection_.options()->max_packet_length = 1285 connection_.options()->max_packet_length =
1324 GetPacketLengthForOneStream( 1286 GetPacketLengthForOneStream(
1325 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1287 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1326 IN_FEC_GROUP, &payload_length); 1288 IN_FEC_GROUP, &payload_length);
1327 // And send FEC every two packets. 1289 // And send FEC every two packets.
1328 connection_.options()->max_packets_per_fec_group = 2; 1290 connection_.options()->max_packets_per_fec_group = 2;
1329 1291
1330 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1292 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1331 writer_->set_blocked(true); 1293 writer_->set_blocked(true);
1332 const string payload(payload_length, 'a'); 1294 const string payload(payload_length, 'a');
1333 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1295 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1334 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1296 EXPECT_FALSE(creator_.ShouldSendFec(true));
1335 // Expect the first data packet and the fec packet to be queued. 1297 // Expect the first data packet and the fec packet to be queued.
1336 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1298 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1337 } 1299 }
1338 1300
1339 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1301 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1340 connection_.options()->max_packets_per_fec_group = 1; 1302 connection_.options()->max_packets_per_fec_group = 1;
1341 // 1 Data and 1 FEC packet. 1303 // 1 Data and 1 FEC packet.
1342 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1304 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1343 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1305 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1344 1306
1345 const QuicTime::Delta retransmission_time = 1307 const QuicTime::Delta retransmission_time =
1346 QuicTime::Delta::FromMilliseconds(5000); 1308 QuicTime::Delta::FromMilliseconds(5000);
1347 clock_.AdvanceTime(retransmission_time); 1309 clock_.AdvanceTime(retransmission_time);
1348 1310
1349 // Abandon FEC packet. 1311 // Abandon FEC packet.
1350 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); 1312 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1);
1351 EXPECT_CALL(visitor_, OnCanWrite()); 1313 EXPECT_CALL(visitor_, OnCanWrite());
1352 connection_.OnAbandonFecTimeout(); 1314 connection_.OnAbandonFecTimeout();
1353 } 1315 }
1354 1316
1355 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { 1317 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) {
1356 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1318 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1357 connection_.options()->max_packets_per_fec_group = 1; 1319 connection_.options()->max_packets_per_fec_group = 1;
1358 const QuicPacketSequenceNumber sequence_number = 1320 const QuicPacketSequenceNumber sequence_number =
1359 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number() + 1; 1321 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number() + 1;
1360 1322
1361 // 1 Data and 1 FEC packet. 1323 // 1 Data and 1 FEC packet.
1362 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1324 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1363 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1325 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1364 1326
1365 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1); 1327 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1);
(...skipping 10 matching lines...) Expand all
1376 1338
1377 clock_.AdvanceTime(DefaultRetransmissionTime()); 1339 clock_.AdvanceTime(DefaultRetransmissionTime());
1378 1340
1379 // Abandon only data packet, FEC has been acked. 1341 // Abandon only data packet, FEC has been acked.
1380 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(sequence_number, _)).Times(1); 1342 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(sequence_number, _)).Times(1);
1381 // Send only data packet. 1343 // Send only data packet.
1382 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1344 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1383 connection_.GetRetransmissionAlarm()->Fire(); 1345 connection_.GetRetransmissionAlarm()->Fire();
1384 } 1346 }
1385 1347
1386 TEST_P(QuicConnectionTest, FramePacking) { 1348 TEST_F(QuicConnectionTest, FramePacking) {
1387 // Block the connection. 1349 // Block the connection.
1388 connection_.GetSendAlarm()->Set( 1350 connection_.GetSendAlarm()->Set(
1389 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1351 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1390 1352
1391 // Send an ack and two stream frames in 1 packet by queueing them. 1353 // Send an ack and two stream frames in 1 packet by queueing them.
1392 connection_.SendAck(); 1354 connection_.SendAck();
1393 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1355 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1394 IgnoreResult(InvokeWithoutArgs(&connection_, 1356 IgnoreResult(InvokeWithoutArgs(&connection_,
1395 &TestConnection::SendStreamData3)), 1357 &TestConnection::SendStreamData3)),
1396 IgnoreResult(InvokeWithoutArgs(&connection_, 1358 IgnoreResult(InvokeWithoutArgs(&connection_,
(...skipping 10 matching lines...) Expand all
1407 1369
1408 // Parse the last packet and ensure it's an ack and two stream frames from 1370 // Parse the last packet and ensure it's an ack and two stream frames from
1409 // two different streams. 1371 // two different streams.
1410 EXPECT_EQ(3u, writer_->frame_count()); 1372 EXPECT_EQ(3u, writer_->frame_count());
1411 EXPECT_TRUE(writer_->ack()); 1373 EXPECT_TRUE(writer_->ack());
1412 EXPECT_EQ(2u, writer_->stream_frames()->size()); 1374 EXPECT_EQ(2u, writer_->stream_frames()->size());
1413 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1375 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1414 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); 1376 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id);
1415 } 1377 }
1416 1378
1417 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { 1379 TEST_F(QuicConnectionTest, FramePackingNonCryptoThenCrypto) {
1418 // Block the connection. 1380 // Block the connection.
1419 connection_.GetSendAlarm()->Set( 1381 connection_.GetSendAlarm()->Set(
1420 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1382 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1421 1383
1422 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 1384 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2
1423 // packets by queueing them. 1385 // packets by queueing them.
1424 connection_.SendAck(); 1386 connection_.SendAck();
1425 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1387 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1426 IgnoreResult(InvokeWithoutArgs(&connection_, 1388 IgnoreResult(InvokeWithoutArgs(&connection_,
1427 &TestConnection::SendStreamData3)), 1389 &TestConnection::SendStreamData3)),
1428 IgnoreResult(InvokeWithoutArgs(&connection_, 1390 IgnoreResult(InvokeWithoutArgs(&connection_,
1429 &TestConnection::SendCryptoStreamData)), 1391 &TestConnection::SendCryptoStreamData)),
1430 Return(true))); 1392 Return(true)));
1431 1393
1432 EXPECT_CALL(*send_algorithm_, 1394 EXPECT_CALL(*send_algorithm_,
1433 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1395 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1434 .Times(2); 1396 .Times(2);
1435 // Unblock the connection. 1397 // Unblock the connection.
1436 connection_.GetSendAlarm()->Fire(); 1398 connection_.GetSendAlarm()->Fire();
1437 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1399 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1438 EXPECT_FALSE(connection_.HasQueuedData()); 1400 EXPECT_FALSE(connection_.HasQueuedData());
1439 1401
1440 // Parse the last packet and ensure it's the crypto stream frame. 1402 // Parse the last packet and ensure it's the crypto stream frame.
1441 EXPECT_EQ(1u, writer_->frame_count()); 1403 EXPECT_EQ(1u, writer_->frame_count());
1442 EXPECT_TRUE(writer_->ack());
1443 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1404 EXPECT_EQ(1u, writer_->stream_frames()->size());
1444 EXPECT_EQ(kCryptoStreamId, (*writer_->stream_frames())[0].stream_id); 1405 EXPECT_EQ(kCryptoStreamId, (*writer_->stream_frames())[0].stream_id);
1445 } 1406 }
1446 1407
1447 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { 1408 TEST_F(QuicConnectionTest, FramePackingCryptoThenNonCrypto) {
1448 // Block the connection. 1409 // Block the connection.
1449 connection_.GetSendAlarm()->Set( 1410 connection_.GetSendAlarm()->Set(
1450 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1411 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1451 1412
1452 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 1413 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3
1453 // packets by queueing them. 1414 // packets by queueing them.
1454 connection_.SendAck(); 1415 connection_.SendAck();
1455 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1416 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1456 IgnoreResult(InvokeWithoutArgs(&connection_, 1417 IgnoreResult(InvokeWithoutArgs(&connection_,
1457 &TestConnection::SendCryptoStreamData)), 1418 &TestConnection::SendCryptoStreamData)),
1458 IgnoreResult(InvokeWithoutArgs(&connection_, 1419 IgnoreResult(InvokeWithoutArgs(&connection_,
1459 &TestConnection::SendStreamData3)), 1420 &TestConnection::SendStreamData3)),
1460 Return(true))); 1421 Return(true)));
1461 1422
1462 EXPECT_CALL(*send_algorithm_, 1423 EXPECT_CALL(*send_algorithm_,
1463 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1424 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1464 .Times(3); 1425 .Times(3);
1465 // Unblock the connection. 1426 // Unblock the connection.
1466 connection_.GetSendAlarm()->Fire(); 1427 connection_.GetSendAlarm()->Fire();
1467 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1428 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1468 EXPECT_FALSE(connection_.HasQueuedData()); 1429 EXPECT_FALSE(connection_.HasQueuedData());
1469 1430
1470 // Parse the last packet and ensure it's the stream frame from stream 3. 1431 // Parse the last packet and ensure it's the stream frame from stream 3.
1471 EXPECT_EQ(1u, writer_->frame_count()); 1432 EXPECT_EQ(1u, writer_->frame_count());
1472 EXPECT_TRUE(writer_->ack());
1473 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1433 EXPECT_EQ(1u, writer_->stream_frames()->size());
1474 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1434 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1475 } 1435 }
1476 1436
1477 TEST_P(QuicConnectionTest, FramePackingFEC) { 1437 TEST_F(QuicConnectionTest, FramePackingFEC) {
1478 // Enable fec. 1438 // Enable fec.
1479 connection_.options()->max_packets_per_fec_group = 6; 1439 connection_.options()->max_packets_per_fec_group = 6;
1480 // Block the connection. 1440 // Block the connection.
1481 connection_.GetSendAlarm()->Set( 1441 connection_.GetSendAlarm()->Set(
1482 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1442 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1483 1443
1484 // Send an ack and two stream frames in 1 packet by queueing them. 1444 // Send an ack and two stream frames in 1 packet by queueing them.
1485 connection_.SendAck(); 1445 connection_.SendAck();
1486 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1446 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1487 IgnoreResult(InvokeWithoutArgs(&connection_, 1447 IgnoreResult(InvokeWithoutArgs(&connection_,
1488 &TestConnection::SendStreamData3)), 1448 &TestConnection::SendStreamData3)),
1489 IgnoreResult(InvokeWithoutArgs(&connection_, 1449 IgnoreResult(InvokeWithoutArgs(&connection_,
1490 &TestConnection::SendStreamData5)), 1450 &TestConnection::SendStreamData5)),
1491 Return(true))); 1451 Return(true)));
1492 1452
1493 EXPECT_CALL(*send_algorithm_, 1453 EXPECT_CALL(*send_algorithm_,
1494 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)).Times(2); 1454 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)).Times(2);
1495 // Unblock the connection. 1455 // Unblock the connection.
1496 connection_.GetSendAlarm()->Fire(); 1456 connection_.GetSendAlarm()->Fire();
1497 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1457 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1498 EXPECT_FALSE(connection_.HasQueuedData()); 1458 EXPECT_FALSE(connection_.HasQueuedData());
1499 1459
1500 // Parse the last packet and ensure it's in an fec group. 1460 // Parse the last packet and ensure it's in an fec group.
1501 EXPECT_EQ(1u, writer_->header()->fec_group); 1461 EXPECT_EQ(1u, writer_->header()->fec_group);
1502 EXPECT_EQ(0u, writer_->frame_count()); 1462 EXPECT_EQ(0u, writer_->frame_count());
1503 } 1463 }
1504 1464
1505 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 1465 TEST_F(QuicConnectionTest, FramePackingAckResponse) {
1506 if (!GetParam()) {
1507 // This test depends on BundleAckWithPacket being true.
1508 return;
1509 }
1510 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1466 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1511
1512 // Process a data packet to queue up a pending ack. 1467 // Process a data packet to queue up a pending ack.
1513 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); 1468 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true));
1514 ProcessDataPacket(1, 1, kEntropyFlag); 1469 ProcessDataPacket(1, 1, kEntropyFlag);
1515 1470
1516 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1471 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1517 IgnoreResult(InvokeWithoutArgs(&connection_, 1472 IgnoreResult(InvokeWithoutArgs(&connection_,
1518 &TestConnection::SendStreamData3)), 1473 &TestConnection::SendStreamData3)),
1519 IgnoreResult(InvokeWithoutArgs(&connection_, 1474 IgnoreResult(InvokeWithoutArgs(&connection_,
1520 &TestConnection::SendStreamData5)), 1475 &TestConnection::SendStreamData5)),
1521 Return(true))); 1476 Return(true)));
(...skipping 12 matching lines...) Expand all
1534 1489
1535 // Parse the last packet and ensure it's an ack and two stream frames from 1490 // Parse the last packet and ensure it's an ack and two stream frames from
1536 // two different streams. 1491 // two different streams.
1537 EXPECT_EQ(3u, writer_->frame_count()); 1492 EXPECT_EQ(3u, writer_->frame_count());
1538 EXPECT_TRUE(writer_->ack()); 1493 EXPECT_TRUE(writer_->ack());
1539 ASSERT_EQ(2u, writer_->stream_frames()->size()); 1494 ASSERT_EQ(2u, writer_->stream_frames()->size());
1540 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1495 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1541 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); 1496 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id);
1542 } 1497 }
1543 1498
1544 TEST_P(QuicConnectionTest, FramePackingSendv) { 1499 TEST_F(QuicConnectionTest, FramePackingSendv) {
1545 // Send data in 1 packet by writing multiple blocks in a single iovector 1500 // Send data in 1 packet by writing multiple blocks in a single iovector
1546 // using writev. 1501 // using writev.
1547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1502 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1548 1503
1549 char data[] = "ABCD"; 1504 char data[] = "ABCD";
1550 IOVector data_iov; 1505 IOVector data_iov;
1551 data_iov.AppendNoCoalesce(data, 2); 1506 data_iov.AppendNoCoalesce(data, 2);
1552 data_iov.AppendNoCoalesce(data + 2, 2); 1507 data_iov.AppendNoCoalesce(data + 2, 2);
1553 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1508 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
1554 1509
1555 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1510 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1556 EXPECT_FALSE(connection_.HasQueuedData()); 1511 EXPECT_FALSE(connection_.HasQueuedData());
1557 1512
1558 // Parse the last packet and ensure multiple iovector blocks have 1513 // Parse the last packet and ensure multiple iovector blocks have
1559 // been packed into a single stream frame from one stream. 1514 // been packed into a single stream frame from one stream.
1560 EXPECT_EQ(1u, writer_->frame_count()); 1515 EXPECT_EQ(1u, writer_->frame_count());
1561 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1516 EXPECT_EQ(1u, writer_->stream_frames()->size());
1562 QuicStreamFrame frame = (*writer_->stream_frames())[0]; 1517 QuicStreamFrame frame = (*writer_->stream_frames())[0];
1563 EXPECT_EQ(1u, frame.stream_id); 1518 EXPECT_EQ(1u, frame.stream_id);
1564 EXPECT_EQ("ABCD", string(static_cast<char*> 1519 EXPECT_EQ("ABCD", string(static_cast<char*>
1565 (frame.data.iovec()[0].iov_base), 1520 (frame.data.iovec()[0].iov_base),
1566 (frame.data.iovec()[0].iov_len))); 1521 (frame.data.iovec()[0].iov_len)));
1567 } 1522 }
1568 1523
1569 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { 1524 TEST_F(QuicConnectionTest, FramePackingSendvQueued) {
1570 // Try to send two stream frames in 1 packet by using writev. 1525 // Try to send two stream frames in 1 packet by using writev.
1571 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1526 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1572 1527
1573 writer_->set_blocked(true); 1528 writer_->set_blocked(true);
1574 char data[] = "ABCD"; 1529 char data[] = "ABCD";
1575 IOVector data_iov; 1530 IOVector data_iov;
1576 data_iov.AppendNoCoalesce(data, 2); 1531 data_iov.AppendNoCoalesce(data, 2);
1577 data_iov.AppendNoCoalesce(data + 2, 2); 1532 data_iov.AppendNoCoalesce(data + 2, 2);
1578 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1533 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
1579 1534
1580 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1535 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1581 EXPECT_TRUE(connection_.HasQueuedData()); 1536 EXPECT_TRUE(connection_.HasQueuedData());
1582 1537
1583 // Attempt to send all packets, but since we're actually still 1538 // Attempt to send all packets, but since we're actually still
1584 // blocked, they should all remain queued. 1539 // blocked, they should all remain queued.
1585 EXPECT_FALSE(connection_.OnCanWrite()); 1540 EXPECT_FALSE(connection_.OnCanWrite());
1586 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1541 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1587 1542
1588 // Unblock the writes and actually send. 1543 // Unblock the writes and actually send.
1589 writer_->set_blocked(false); 1544 writer_->set_blocked(false);
1590 EXPECT_TRUE(connection_.OnCanWrite()); 1545 EXPECT_TRUE(connection_.OnCanWrite());
1591 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1546 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1592 1547
1593 // Parse the last packet and ensure it's one stream frame from one stream. 1548 // Parse the last packet and ensure it's one stream frame from one stream.
1594 EXPECT_EQ(1u, writer_->frame_count()); 1549 EXPECT_EQ(1u, writer_->frame_count());
1595 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1550 EXPECT_EQ(1u, writer_->stream_frames()->size());
1596 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); 1551 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id);
1597 } 1552 }
1598 1553
1599 TEST_P(QuicConnectionTest, SendingZeroBytes) { 1554 TEST_F(QuicConnectionTest, SendingZeroBytes) {
1600 // Send a zero byte write with a fin using writev. 1555 // Send a zero byte write with a fin using writev.
1601 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1556 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1602 IOVector empty_iov; 1557 IOVector empty_iov;
1603 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL); 1558 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL);
1604 1559
1605 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1560 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1606 EXPECT_FALSE(connection_.HasQueuedData()); 1561 EXPECT_FALSE(connection_.HasQueuedData());
1607 1562
1608 // Parse the last packet and ensure it's one stream frame from one stream. 1563 // Parse the last packet and ensure it's one stream frame from one stream.
1609 EXPECT_EQ(1u, writer_->frame_count()); 1564 EXPECT_EQ(1u, writer_->frame_count());
1610 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1565 EXPECT_EQ(1u, writer_->stream_frames()->size());
1611 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); 1566 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id);
1612 EXPECT_TRUE((*writer_->stream_frames())[0].fin); 1567 EXPECT_TRUE((*writer_->stream_frames())[0].fin);
1613 } 1568 }
1614 1569
1615 TEST_P(QuicConnectionTest, OnCanWrite) { 1570 TEST_F(QuicConnectionTest, OnCanWrite) {
1616 // Visitor's OnCanWill send data, but will return false. 1571 // Visitor's OnCanWill send data, but will return false.
1617 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1572 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1618 IgnoreResult(InvokeWithoutArgs(&connection_, 1573 IgnoreResult(InvokeWithoutArgs(&connection_,
1619 &TestConnection::SendStreamData3)), 1574 &TestConnection::SendStreamData3)),
1620 IgnoreResult(InvokeWithoutArgs(&connection_, 1575 IgnoreResult(InvokeWithoutArgs(&connection_,
1621 &TestConnection::SendStreamData5)), 1576 &TestConnection::SendStreamData5)),
1622 Return(false))); 1577 Return(false)));
1623 1578
1624 EXPECT_CALL(*send_algorithm_, 1579 EXPECT_CALL(*send_algorithm_,
1625 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 1580 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
1626 testing::Return(QuicTime::Delta::Zero())); 1581 testing::Return(QuicTime::Delta::Zero()));
1627 1582
1628 // Unblock the connection. 1583 // Unblock the connection.
1629 connection_.OnCanWrite(); 1584 connection_.OnCanWrite();
1630 // Parse the last packet and ensure it's the two stream frames from 1585 // Parse the last packet and ensure it's the two stream frames from
1631 // two different streams. 1586 // two different streams.
1632 EXPECT_EQ(2u, writer_->frame_count()); 1587 EXPECT_EQ(2u, writer_->frame_count());
1633 EXPECT_EQ(2u, writer_->stream_frames()->size()); 1588 EXPECT_EQ(2u, writer_->stream_frames()->size());
1634 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1589 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1635 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); 1590 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id);
1636 } 1591 }
1637 1592
1638 TEST_P(QuicConnectionTest, RetransmitOnNack) { 1593 TEST_F(QuicConnectionTest, RetransmitOnNack) {
1639 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 1594 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
1640 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1595 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1641 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1596 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1642 QuicPacketSequenceNumber last_packet; 1597 QuicPacketSequenceNumber last_packet;
1643 QuicByteCount second_packet_size; 1598 QuicByteCount second_packet_size;
1644 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1599 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1
1645 second_packet_size = 1600 second_packet_size =
1646 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1601 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2
1647 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1602 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3
1648 1603
(...skipping 19 matching lines...) Expand all
1668 ProcessAckPacket(&nack_two); 1623 ProcessAckPacket(&nack_two);
1669 ProcessAckPacket(&nack_two); 1624 ProcessAckPacket(&nack_two);
1670 1625
1671 // The third nack should trigger a retransimission. 1626 // The third nack should trigger a retransimission.
1672 EXPECT_CALL(*send_algorithm_, 1627 EXPECT_CALL(*send_algorithm_,
1673 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, 1628 OnPacketSent(_, _, second_packet_size - kQuicVersionSize,
1674 NACK_RETRANSMISSION, _)).Times(1); 1629 NACK_RETRANSMISSION, _)).Times(1);
1675 ProcessAckPacket(&nack_two); 1630 ProcessAckPacket(&nack_two);
1676 } 1631 }
1677 1632
1678 TEST_P(QuicConnectionTest, DiscardRetransmit) { 1633 TEST_F(QuicConnectionTest, DiscardRetransmit) {
1679 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 1634 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
1680 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1635 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1681 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1636 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1682 QuicPacketSequenceNumber last_packet; 1637 QuicPacketSequenceNumber last_packet;
1683 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1638 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1684 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 1639 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
1685 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 1640 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
1686 1641
1687 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1642 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1688 1643
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 // send the retransmission. 1679 // send the retransmission.
1725 EXPECT_CALL(*send_algorithm_, 1680 EXPECT_CALL(*send_algorithm_,
1726 OnPacketSent(_, _, _, _, _)).Times(0); 1681 OnPacketSent(_, _, _, _, _)).Times(0);
1727 1682
1728 writer_->set_blocked(false); 1683 writer_->set_blocked(false);
1729 connection_.OnCanWrite(); 1684 connection_.OnCanWrite();
1730 1685
1731 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1686 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1732 } 1687 }
1733 1688
1734 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 1689 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) {
1735 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1690 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1736 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1691 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1737 QuicPacketSequenceNumber largest_observed; 1692 QuicPacketSequenceNumber largest_observed;
1738 QuicByteCount packet_size; 1693 QuicByteCount packet_size;
1739 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1694 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1740 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), 1695 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size),
1741 Return(true))); 1696 Return(true)));
1742 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1697 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1743 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1698 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1744 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed); 1699 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed);
1745 frame.received_info.missing_packets.insert(largest_observed); 1700 frame.received_info.missing_packets.insert(largest_observed);
1746 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1701 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1747 &connection_, largest_observed - 1); 1702 &connection_, largest_observed - 1);
1748 ProcessAckPacket(&frame); 1703 ProcessAckPacket(&frame);
1749 ProcessAckPacket(&frame); 1704 ProcessAckPacket(&frame);
1750 // Third nack should retransmit the largest observed packet. 1705 // Third nack should retransmit the largest observed packet.
1751 EXPECT_CALL(*send_algorithm_, 1706 EXPECT_CALL(*send_algorithm_,
1752 OnPacketSent(_, _, packet_size - kQuicVersionSize, 1707 OnPacketSent(_, _, packet_size - kQuicVersionSize,
1753 NACK_RETRANSMISSION, _)); 1708 NACK_RETRANSMISSION, _));
1754 ProcessAckPacket(&frame); 1709 ProcessAckPacket(&frame);
1755 } 1710 }
1756 1711
1757 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 1712 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) {
1758 for (int i = 0; i < 10; ++i) { 1713 for (int i = 0; i < 10; ++i) {
1759 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1760 connection_.SendStreamDataWithString(1, "foo", i * 3, !kFin, NULL); 1715 connection_.SendStreamDataWithString(1, "foo", i * 3, !kFin, NULL);
1761 } 1716 }
1762 1717
1763 // Block the congestion window and ensure they're queued. 1718 // Block the congestion window and ensure they're queued.
1764 writer_->set_blocked(true); 1719 writer_->set_blocked(true);
1765 clock_.AdvanceTime(DefaultRetransmissionTime()); 1720 clock_.AdvanceTime(DefaultRetransmissionTime());
1766 // Only one packet should be retransmitted. 1721 // Only one packet should be retransmitted.
1767 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); 1722 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10);
1768 connection_.GetRetransmissionAlarm()->Fire(); 1723 connection_.GetRetransmissionAlarm()->Fire();
1769 EXPECT_TRUE(connection_.HasQueuedData()); 1724 EXPECT_TRUE(connection_.HasQueuedData());
1770 1725
1771 // Unblock the congestion window. 1726 // Unblock the congestion window.
1772 writer_->set_blocked(false); 1727 writer_->set_blocked(false);
1773 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 1728 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1774 2 * DefaultRetransmissionTime().ToMicroseconds())); 1729 2 * DefaultRetransmissionTime().ToMicroseconds()));
1775 // Retransmit already retransmitted packets event though the sequence number 1730 // Retransmit already retransmitted packets event though the sequence number
1776 // greater than the largest observed. 1731 // greater than the largest observed.
1777 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1732 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
1778 connection_.GetRetransmissionAlarm()->Fire(); 1733 connection_.GetRetransmissionAlarm()->Fire();
1779 connection_.OnCanWrite(); 1734 connection_.OnCanWrite();
1780 } 1735 }
1781 1736
1782 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 1737 TEST_F(QuicConnectionTest, WriteBlockedThenSent) {
1783 writer_->set_blocked(true); 1738 writer_->set_blocked(true);
1784 1739
1785 writer_->set_is_write_blocked_data_buffered(true); 1740 writer_->set_is_write_blocked_data_buffered(true);
1786 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1741 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1787 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1742 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1788 1743
1789 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1744 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1790 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); 1745 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1791 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1746 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1792 } 1747 }
1793 1748
1794 TEST_P(QuicConnectionTest, ResumptionAlarmThenWriteBlocked) { 1749 TEST_F(QuicConnectionTest, ResumptionAlarmThenWriteBlocked) {
1795 // Set the send and resumption alarm, then block the connection. 1750 // Set the send and resumption alarm, then block the connection.
1796 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); 1751 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow());
1797 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); 1752 connection_.GetSendAlarm()->Set(clock_.ApproximateNow());
1798 QuicConnectionPeer::SetIsWriteBlocked(&connection_, true); 1753 QuicConnectionPeer::SetIsWriteBlocked(&connection_, true);
1799 1754
1800 // Fire the alarms and ensure the connection is still write blocked. 1755 // Fire the alarms and ensure the connection is still write blocked.
1801 connection_.GetResumeWritesAlarm()->Fire(); 1756 connection_.GetResumeWritesAlarm()->Fire();
1802 connection_.GetSendAlarm()->Fire(); 1757 connection_.GetSendAlarm()->Fire();
1803 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); 1758 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
1804 } 1759 }
1805 1760
1806 TEST_P(QuicConnectionTest, LimitPacketsPerNack) { 1761 TEST_F(QuicConnectionTest, LimitPacketsPerNack) {
1807 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1762 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1808 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); 1763 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1);
1809 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1764 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1810 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(11); 1765 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(11);
1811 int offset = 0; 1766 int offset = 0;
1812 // Send packets 1 to 12. 1767 // Send packets 1 to 12.
1813 for (int i = 0; i < 12; ++i) { 1768 for (int i = 0; i < 12; ++i) {
1814 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); 1769 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL);
1815 offset += 3; 1770 offset += 3;
1816 } 1771 }
(...skipping 14 matching lines...) Expand all
1831 // The third call should trigger retransmitting 10 packets. 1786 // The third call should trigger retransmitting 10 packets.
1832 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1787 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
1833 ProcessAckPacket(&nack); 1788 ProcessAckPacket(&nack);
1834 1789
1835 // The fourth call should trigger retransmitting the 11th packet. 1790 // The fourth call should trigger retransmitting the 11th packet.
1836 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1791 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1837 ProcessAckPacket(&nack); 1792 ProcessAckPacket(&nack);
1838 } 1793 }
1839 1794
1840 // Test sending multiple acks from the connection to the session. 1795 // Test sending multiple acks from the connection to the session.
1841 TEST_P(QuicConnectionTest, MultipleAcks) { 1796 TEST_F(QuicConnectionTest, MultipleAcks) {
1842 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); 1797 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6);
1843 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 1798 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
1844 QuicPacketSequenceNumber last_packet; 1799 QuicPacketSequenceNumber last_packet;
1845 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1800 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1846 EXPECT_EQ(1u, last_packet); 1801 EXPECT_EQ(1u, last_packet);
1847 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 1802 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2
1848 EXPECT_EQ(2u, last_packet); 1803 EXPECT_EQ(2u, last_packet);
1849 SendAckPacketToPeer(); // Packet 3 1804 SendAckPacketToPeer(); // Packet 3
1850 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 1805 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4
1851 EXPECT_EQ(4u, last_packet); 1806 EXPECT_EQ(4u, last_packet);
(...skipping 15 matching lines...) Expand all
1867 ProcessAckPacket(&frame1); 1822 ProcessAckPacket(&frame1);
1868 1823
1869 // Now the client implicitly acks 2, and explicitly acks 6. 1824 // Now the client implicitly acks 2, and explicitly acks 6.
1870 QuicAckFrame frame2(6, QuicTime::Zero(), 0); 1825 QuicAckFrame frame2(6, QuicTime::Zero(), 0);
1871 frame2.received_info.entropy_hash = 1826 frame2.received_info.entropy_hash =
1872 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); 1827 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6);
1873 1828
1874 ProcessAckPacket(&frame2); 1829 ProcessAckPacket(&frame2);
1875 } 1830 }
1876 1831
1877 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { 1832 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) {
1878 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 1833 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
1879 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; 1834 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1;
1880 SendAckPacketToPeer(); // Packet 2 1835 SendAckPacketToPeer(); // Packet 2
1881 1836
1882 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1837 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1883 QuicAckFrame frame(1, QuicTime::Zero(), 0); 1838 QuicAckFrame frame(1, QuicTime::Zero(), 0);
1884 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1839 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1885 &connection_, 1); 1840 &connection_, 1);
1886 ProcessAckPacket(&frame); 1841 ProcessAckPacket(&frame);
1887 1842
1888 // Verify that our internal state has least-unacked as 3. 1843 // Verify that our internal state has least-unacked as 3.
1889 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); 1844 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked);
1890 1845
1891 // When we send an ack, we make sure our least-unacked makes sense. In this 1846 // When we send an ack, we make sure our least-unacked makes sense. In this
1892 // case since we're not waiting on an ack for 2 and all packets are acked, we 1847 // case since we're not waiting on an ack for 2 and all packets are acked, we
1893 // set it to 3. 1848 // set it to 3.
1894 SendAckPacketToPeer(); // Packet 3 1849 SendAckPacketToPeer(); // Packet 3
1895 // Since this was an ack packet, we set least_unacked to 4. 1850 // Since this was an ack packet, we set least_unacked to 4.
1896 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); 1851 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked);
1897 // Check that the outgoing ack had its sequence number as least_unacked. 1852 // Check that the outgoing ack had its sequence number as least_unacked.
1898 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); 1853 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked);
1899 1854
1900 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 1855 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4
1901 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); 1856 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked);
1902 SendAckPacketToPeer(); // Packet 5 1857 SendAckPacketToPeer(); // Packet 5
1903 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); 1858 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked);
1904 } 1859 }
1905 1860
1906 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { 1861 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) {
1907 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1862 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1908 1863
1909 // Don't send missing packet 1. 1864 // Don't send missing packet 1.
1910 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); 1865 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL);
1911 // Entropy flag should be false, so entropy should be 0. 1866 // Entropy flag should be false, so entropy should be 0.
1912 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 1867 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
1913 } 1868 }
1914 1869
1915 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { 1870 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) {
1916 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1871 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1917 1872
1918 ProcessFecProtectedPacket(1, false, kEntropyFlag); 1873 ProcessFecProtectedPacket(1, false, kEntropyFlag);
1919 // Don't send missing packet 2. 1874 // Don't send missing packet 2.
1920 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); 1875 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL);
1921 // Entropy flag should be true, so entropy should not be 0. 1876 // Entropy flag should be true, so entropy should not be 0.
1922 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 1877 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
1923 } 1878 }
1924 1879
1925 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { 1880 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) {
1926 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1881 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1927 1882
1928 ProcessFecProtectedPacket(1, false, !kEntropyFlag); 1883 ProcessFecProtectedPacket(1, false, !kEntropyFlag);
1929 // Don't send missing packet 2. 1884 // Don't send missing packet 2.
1930 ProcessFecProtectedPacket(3, false, !kEntropyFlag); 1885 ProcessFecProtectedPacket(3, false, !kEntropyFlag);
1931 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); 1886 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL);
1932 // Entropy flag should be true, so entropy should not be 0. 1887 // Entropy flag should be true, so entropy should not be 0.
1933 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 1888 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
1934 } 1889 }
1935 1890
1936 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { 1891 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) {
1937 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1892 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1938 1893
1939 // Don't send missing packet 1. 1894 // Don't send missing packet 1.
1940 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); 1895 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL);
1941 // Out of order. 1896 // Out of order.
1942 ProcessFecProtectedPacket(2, true, !kEntropyFlag); 1897 ProcessFecProtectedPacket(2, true, !kEntropyFlag);
1943 // Entropy flag should be false, so entropy should be 0. 1898 // Entropy flag should be false, so entropy should be 0.
1944 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 1899 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
1945 } 1900 }
1946 1901
1947 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { 1902 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) {
1948 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1903 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1949 1904
1950 ProcessFecProtectedPacket(1, false, !kEntropyFlag); 1905 ProcessFecProtectedPacket(1, false, !kEntropyFlag);
1951 // Don't send missing packet 2. 1906 // Don't send missing packet 2.
1952 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); 1907 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL);
1953 ProcessFecProtectedPacket(3, false, kEntropyFlag); 1908 ProcessFecProtectedPacket(3, false, kEntropyFlag);
1954 ProcessFecProtectedPacket(4, false, kEntropyFlag); 1909 ProcessFecProtectedPacket(4, false, kEntropyFlag);
1955 ProcessFecProtectedPacket(5, true, !kEntropyFlag); 1910 ProcessFecProtectedPacket(5, true, !kEntropyFlag);
1956 // Entropy flag should be true, so entropy should be 0. 1911 // Entropy flag should be true, so entropy should be 0.
1957 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 1912 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
1958 } 1913 }
1959 1914
1960 TEST_P(QuicConnectionTest, TestRetransmit) { 1915 TEST_F(QuicConnectionTest, TestRetransmit) {
1961 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1916 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1962 DefaultRetransmissionTime()); 1917 DefaultRetransmissionTime());
1963 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1918 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1964 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 1919 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
1965 1920
1966 EXPECT_EQ(1u, last_header()->packet_sequence_number); 1921 EXPECT_EQ(1u, last_header()->packet_sequence_number);
1967 EXPECT_EQ(default_retransmission_time, 1922 EXPECT_EQ(default_retransmission_time,
1968 connection_.GetRetransmissionAlarm()->deadline()); 1923 connection_.GetRetransmissionAlarm()->deadline());
1969 // Simulate the retransimission alarm firing. 1924 // Simulate the retransimission alarm firing.
1970 clock_.AdvanceTime(DefaultRetransmissionTime()); 1925 clock_.AdvanceTime(DefaultRetransmissionTime());
1971 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1926 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1972 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1927 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1973 connection_.RetransmitPacket(1, RTO_RETRANSMISSION); 1928 connection_.RetransmitPacket(1, RTO_RETRANSMISSION);
1974 EXPECT_EQ(2u, last_header()->packet_sequence_number); 1929 EXPECT_EQ(2u, last_header()->packet_sequence_number);
1975 // We do not raise the high water mark yet. 1930 // We do not raise the high water mark yet.
1976 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 1931 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
1977 } 1932 }
1978 1933
1979 TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) { 1934 TEST_F(QuicConnectionTest, RetransmitWithSameEncryptionLevel) {
1980 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1935 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1981 DefaultRetransmissionTime()); 1936 DefaultRetransmissionTime());
1982 use_tagging_decrypter(); 1937 use_tagging_decrypter();
1983 1938
1984 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 1939 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
1985 // the end of the packet. We can test this to check which encrypter was used. 1940 // the end of the packet. We can test this to check which encrypter was used.
1986 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1941 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
1987 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1942 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1988 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1943 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
1989 1944
(...skipping 12 matching lines...) Expand all
2002 connection_.RetransmitPacket(1, RTO_RETRANSMISSION); 1957 connection_.RetransmitPacket(1, RTO_RETRANSMISSION);
2003 // Packet should have been sent with ENCRYPTION_NONE. 1958 // Packet should have been sent with ENCRYPTION_NONE.
2004 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1959 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
2005 1960
2006 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1961 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2007 connection_.RetransmitPacket(2, RTO_RETRANSMISSION); 1962 connection_.RetransmitPacket(2, RTO_RETRANSMISSION);
2008 // Packet should have been sent with ENCRYPTION_INITIAL. 1963 // Packet should have been sent with ENCRYPTION_INITIAL.
2009 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); 1964 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet());
2010 } 1965 }
2011 1966
2012 TEST_P(QuicConnectionTest, SendHandshakeMessages) { 1967 TEST_F(QuicConnectionTest, SendHandshakeMessages) {
2013 use_tagging_decrypter(); 1968 use_tagging_decrypter();
2014 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 1969 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2015 // the end of the packet. We can test this to check which encrypter was used. 1970 // the end of the packet. We can test this to check which encrypter was used.
2016 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1971 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2017 1972
2018 // Attempt to send a handshake message while the congestion manager 1973 // Attempt to send a handshake message while the congestion manager
2019 // does not permit sending. 1974 // does not permit sending.
2020 EXPECT_CALL(*send_algorithm_, 1975 EXPECT_CALL(*send_algorithm_,
2021 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( 1976 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly(
2022 testing::Return(QuicTime::Delta::Infinite())); 1977 testing::Return(QuicTime::Delta::Infinite()));
(...skipping 10 matching lines...) Expand all
2033 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( 1988 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly(
2034 testing::Return(QuicTime::Delta::Zero())); 1989 testing::Return(QuicTime::Delta::Zero()));
2035 EXPECT_CALL(visitor_, OnCanWrite()); 1990 EXPECT_CALL(visitor_, OnCanWrite());
2036 connection_.OnCanWrite(); 1991 connection_.OnCanWrite();
2037 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1992 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2038 1993
2039 // Verify that the handshake packet went out at the null encryption. 1994 // Verify that the handshake packet went out at the null encryption.
2040 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1995 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
2041 } 1996 }
2042 1997
2043 TEST_P(QuicConnectionTest, 1998 TEST_F(QuicConnectionTest,
2044 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 1999 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2045 use_tagging_decrypter(); 2000 use_tagging_decrypter();
2046 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2001 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2047 QuicPacketSequenceNumber sequence_number; 2002 QuicPacketSequenceNumber sequence_number;
2048 SendStreamDataToPeer(1, "foo", 0, !kFin, &sequence_number); 2003 SendStreamDataToPeer(1, "foo", 0, !kFin, &sequence_number);
2049 2004
2050 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2005 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2051 new TaggingEncrypter(0x02)); 2006 new TaggingEncrypter(0x02));
2052 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2007 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2053 2008
2054 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2009 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2055 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(sequence_number, _)).Times(1); 2010 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(sequence_number, _)).Times(1);
2056 2011
2057 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2012 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2058 DefaultRetransmissionTime()); 2013 DefaultRetransmissionTime());
2059 2014
2060 EXPECT_EQ(default_retransmission_time, 2015 EXPECT_EQ(default_retransmission_time,
2061 connection_.GetRetransmissionAlarm()->deadline()); 2016 connection_.GetRetransmissionAlarm()->deadline());
2062 // Simulate the retransimission alarm firing. 2017 // Simulate the retransimission alarm firing.
2063 clock_.AdvanceTime(DefaultRetransmissionTime()); 2018 clock_.AdvanceTime(DefaultRetransmissionTime());
2064 connection_.GetRetransmissionAlarm()->Fire(); 2019 connection_.GetRetransmissionAlarm()->Fire();
2065 } 2020 }
2066 2021
2067 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { 2022 TEST_F(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) {
2068 use_tagging_decrypter(); 2023 use_tagging_decrypter();
2069 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2024 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2070 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); 2025 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE);
2071 2026
2072 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 2027 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
2073 2028
2074 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2029 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2075 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2030 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2076 2031
2077 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); 2032 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL);
2078 2033
2079 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2034 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2080 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); 2035 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1);
2081 2036
2082 connection_.RetransmitUnackedPackets(QuicConnection::INITIAL_ENCRYPTION_ONLY); 2037 connection_.RetransmitUnackedPackets(QuicConnection::INITIAL_ENCRYPTION_ONLY);
2083 } 2038 }
2084 2039
2085 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2040 TEST_F(QuicConnectionTest, BufferNonDecryptablePackets) {
2086 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2041 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2087 use_tagging_decrypter(); 2042 use_tagging_decrypter();
2088 2043
2089 const uint8 tag = 0x07; 2044 const uint8 tag = 0x07;
2090 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2045 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2091 2046
2092 // Process an encrypted packet which can not yet be decrypted 2047 // Process an encrypted packet which can not yet be decrypted
2093 // which should result in the packet being buffered. 2048 // which should result in the packet being buffered.
2094 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); 2049 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL);
2095 2050
2096 // Transition to the new encryption state and process another 2051 // Transition to the new encryption state and process another
2097 // encrypted packet which should result in the original packet being 2052 // encrypted packet which should result in the original packet being
2098 // processed. 2053 // processed.
2099 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); 2054 connection_.SetDecrypter(new StrictTaggingDecrypter(tag));
2100 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2055 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2101 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2056 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2102 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2).WillRepeatedly( 2057 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2).WillRepeatedly(
2103 Return(true)); 2058 Return(true));
2104 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); 2059 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL);
2105 2060
2106 // Finally, process a third packet and note that we do not 2061 // Finally, process a third packet and note that we do not
2107 // reprocess the buffered packet. 2062 // reprocess the buffered packet.
2108 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); 2063 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true));
2109 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); 2064 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL);
2110 } 2065 }
2111 2066
2112 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2067 TEST_F(QuicConnectionTest, TestRetransmitOrder) {
2113 QuicByteCount first_packet_size; 2068 QuicByteCount first_packet_size;
2114 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2069 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2115 DoAll(SaveArg<2>(&first_packet_size), Return(true))); 2070 DoAll(SaveArg<2>(&first_packet_size), Return(true)));
2116 2071
2117 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL); 2072 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL);
2118 QuicByteCount second_packet_size; 2073 QuicByteCount second_packet_size;
2119 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2074 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2120 DoAll(SaveArg<2>(&second_packet_size), Return(true))); 2075 DoAll(SaveArg<2>(&second_packet_size), Return(true)));
2121 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL); 2076 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL);
2122 EXPECT_NE(first_packet_size, second_packet_size); 2077 EXPECT_NE(first_packet_size, second_packet_size);
(...skipping 15 matching lines...) Expand all
2138 { 2093 {
2139 InSequence s; 2094 InSequence s;
2140 EXPECT_CALL(*send_algorithm_, 2095 EXPECT_CALL(*send_algorithm_,
2141 OnPacketSent(_, _, first_packet_size, _, _)); 2096 OnPacketSent(_, _, first_packet_size, _, _));
2142 EXPECT_CALL(*send_algorithm_, 2097 EXPECT_CALL(*send_algorithm_,
2143 OnPacketSent(_, _, second_packet_size, _, _)); 2098 OnPacketSent(_, _, second_packet_size, _, _));
2144 } 2099 }
2145 connection_.GetRetransmissionAlarm()->Fire(); 2100 connection_.GetRetransmissionAlarm()->Fire();
2146 } 2101 }
2147 2102
2148 TEST_P(QuicConnectionTest, TestRetransmissionCountCalculation) { 2103 TEST_F(QuicConnectionTest, TestRetransmissionTracking) {
2149 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2104 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2150 QuicPacketSequenceNumber original_sequence_number; 2105 QuicPacketSequenceNumber original_sequence_number;
2151 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2106 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2152 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true))); 2107 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true)));
2153 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2108 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2154 2109
2155 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2110 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2156 &connection_, original_sequence_number)); 2111 &connection_, original_sequence_number));
2157 EXPECT_EQ(0u, QuicConnectionPeer::GetRetransmissionCount( 2112 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission(
2158 &connection_, original_sequence_number)); 2113 &connection_, original_sequence_number));
2159 // Force retransmission due to RTO. 2114 // Force retransmission due to RTO.
2160 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2115 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2161 EXPECT_CALL(*send_algorithm_, 2116 EXPECT_CALL(*send_algorithm_,
2162 OnPacketAbandoned(original_sequence_number, _)).Times(1); 2117 OnPacketAbandoned(original_sequence_number, _)).Times(1);
2163 QuicPacketSequenceNumber rto_sequence_number; 2118 QuicPacketSequenceNumber rto_sequence_number;
2164 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)) 2119 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _))
2165 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true))); 2120 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
2166 connection_.GetRetransmissionAlarm()->Fire(); 2121 connection_.GetRetransmissionAlarm()->Fire();
2167 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2122 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2168 &connection_, original_sequence_number)); 2123 &connection_, original_sequence_number));
2169 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2124 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2170 &connection_, rto_sequence_number)); 2125 &connection_, rto_sequence_number));
2171 EXPECT_EQ(1u, QuicConnectionPeer::GetRetransmissionCount( 2126 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2172 &connection_, rto_sequence_number)); 2127 &connection_, rto_sequence_number));
2173 // Once by explicit nack. 2128 // Once by explicit nack.
2174 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 2129 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
2175 EXPECT_CALL(*send_algorithm_, 2130 EXPECT_CALL(*send_algorithm_,
2176 OnPacketAbandoned(rto_sequence_number, _)).Times(1); 2131 OnPacketAbandoned(rto_sequence_number, _)).Times(1);
2177 QuicPacketSequenceNumber nack_sequence_number = 0; 2132 QuicPacketSequenceNumber nack_sequence_number = 0;
2178 // Ack packets might generate some other packets, which are not 2133 // Ack packets might generate some other packets, which are not
2179 // retransmissions. (More ack packets). 2134 // retransmissions. (More ack packets).
2180 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2135 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2181 .Times(AnyNumber()); 2136 .Times(AnyNumber());
2182 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)) 2137 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _))
2183 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); 2138 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true)));
2184 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0); 2139 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0);
2185 // Ack the retransmitted packet. 2140 // Ack the retransmitted packet.
2186 ack.received_info.missing_packets.insert(original_sequence_number); 2141 ack.received_info.missing_packets.insert(original_sequence_number);
2187 ack.received_info.missing_packets.insert(rto_sequence_number); 2142 ack.received_info.missing_packets.insert(rto_sequence_number);
2188 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 2143 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
2189 &connection_, rto_sequence_number - 1); 2144 &connection_, rto_sequence_number - 1);
2190 for (int i = 0; i < 3; i++) { 2145 for (int i = 0; i < 3; i++) {
2191 ProcessAckPacket(&ack); 2146 ProcessAckPacket(&ack);
2192 } 2147 }
2193 ASSERT_NE(0u, nack_sequence_number); 2148 ASSERT_NE(0u, nack_sequence_number);
2194 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2149 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2195 &connection_, rto_sequence_number)); 2150 &connection_, rto_sequence_number));
2196 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2151 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2197 &connection_, nack_sequence_number)); 2152 &connection_, nack_sequence_number));
2198 EXPECT_EQ(2u, QuicConnectionPeer::GetRetransmissionCount( 2153 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2199 &connection_, nack_sequence_number)); 2154 &connection_, nack_sequence_number));
2200 } 2155 }
2201 2156
2202 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2157 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2203 writer_->set_blocked(true); 2158 writer_->set_blocked(true);
2204 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2159 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2205 // Make sure that RTO is not started when the packet is queued. 2160 // Make sure that RTO is not started when the packet is queued.
2206 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2161 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2207 2162
2208 // Test that RTO is started once we write to the socket. 2163 // Test that RTO is started once we write to the socket.
2209 writer_->set_blocked(false); 2164 writer_->set_blocked(false);
2210 connection_.OnCanWrite(); 2165 connection_.OnCanWrite();
2211 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2166 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2212 } 2167 }
2213 2168
2214 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { 2169 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) {
2215 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2170 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2216 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2171 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2217 .Times(2); 2172 .Times(2);
2218 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2173 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2219 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); 2174 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL);
2220 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2175 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2221 EXPECT_TRUE(retransmission_alarm->IsSet()); 2176 EXPECT_TRUE(retransmission_alarm->IsSet());
2222 2177
2223 // Advance the time right before the RTO, then receive an ack for the first 2178 // Advance the time right before the RTO, then receive an ack for the first
2224 // packet to delay the RTO. 2179 // packet to delay the RTO.
(...skipping 18 matching lines...) Expand all
2243 2198
2244 // The new retransmitted sequence number should set the RTO to a larger value 2199 // The new retransmitted sequence number should set the RTO to a larger value
2245 // than previously. 2200 // than previously.
2246 EXPECT_TRUE(retransmission_alarm->IsSet()); 2201 EXPECT_TRUE(retransmission_alarm->IsSet());
2247 QuicTime next_rto_time = retransmission_alarm->deadline(); 2202 QuicTime next_rto_time = retransmission_alarm->deadline();
2248 QuicTime::Delta expected_rto = 2203 QuicTime::Delta expected_rto =
2249 connection_.congestion_manager().GetRetransmissionDelay(1, 1); 2204 connection_.congestion_manager().GetRetransmissionDelay(1, 1);
2250 EXPECT_EQ(next_rto_time, clock_.ApproximateNow().Add(expected_rto)); 2205 EXPECT_EQ(next_rto_time, clock_.ApproximateNow().Add(expected_rto));
2251 } 2206 }
2252 2207
2253 TEST_P(QuicConnectionTest, TestQueued) { 2208 TEST_F(QuicConnectionTest, TestQueued) {
2254 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2209 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2255 writer_->set_blocked(true); 2210 writer_->set_blocked(true);
2256 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2211 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2257 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2212 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2258 2213
2259 // Attempt to send all packets, but since we're actually still 2214 // Attempt to send all packets, but since we're actually still
2260 // blocked, they should all remain queued. 2215 // blocked, they should all remain queued.
2261 EXPECT_FALSE(connection_.OnCanWrite()); 2216 EXPECT_FALSE(connection_.OnCanWrite());
2262 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2217 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2263 2218
2264 // Unblock the writes and actually send. 2219 // Unblock the writes and actually send.
2265 writer_->set_blocked(false); 2220 writer_->set_blocked(false);
2266 EXPECT_TRUE(connection_.OnCanWrite()); 2221 EXPECT_TRUE(connection_.OnCanWrite());
2267 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2222 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2268 } 2223 }
2269 2224
2270 TEST_P(QuicConnectionTest, CloseFecGroup) { 2225 TEST_F(QuicConnectionTest, CloseFecGroup) {
2271 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2226 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2272 // Don't send missing packet 1. 2227 // Don't send missing packet 1.
2273 // Don't send missing packet 2. 2228 // Don't send missing packet 2.
2274 ProcessFecProtectedPacket(3, false, !kEntropyFlag); 2229 ProcessFecProtectedPacket(3, false, !kEntropyFlag);
2275 // Don't send missing FEC packet 3. 2230 // Don't send missing FEC packet 3.
2276 ASSERT_EQ(1u, connection_.NumFecGroups()); 2231 ASSERT_EQ(1u, connection_.NumFecGroups());
2277 2232
2278 // Now send non-fec protected ack packet and close the group. 2233 // Now send non-fec protected ack packet and close the group.
2279 QuicAckFrame frame(0, QuicTime::Zero(), 5); 2234 QuicAckFrame frame(0, QuicTime::Zero(), 5);
2280 creator_.set_sequence_number(4); 2235 creator_.set_sequence_number(4);
2281 ProcessAckPacket(&frame); 2236 ProcessAckPacket(&frame);
2282 ASSERT_EQ(0u, connection_.NumFecGroups()); 2237 ASSERT_EQ(0u, connection_.NumFecGroups());
2283 } 2238 }
2284 2239
2285 TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { 2240 TEST_F(QuicConnectionTest, NoQuicCongestionFeedbackFrame) {
2286 SendAckPacketToPeer(); 2241 SendAckPacketToPeer();
2287 EXPECT_TRUE(last_feedback() == NULL); 2242 EXPECT_TRUE(last_feedback() == NULL);
2288 } 2243 }
2289 2244
2290 TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { 2245 TEST_F(QuicConnectionTest, WithQuicCongestionFeedbackFrame) {
2291 QuicCongestionFeedbackFrame info; 2246 QuicCongestionFeedbackFrame info;
2292 info.type = kFixRate; 2247 info.type = kFixRate;
2293 info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123); 2248 info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123);
2294 SetFeedback(&info); 2249 SetFeedback(&info);
2295 2250
2296 SendAckPacketToPeer(); 2251 SendAckPacketToPeer();
2297 EXPECT_EQ(kFixRate, last_feedback()->type); 2252 EXPECT_EQ(kFixRate, last_feedback()->type);
2298 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate); 2253 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate);
2299 } 2254 }
2300 2255
2301 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { 2256 TEST_F(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) {
2302 SendAckPacketToPeer(); 2257 SendAckPacketToPeer();
2303 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); 2258 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _));
2304 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2259 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2305 ProcessPacket(1); 2260 ProcessPacket(1);
2306 } 2261 }
2307 2262
2308 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { 2263 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) {
2309 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2264 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2310 SendAckPacketToPeer(); 2265 SendAckPacketToPeer();
2311 // Process an FEC packet, and revive the missing data packet 2266 // Process an FEC packet, and revive the missing data packet
2312 // but only contact the receive_algorithm once. 2267 // but only contact the receive_algorithm once.
2313 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); 2268 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _));
2314 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); 2269 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL);
2315 } 2270 }
2316 2271
2317 TEST_P(QuicConnectionTest, InitialTimeout) { 2272 TEST_F(QuicConnectionTest, InitialTimeout) {
2318 EXPECT_TRUE(connection_.connected()); 2273 EXPECT_TRUE(connection_.connected());
2319 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 2274 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2320 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2275 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2321 2276
2322 QuicTime default_timeout = clock_.ApproximateNow().Add( 2277 QuicTime default_timeout = clock_.ApproximateNow().Add(
2323 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2278 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2324 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2279 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2325 2280
2326 // Simulate the timeout alarm firing. 2281 // Simulate the timeout alarm firing.
2327 clock_.AdvanceTime( 2282 clock_.AdvanceTime(
2328 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2283 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2329 connection_.GetTimeoutAlarm()->Fire(); 2284 connection_.GetTimeoutAlarm()->Fire();
2330 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2285 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2331 EXPECT_FALSE(connection_.connected()); 2286 EXPECT_FALSE(connection_.connected());
2332 2287
2333 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2288 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2334 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2289 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2335 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2290 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2336 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2291 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2337 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2292 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2338 } 2293 }
2339 2294
2340 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 2295 TEST_F(QuicConnectionTest, TimeoutAfterSend) {
2341 EXPECT_TRUE(connection_.connected()); 2296 EXPECT_TRUE(connection_.connected());
2342 2297
2343 QuicTime default_timeout = clock_.ApproximateNow().Add( 2298 QuicTime default_timeout = clock_.ApproximateNow().Add(
2344 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2299 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2345 2300
2346 // When we send a packet, the timeout will change to 5000 + 2301 // When we send a packet, the timeout will change to 5000 +
2347 // kDefaultInitialTimeoutSecs. 2302 // kDefaultInitialTimeoutSecs.
2348 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2303 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2349 2304
2350 // Send an ack so we don't set the retransimission alarm. 2305 // Send an ack so we don't set the retransimission alarm.
(...skipping 16 matching lines...) Expand all
2367 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2322 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2368 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2323 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2369 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2324 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2370 clock_.ApproximateNow()); 2325 clock_.ApproximateNow());
2371 connection_.GetTimeoutAlarm()->Fire(); 2326 connection_.GetTimeoutAlarm()->Fire();
2372 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2327 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2373 EXPECT_FALSE(connection_.connected()); 2328 EXPECT_FALSE(connection_.connected());
2374 } 2329 }
2375 2330
2376 // TODO(ianswett): Add scheduler tests when should_retransmit is false. 2331 // TODO(ianswett): Add scheduler tests when should_retransmit is false.
2377 TEST_P(QuicConnectionTest, SendScheduler) { 2332 TEST_F(QuicConnectionTest, SendScheduler) {
2378 // Test that if we send a packet without delay, it is not queued. 2333 // Test that if we send a packet without delay, it is not queued.
2379 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2334 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2380 EXPECT_CALL(*send_algorithm_, 2335 EXPECT_CALL(*send_algorithm_,
2381 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2336 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2382 testing::Return(QuicTime::Delta::Zero())); 2337 testing::Return(QuicTime::Delta::Zero()));
2383 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2338 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2384 connection_.SendPacket( 2339 connection_.SendPacket(
2385 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2340 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2386 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2341 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2387 } 2342 }
2388 2343
2389 TEST_P(QuicConnectionTest, SendSchedulerDelay) { 2344 TEST_F(QuicConnectionTest, SendSchedulerDelay) {
2390 // Test that if we send a packet with a delay, it ends up queued. 2345 // Test that if we send a packet with a delay, it ends up queued.
2391 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2346 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2392 EXPECT_CALL(*send_algorithm_, 2347 EXPECT_CALL(*send_algorithm_,
2393 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2348 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2394 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2349 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2395 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); 2350 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0);
2396 connection_.SendPacket( 2351 connection_.SendPacket(
2397 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2352 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2398 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2353 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2399 } 2354 }
2400 2355
2401 TEST_P(QuicConnectionTest, SendSchedulerForce) { 2356 TEST_F(QuicConnectionTest, SendSchedulerForce) {
2402 // Test that if we force send a packet, it is not queued. 2357 // Test that if we force send a packet, it is not queued.
2403 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2358 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2404 EXPECT_CALL(*send_algorithm_, 2359 EXPECT_CALL(*send_algorithm_,
2405 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); 2360 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0);
2406 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2361 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2407 connection_.SendPacket( 2362 connection_.SendPacket(
2408 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2363 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2409 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); 2364 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce);
2410 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2365 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2411 } 2366 }
2412 2367
2413 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { 2368 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) {
2414 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2369 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2415 writer_->set_blocked(true); 2370 writer_->set_blocked(true);
2416 EXPECT_CALL(*send_algorithm_, 2371 EXPECT_CALL(*send_algorithm_,
2417 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2372 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2418 testing::Return(QuicTime::Delta::Zero())); 2373 testing::Return(QuicTime::Delta::Zero()));
2419 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); 2374 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0);
2420 connection_.SendPacket( 2375 connection_.SendPacket(
2421 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2376 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2422 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2377 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2423 } 2378 }
2424 2379
2425 TEST_P(QuicConnectionTest, SendSchedulerDelayThenSend) { 2380 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) {
2426 // Test that if we send a packet with a delay, it ends up queued. 2381 // Test that if we send a packet with a delay, it ends up queued.
2427 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2382 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2428 EXPECT_CALL(*send_algorithm_, 2383 EXPECT_CALL(*send_algorithm_,
2429 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2384 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2430 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2385 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2431 connection_.SendPacket( 2386 connection_.SendPacket(
2432 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2387 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2433 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2388 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2434 2389
2435 // Advance the clock to fire the alarm, and configure the scheduler 2390 // Advance the clock to fire the alarm, and configure the scheduler
2436 // to permit the packet to be sent. 2391 // to permit the packet to be sent.
2437 EXPECT_CALL(*send_algorithm_, 2392 EXPECT_CALL(*send_algorithm_,
2438 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 2393 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
2439 testing::Return(QuicTime::Delta::Zero())); 2394 testing::Return(QuicTime::Delta::Zero()));
2440 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2395 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2441 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2396 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2442 connection_.GetSendAlarm()->Fire(); 2397 connection_.GetSendAlarm()->Fire();
2443 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2398 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2444 } 2399 }
2445 2400
2446 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { 2401 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) {
2447 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)) 2402 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _))
2448 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2403 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2449 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 2404 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
2450 EXPECT_CALL(*send_algorithm_, 2405 EXPECT_CALL(*send_algorithm_,
2451 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _)); 2406 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _));
2452 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2407 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2453 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2408 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2454 // Advance the time for retransmission of lost packet. 2409 // Advance the time for retransmission of lost packet.
2455 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); 2410 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501));
2456 // Test that if we send a retransmit with a delay, it ends up queued in the 2411 // Test that if we send a retransmit with a delay, it ends up queued in the
(...skipping 11 matching lines...) Expand all
2468 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2423 WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2469 2424
2470 // Ensure the scheduler is notified this is a retransmit. 2425 // Ensure the scheduler is notified this is a retransmit.
2471 EXPECT_CALL(*send_algorithm_, 2426 EXPECT_CALL(*send_algorithm_,
2472 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)); 2427 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _));
2473 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2428 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2474 connection_.GetSendAlarm()->Fire(); 2429 connection_.GetSendAlarm()->Fire();
2475 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2430 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2476 } 2431 }
2477 2432
2478 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) { 2433 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) {
2479 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2434 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2480 EXPECT_CALL(*send_algorithm_, 2435 EXPECT_CALL(*send_algorithm_,
2481 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2436 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2482 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2437 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2483 connection_.SendPacket( 2438 connection_.SendPacket(
2484 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2439 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2485 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2440 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2486 2441
2487 // Attempt to send another packet and make sure that it gets queued. 2442 // Attempt to send another packet and make sure that it gets queued.
2488 packet = ConstructDataPacket(2, 0, !kEntropyFlag); 2443 packet = ConstructDataPacket(2, 0, !kEntropyFlag);
2489 connection_.SendPacket( 2444 connection_.SendPacket(
2490 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2445 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2491 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 2446 EXPECT_EQ(2u, connection_.NumQueuedPackets());
2492 } 2447 }
2493 2448
2494 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { 2449 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) {
2495 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2450 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2496 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2451 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2497 EXPECT_CALL(*send_algorithm_, 2452 EXPECT_CALL(*send_algorithm_,
2498 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2453 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2499 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2454 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2500 connection_.SendPacket( 2455 connection_.SendPacket(
2501 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2456 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2502 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2457 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2503 2458
2504 // Now send non-retransmitting information, that we're not going to 2459 // Now send non-retransmitting information, that we're not going to
2505 // retransmit 3. The far end should stop waiting for it. 2460 // retransmit 3. The far end should stop waiting for it.
2506 QuicAckFrame frame(0, QuicTime::Zero(), 1); 2461 QuicAckFrame frame(0, QuicTime::Zero(), 1);
2507 EXPECT_CALL(*send_algorithm_, 2462 EXPECT_CALL(*send_algorithm_,
2508 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 2463 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
2509 testing::Return(QuicTime::Delta::Zero())); 2464 testing::Return(QuicTime::Delta::Zero()));
2510 EXPECT_CALL(*send_algorithm_, 2465 EXPECT_CALL(*send_algorithm_,
2511 OnPacketSent(_, _, _, _, _)); 2466 OnPacketSent(_, _, _, _, _));
2512 ProcessAckPacket(&frame); 2467 ProcessAckPacket(&frame);
2513 2468
2514 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2469 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2515 // Ensure alarm is not set 2470 // Ensure alarm is not set
2516 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2471 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2517 } 2472 }
2518 2473
2519 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { 2474 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) {
2520 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2475 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2521 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2476 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2522 EXPECT_CALL(*send_algorithm_, 2477 EXPECT_CALL(*send_algorithm_,
2523 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2478 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2524 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2479 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2525 connection_.SendPacket( 2480 connection_.SendPacket(
2526 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2481 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2527 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2482 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2528 2483
2529 // Now send non-retransmitting information, that we're not going to 2484 // Now send non-retransmitting information, that we're not going to
2530 // retransmit 3. The far end should stop waiting for it. 2485 // retransmit 3. The far end should stop waiting for it.
2531 QuicAckFrame frame(0, QuicTime::Zero(), 1); 2486 QuicAckFrame frame(0, QuicTime::Zero(), 1);
2532 EXPECT_CALL(*send_algorithm_, 2487 EXPECT_CALL(*send_algorithm_,
2533 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2488 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2534 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2489 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2535 ProcessAckPacket(&frame); 2490 ProcessAckPacket(&frame);
2536 2491
2537 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2492 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2538 } 2493 }
2539 2494
2540 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { 2495 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) {
2541 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2496 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2542 EXPECT_CALL(*send_algorithm_, 2497 EXPECT_CALL(*send_algorithm_,
2543 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2498 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2544 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2499 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2545 connection_.SendPacket( 2500 connection_.SendPacket(
2546 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2501 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2547 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2502 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2548 2503
2549 // OnCanWrite should not send the packet (because of the delay) 2504 // OnCanWrite should not send the packet (because of the delay)
2550 // but should still return true. 2505 // but should still return true.
2551 EXPECT_TRUE(connection_.OnCanWrite()); 2506 EXPECT_TRUE(connection_.OnCanWrite());
2552 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2507 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2553 } 2508 }
2554 2509
2555 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 2510 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
2556 // All packets carry version info till version is negotiated. 2511 // All packets carry version info till version is negotiated.
2557 size_t payload_length; 2512 size_t payload_length;
2558 connection_.options()->max_packet_length = 2513 connection_.options()->max_packet_length =
2559 GetPacketLengthForOneStream( 2514 GetPacketLengthForOneStream(
2560 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2515 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
2561 NOT_IN_FEC_GROUP, &payload_length); 2516 NOT_IN_FEC_GROUP, &payload_length);
2562 2517
2563 // Queue the first packet. 2518 // Queue the first packet.
2564 EXPECT_CALL(*send_algorithm_, 2519 EXPECT_CALL(*send_algorithm_,
2565 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2520 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2566 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2521 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2567 const string payload(payload_length, 'a'); 2522 const string payload(payload_length, 'a');
2568 EXPECT_EQ(0u, 2523 EXPECT_EQ(0u,
2569 connection_.SendStreamDataWithString(3, payload, 0, 2524 connection_.SendStreamDataWithString(3, payload, 0,
2570 !kFin, NULL).bytes_consumed); 2525 !kFin, NULL).bytes_consumed);
2571 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2526 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2572 } 2527 }
2573 2528
2574 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 2529 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) {
2575 // All packets carry version info till version is negotiated. 2530 // All packets carry version info till version is negotiated.
2576 size_t payload_length; 2531 size_t payload_length;
2577 connection_.options()->max_packet_length = 2532 connection_.options()->max_packet_length =
2578 GetPacketLengthForOneStream( 2533 GetPacketLengthForOneStream(
2579 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2534 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
2580 NOT_IN_FEC_GROUP, &payload_length); 2535 NOT_IN_FEC_GROUP, &payload_length);
2581 2536
2582 // Queue the first packet. 2537 // Queue the first packet.
2583 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 2538 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
2584 // The first stream frame will consume 2 fewer bytes than the other six. 2539 // The first stream frame will consume 2 fewer bytes than the other six.
2585 const string payload(payload_length * 7 - 12, 'a'); 2540 const string payload(payload_length * 7 - 12, 'a');
2586 EXPECT_EQ(payload.size(), 2541 EXPECT_EQ(payload.size(),
2587 connection_.SendStreamDataWithString(1, payload, 0, 2542 connection_.SendStreamDataWithString(1, payload, 0,
2588 !kFin, NULL).bytes_consumed); 2543 !kFin, NULL).bytes_consumed);
2589 } 2544 }
2590 2545
2591 TEST_P(QuicConnectionTest, SendDelayedAckOnTimer) { 2546 TEST_F(QuicConnectionTest, SendDelayedAckOnTimer) {
2592 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 2547 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime());
2593 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2548 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2594 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2549 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2595 ProcessPacket(1); 2550 ProcessPacket(1);
2596 // Check if delayed ack timer is running for the expected interval. 2551 // Check if delayed ack timer is running for the expected interval.
2597 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 2552 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
2598 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 2553 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
2599 // Simulate delayed ack alarm firing. 2554 // Simulate delayed ack alarm firing.
2600 connection_.GetAckAlarm()->Fire(); 2555 connection_.GetAckAlarm()->Fire();
2601 // Check that ack is sent and that delayed ack alarm is reset. 2556 // Check that ack is sent and that delayed ack alarm is reset.
2602 EXPECT_EQ(1u, writer_->frame_count()); 2557 EXPECT_EQ(1u, writer_->frame_count());
2603 EXPECT_TRUE(writer_->ack()); 2558 EXPECT_TRUE(writer_->ack());
2604 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2559 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2605 } 2560 }
2606 2561
2607 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { 2562 TEST_F(QuicConnectionTest, SendDelayedAckOnSecondPacket) {
2608 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2563 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2609 ProcessPacket(1); 2564 ProcessPacket(1);
2610 ProcessPacket(2); 2565 ProcessPacket(2);
2611 // Check that ack is sent and that delayed ack alarm is reset. 2566 // Check that ack is sent and that delayed ack alarm is reset.
2612 EXPECT_EQ(1u, writer_->frame_count()); 2567 EXPECT_EQ(1u, writer_->frame_count());
2613 EXPECT_TRUE(writer_->ack()); 2568 EXPECT_TRUE(writer_->ack());
2614 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2569 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2615 } 2570 }
2616 2571
2617 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { 2572 TEST_F(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) {
2618 if (!FLAGS_bundle_ack_with_outgoing_packet) {
2619 // This test specifically tests ack bundling behavior.
2620 return;
2621 }
2622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2573 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2623 ProcessPacket(1); 2574 ProcessPacket(1);
2624 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); 2575 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL);
2625 // Check that ack is bundled with outgoing data and that delayed ack 2576 // Check that ack is bundled with outgoing data and that delayed ack
2626 // alarm is reset. 2577 // alarm is reset.
2627 EXPECT_EQ(2u, writer_->frame_count()); 2578 EXPECT_EQ(2u, writer_->frame_count());
2628 EXPECT_TRUE(writer_->ack()); 2579 EXPECT_TRUE(writer_->ack());
2629 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2580 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2630 } 2581 }
2631 2582
2632 TEST_P(QuicConnectionTest, DontSendDelayedAckOnOutgoingCryptoPacket) { 2583 TEST_F(QuicConnectionTest, DontSendDelayedAckOnOutgoingCryptoPacket) {
2633 if (!FLAGS_bundle_ack_with_outgoing_packet) {
2634 // This test specifically tests ack bundling behavior.
2635 return;
2636 }
2637 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2638 ProcessPacket(1); 2585 ProcessPacket(1);
2639 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); 2586 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL);
2640 // Check that ack is not bundled with outgoing data. 2587 // Check that ack is not bundled with outgoing data.
2641 EXPECT_EQ(1u, writer_->frame_count()); 2588 EXPECT_EQ(1u, writer_->frame_count());
2642 EXPECT_FALSE(writer_->ack()); 2589 EXPECT_FALSE(writer_->ack());
2643 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 2590 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
2644 } 2591 }
2645 2592
2646 TEST_P(QuicConnectionTest, NoAckForClose) { 2593 TEST_F(QuicConnectionTest, NoAckForClose) {
2647 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2594 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2648 ProcessPacket(1); 2595 ProcessPacket(1);
2649 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0); 2596 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0);
2650 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); 2597 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true));
2651 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2598 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2652 ProcessClosePacket(2, 0); 2599 ProcessClosePacket(2, 0);
2653 } 2600 }
2654 2601
2655 TEST_P(QuicConnectionTest, SendWhenDisconnected) { 2602 TEST_F(QuicConnectionTest, SendWhenDisconnected) {
2656 EXPECT_TRUE(connection_.connected()); 2603 EXPECT_TRUE(connection_.connected());
2657 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); 2604 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false));
2658 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); 2605 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false);
2659 EXPECT_FALSE(connection_.connected()); 2606 EXPECT_FALSE(connection_.connected());
2660 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2607 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2661 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); 2608 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0);
2662 connection_.SendPacket( 2609 connection_.SendPacket(
2663 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2610 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2664 } 2611 }
2665 2612
2666 TEST_P(QuicConnectionTest, PublicReset) { 2613 TEST_F(QuicConnectionTest, PublicReset) {
2667 QuicPublicResetPacket header; 2614 QuicPublicResetPacket header;
2668 header.public_header.guid = guid_; 2615 header.public_header.guid = guid_;
2669 header.public_header.reset_flag = true; 2616 header.public_header.reset_flag = true;
2670 header.public_header.version_flag = false; 2617 header.public_header.version_flag = false;
2671 header.rejected_sequence_number = 10101; 2618 header.rejected_sequence_number = 10101;
2672 scoped_ptr<QuicEncryptedPacket> packet( 2619 scoped_ptr<QuicEncryptedPacket> packet(
2673 framer_.BuildPublicResetPacket(header)); 2620 framer_.BuildPublicResetPacket(header));
2674 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)); 2621 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true));
2675 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); 2622 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet);
2676 } 2623 }
2677 2624
2678 TEST_P(QuicConnectionTest, GoAway) { 2625 TEST_F(QuicConnectionTest, GoAway) {
2679 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2626 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2680 2627
2681 QuicGoAwayFrame goaway; 2628 QuicGoAwayFrame goaway;
2682 goaway.last_good_stream_id = 1; 2629 goaway.last_good_stream_id = 1;
2683 goaway.error_code = QUIC_PEER_GOING_AWAY; 2630 goaway.error_code = QUIC_PEER_GOING_AWAY;
2684 goaway.reason_phrase = "Going away."; 2631 goaway.reason_phrase = "Going away.";
2685 EXPECT_CALL(visitor_, OnGoAway(_)); 2632 EXPECT_CALL(visitor_, OnGoAway(_));
2686 ProcessGoAwayPacket(&goaway); 2633 ProcessGoAwayPacket(&goaway);
2687 } 2634 }
2688 2635
2689 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { 2636 TEST_F(QuicConnectionTest, InvalidPacket) {
2637 EXPECT_CALL(visitor_,
2638 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
2639 QuicEncryptedPacket encrypted(NULL, 0);
2640 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted);
2641 // The connection close packet should have error details.
2642 ASSERT_TRUE(last_close() != NULL);
2643 EXPECT_EQ("Unable to read public flags.", last_close()->error_details);
2644 }
2645
2646 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) {
2690 QuicAckFrame ack(0, QuicTime::Zero(), 4); 2647 QuicAckFrame ack(0, QuicTime::Zero(), 4);
2691 // Set the sequence number of the ack packet to be least unacked (4). 2648 // Set the sequence number of the ack packet to be least unacked (4).
2692 creator_.set_sequence_number(3); 2649 creator_.set_sequence_number(3);
2693 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2650 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2694 ProcessAckPacket(&ack); 2651 ProcessAckPacket(&ack);
2695 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); 2652 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty());
2696 } 2653 }
2697 2654
2698 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { 2655 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) {
2699 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); 2656 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true));
2700 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2657 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2701 ProcessDataPacket(1, 1, kEntropyFlag); 2658 ProcessDataPacket(1, 1, kEntropyFlag);
2702 ProcessDataPacket(4, 1, kEntropyFlag); 2659 ProcessDataPacket(4, 1, kEntropyFlag);
2703 ProcessDataPacket(3, 1, !kEntropyFlag); 2660 ProcessDataPacket(3, 1, !kEntropyFlag);
2704 ProcessDataPacket(7, 1, kEntropyFlag); 2661 ProcessDataPacket(7, 1, kEntropyFlag);
2705 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); 2662 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash);
2706 } 2663 }
2707 2664
2708 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { 2665 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) {
2709 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); 2666 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true));
2710 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2711 ProcessDataPacket(1, 1, kEntropyFlag); 2668 ProcessDataPacket(1, 1, kEntropyFlag);
2712 ProcessDataPacket(5, 1, kEntropyFlag); 2669 ProcessDataPacket(5, 1, kEntropyFlag);
2713 ProcessDataPacket(4, 1, !kEntropyFlag); 2670 ProcessDataPacket(4, 1, !kEntropyFlag);
2714 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); 2671 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash);
2715 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. 2672 // Make 4th packet my least unacked, and update entropy for 2, 3 packets.
2716 QuicAckFrame ack(0, QuicTime::Zero(), 4); 2673 QuicAckFrame ack(0, QuicTime::Zero(), 4);
2717 QuicPacketEntropyHash kRandomEntropyHash = 129u; 2674 QuicPacketEntropyHash kRandomEntropyHash = 129u;
2718 ack.sent_info.entropy_hash = kRandomEntropyHash; 2675 ack.sent_info.entropy_hash = kRandomEntropyHash;
2719 creator_.set_sequence_number(5); 2676 creator_.set_sequence_number(5);
2720 QuicPacketEntropyHash six_packet_entropy_hash = 0; 2677 QuicPacketEntropyHash six_packet_entropy_hash = 0;
2721 if (ProcessAckPacket(&ack)) { 2678 if (ProcessAckPacket(&ack)) {
2722 six_packet_entropy_hash = 1 << 6; 2679 six_packet_entropy_hash = 1 << 6;
2723 } 2680 }
2724 2681
2725 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), 2682 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash),
2726 outgoing_ack()->received_info.entropy_hash); 2683 outgoing_ack()->received_info.entropy_hash);
2727 } 2684 }
2728 2685
2729 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { 2686 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) {
2730 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); 2687 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true));
2731 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2732 ProcessDataPacket(1, 1, kEntropyFlag); 2689 ProcessDataPacket(1, 1, kEntropyFlag);
2733 ProcessDataPacket(5, 1, !kEntropyFlag); 2690 ProcessDataPacket(5, 1, !kEntropyFlag);
2734 ProcessDataPacket(22, 1, kEntropyFlag); 2691 ProcessDataPacket(22, 1, kEntropyFlag);
2735 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); 2692 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash);
2736 creator_.set_sequence_number(22); 2693 creator_.set_sequence_number(22);
2737 QuicPacketEntropyHash kRandomEntropyHash = 85u; 2694 QuicPacketEntropyHash kRandomEntropyHash = 85u;
2738 // Current packet is the least unacked packet. 2695 // Current packet is the least unacked packet.
2739 QuicAckFrame ack(0, QuicTime::Zero(), 23); 2696 QuicAckFrame ack(0, QuicTime::Zero(), 23);
2740 ack.sent_info.entropy_hash = kRandomEntropyHash; 2697 ack.sent_info.entropy_hash = kRandomEntropyHash;
2741 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack); 2698 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack);
2742 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), 2699 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash),
2743 outgoing_ack()->received_info.entropy_hash); 2700 outgoing_ack()->received_info.entropy_hash);
2744 ProcessDataPacket(25, 1, kEntropyFlag); 2701 ProcessDataPacket(25, 1, kEntropyFlag);
2745 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), 2702 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))),
2746 outgoing_ack()->received_info.entropy_hash); 2703 outgoing_ack()->received_info.entropy_hash);
2747 } 2704 }
2748 2705
2749 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { 2706 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) {
2750 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); 2707 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true));
2751 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2708 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2752 QuicPacketEntropyHash entropy[51]; 2709 QuicPacketEntropyHash entropy[51];
2753 entropy[0] = 0; 2710 entropy[0] = 0;
2754 for (int i = 1; i < 51; ++i) { 2711 for (int i = 1; i < 51; ++i) {
2755 bool should_send = i % 10 != 0; 2712 bool should_send = i % 10 != 0;
2756 bool entropy_flag = (i & (i - 1)) != 0; 2713 bool entropy_flag = (i & (i - 1)) != 0;
2757 if (!should_send) { 2714 if (!should_send) {
2758 entropy[i] = entropy[i - 1]; 2715 entropy[i] = entropy[i - 1];
2759 continue; 2716 continue;
2760 } 2717 }
2761 if (entropy_flag) { 2718 if (entropy_flag) {
2762 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); 2719 entropy[i] = entropy[i - 1] ^ (1 << (i % 8));
2763 } else { 2720 } else {
2764 entropy[i] = entropy[i - 1]; 2721 entropy[i] = entropy[i - 1];
2765 } 2722 }
2766 ProcessDataPacket(i, 1, entropy_flag); 2723 ProcessDataPacket(i, 1, entropy_flag);
2767 } 2724 }
2768 // Till 50 since 50th packet is not sent. 2725 // Till 50 since 50th packet is not sent.
2769 for (int i = 1; i < 50; ++i) { 2726 for (int i = 1; i < 50; ++i) {
2770 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( 2727 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash(
2771 &connection_, i)); 2728 &connection_, i));
2772 } 2729 }
2773 } 2730 }
2774 2731
2775 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { 2732 TEST_F(QuicConnectionTest, CheckSentEntropyHash) {
2776 creator_.set_sequence_number(1); 2733 creator_.set_sequence_number(1);
2777 SequenceNumberSet missing_packets; 2734 SequenceNumberSet missing_packets;
2778 QuicPacketEntropyHash entropy_hash = 0; 2735 QuicPacketEntropyHash entropy_hash = 0;
2779 QuicPacketSequenceNumber max_sequence_number = 51; 2736 QuicPacketSequenceNumber max_sequence_number = 51;
2780 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { 2737 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) {
2781 bool is_missing = i % 10 != 0; 2738 bool is_missing = i % 10 != 0;
2782 bool entropy_flag = (i & (i - 1)) != 0; 2739 bool entropy_flag = (i & (i - 1)) != 0;
2783 QuicPacketEntropyHash packet_entropy_hash = 0; 2740 QuicPacketEntropyHash packet_entropy_hash = 0;
2784 if (entropy_flag) { 2741 if (entropy_flag) {
2785 packet_entropy_hash = 1 << (i % 8); 2742 packet_entropy_hash = 1 << (i % 8);
2786 } 2743 }
2787 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); 2744 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag);
2788 connection_.SendPacket( 2745 connection_.SendPacket(
2789 ENCRYPTION_NONE, i, packet, packet_entropy_hash, 2746 ENCRYPTION_NONE, i, packet, packet_entropy_hash,
2790 HAS_RETRANSMITTABLE_DATA); 2747 HAS_RETRANSMITTABLE_DATA);
2791 2748
2792 if (is_missing) { 2749 if (is_missing) {
2793 missing_packets.insert(i); 2750 missing_packets.insert(i);
2794 continue; 2751 continue;
2795 } 2752 }
2796 2753
2797 entropy_hash ^= packet_entropy_hash; 2754 entropy_hash ^= packet_entropy_hash;
2798 } 2755 }
2799 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( 2756 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy(
2800 &connection_, max_sequence_number, missing_packets, entropy_hash)) 2757 &connection_, max_sequence_number, missing_packets, entropy_hash))
2801 << ""; 2758 << "";
2802 } 2759 }
2803 2760
2804 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { 2761 TEST_F(QuicConnectionTest, ServerSendsVersionNegotiationPacket) {
2805 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); 2762 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
2806 2763
2807 QuicPacketHeader header; 2764 QuicPacketHeader header;
2808 header.public_header.guid = guid_; 2765 header.public_header.guid = guid_;
2809 header.public_header.reset_flag = false; 2766 header.public_header.reset_flag = false;
2810 header.public_header.version_flag = true; 2767 header.public_header.version_flag = true;
2811 header.entropy_flag = false; 2768 header.entropy_flag = false;
2812 header.fec_flag = false; 2769 header.fec_flag = false;
2813 header.packet_sequence_number = 12; 2770 header.packet_sequence_number = 12;
2814 header.fec_group = 0; 2771 header.fec_group = 0;
(...skipping 16 matching lines...) Expand all
2831 writer_->version_negotiation_packet()->versions.size()); 2788 writer_->version_negotiation_packet()->versions.size());
2832 2789
2833 // We expect all versions in kSupportedQuicVersions to be 2790 // We expect all versions in kSupportedQuicVersions to be
2834 // included in the packet. 2791 // included in the packet.
2835 for (size_t i = 0; i < num_versions; ++i) { 2792 for (size_t i = 0; i < num_versions; ++i) {
2836 EXPECT_EQ(kSupportedQuicVersions[i], 2793 EXPECT_EQ(kSupportedQuicVersions[i],
2837 writer_->version_negotiation_packet()->versions[i]); 2794 writer_->version_negotiation_packet()->versions[i]);
2838 } 2795 }
2839 } 2796 }
2840 2797
2841 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { 2798 TEST_F(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) {
2842 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); 2799 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
2843 2800
2844 QuicPacketHeader header; 2801 QuicPacketHeader header;
2845 header.public_header.guid = guid_; 2802 header.public_header.guid = guid_;
2846 header.public_header.reset_flag = false; 2803 header.public_header.reset_flag = false;
2847 header.public_header.version_flag = true; 2804 header.public_header.version_flag = true;
2848 header.entropy_flag = false; 2805 header.entropy_flag = false;
2849 header.fec_flag = false; 2806 header.fec_flag = false;
2850 header.packet_sequence_number = 12; 2807 header.packet_sequence_number = 12;
2851 header.fec_group = 0; 2808 header.fec_group = 0;
(...skipping 23 matching lines...) Expand all
2875 writer_->version_negotiation_packet()->versions.size()); 2832 writer_->version_negotiation_packet()->versions.size());
2876 2833
2877 // We expect all versions in kSupportedQuicVersions to be 2834 // We expect all versions in kSupportedQuicVersions to be
2878 // included in the packet. 2835 // included in the packet.
2879 for (size_t i = 0; i < num_versions; ++i) { 2836 for (size_t i = 0; i < num_versions; ++i) {
2880 EXPECT_EQ(kSupportedQuicVersions[i], 2837 EXPECT_EQ(kSupportedQuicVersions[i],
2881 writer_->version_negotiation_packet()->versions[i]); 2838 writer_->version_negotiation_packet()->versions[i]);
2882 } 2839 }
2883 } 2840 }
2884 2841
2885 TEST_P(QuicConnectionTest, 2842 TEST_F(QuicConnectionTest,
2886 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { 2843 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) {
2887 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); 2844 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
2888 2845
2889 QuicPacketHeader header; 2846 QuicPacketHeader header;
2890 header.public_header.guid = guid_; 2847 header.public_header.guid = guid_;
2891 header.public_header.reset_flag = false; 2848 header.public_header.reset_flag = false;
2892 header.public_header.version_flag = true; 2849 header.public_header.version_flag = true;
2893 header.entropy_flag = false; 2850 header.entropy_flag = false;
2894 header.fec_flag = false; 2851 header.fec_flag = false;
2895 header.packet_sequence_number = 12; 2852 header.packet_sequence_number = 12;
(...skipping 10 matching lines...) Expand all
2906 framer_.set_version(QuicVersionMax()); 2863 framer_.set_version(QuicVersionMax());
2907 connection_.set_is_server(true); 2864 connection_.set_is_server(true);
2908 writer_->set_blocked(true); 2865 writer_->set_blocked(true);
2909 writer_->set_is_write_blocked_data_buffered(true); 2866 writer_->set_is_write_blocked_data_buffered(true);
2910 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2867 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2911 EXPECT_EQ(0u, writer_->last_packet_size()); 2868 EXPECT_EQ(0u, writer_->last_packet_size());
2912 EXPECT_FALSE(connection_.HasQueuedData()); 2869 EXPECT_FALSE(connection_.HasQueuedData());
2913 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); 2870 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
2914 } 2871 }
2915 2872
2916 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { 2873 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) {
2917 // Start out with some unsupported version. 2874 // Start out with some unsupported version.
2918 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( 2875 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests(
2919 QUIC_VERSION_UNSUPPORTED); 2876 QUIC_VERSION_UNSUPPORTED);
2920 2877
2921 QuicPacketHeader header; 2878 QuicPacketHeader header;
2922 header.public_header.guid = guid_; 2879 header.public_header.guid = guid_;
2923 header.public_header.reset_flag = false; 2880 header.public_header.reset_flag = false;
2924 header.public_header.version_flag = true; 2881 header.public_header.version_flag = true;
2925 header.entropy_flag = false; 2882 header.entropy_flag = false;
2926 header.fec_flag = false; 2883 header.fec_flag = false;
(...skipping 21 matching lines...) Expand all
2948 framer_.BuildUnsizedDataPacket(header, frames).packet); 2905 framer_.BuildUnsizedDataPacket(header, frames).packet);
2949 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2906 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2950 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2907 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2908 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2952 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2909 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2953 2910
2954 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( 2911 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(
2955 QuicConnectionPeer::GetPacketCreator(&connection_))); 2912 QuicConnectionPeer::GetPacketCreator(&connection_)));
2956 } 2913 }
2957 2914
2958 TEST_P(QuicConnectionTest, BadVersionNegotiation) { 2915 TEST_F(QuicConnectionTest, BadVersionNegotiation) {
2959 QuicPacketHeader header; 2916 QuicPacketHeader header;
2960 header.public_header.guid = guid_; 2917 header.public_header.guid = guid_;
2961 header.public_header.reset_flag = false; 2918 header.public_header.reset_flag = false;
2962 header.public_header.version_flag = true; 2919 header.public_header.version_flag = true;
2963 header.entropy_flag = false; 2920 header.entropy_flag = false;
2964 header.fec_flag = false; 2921 header.fec_flag = false;
2965 header.packet_sequence_number = 12; 2922 header.packet_sequence_number = 12;
2966 header.fec_group = 0; 2923 header.fec_group = 0;
2967 2924
2968 QuicVersionVector supported_versions; 2925 QuicVersionVector supported_versions;
2969 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 2926 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
2970 supported_versions.push_back(kSupportedQuicVersions[i]); 2927 supported_versions.push_back(kSupportedQuicVersions[i]);
2971 } 2928 }
2972 2929
2973 // Send a version negotiation packet with the version the client started with. 2930 // Send a version negotiation packet with the version the client started with.
2974 // It should be rejected. 2931 // It should be rejected.
2975 EXPECT_CALL(visitor_, 2932 EXPECT_CALL(visitor_,
2976 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, 2933 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET,
2977 false)); 2934 false));
2978 scoped_ptr<QuicEncryptedPacket> encrypted( 2935 scoped_ptr<QuicEncryptedPacket> encrypted(
2979 framer_.BuildVersionNegotiationPacket( 2936 framer_.BuildVersionNegotiationPacket(
2980 header.public_header, supported_versions)); 2937 header.public_header, supported_versions));
2981 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2938 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2982 } 2939 }
2983 2940
2984 TEST_P(QuicConnectionTest, CheckSendStats) { 2941 TEST_F(QuicConnectionTest, CheckSendStats) {
2985 EXPECT_CALL(*send_algorithm_, 2942 EXPECT_CALL(*send_algorithm_,
2986 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 2943 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
2987 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL); 2944 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL);
2988 size_t first_packet_size = last_sent_packet_size(); 2945 size_t first_packet_size = last_sent_packet_size();
2989 2946
2990 EXPECT_CALL(*send_algorithm_, 2947 EXPECT_CALL(*send_algorithm_,
2991 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 2948 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
2992 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL); 2949 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL);
2993 size_t second_packet_size = last_sent_packet_size(); 2950 size_t second_packet_size = last_sent_packet_size();
2994 2951
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 const QuicConnectionStats& stats = connection_.GetStats(); 2988 const QuicConnectionStats& stats = connection_.GetStats();
3032 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 2989 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
3033 stats.bytes_sent); 2990 stats.bytes_sent);
3034 EXPECT_EQ(5u, stats.packets_sent); 2991 EXPECT_EQ(5u, stats.packets_sent);
3035 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 2992 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
3036 stats.bytes_retransmitted); 2993 stats.bytes_retransmitted);
3037 EXPECT_EQ(3u, stats.packets_retransmitted); 2994 EXPECT_EQ(3u, stats.packets_retransmitted);
3038 EXPECT_EQ(1u, stats.rto_count); 2995 EXPECT_EQ(1u, stats.rto_count);
3039 } 2996 }
3040 2997
3041 TEST_P(QuicConnectionTest, CheckReceiveStats) { 2998 TEST_F(QuicConnectionTest, CheckReceiveStats) {
3042 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2999 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3043 3000
3044 size_t received_bytes = 0; 3001 size_t received_bytes = 0;
3045 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); 3002 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag);
3046 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); 3003 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag);
3047 // Should be counted against dropped packets. 3004 // Should be counted against dropped packets.
3048 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); 3005 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag);
3049 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); 3006 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL);
3050 3007
3051 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( 3008 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce(
3052 Return(QuicTime::Delta::Zero())); 3009 Return(QuicTime::Delta::Zero()));
3053 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3010 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
3054 Return(QuicBandwidth::Zero())); 3011 Return(QuicBandwidth::Zero()));
3055 3012
3056 const QuicConnectionStats& stats = connection_.GetStats(); 3013 const QuicConnectionStats& stats = connection_.GetStats();
3057 EXPECT_EQ(received_bytes, stats.bytes_received); 3014 EXPECT_EQ(received_bytes, stats.bytes_received);
3058 EXPECT_EQ(4u, stats.packets_received); 3015 EXPECT_EQ(4u, stats.packets_received);
3059 3016
3060 EXPECT_EQ(1u, stats.packets_revived); 3017 EXPECT_EQ(1u, stats.packets_revived);
3061 EXPECT_EQ(1u, stats.packets_dropped); 3018 EXPECT_EQ(1u, stats.packets_dropped);
3062 } 3019 }
3063 3020
3064 TEST_P(QuicConnectionTest, TestFecGroupLimits) { 3021 TEST_F(QuicConnectionTest, TestFecGroupLimits) {
3065 // Create and return a group for 1. 3022 // Create and return a group for 1.
3066 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != NULL); 3023 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != NULL);
3067 3024
3068 // Create and return a group for 2. 3025 // Create and return a group for 2.
3069 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); 3026 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL);
3070 3027
3071 // Create and return a group for 4. This should remove 1 but not 2. 3028 // Create and return a group for 4. This should remove 1 but not 2.
3072 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); 3029 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL);
3073 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == NULL); 3030 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == NULL);
3074 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); 3031 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL);
3075 3032
3076 // Create and return a group for 3. This will kill off 2. 3033 // Create and return a group for 3. This will kill off 2.
3077 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != NULL); 3034 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != NULL);
3078 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == NULL); 3035 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == NULL);
3079 3036
3080 // Verify that adding 5 kills off 3, despite 4 being created before 3. 3037 // Verify that adding 5 kills off 3, despite 4 being created before 3.
3081 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != NULL); 3038 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != NULL);
3082 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); 3039 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL);
3083 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == NULL); 3040 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == NULL);
3084 } 3041 }
3085 3042
3086 TEST_P(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) { 3043 TEST_F(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) {
3087 // Construct a packet with stream frame and connection close frame. 3044 // Construct a packet with stream frame and connection close frame.
3088 header_.public_header.guid = guid_; 3045 header_.public_header.guid = guid_;
3089 header_.packet_sequence_number = 1; 3046 header_.packet_sequence_number = 1;
3090 header_.public_header.reset_flag = false; 3047 header_.public_header.reset_flag = false;
3091 header_.public_header.version_flag = false; 3048 header_.public_header.version_flag = false;
3092 header_.entropy_flag = false; 3049 header_.entropy_flag = false;
3093 header_.fec_flag = false; 3050 header_.fec_flag = false;
3094 header_.fec_group = 0; 3051 header_.fec_group = 0;
3095 3052
3096 QuicConnectionCloseFrame qccf; 3053 QuicConnectionCloseFrame qccf;
(...skipping 11 matching lines...) Expand all
3108 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 3065 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(
3109 ENCRYPTION_NONE, 1, *packet)); 3066 ENCRYPTION_NONE, 1, *packet));
3110 3067
3111 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); 3068 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true));
3112 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 3069 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
3113 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3070 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3114 3071
3115 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3072 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3116 } 3073 }
3117 3074
3118 TEST_P(QuicConnectionTest, SelectMutualVersion) { 3075 TEST_F(QuicConnectionTest, SelectMutualVersion) {
3119 // Set the connection to speak the lowest quic version. 3076 // Set the connection to speak the lowest quic version.
3120 connection_.set_version(QuicVersionMin()); 3077 connection_.set_version(QuicVersionMin());
3121 EXPECT_EQ(QuicVersionMin(), connection_.version()); 3078 EXPECT_EQ(QuicVersionMin(), connection_.version());
3122 3079
3123 // Pass in available versions which includes a higher mutually supported 3080 // Pass in available versions which includes a higher mutually supported
3124 // version. The higher mutually supported version should be selected. 3081 // version. The higher mutually supported version should be selected.
3125 QuicVersionVector supported_versions; 3082 QuicVersionVector supported_versions;
3126 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 3083 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
3127 supported_versions.push_back(kSupportedQuicVersions[i]); 3084 supported_versions.push_back(kSupportedQuicVersions[i]);
3128 } 3085 }
3129 EXPECT_TRUE(connection_.SelectMutualVersion(supported_versions)); 3086 EXPECT_TRUE(connection_.SelectMutualVersion(supported_versions));
3130 EXPECT_EQ(QuicVersionMax(), connection_.version()); 3087 EXPECT_EQ(QuicVersionMax(), connection_.version());
3131 3088
3132 // Expect that the lowest version is selected. 3089 // Expect that the lowest version is selected.
3133 // Ensure the lowest supported version is less than the max, unless they're 3090 // Ensure the lowest supported version is less than the max, unless they're
3134 // the same. 3091 // the same.
3135 EXPECT_LE(QuicVersionMin(), QuicVersionMax()); 3092 EXPECT_LE(QuicVersionMin(), QuicVersionMax());
3136 QuicVersionVector lowest_version_vector; 3093 QuicVersionVector lowest_version_vector;
3137 lowest_version_vector.push_back(QuicVersionMin()); 3094 lowest_version_vector.push_back(QuicVersionMin());
3138 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); 3095 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector));
3139 EXPECT_EQ(QuicVersionMin(), connection_.version()); 3096 EXPECT_EQ(QuicVersionMin(), connection_.version());
3140 3097
3141 // Shouldn't be able to find a mutually supported version. 3098 // Shouldn't be able to find a mutually supported version.
3142 QuicVersionVector unsupported_version; 3099 QuicVersionVector unsupported_version;
3143 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); 3100 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED);
3144 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); 3101 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version));
3145 } 3102 }
3146 3103
3147 TEST_P(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) { 3104 TEST_F(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) {
3148 writer_->set_blocked(false); // Already default. 3105 writer_->set_blocked(false); // Already default.
3149 3106
3150 // Send a packet (but write will not block). 3107 // Send a packet (but write will not block).
3151 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3108 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3152 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3109 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3153 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3110 EXPECT_EQ(1u, writer_->packets_write_attempts());
3154 3111
3155 // Send an erroneous packet to close the connection. 3112 // Send an erroneous packet to close the connection.
3156 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3113 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3157 ProcessDataPacket(6000, 0, !kEntropyFlag); 3114 ProcessDataPacket(6000, 0, !kEntropyFlag);
3158 EXPECT_EQ(2u, writer_->packets_write_attempts()); 3115 EXPECT_EQ(2u, writer_->packets_write_attempts());
3159 } 3116 }
3160 3117
3161 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { 3118 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) {
3162 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3119 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3163 writer_->set_blocked(true); 3120 writer_->set_blocked(true);
3164 3121
3165 // Send a packet to so that write will really block. 3122 // Send a packet to so that write will really block.
3166 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3123 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3167 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3124 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3168 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3125 EXPECT_EQ(1u, writer_->packets_write_attempts());
3169 3126
3170 // Send an erroneous packet to close the connection. 3127 // Send an erroneous packet to close the connection.
3171 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3128 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3172 ProcessDataPacket(6000, 0, !kEntropyFlag); 3129 ProcessDataPacket(6000, 0, !kEntropyFlag);
3173 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3130 EXPECT_EQ(1u, writer_->packets_write_attempts());
3174 } 3131 }
3175 3132
3176 TEST_P(QuicConnectionTest, ConnectionCloseWhenNothingPending) { 3133 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) {
3177 writer_->set_blocked(true); 3134 writer_->set_blocked(true);
3178 3135
3179 // Send an erroneous packet to close the connection. 3136 // Send an erroneous packet to close the connection.
3180 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 3137 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3181 ProcessDataPacket(6000, 0, !kEntropyFlag); 3138 ProcessDataPacket(6000, 0, !kEntropyFlag);
3182 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3139 EXPECT_EQ(1u, writer_->packets_write_attempts());
3183 } 3140 }
3184 3141
3185 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { 3142 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) {
3186 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3143 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3187 3144
3188 // Create a delegate which we expect to be called. 3145 // Create a delegate which we expect to be called.
3189 MockAckNotifierDelegate delegate; 3146 MockAckNotifierDelegate delegate;
3190 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3147 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
3191 3148
3192 // Send some data, which will register the delegate to be notified. 3149 // Send some data, which will register the delegate to be notified.
3193 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); 3150 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate);
3194 3151
3195 // Process an ACK from the server which should trigger the callback. 3152 // Process an ACK from the server which should trigger the callback.
3196 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 3153 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
3197 QuicAckFrame frame(1, QuicTime::Zero(), 0); 3154 QuicAckFrame frame(1, QuicTime::Zero(), 0);
3198 ProcessAckPacket(&frame); 3155 ProcessAckPacket(&frame);
3199 } 3156 }
3200 3157
3201 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 3158 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3202 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3159 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3203 3160
3204 // Create a delegate which we don't expect to be called. 3161 // Create a delegate which we don't expect to be called.
3205 MockAckNotifierDelegate delegate; 3162 MockAckNotifierDelegate delegate;
3206 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; 3163 EXPECT_CALL(delegate, OnAckNotification()).Times(0);;
3207 3164
3208 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 3165 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
3209 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1); 3166 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_, _)).Times(1);
3210 3167
3211 // Send some data, which will register the delegate to be notified. This will 3168 // Send some data, which will register the delegate to be notified. This will
3212 // not be ACKed and so the delegate should never be called. 3169 // not be ACKed and so the delegate should never be called.
3213 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); 3170 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate);
3214 3171
3215 // Send some other data which we will ACK. 3172 // Send some other data which we will ACK.
3216 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3173 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3217 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); 3174 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL);
3218 3175
3219 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 3176 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
3220 // which we registered to be notified about. 3177 // which we registered to be notified about.
3221 QuicAckFrame frame(3, QuicTime::Zero(), 0); 3178 QuicAckFrame frame(3, QuicTime::Zero(), 0);
3222 frame.received_info.missing_packets.insert(1); 3179 frame.received_info.missing_packets.insert(1);
3223 ProcessAckPacket(&frame); 3180 ProcessAckPacket(&frame);
3224 } 3181 }
3225 3182
3226 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 3183 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3227 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3184 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3228 3185
3229 // Create a delegate which we expect to be called. 3186 // Create a delegate which we expect to be called.
3230 MockAckNotifierDelegate delegate; 3187 MockAckNotifierDelegate delegate;
3231 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3188 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
3232 3189
3233 // In total expect ACKs for all 4 packets. 3190 // In total expect ACKs for all 4 packets.
3234 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4); 3191 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4);
3235 3192
3236 // We will lose the second packet. 3193 // We will lose the second packet.
(...skipping 19 matching lines...) Expand all
3256 connection_.GetRetransmissionAlarm()->Fire(); 3213 connection_.GetRetransmissionAlarm()->Fire();
3257 3214
3258 // Now we get an ACK for packet 5 (retransmitted packet 2), which should 3215 // Now we get an ACK for packet 5 (retransmitted packet 2), which should
3259 // trigger the callback. 3216 // trigger the callback.
3260 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0); 3217 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0);
3261 ProcessAckPacket(&second_ack_frame); 3218 ProcessAckPacket(&second_ack_frame);
3262 } 3219 }
3263 3220
3264 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting 3221 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting
3265 // ACK) triggers notification on our end. 3222 // ACK) triggers notification on our end.
3266 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 3223 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
3267 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3224 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3268 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 3225 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
3269 3226
3270 // Create a delegate which we expect to be called. 3227 // Create a delegate which we expect to be called.
3271 MockAckNotifierDelegate delegate; 3228 MockAckNotifierDelegate delegate;
3272 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 3229 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
3273 3230
3274 // Expect ACKs for 1 packet. 3231 // Expect ACKs for 1 packet.
3275 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 3232 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
3276 3233
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 MOCK_METHOD1(OnPublicResetPacket, 3307 MOCK_METHOD1(OnPublicResetPacket,
3351 void(const QuicPublicResetPacket&)); 3308 void(const QuicPublicResetPacket&));
3352 3309
3353 MOCK_METHOD1(OnVersionNegotiationPacket, 3310 MOCK_METHOD1(OnVersionNegotiationPacket,
3354 void(const QuicVersionNegotiationPacket&)); 3311 void(const QuicVersionNegotiationPacket&));
3355 3312
3356 MOCK_METHOD2(OnRevivedPacket, 3313 MOCK_METHOD2(OnRevivedPacket,
3357 void(const QuicPacketHeader&, StringPiece payload)); 3314 void(const QuicPacketHeader&, StringPiece payload));
3358 }; 3315 };
3359 3316
3360 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { 3317 TEST_F(QuicConnectionTest, OnPacketHeaderDebugVisitor) {
3361 QuicPacketHeader header; 3318 QuicPacketHeader header;
3362 3319
3363 scoped_ptr<MockQuicConnectionDebugVisitor> 3320 scoped_ptr<MockQuicConnectionDebugVisitor>
3364 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); 3321 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>);
3365 connection_.set_debug_visitor(debug_visitor.get()); 3322 connection_.set_debug_visitor(debug_visitor.get());
3366 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 3323 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
3367 connection_.OnPacketHeader(header); 3324 connection_.OnPacketHeader(header);
3368 } 3325 }
3369 3326
3370 } // namespace 3327 } // namespace
3371 } // namespace test 3328 } // namespace test
3372 } // namespace net 3329 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_helper_test.cc ('k') | net/quic/quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698