OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/core/quic_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 return os; | 655 return os; |
656 } | 656 } |
657 | 657 |
658 QuicVersion version; | 658 QuicVersion version; |
659 AckResponse ack_response; | 659 AckResponse ack_response; |
660 }; | 660 }; |
661 | 661 |
662 // Constructs various test permutations. | 662 // Constructs various test permutations. |
663 vector<TestParams> GetTestParams() { | 663 vector<TestParams> GetTestParams() { |
664 vector<TestParams> params; | 664 vector<TestParams> params; |
665 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 665 QuicVersionVector all_supported_versions = AllSupportedVersions(); |
666 for (size_t i = 0; i < all_supported_versions.size(); ++i) { | 666 for (size_t i = 0; i < all_supported_versions.size(); ++i) { |
667 for (AckResponse ack_response : | 667 for (AckResponse ack_response : |
668 {AckResponse::kDefer, AckResponse::kImmediate}) { | 668 {AckResponse::kDefer, AckResponse::kImmediate}) { |
669 params.push_back(TestParams(all_supported_versions[i], ack_response)); | 669 params.push_back(TestParams(all_supported_versions[i], ack_response)); |
670 } | 670 } |
671 } | 671 } |
672 return params; | 672 return params; |
673 } | 673 } |
674 | 674 |
675 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { | 675 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { |
(...skipping 29 matching lines...) Expand all Loading... |
705 kDefaultPathId)), | 705 kDefaultPathId)), |
706 frame1_(1, false, 0, StringPiece(data1)), | 706 frame1_(1, false, 0, StringPiece(data1)), |
707 frame2_(1, false, 3, StringPiece(data2)), | 707 frame2_(1, false, 3, StringPiece(data2)), |
708 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 708 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
709 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 709 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
710 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == | 710 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == |
711 AckResponse::kDefer); | 711 AckResponse::kDefer); |
712 FLAGS_quic_always_log_bugs_for_tests = true; | 712 FLAGS_quic_always_log_bugs_for_tests = true; |
713 connection_.set_visitor(&visitor_); | 713 connection_.set_visitor(&visitor_); |
714 connection_.SetSendAlgorithm(kDefaultPathId, send_algorithm_); | 714 connection_.SetSendAlgorithm(kDefaultPathId, send_algorithm_); |
715 connection_.SetLossAlgorithm(kDefaultPathId, loss_algorithm_); | 715 connection_.SetLossAlgorithm(kDefaultPathId, loss_algorithm_.get()); |
716 framer_.set_received_entropy_calculator(&entropy_calculator_); | 716 framer_.set_received_entropy_calculator(&entropy_calculator_); |
717 peer_framer_.set_received_entropy_calculator(&peer_entropy_calculator_); | 717 peer_framer_.set_received_entropy_calculator(&peer_entropy_calculator_); |
718 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | 718 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
719 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 719 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
720 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 720 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
721 .Times(AnyNumber()); | 721 .Times(AnyNumber()); |
722 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 722 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
723 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 723 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
724 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | 724 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
725 .WillRepeatedly(Return(kDefaultTCPMSS)); | 725 .WillRepeatedly(Return(kDefaultTCPMSS)); |
726 EXPECT_CALL(*send_algorithm_, PacingRate(_)) | 726 EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
727 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 727 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
728 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 728 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
729 .WillByDefault(Return(true)); | 729 .WillByDefault(Return(true)); |
730 EXPECT_CALL(*send_algorithm_, HasReliableBandwidthEstimate()) | 730 EXPECT_CALL(*send_algorithm_, HasReliableBandwidthEstimate()) |
731 .Times(AnyNumber()); | 731 .Times(AnyNumber()); |
732 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) | 732 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
733 .Times(AnyNumber()) | 733 .Times(AnyNumber()) |
734 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 734 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
735 EXPECT_CALL(*send_algorithm_, InSlowStart()).Times(AnyNumber()); | 735 EXPECT_CALL(*send_algorithm_, InSlowStart()).Times(AnyNumber()); |
736 EXPECT_CALL(*send_algorithm_, InRecovery()).Times(AnyNumber()); | 736 EXPECT_CALL(*send_algorithm_, InRecovery()).Times(AnyNumber()); |
| 737 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(AnyNumber()); |
737 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); | 738 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); |
738 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); | 739 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
739 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); | 740 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); |
740 EXPECT_CALL(visitor_, PostProcessAfterData()).Times(AnyNumber()); | 741 EXPECT_CALL(visitor_, PostProcessAfterData()).Times(AnyNumber()); |
741 EXPECT_CALL(visitor_, HasOpenDynamicStreams()) | 742 EXPECT_CALL(visitor_, HasOpenDynamicStreams()) |
742 .WillRepeatedly(Return(false)); | 743 .WillRepeatedly(Return(false)); |
743 EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber()); | 744 EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber()); |
744 | 745 |
745 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) | 746 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) |
746 .WillRepeatedly(Return(QuicTime::Zero())); | 747 .WillRepeatedly(Return(QuicTime::Zero())); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 QuicFramerPeer::SetPerspective(&peer_framer_, | 1062 QuicFramerPeer::SetPerspective(&peer_framer_, |
1062 InvertPerspective(perspective)); | 1063 InvertPerspective(perspective)); |
1063 } | 1064 } |
1064 | 1065 |
1065 QuicConnectionId connection_id_; | 1066 QuicConnectionId connection_id_; |
1066 QuicFramer framer_; | 1067 QuicFramer framer_; |
1067 MockEntropyCalculator entropy_calculator_; | 1068 MockEntropyCalculator entropy_calculator_; |
1068 MockEntropyCalculator peer_entropy_calculator_; | 1069 MockEntropyCalculator peer_entropy_calculator_; |
1069 | 1070 |
1070 MockSendAlgorithm* send_algorithm_; | 1071 MockSendAlgorithm* send_algorithm_; |
1071 MockLossAlgorithm* loss_algorithm_; | 1072 std::unique_ptr<MockLossAlgorithm> loss_algorithm_; |
1072 MockClock clock_; | 1073 MockClock clock_; |
1073 MockRandom random_generator_; | 1074 MockRandom random_generator_; |
1074 SimpleBufferAllocator buffer_allocator_; | 1075 SimpleBufferAllocator buffer_allocator_; |
1075 std::unique_ptr<TestConnectionHelper> helper_; | 1076 std::unique_ptr<TestConnectionHelper> helper_; |
1076 std::unique_ptr<TestAlarmFactory> alarm_factory_; | 1077 std::unique_ptr<TestAlarmFactory> alarm_factory_; |
1077 QuicFramer peer_framer_; | 1078 QuicFramer peer_framer_; |
1078 QuicPacketCreator peer_creator_; | 1079 QuicPacketCreator peer_creator_; |
1079 std::unique_ptr<TestPacketWriter> writer_; | 1080 std::unique_ptr<TestPacketWriter> writer_; |
1080 TestConnection connection_; | 1081 TestConnection connection_; |
1081 QuicPacketCreator* creator_; | 1082 QuicPacketCreator* creator_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); | 1149 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); |
1149 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); | 1150 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); |
1150 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AnyNumber()); | 1151 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AnyNumber()); |
1151 const IPEndPoint kNewPeerAddress = IPEndPoint(Loopback6(), | 1152 const IPEndPoint kNewPeerAddress = IPEndPoint(Loopback6(), |
1152 /*port=*/23456); | 1153 /*port=*/23456); |
1153 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, | 1154 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, |
1154 kNewPeerAddress); | 1155 kNewPeerAddress); |
1155 | 1156 |
1156 // Decrease packet number to simulate out-of-order packets. | 1157 // Decrease packet number to simulate out-of-order packets. |
1157 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); | 1158 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); |
1158 if (FLAGS_quic_do_not_migrate_on_old_packet) { | 1159 // This is an old packet, do not migrate. |
1159 // This is an old packet, do not migrate. | 1160 EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(0); |
1160 EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)).Times(0); | |
1161 } else { | |
1162 // A connection migration is observed. | |
1163 EXPECT_CALL(visitor_, OnConnectionMigration(PORT_CHANGE)); | |
1164 } | |
1165 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, | 1161 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, |
1166 kPeerAddress); | 1162 kPeerAddress); |
1167 } | 1163 } |
1168 | 1164 |
1169 TEST_P(QuicConnectionTest, MaxPacketSize) { | 1165 TEST_P(QuicConnectionTest, MaxPacketSize) { |
1170 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); | 1166 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); |
1171 EXPECT_EQ(1350u, connection_.max_packet_length()); | 1167 EXPECT_EQ(1350u, connection_.max_packet_length()); |
1172 } | 1168 } |
1173 | 1169 |
1174 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { | 1170 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 EXPECT_FALSE(ack_alarm->IsSet()); | 1938 EXPECT_FALSE(ack_alarm->IsSet()); |
1943 } | 1939 } |
1944 | 1940 |
1945 TEST_P(QuicConnectionTest, OnCanWrite) { | 1941 TEST_P(QuicConnectionTest, OnCanWrite) { |
1946 // Visitor's OnCanWrite will send data, but will have more pending writes. | 1942 // Visitor's OnCanWrite will send data, but will have more pending writes. |
1947 EXPECT_CALL(visitor_, OnCanWrite()) | 1943 EXPECT_CALL(visitor_, OnCanWrite()) |
1948 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( | 1944 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( |
1949 &connection_, &TestConnection::SendStreamData3)), | 1945 &connection_, &TestConnection::SendStreamData3)), |
1950 IgnoreResult(InvokeWithoutArgs( | 1946 IgnoreResult(InvokeWithoutArgs( |
1951 &connection_, &TestConnection::SendStreamData5)))); | 1947 &connection_, &TestConnection::SendStreamData5)))); |
1952 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillOnce(Return(true)); | 1948 { |
| 1949 InSequence seq; |
| 1950 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillOnce(Return(true)); |
| 1951 EXPECT_CALL(visitor_, WillingAndAbleToWrite()) |
| 1952 .WillRepeatedly(Return(false)); |
| 1953 } |
| 1954 |
1953 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | 1955 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
1954 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 1956 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
1955 | 1957 |
1956 connection_.OnCanWrite(); | 1958 connection_.OnCanWrite(); |
1957 | 1959 |
1958 // Parse the last packet and ensure it's the two stream frames from | 1960 // Parse the last packet and ensure it's the two stream frames from |
1959 // two different streams. | 1961 // two different streams. |
1960 EXPECT_EQ(2u, writer_->frame_count()); | 1962 EXPECT_EQ(2u, writer_->frame_count()); |
1961 EXPECT_EQ(2u, writer_->stream_frames().size()); | 1963 EXPECT_EQ(2u, writer_->stream_frames().size()); |
1962 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); | 1964 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); |
(...skipping 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4265 } | 4267 } |
4266 ProcessDataPacket(kDefaultPathId, i, entropy_flag); | 4268 ProcessDataPacket(kDefaultPathId, i, entropy_flag); |
4267 } | 4269 } |
4268 for (int i = 1; i < 50; ++i) { | 4270 for (int i = 1; i < 50; ++i) { |
4269 EXPECT_EQ(entropy[i], | 4271 EXPECT_EQ(entropy[i], |
4270 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); | 4272 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); |
4271 } | 4273 } |
4272 } | 4274 } |
4273 | 4275 |
4274 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { | 4276 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { |
4275 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4277 connection_.SetSupportedVersions(AllSupportedVersions()); |
4276 set_perspective(Perspective::IS_SERVER); | 4278 set_perspective(Perspective::IS_SERVER); |
4277 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4279 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4278 | 4280 |
4279 QuicPacketHeader header; | 4281 QuicPacketHeader header; |
4280 header.public_header.connection_id = connection_id_; | 4282 header.public_header.connection_id = connection_id_; |
4281 header.public_header.version_flag = true; | 4283 header.public_header.version_flag = true; |
4282 header.path_id = kDefaultPathId; | 4284 header.path_id = kDefaultPathId; |
4283 header.packet_number = 12; | 4285 header.packet_number = 12; |
4284 | 4286 |
4285 QuicFrames frames; | 4287 QuicFrames frames; |
(...skipping 15 matching lines...) Expand all Loading... |
4301 | 4303 |
4302 // We expect all versions in kSupportedQuicVersions to be | 4304 // We expect all versions in kSupportedQuicVersions to be |
4303 // included in the packet. | 4305 // included in the packet. |
4304 for (size_t i = 0; i < num_versions; ++i) { | 4306 for (size_t i = 0; i < num_versions; ++i) { |
4305 EXPECT_EQ(kSupportedQuicVersions[i], | 4307 EXPECT_EQ(kSupportedQuicVersions[i], |
4306 writer_->version_negotiation_packet()->versions[i]); | 4308 writer_->version_negotiation_packet()->versions[i]); |
4307 } | 4309 } |
4308 } | 4310 } |
4309 | 4311 |
4310 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { | 4312 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { |
4311 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4313 connection_.SetSupportedVersions(AllSupportedVersions()); |
4312 set_perspective(Perspective::IS_SERVER); | 4314 set_perspective(Perspective::IS_SERVER); |
4313 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4315 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4314 | 4316 |
4315 QuicPacketHeader header; | 4317 QuicPacketHeader header; |
4316 header.public_header.connection_id = connection_id_; | 4318 header.public_header.connection_id = connection_id_; |
4317 header.public_header.version_flag = true; | 4319 header.public_header.version_flag = true; |
4318 header.packet_number = 12; | 4320 header.packet_number = 12; |
4319 | 4321 |
4320 QuicFrames frames; | 4322 QuicFrames frames; |
4321 frames.push_back(QuicFrame(&frame1_)); | 4323 frames.push_back(QuicFrame(&frame1_)); |
(...skipping 21 matching lines...) Expand all Loading... |
4343 // We expect all versions in kSupportedQuicVersions to be | 4345 // We expect all versions in kSupportedQuicVersions to be |
4344 // included in the packet. | 4346 // included in the packet. |
4345 for (size_t i = 0; i < num_versions; ++i) { | 4347 for (size_t i = 0; i < num_versions; ++i) { |
4346 EXPECT_EQ(kSupportedQuicVersions[i], | 4348 EXPECT_EQ(kSupportedQuicVersions[i], |
4347 writer_->version_negotiation_packet()->versions[i]); | 4349 writer_->version_negotiation_packet()->versions[i]); |
4348 } | 4350 } |
4349 } | 4351 } |
4350 | 4352 |
4351 TEST_P(QuicConnectionTest, | 4353 TEST_P(QuicConnectionTest, |
4352 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { | 4354 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { |
4353 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4355 connection_.SetSupportedVersions(AllSupportedVersions()); |
4354 set_perspective(Perspective::IS_SERVER); | 4356 set_perspective(Perspective::IS_SERVER); |
4355 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4357 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4356 | 4358 |
4357 QuicPacketHeader header; | 4359 QuicPacketHeader header; |
4358 header.public_header.connection_id = connection_id_; | 4360 header.public_header.connection_id = connection_id_; |
4359 header.public_header.version_flag = true; | 4361 header.public_header.version_flag = true; |
4360 header.packet_number = 12; | 4362 header.packet_number = 12; |
4361 | 4363 |
4362 QuicFrames frames; | 4364 QuicFrames frames; |
4363 frames.push_back(QuicFrame(&frame1_)); | 4365 frames.push_back(QuicFrame(&frame1_)); |
(...skipping 14 matching lines...) Expand all Loading... |
4378 } | 4380 } |
4379 | 4381 |
4380 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4382 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
4381 // Start out with some unsupported version. | 4383 // Start out with some unsupported version. |
4382 QuicConnectionPeer::GetFramer(&connection_) | 4384 QuicConnectionPeer::GetFramer(&connection_) |
4383 ->set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4385 ->set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4384 | 4386 |
4385 // Send a version negotiation packet. | 4387 // Send a version negotiation packet. |
4386 std::unique_ptr<QuicEncryptedPacket> encrypted( | 4388 std::unique_ptr<QuicEncryptedPacket> encrypted( |
4387 framer_.BuildVersionNegotiationPacket(connection_id_, | 4389 framer_.BuildVersionNegotiationPacket(connection_id_, |
4388 QuicSupportedVersions())); | 4390 AllSupportedVersions())); |
4389 std::unique_ptr<QuicReceivedPacket> received( | 4391 std::unique_ptr<QuicReceivedPacket> received( |
4390 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); | 4392 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); |
4391 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); | 4393 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); |
4392 | 4394 |
4393 // Now force another packet. The connection should transition into | 4395 // Now force another packet. The connection should transition into |
4394 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4396 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
4395 QuicPacketHeader header; | 4397 QuicPacketHeader header; |
4396 header.public_header.connection_id = connection_id_; | 4398 header.public_header.connection_id = connection_id_; |
4397 header.path_id = kDefaultPathId; | 4399 header.path_id = kDefaultPathId; |
4398 header.packet_number = 12; | 4400 header.packet_number = 12; |
(...skipping 15 matching lines...) Expand all Loading... |
4414 } | 4416 } |
4415 | 4417 |
4416 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4418 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
4417 // Send a version negotiation packet with the version the client started with. | 4419 // Send a version negotiation packet with the version the client started with. |
4418 // It should be rejected. | 4420 // It should be rejected. |
4419 EXPECT_CALL(visitor_, | 4421 EXPECT_CALL(visitor_, |
4420 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, _, | 4422 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, _, |
4421 ConnectionCloseSource::FROM_SELF)); | 4423 ConnectionCloseSource::FROM_SELF)); |
4422 std::unique_ptr<QuicEncryptedPacket> encrypted( | 4424 std::unique_ptr<QuicEncryptedPacket> encrypted( |
4423 framer_.BuildVersionNegotiationPacket(connection_id_, | 4425 framer_.BuildVersionNegotiationPacket(connection_id_, |
4424 QuicSupportedVersions())); | 4426 AllSupportedVersions())); |
4425 std::unique_ptr<QuicReceivedPacket> received( | 4427 std::unique_ptr<QuicReceivedPacket> received( |
4426 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); | 4428 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); |
4427 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); | 4429 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); |
4428 } | 4430 } |
4429 | 4431 |
4430 TEST_P(QuicConnectionTest, CheckSendStats) { | 4432 TEST_P(QuicConnectionTest, CheckSendStats) { |
4431 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); | 4433 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); |
4432 | 4434 |
4433 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4435 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4434 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4436 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4497 ConnectionCloseSource::FROM_PEER)); | 4499 ConnectionCloseSource::FROM_PEER)); |
4498 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4500 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4499 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4501 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4500 | 4502 |
4501 connection_.ProcessUdpPacket( | 4503 connection_.ProcessUdpPacket( |
4502 kSelfAddress, kPeerAddress, | 4504 kSelfAddress, kPeerAddress, |
4503 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); | 4505 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); |
4504 } | 4506 } |
4505 | 4507 |
4506 TEST_P(QuicConnectionTest, SelectMutualVersion) { | 4508 TEST_P(QuicConnectionTest, SelectMutualVersion) { |
4507 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4509 connection_.SetSupportedVersions(AllSupportedVersions()); |
4508 // Set the connection to speak the lowest quic version. | 4510 // Set the connection to speak the lowest quic version. |
4509 connection_.set_version(QuicVersionMin()); | 4511 connection_.set_version(QuicVersionMin()); |
4510 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 4512 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
4511 | 4513 |
4512 // Pass in available versions which includes a higher mutually supported | 4514 // Pass in available versions which includes a higher mutually supported |
4513 // version. The higher mutually supported version should be selected. | 4515 // version. The higher mutually supported version should be selected. |
4514 QuicVersionVector supported_versions; | 4516 QuicVersionVector supported_versions; |
4515 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 4517 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
4516 supported_versions.push_back(kSupportedQuicVersions[i]); | 4518 supported_versions.push_back(kSupportedQuicVersions[i]); |
4517 } | 4519 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4983 // close packet. | 4985 // close packet. |
4984 FLAGS_quic_close_connection_on_packet_too_large = true; | 4986 FLAGS_quic_close_connection_on_packet_too_large = true; |
4985 AlwaysGetPacketTooLarge(); | 4987 AlwaysGetPacketTooLarge(); |
4986 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 4988 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
4987 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, | 4989 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, |
4988 ConnectionCloseSource::FROM_SELF)) | 4990 ConnectionCloseSource::FROM_SELF)) |
4989 .Times(1); | 4991 .Times(1); |
4990 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 4992 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
4991 } | 4993 } |
4992 | 4994 |
| 4995 // Verify that if connection has no outstanding data, it notifies the send |
| 4996 // algorithm after the write. |
| 4997 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) { |
| 4998 FLAGS_quic_enable_app_limited_check = true; |
| 4999 |
| 5000 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1); |
| 5001 { |
| 5002 InSequence seq; |
| 5003 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); |
| 5004 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 5005 .WillOnce(Return(true)); |
| 5006 EXPECT_CALL(visitor_, WillingAndAbleToWrite()) |
| 5007 .WillRepeatedly(Return(false)); |
| 5008 } |
| 5009 |
| 5010 connection_.SendStreamData3(); |
| 5011 } |
| 5012 |
| 5013 // Verify that the connection does not become app-limited if there is |
| 5014 // outstanding data to send after the write. |
| 5015 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedIfMoreDataAvailable) { |
| 5016 FLAGS_quic_enable_app_limited_check = true; |
| 5017 |
| 5018 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); |
| 5019 { |
| 5020 InSequence seq; |
| 5021 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 5022 .WillOnce(Return(true)); |
| 5023 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); |
| 5024 } |
| 5025 |
| 5026 connection_.SendStreamData3(); |
| 5027 } |
| 5028 |
| 5029 // Verify that the connection does not become app-limited after blocked write |
| 5030 // even if there is outstanding data to send after the write. |
| 5031 TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedDueToWriteBlock) { |
| 5032 FLAGS_quic_enable_app_limited_check = true; |
| 5033 |
| 5034 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); |
| 5035 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); |
| 5036 BlockOnNextWrite(); |
| 5037 |
| 5038 connection_.SendStreamData3(); |
| 5039 } |
| 5040 |
4993 } // namespace | 5041 } // namespace |
4994 } // namespace test | 5042 } // namespace test |
4995 } // namespace net | 5043 } // namespace net |
OLD | NEW |