| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using base::StringPiece; | 31 using base::StringPiece; |
| 32 using std::map; | 32 using std::map; |
| 33 using std::vector; | 33 using std::vector; |
| 34 using testing::AnyNumber; | 34 using testing::AnyNumber; |
| 35 using testing::AtLeast; | 35 using testing::AtLeast; |
| 36 using testing::ContainerEq; | 36 using testing::ContainerEq; |
| 37 using testing::Contains; | 37 using testing::Contains; |
| 38 using testing::DoAll; | 38 using testing::DoAll; |
| 39 using testing::InSequence; | 39 using testing::InSequence; |
| 40 using testing::InvokeWithoutArgs; | 40 using testing::InvokeWithoutArgs; |
| 41 using testing::NiceMock; |
| 41 using testing::Ref; | 42 using testing::Ref; |
| 42 using testing::Return; | 43 using testing::Return; |
| 43 using testing::SaveArg; | 44 using testing::SaveArg; |
| 44 using testing::StrictMock; | 45 using testing::StrictMock; |
| 45 using testing::_; | 46 using testing::_; |
| 46 | 47 |
| 47 namespace net { | 48 namespace net { |
| 48 namespace test { | 49 namespace test { |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 uint32 packets_write_attempts_; | 406 uint32 packets_write_attempts_; |
| 406 | 407 |
| 407 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 408 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
| 408 }; | 409 }; |
| 409 | 410 |
| 410 class TestConnection : public QuicConnection { | 411 class TestConnection : public QuicConnection { |
| 411 public: | 412 public: |
| 412 TestConnection(QuicConnectionId connection_id, | 413 TestConnection(QuicConnectionId connection_id, |
| 413 IPEndPoint address, | 414 IPEndPoint address, |
| 414 TestConnectionHelper* helper, | 415 TestConnectionHelper* helper, |
| 415 TestPacketWriter* writer, | 416 const PacketWriterFactory& factory, |
| 416 bool is_server, | 417 bool is_server, |
| 417 QuicVersion version) | 418 QuicVersion version) |
| 418 : QuicConnection(connection_id, | 419 : QuicConnection(connection_id, |
| 419 address, | 420 address, |
| 420 helper, | 421 helper, |
| 421 writer, | 422 factory, |
| 422 false /* owns_writer */, | 423 /* owns_writer= */ false, |
| 423 is_server, | 424 is_server, |
| 424 SupportedVersions(version)), | 425 SupportedVersions(version)) { |
| 425 writer_(writer) { | |
| 426 // Disable tail loss probes for most tests. | 426 // Disable tail loss probes for most tests. |
| 427 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 427 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 428 QuicConnectionPeer::GetSentPacketManager(this), 0); | 428 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 429 writer_->set_is_server(is_server); | 429 writer()->set_is_server(is_server); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void SendAck() { | 432 void SendAck() { |
| 433 QuicConnectionPeer::SendAck(this); | 433 QuicConnectionPeer::SendAck(this); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { | 436 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { |
| 437 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); | 437 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); |
| 438 } | 438 } |
| 439 | 439 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 bool is_server() { | 531 bool is_server() { |
| 532 return QuicConnectionPeer::IsServer(this); | 532 return QuicConnectionPeer::IsServer(this); |
| 533 } | 533 } |
| 534 | 534 |
| 535 void set_version(QuicVersion version) { | 535 void set_version(QuicVersion version) { |
| 536 QuicConnectionPeer::GetFramer(this)->set_version(version); | 536 QuicConnectionPeer::GetFramer(this)->set_version(version); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void SetSupportedVersions(const QuicVersionVector& versions) { | 539 void SetSupportedVersions(const QuicVersionVector& versions) { |
| 540 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); | 540 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); |
| 541 writer_->SetSupportedVersions(versions); | 541 writer()->SetSupportedVersions(versions); |
| 542 } | 542 } |
| 543 | 543 |
| 544 void set_is_server(bool is_server) { | 544 void set_is_server(bool is_server) { |
| 545 writer_->set_is_server(is_server); | 545 writer()->set_is_server(is_server); |
| 546 QuicConnectionPeer::SetIsServer(this, is_server); | 546 QuicConnectionPeer::SetIsServer(this, is_server); |
| 547 } | 547 } |
| 548 | 548 |
| 549 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 549 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
| 550 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 550 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 551 QuicConnectionPeer::GetAckAlarm(this)); | 551 QuicConnectionPeer::GetAckAlarm(this)); |
| 552 } | 552 } |
| 553 | 553 |
| 554 TestConnectionHelper::TestAlarm* GetPingAlarm() { | 554 TestConnectionHelper::TestAlarm* GetPingAlarm() { |
| 555 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 555 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 572 } | 572 } |
| 573 | 573 |
| 574 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { | 574 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { |
| 575 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 575 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 576 QuicConnectionPeer::GetTimeoutAlarm(this)); | 576 QuicConnectionPeer::GetTimeoutAlarm(this)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 using QuicConnection::SelectMutualVersion; | 579 using QuicConnection::SelectMutualVersion; |
| 580 | 580 |
| 581 private: | 581 private: |
| 582 TestPacketWriter* writer_; | 582 TestPacketWriter* writer() { |
| 583 return reinterpret_cast<TestPacketWriter*>(QuicConnection::writer()); |
| 584 } |
| 583 | 585 |
| 584 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 586 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 585 }; | 587 }; |
| 586 | 588 |
| 587 // Used for testing packets revived from FEC packets. | 589 // Used for testing packets revived from FEC packets. |
| 588 class FecQuicConnectionDebugVisitor | 590 class FecQuicConnectionDebugVisitor |
| 589 : public QuicConnectionDebugVisitor { | 591 : public QuicConnectionDebugVisitor { |
| 590 public: | 592 public: |
| 591 virtual void OnRevivedPacket(const QuicPacketHeader& header, | 593 virtual void OnRevivedPacket(const QuicPacketHeader& header, |
| 592 StringPiece data) OVERRIDE { | 594 StringPiece data) OVERRIDE { |
| 593 revived_header_ = header; | 595 revived_header_ = header; |
| 594 } | 596 } |
| 595 | 597 |
| 596 // Public accessor method. | 598 // Public accessor method. |
| 597 QuicPacketHeader revived_header() const { | 599 QuicPacketHeader revived_header() const { |
| 598 return revived_header_; | 600 return revived_header_; |
| 599 } | 601 } |
| 600 | 602 |
| 601 private: | 603 private: |
| 602 QuicPacketHeader revived_header_; | 604 QuicPacketHeader revived_header_; |
| 603 }; | 605 }; |
| 604 | 606 |
| 607 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
| 608 public: |
| 609 MockPacketWriterFactory(QuicPacketWriter* writer) { |
| 610 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); |
| 611 } |
| 612 virtual ~MockPacketWriterFactory() {} |
| 613 |
| 614 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); |
| 615 }; |
| 616 |
| 605 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 617 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
| 606 protected: | 618 protected: |
| 607 QuicConnectionTest() | 619 QuicConnectionTest() |
| 608 : connection_id_(42), | 620 : connection_id_(42), |
| 609 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 621 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
| 610 peer_creator_(connection_id_, &framer_, &random_generator_), | 622 peer_creator_(connection_id_, &framer_, &random_generator_), |
| 611 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 623 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 612 loss_algorithm_(new MockLossAlgorithm()), | 624 loss_algorithm_(new MockLossAlgorithm()), |
| 613 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 625 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 614 writer_(new TestPacketWriter(version())), | 626 writer_(new TestPacketWriter(version())), |
| 627 factory_(writer_.get()), |
| 615 connection_(connection_id_, IPEndPoint(), helper_.get(), | 628 connection_(connection_id_, IPEndPoint(), helper_.get(), |
| 616 writer_.get(), false, version()), | 629 factory_, false, version()), |
| 617 frame1_(1, false, 0, MakeIOVector(data1)), | 630 frame1_(1, false, 0, MakeIOVector(data1)), |
| 618 frame2_(1, false, 3, MakeIOVector(data2)), | 631 frame2_(1, false, 3, MakeIOVector(data2)), |
| 619 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 632 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
| 620 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 633 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
| 621 connection_.set_visitor(&visitor_); | 634 connection_.set_visitor(&visitor_); |
| 622 connection_.SetSendAlgorithm(send_algorithm_); | 635 connection_.SetSendAlgorithm(send_algorithm_); |
| 623 connection_.SetLossAlgorithm(loss_algorithm_); | 636 connection_.SetLossAlgorithm(loss_algorithm_); |
| 624 framer_.set_received_entropy_calculator(&entropy_calculator_); | 637 framer_.set_received_entropy_calculator(&entropy_calculator_); |
| 625 // Simplify tests by not sending feedback unless specifically configured. | 638 // Simplify tests by not sending feedback unless specifically configured. |
| 626 SetFeedback(NULL); | 639 SetFeedback(NULL); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 QuicPacketCreator peer_creator_; | 974 QuicPacketCreator peer_creator_; |
| 962 MockEntropyCalculator entropy_calculator_; | 975 MockEntropyCalculator entropy_calculator_; |
| 963 | 976 |
| 964 MockSendAlgorithm* send_algorithm_; | 977 MockSendAlgorithm* send_algorithm_; |
| 965 MockLossAlgorithm* loss_algorithm_; | 978 MockLossAlgorithm* loss_algorithm_; |
| 966 TestReceiveAlgorithm* receive_algorithm_; | 979 TestReceiveAlgorithm* receive_algorithm_; |
| 967 MockClock clock_; | 980 MockClock clock_; |
| 968 MockRandom random_generator_; | 981 MockRandom random_generator_; |
| 969 scoped_ptr<TestConnectionHelper> helper_; | 982 scoped_ptr<TestConnectionHelper> helper_; |
| 970 scoped_ptr<TestPacketWriter> writer_; | 983 scoped_ptr<TestPacketWriter> writer_; |
| 984 NiceMock<MockPacketWriterFactory> factory_; |
| 971 TestConnection connection_; | 985 TestConnection connection_; |
| 972 StrictMock<MockConnectionVisitor> visitor_; | 986 StrictMock<MockConnectionVisitor> visitor_; |
| 973 | 987 |
| 974 QuicPacketHeader header_; | 988 QuicPacketHeader header_; |
| 975 QuicStreamFrame frame1_; | 989 QuicStreamFrame frame1_; |
| 976 QuicStreamFrame frame2_; | 990 QuicStreamFrame frame2_; |
| 977 scoped_ptr<QuicAckFrame> outgoing_ack_; | 991 scoped_ptr<QuicAckFrame> outgoing_ack_; |
| 978 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; | 992 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; |
| 979 QuicSequenceNumberLength sequence_number_length_; | 993 QuicSequenceNumberLength sequence_number_length_; |
| 980 QuicConnectionIdLength connection_id_length_; | 994 QuicConnectionIdLength connection_id_length_; |
| (...skipping 2971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3952 new MockQuicConnectionDebugVisitor(); | 3966 new MockQuicConnectionDebugVisitor(); |
| 3953 connection_.set_debug_visitor(debug_visitor); | 3967 connection_.set_debug_visitor(debug_visitor); |
| 3954 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 3968 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 3955 connection_.OnPacketHeader(header); | 3969 connection_.OnPacketHeader(header); |
| 3956 } | 3970 } |
| 3957 | 3971 |
| 3958 TEST_P(QuicConnectionTest, Pacing) { | 3972 TEST_P(QuicConnectionTest, Pacing) { |
| 3959 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); | 3973 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); |
| 3960 | 3974 |
| 3961 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 3975 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), |
| 3962 writer_.get(), true, version()); | 3976 factory_, /* is_server= */ true, version()); |
| 3963 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 3977 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), |
| 3964 writer_.get(), false, version()); | 3978 factory_, /* is_server= */ false, version()); |
| 3965 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3979 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
| 3966 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3980 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3967 } | 3981 } |
| 3968 | 3982 |
| 3969 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { | 3983 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
| 3970 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3984 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3971 | 3985 |
| 3972 // Send a WINDOW_UPDATE frame. | 3986 // Send a WINDOW_UPDATE frame. |
| 3973 QuicWindowUpdateFrame window_update; | 3987 QuicWindowUpdateFrame window_update; |
| 3974 window_update.stream_id = 3; | 3988 window_update.stream_id = 3; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3985 QuicBlockedFrame blocked; | 3999 QuicBlockedFrame blocked; |
| 3986 blocked.stream_id = 3; | 4000 blocked.stream_id = 3; |
| 3987 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4001 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3988 ProcessFramePacket(QuicFrame(&blocked)); | 4002 ProcessFramePacket(QuicFrame(&blocked)); |
| 3989 EXPECT_TRUE(ack_alarm->IsSet()); | 4003 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3990 } | 4004 } |
| 3991 | 4005 |
| 3992 } // namespace | 4006 } // namespace |
| 3993 } // namespace test | 4007 } // namespace test |
| 3994 } // namespace net | 4008 } // namespace net |
| OLD | NEW |