| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 324 } |
| 325 | 325 |
| 326 const QuicVersionNegotiationPacket* version_negotiation_packet() { | 326 const QuicVersionNegotiationPacket* version_negotiation_packet() { |
| 327 return framer_.version_negotiation_packet(); | 327 return framer_.version_negotiation_packet(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void set_is_write_blocked_data_buffered(bool buffered) { | 330 void set_is_write_blocked_data_buffered(bool buffered) { |
| 331 is_write_blocked_data_buffered_ = buffered; | 331 is_write_blocked_data_buffered_ = buffered; |
| 332 } | 332 } |
| 333 | 333 |
| 334 void set_is_server(bool is_server) { | 334 void set_perspective(Perspective perspective) { |
| 335 // We invert is_server here, because the framer needs to parse packets | 335 // We invert perspective here, because the framer needs to parse packets |
| 336 // we send. | 336 // we send. |
| 337 QuicFramerPeer::SetIsServer(framer_.framer(), !is_server); | 337 perspective = perspective == Perspective::IS_CLIENT |
| 338 ? Perspective::IS_SERVER |
| 339 : Perspective::IS_CLIENT; |
| 340 QuicFramerPeer::SetPerspective(framer_.framer(), perspective); |
| 338 } | 341 } |
| 339 | 342 |
| 340 // 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 |
| 341 // 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 |
| 342 // TaggingEncrypter so that tests can determine which encrypter was used for | 345 // TaggingEncrypter so that tests can determine which encrypter was used for |
| 343 // a given packet. | 346 // a given packet. |
| 344 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_; } |
| 345 | 348 |
| 346 // Returns the final bytes of the second to last packet. | 349 // Returns the final bytes of the second to last packet. |
| 347 uint32 final_bytes_of_previous_packet() { | 350 uint32 final_bytes_of_previous_packet() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 378 | 381 |
| 379 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 382 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
| 380 }; | 383 }; |
| 381 | 384 |
| 382 class TestConnection : public QuicConnection { | 385 class TestConnection : public QuicConnection { |
| 383 public: | 386 public: |
| 384 TestConnection(QuicConnectionId connection_id, | 387 TestConnection(QuicConnectionId connection_id, |
| 385 IPEndPoint address, | 388 IPEndPoint address, |
| 386 TestConnectionHelper* helper, | 389 TestConnectionHelper* helper, |
| 387 const PacketWriterFactory& factory, | 390 const PacketWriterFactory& factory, |
| 388 bool is_server, | 391 Perspective perspective, |
| 389 QuicVersion version) | 392 QuicVersion version) |
| 390 : QuicConnection(connection_id, | 393 : QuicConnection(connection_id, |
| 391 address, | 394 address, |
| 392 helper, | 395 helper, |
| 393 factory, | 396 factory, |
| 394 /* owns_writer= */ false, | 397 /* owns_writer= */ false, |
| 395 is_server, | 398 perspective, |
| 396 /* is_secure= */ false, | 399 /* is_secure= */ false, |
| 397 SupportedVersions(version)) { | 400 SupportedVersions(version)) { |
| 398 // Disable tail loss probes for most tests. | 401 // Disable tail loss probes for most tests. |
| 399 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 402 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 400 QuicConnectionPeer::GetSentPacketManager(this), 0); | 403 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 401 writer()->set_is_server(is_server); | 404 writer()->set_perspective(perspective); |
| 402 } | 405 } |
| 403 | 406 |
| 404 void SendAck() { | 407 void SendAck() { |
| 405 QuicConnectionPeer::SendAck(this); | 408 QuicConnectionPeer::SendAck(this); |
| 406 } | 409 } |
| 407 | 410 |
| 408 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 411 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 409 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 412 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 410 } | 413 } |
| 411 | 414 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 497 |
| 495 // The crypto stream has special semantics so that it is not blocked by a | 498 // The crypto stream has special semantics so that it is not blocked by a |
| 496 // congestion window limitation, and also so that it gets put into a separate | 499 // congestion window limitation, and also so that it gets put into a separate |
| 497 // packet (so that it is easier to reason about a crypto frame not being | 500 // packet (so that it is easier to reason about a crypto frame not being |
| 498 // split needlessly across packet boundaries). As a result, we have separate | 501 // split needlessly across packet boundaries). As a result, we have separate |
| 499 // tests for some cases for this stream. | 502 // tests for some cases for this stream. |
| 500 QuicConsumedData SendCryptoStreamData() { | 503 QuicConsumedData SendCryptoStreamData() { |
| 501 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, nullptr); | 504 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, nullptr); |
| 502 } | 505 } |
| 503 | 506 |
| 504 bool is_server() { | |
| 505 return QuicConnectionPeer::IsServer(this); | |
| 506 } | |
| 507 | |
| 508 void set_version(QuicVersion version) { | 507 void set_version(QuicVersion version) { |
| 509 QuicConnectionPeer::GetFramer(this)->set_version(version); | 508 QuicConnectionPeer::GetFramer(this)->set_version(version); |
| 510 } | 509 } |
| 511 | 510 |
| 512 void SetSupportedVersions(const QuicVersionVector& versions) { | 511 void SetSupportedVersions(const QuicVersionVector& versions) { |
| 513 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); | 512 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); |
| 514 writer()->SetSupportedVersions(versions); | 513 writer()->SetSupportedVersions(versions); |
| 515 } | 514 } |
| 516 | 515 |
| 517 void set_is_server(bool is_server) { | 516 void set_perspective(Perspective perspective) { |
| 518 writer()->set_is_server(is_server); | 517 writer()->set_perspective(perspective); |
| 519 QuicConnectionPeer::SetIsServer(this, is_server); | 518 QuicConnectionPeer::SetPerspective(this, perspective); |
| 520 } | 519 } |
| 521 | 520 |
| 522 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 521 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
| 523 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 522 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 524 QuicConnectionPeer::GetAckAlarm(this)); | 523 QuicConnectionPeer::GetAckAlarm(this)); |
| 525 } | 524 } |
| 526 | 525 |
| 527 TestConnectionHelper::TestAlarm* GetPingAlarm() { | 526 TestConnectionHelper::TestAlarm* GetPingAlarm() { |
| 528 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 527 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 529 QuicConnectionPeer::GetPingAlarm(this)); | 528 QuicConnectionPeer::GetPingAlarm(this)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 588 } |
| 590 ~MockPacketWriterFactory() override {} | 589 ~MockPacketWriterFactory() override {} |
| 591 | 590 |
| 592 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); | 591 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); |
| 593 }; | 592 }; |
| 594 | 593 |
| 595 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 594 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
| 596 protected: | 595 protected: |
| 597 QuicConnectionTest() | 596 QuicConnectionTest() |
| 598 : connection_id_(42), | 597 : connection_id_(42), |
| 599 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 598 framer_(SupportedVersions(version()), |
| 599 QuicTime::Zero(), |
| 600 Perspective::IS_CLIENT), |
| 600 peer_creator_(connection_id_, &framer_, &random_generator_), | 601 peer_creator_(connection_id_, &framer_, &random_generator_), |
| 601 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 602 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 602 loss_algorithm_(new MockLossAlgorithm()), | 603 loss_algorithm_(new MockLossAlgorithm()), |
| 603 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 604 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 604 writer_(new TestPacketWriter(version(), &clock_)), | 605 writer_(new TestPacketWriter(version(), &clock_)), |
| 605 factory_(writer_.get()), | 606 factory_(writer_.get()), |
| 606 connection_(connection_id_, | 607 connection_(connection_id_, |
| 607 IPEndPoint(), | 608 IPEndPoint(), |
| 608 helper_.get(), | 609 helper_.get(), |
| 609 factory_, | 610 factory_, |
| 610 false, | 611 Perspective::IS_CLIENT, |
| 611 version()), | 612 version()), |
| 612 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), | 613 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), |
| 613 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), | 614 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), |
| 614 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), | 615 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), |
| 615 frame1_(1, false, 0, MakeIOVector(data1)), | 616 frame1_(1, false, 0, MakeIOVector(data1)), |
| 616 frame2_(1, false, 3, MakeIOVector(data2)), | 617 frame2_(1, false, 3, MakeIOVector(data2)), |
| 617 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 618 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
| 618 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 619 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
| 619 connection_.set_visitor(&visitor_); | 620 connection_.set_visitor(&visitor_); |
| 620 connection_.SetSendAlgorithm(send_algorithm_); | 621 connection_.SetSendAlgorithm(send_algorithm_); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 677 } |
| 677 | 678 |
| 678 void ProcessPacket(QuicPacketSequenceNumber number) { | 679 void ProcessPacket(QuicPacketSequenceNumber number) { |
| 679 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 680 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 680 ProcessDataPacket(number, 0, !kEntropyFlag); | 681 ProcessDataPacket(number, 0, !kEntropyFlag); |
| 681 } | 682 } |
| 682 | 683 |
| 683 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { | 684 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { |
| 684 QuicFrames frames; | 685 QuicFrames frames; |
| 685 frames.push_back(QuicFrame(frame)); | 686 frames.push_back(QuicFrame(frame)); |
| 686 QuicPacketCreatorPeer::SetSendVersionInPacket(&peer_creator_, | 687 QuicPacketCreatorPeer::SetSendVersionInPacket( |
| 687 connection_.is_server()); | 688 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); |
| 689 |
| 688 SerializedPacket serialized_packet = | 690 SerializedPacket serialized_packet = |
| 689 peer_creator_.SerializeAllFrames(frames); | 691 peer_creator_.SerializeAllFrames(frames); |
| 690 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet); | 692 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet); |
| 691 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 693 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 692 return serialized_packet.entropy_hash; | 694 return serialized_packet.entropy_hash; |
| 693 } | 695 } |
| 694 | 696 |
| 695 size_t ProcessDataPacket(QuicPacketSequenceNumber number, | 697 size_t ProcessDataPacket(QuicPacketSequenceNumber number, |
| 696 QuicFecGroupNumber fec_group, | 698 QuicFecGroupNumber fec_group, |
| 697 bool entropy_flag) { | 699 bool entropy_flag) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 private: | 974 private: |
| 973 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 975 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 974 }; | 976 }; |
| 975 | 977 |
| 976 // Run all end to end tests with all supported versions. | 978 // Run all end to end tests with all supported versions. |
| 977 INSTANTIATE_TEST_CASE_P(SupportedVersion, | 979 INSTANTIATE_TEST_CASE_P(SupportedVersion, |
| 978 QuicConnectionTest, | 980 QuicConnectionTest, |
| 979 ::testing::ValuesIn(QuicSupportedVersions())); | 981 ::testing::ValuesIn(QuicSupportedVersions())); |
| 980 | 982 |
| 981 TEST_P(QuicConnectionTest, MaxPacketSize) { | 983 TEST_P(QuicConnectionTest, MaxPacketSize) { |
| 982 EXPECT_FALSE(connection_.is_server()); | 984 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); |
| 983 EXPECT_EQ(1350u, connection_.max_packet_length()); | 985 EXPECT_EQ(1350u, connection_.max_packet_length()); |
| 984 } | 986 } |
| 985 | 987 |
| 986 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { | 988 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { |
| 987 ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, true); | 989 ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, true); |
| 988 QuicConnectionId connection_id = 42; | 990 QuicConnectionId connection_id = 42; |
| 989 bool kIsServer = true; | |
| 990 TestConnection connection(connection_id, IPEndPoint(), helper_.get(), | 991 TestConnection connection(connection_id, IPEndPoint(), helper_.get(), |
| 991 factory_, kIsServer, version()); | 992 factory_, Perspective::IS_SERVER, version()); |
| 992 EXPECT_TRUE(connection.is_server()); | 993 EXPECT_EQ(Perspective::IS_SERVER, connection.perspective()); |
| 993 EXPECT_EQ(1000u, connection.max_packet_length()); | 994 EXPECT_EQ(1000u, connection.max_packet_length()); |
| 994 } | 995 } |
| 995 | 996 |
| 996 TEST_P(QuicConnectionTest, ServerMaxPacketSize) { | 997 TEST_P(QuicConnectionTest, ServerMaxPacketSize) { |
| 997 ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, false); | 998 ValueRestore<bool> old_flag(&FLAGS_quic_small_default_packet_size, false); |
| 998 QuicConnectionId connection_id = 42; | 999 QuicConnectionId connection_id = 42; |
| 999 bool kIsServer = true; | |
| 1000 TestConnection connection(connection_id, IPEndPoint(), helper_.get(), | 1000 TestConnection connection(connection_id, IPEndPoint(), helper_.get(), |
| 1001 factory_, kIsServer, version()); | 1001 factory_, Perspective::IS_SERVER, version()); |
| 1002 EXPECT_TRUE(connection.is_server()); | 1002 EXPECT_EQ(Perspective::IS_SERVER, connection.perspective()); |
| 1003 EXPECT_EQ(1350u, connection.max_packet_length()); | 1003 EXPECT_EQ(1350u, connection.max_packet_length()); |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { | 1006 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { |
| 1007 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1007 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1008 | 1008 |
| 1009 connection_.set_is_server(true); | 1009 connection_.set_perspective(Perspective::IS_SERVER); |
| 1010 connection_.set_max_packet_length(1000); | 1010 connection_.set_max_packet_length(1000); |
| 1011 | 1011 |
| 1012 QuicPacketHeader header; | 1012 QuicPacketHeader header; |
| 1013 header.public_header.connection_id = connection_id_; | 1013 header.public_header.connection_id = connection_id_; |
| 1014 header.public_header.reset_flag = false; | 1014 header.public_header.reset_flag = false; |
| 1015 header.public_header.version_flag = true; | 1015 header.public_header.version_flag = true; |
| 1016 header.entropy_flag = false; | 1016 header.entropy_flag = false; |
| 1017 header.fec_flag = false; | 1017 header.fec_flag = false; |
| 1018 header.packet_sequence_number = 1; | 1018 header.packet_sequence_number = 1; |
| 1019 header.fec_group = 0; | 1019 header.fec_group = 0; |
| (...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3292 | 3292 |
| 3293 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { | 3293 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { |
| 3294 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3294 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3295 ProcessPacket(1); | 3295 ProcessPacket(1); |
| 3296 // Check that ack is sent and that delayed ack alarm is set. | 3296 // Check that ack is sent and that delayed ack alarm is set. |
| 3297 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3297 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 3298 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); | 3298 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); |
| 3299 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3299 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 3300 | 3300 |
| 3301 // Completing the handshake as the server does nothing. | 3301 // Completing the handshake as the server does nothing. |
| 3302 QuicConnectionPeer::SetIsServer(&connection_, true); | 3302 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_SERVER); |
| 3303 connection_.OnHandshakeComplete(); | 3303 connection_.OnHandshakeComplete(); |
| 3304 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3304 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 3305 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3305 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 3306 | 3306 |
| 3307 // Complete the handshake as the client decreases the delayed ack time to 0ms. | 3307 // Complete the handshake as the client decreases the delayed ack time to 0ms. |
| 3308 QuicConnectionPeer::SetIsServer(&connection_, false); | 3308 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_CLIENT); |
| 3309 connection_.OnHandshakeComplete(); | 3309 connection_.OnHandshakeComplete(); |
| 3310 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3310 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 3311 EXPECT_EQ(clock_.ApproximateNow(), connection_.GetAckAlarm()->deadline()); | 3311 EXPECT_EQ(clock_.ApproximateNow(), connection_.GetAckAlarm()->deadline()); |
| 3312 } | 3312 } |
| 3313 | 3313 |
| 3314 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { | 3314 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { |
| 3315 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3315 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3316 ProcessPacket(1); | 3316 ProcessPacket(1); |
| 3317 ProcessPacket(2); | 3317 ProcessPacket(2); |
| 3318 // Check that ack is sent and that delayed ack alarm is reset. | 3318 // Check that ack is sent and that delayed ack alarm is reset. |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3639 | 3639 |
| 3640 QuicFrames frames; | 3640 QuicFrames frames; |
| 3641 QuicFrame frame(&frame1_); | 3641 QuicFrame frame(&frame1_); |
| 3642 frames.push_back(frame); | 3642 frames.push_back(frame); |
| 3643 scoped_ptr<QuicPacket> packet( | 3643 scoped_ptr<QuicPacket> packet( |
| 3644 BuildUnsizedDataPacket(&framer_, header, frames)); | 3644 BuildUnsizedDataPacket(&framer_, header, frames)); |
| 3645 scoped_ptr<QuicEncryptedPacket> encrypted( | 3645 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3646 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3646 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3647 | 3647 |
| 3648 framer_.set_version(version()); | 3648 framer_.set_version(version()); |
| 3649 connection_.set_is_server(true); | 3649 connection_.set_perspective(Perspective::IS_SERVER); |
| 3650 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3650 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3651 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 3651 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
| 3652 | 3652 |
| 3653 size_t num_versions = arraysize(kSupportedQuicVersions); | 3653 size_t num_versions = arraysize(kSupportedQuicVersions); |
| 3654 ASSERT_EQ(num_versions, | 3654 ASSERT_EQ(num_versions, |
| 3655 writer_->version_negotiation_packet()->versions.size()); | 3655 writer_->version_negotiation_packet()->versions.size()); |
| 3656 | 3656 |
| 3657 // We expect all versions in kSupportedQuicVersions to be | 3657 // We expect all versions in kSupportedQuicVersions to be |
| 3658 // included in the packet. | 3658 // included in the packet. |
| 3659 for (size_t i = 0; i < num_versions; ++i) { | 3659 for (size_t i = 0; i < num_versions; ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3677 | 3677 |
| 3678 QuicFrames frames; | 3678 QuicFrames frames; |
| 3679 QuicFrame frame(&frame1_); | 3679 QuicFrame frame(&frame1_); |
| 3680 frames.push_back(frame); | 3680 frames.push_back(frame); |
| 3681 scoped_ptr<QuicPacket> packet( | 3681 scoped_ptr<QuicPacket> packet( |
| 3682 BuildUnsizedDataPacket(&framer_, header, frames)); | 3682 BuildUnsizedDataPacket(&framer_, header, frames)); |
| 3683 scoped_ptr<QuicEncryptedPacket> encrypted( | 3683 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3684 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3684 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3685 | 3685 |
| 3686 framer_.set_version(version()); | 3686 framer_.set_version(version()); |
| 3687 connection_.set_is_server(true); | 3687 connection_.set_perspective(Perspective::IS_SERVER); |
| 3688 BlockOnNextWrite(); | 3688 BlockOnNextWrite(); |
| 3689 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3689 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3690 EXPECT_EQ(0u, writer_->last_packet_size()); | 3690 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 3691 EXPECT_TRUE(connection_.HasQueuedData()); | 3691 EXPECT_TRUE(connection_.HasQueuedData()); |
| 3692 | 3692 |
| 3693 writer_->SetWritable(); | 3693 writer_->SetWritable(); |
| 3694 connection_.OnCanWrite(); | 3694 connection_.OnCanWrite(); |
| 3695 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 3695 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
| 3696 | 3696 |
| 3697 size_t num_versions = arraysize(kSupportedQuicVersions); | 3697 size_t num_versions = arraysize(kSupportedQuicVersions); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3722 | 3722 |
| 3723 QuicFrames frames; | 3723 QuicFrames frames; |
| 3724 QuicFrame frame(&frame1_); | 3724 QuicFrame frame(&frame1_); |
| 3725 frames.push_back(frame); | 3725 frames.push_back(frame); |
| 3726 scoped_ptr<QuicPacket> packet( | 3726 scoped_ptr<QuicPacket> packet( |
| 3727 BuildUnsizedDataPacket(&framer_, header, frames)); | 3727 BuildUnsizedDataPacket(&framer_, header, frames)); |
| 3728 scoped_ptr<QuicEncryptedPacket> encrypted( | 3728 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3729 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3729 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3730 | 3730 |
| 3731 framer_.set_version(version()); | 3731 framer_.set_version(version()); |
| 3732 connection_.set_is_server(true); | 3732 connection_.set_perspective(Perspective::IS_SERVER); |
| 3733 BlockOnNextWrite(); | 3733 BlockOnNextWrite(); |
| 3734 writer_->set_is_write_blocked_data_buffered(true); | 3734 writer_->set_is_write_blocked_data_buffered(true); |
| 3735 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3735 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3736 EXPECT_EQ(0u, writer_->last_packet_size()); | 3736 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 3737 EXPECT_FALSE(connection_.HasQueuedData()); | 3737 EXPECT_FALSE(connection_.HasQueuedData()); |
| 3738 } | 3738 } |
| 3739 | 3739 |
| 3740 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 3740 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 3741 // Start out with some unsupported version. | 3741 // Start out with some unsupported version. |
| 3742 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 3742 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4308 QuicPacketHeader header; | 4308 QuicPacketHeader header; |
| 4309 | 4309 |
| 4310 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 4310 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
| 4311 new MockQuicConnectionDebugVisitor()); | 4311 new MockQuicConnectionDebugVisitor()); |
| 4312 connection_.set_debug_visitor(debug_visitor.get()); | 4312 connection_.set_debug_visitor(debug_visitor.get()); |
| 4313 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 4313 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 4314 connection_.OnPacketHeader(header); | 4314 connection_.OnPacketHeader(header); |
| 4315 } | 4315 } |
| 4316 | 4316 |
| 4317 TEST_P(QuicConnectionTest, Pacing) { | 4317 TEST_P(QuicConnectionTest, Pacing) { |
| 4318 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 4318 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), factory_, |
| 4319 factory_, /* is_server= */ true, version()); | 4319 Perspective::IS_SERVER, version()); |
| 4320 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 4320 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), factory_, |
| 4321 factory_, /* is_server= */ false, version()); | 4321 Perspective::IS_CLIENT, version()); |
| 4322 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 4322 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
| 4323 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 4323 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 4324 } | 4324 } |
| 4325 | 4325 |
| 4326 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { | 4326 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
| 4327 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4327 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4328 | 4328 |
| 4329 // Send a WINDOW_UPDATE frame. | 4329 // Send a WINDOW_UPDATE frame. |
| 4330 QuicWindowUpdateFrame window_update; | 4330 QuicWindowUpdateFrame window_update; |
| 4331 window_update.stream_id = 3; | 4331 window_update.stream_id = 3; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4352 // Regression test for b/18594622 | 4352 // Regression test for b/18594622 |
| 4353 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4353 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 4354 EXPECT_DFATAL( | 4354 EXPECT_DFATAL( |
| 4355 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4355 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
| 4356 "Attempt to send empty stream frame"); | 4356 "Attempt to send empty stream frame"); |
| 4357 } | 4357 } |
| 4358 | 4358 |
| 4359 } // namespace | 4359 } // namespace |
| 4360 } // namespace test | 4360 } // namespace test |
| 4361 } // namespace net | 4361 } // namespace net |
| OLD | NEW |