| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 uint32 packets_write_attempts_; | 405 uint32 packets_write_attempts_; |
| 405 | 406 |
| 406 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 407 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
| 407 }; | 408 }; |
| 408 | 409 |
| 409 class TestConnection : public QuicConnection { | 410 class TestConnection : public QuicConnection { |
| 410 public: | 411 public: |
| 411 TestConnection(QuicConnectionId connection_id, | 412 TestConnection(QuicConnectionId connection_id, |
| 412 IPEndPoint address, | 413 IPEndPoint address, |
| 413 TestConnectionHelper* helper, | 414 TestConnectionHelper* helper, |
| 414 TestPacketWriter* writer, | 415 const PacketWriterFactory& factory, |
| 415 bool is_server, | 416 bool is_server, |
| 416 QuicVersion version) | 417 QuicVersion version) |
| 417 : QuicConnection(connection_id, | 418 : QuicConnection(connection_id, |
| 418 address, | 419 address, |
| 419 helper, | 420 helper, |
| 420 writer, | 421 factory, |
| 421 false /* owns_writer */, | 422 /* owns_writer= */ false, |
| 422 is_server, | 423 is_server, |
| 423 SupportedVersions(version)), | 424 SupportedVersions(version)) { |
| 424 writer_(writer) { | |
| 425 // Disable tail loss probes for most tests. | 425 // Disable tail loss probes for most tests. |
| 426 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 426 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 427 QuicConnectionPeer::GetSentPacketManager(this), 0); | 427 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 428 writer_->set_is_server(is_server); | 428 writer()->set_is_server(is_server); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void SendAck() { | 431 void SendAck() { |
| 432 QuicConnectionPeer::SendAck(this); | 432 QuicConnectionPeer::SendAck(this); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { | 435 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { |
| 436 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); | 436 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); |
| 437 } | 437 } |
| 438 | 438 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 bool is_server() { | 530 bool is_server() { |
| 531 return QuicConnectionPeer::IsServer(this); | 531 return QuicConnectionPeer::IsServer(this); |
| 532 } | 532 } |
| 533 | 533 |
| 534 void set_version(QuicVersion version) { | 534 void set_version(QuicVersion version) { |
| 535 QuicConnectionPeer::GetFramer(this)->set_version(version); | 535 QuicConnectionPeer::GetFramer(this)->set_version(version); |
| 536 } | 536 } |
| 537 | 537 |
| 538 void SetSupportedVersions(const QuicVersionVector& versions) { | 538 void SetSupportedVersions(const QuicVersionVector& versions) { |
| 539 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); | 539 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); |
| 540 writer_->SetSupportedVersions(versions); | 540 writer()->SetSupportedVersions(versions); |
| 541 } | 541 } |
| 542 | 542 |
| 543 void set_is_server(bool is_server) { | 543 void set_is_server(bool is_server) { |
| 544 writer_->set_is_server(is_server); | 544 writer()->set_is_server(is_server); |
| 545 QuicConnectionPeer::SetIsServer(this, is_server); | 545 QuicConnectionPeer::SetIsServer(this, is_server); |
| 546 } | 546 } |
| 547 | 547 |
| 548 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 548 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
| 549 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 549 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 550 QuicConnectionPeer::GetAckAlarm(this)); | 550 QuicConnectionPeer::GetAckAlarm(this)); |
| 551 } | 551 } |
| 552 | 552 |
| 553 TestConnectionHelper::TestAlarm* GetPingAlarm() { | 553 TestConnectionHelper::TestAlarm* GetPingAlarm() { |
| 554 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 554 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 571 } | 571 } |
| 572 | 572 |
| 573 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { | 573 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { |
| 574 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 574 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 575 QuicConnectionPeer::GetTimeoutAlarm(this)); | 575 QuicConnectionPeer::GetTimeoutAlarm(this)); |
| 576 } | 576 } |
| 577 | 577 |
| 578 using QuicConnection::SelectMutualVersion; | 578 using QuicConnection::SelectMutualVersion; |
| 579 | 579 |
| 580 private: | 580 private: |
| 581 TestPacketWriter* writer_; | 581 TestPacketWriter* writer() { |
| 582 return static_cast<TestPacketWriter*>(QuicConnection::writer()); |
| 583 } |
| 582 | 584 |
| 583 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 585 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 584 }; | 586 }; |
| 585 | 587 |
| 586 // Used for testing packets revived from FEC packets. | 588 // Used for testing packets revived from FEC packets. |
| 587 class FecQuicConnectionDebugVisitor | 589 class FecQuicConnectionDebugVisitor |
| 588 : public QuicConnectionDebugVisitor { | 590 : public QuicConnectionDebugVisitor { |
| 589 public: | 591 public: |
| 590 virtual void OnRevivedPacket(const QuicPacketHeader& header, | 592 virtual void OnRevivedPacket(const QuicPacketHeader& header, |
| 591 StringPiece data) OVERRIDE { | 593 StringPiece data) OVERRIDE { |
| 592 revived_header_ = header; | 594 revived_header_ = header; |
| 593 } | 595 } |
| 594 | 596 |
| 595 // Public accessor method. | 597 // Public accessor method. |
| 596 QuicPacketHeader revived_header() const { | 598 QuicPacketHeader revived_header() const { |
| 597 return revived_header_; | 599 return revived_header_; |
| 598 } | 600 } |
| 599 | 601 |
| 600 private: | 602 private: |
| 601 QuicPacketHeader revived_header_; | 603 QuicPacketHeader revived_header_; |
| 602 }; | 604 }; |
| 603 | 605 |
| 606 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
| 607 public: |
| 608 MockPacketWriterFactory(QuicPacketWriter* writer) { |
| 609 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); |
| 610 } |
| 611 virtual ~MockPacketWriterFactory() {} |
| 612 |
| 613 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); |
| 614 }; |
| 615 |
| 604 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 616 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
| 605 protected: | 617 protected: |
| 606 QuicConnectionTest() | 618 QuicConnectionTest() |
| 607 : connection_id_(42), | 619 : connection_id_(42), |
| 608 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 620 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
| 609 peer_creator_(connection_id_, &framer_, &random_generator_), | 621 peer_creator_(connection_id_, &framer_, &random_generator_), |
| 610 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 622 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 611 loss_algorithm_(new MockLossAlgorithm()), | 623 loss_algorithm_(new MockLossAlgorithm()), |
| 612 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 624 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 613 writer_(new TestPacketWriter(version())), | 625 writer_(new TestPacketWriter(version())), |
| 626 factory_(writer_.get()), |
| 614 connection_(connection_id_, IPEndPoint(), helper_.get(), | 627 connection_(connection_id_, IPEndPoint(), helper_.get(), |
| 615 writer_.get(), false, version()), | 628 factory_, false, version()), |
| 616 frame1_(1, false, 0, MakeIOVector(data1)), | 629 frame1_(1, false, 0, MakeIOVector(data1)), |
| 617 frame2_(1, false, 3, MakeIOVector(data2)), | 630 frame2_(1, false, 3, MakeIOVector(data2)), |
| 618 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 631 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
| 619 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 632 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
| 620 connection_.set_visitor(&visitor_); | 633 connection_.set_visitor(&visitor_); |
| 621 connection_.SetSendAlgorithm(send_algorithm_); | 634 connection_.SetSendAlgorithm(send_algorithm_); |
| 622 connection_.SetLossAlgorithm(loss_algorithm_); | 635 connection_.SetLossAlgorithm(loss_algorithm_); |
| 623 framer_.set_received_entropy_calculator(&entropy_calculator_); | 636 framer_.set_received_entropy_calculator(&entropy_calculator_); |
| 624 // Simplify tests by not sending feedback unless specifically configured. | 637 // Simplify tests by not sending feedback unless specifically configured. |
| 625 SetFeedback(NULL); | 638 SetFeedback(NULL); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 QuicPacketCreator peer_creator_; | 966 QuicPacketCreator peer_creator_; |
| 954 MockEntropyCalculator entropy_calculator_; | 967 MockEntropyCalculator entropy_calculator_; |
| 955 | 968 |
| 956 MockSendAlgorithm* send_algorithm_; | 969 MockSendAlgorithm* send_algorithm_; |
| 957 MockLossAlgorithm* loss_algorithm_; | 970 MockLossAlgorithm* loss_algorithm_; |
| 958 TestReceiveAlgorithm* receive_algorithm_; | 971 TestReceiveAlgorithm* receive_algorithm_; |
| 959 MockClock clock_; | 972 MockClock clock_; |
| 960 MockRandom random_generator_; | 973 MockRandom random_generator_; |
| 961 scoped_ptr<TestConnectionHelper> helper_; | 974 scoped_ptr<TestConnectionHelper> helper_; |
| 962 scoped_ptr<TestPacketWriter> writer_; | 975 scoped_ptr<TestPacketWriter> writer_; |
| 976 NiceMock<MockPacketWriterFactory> factory_; |
| 963 TestConnection connection_; | 977 TestConnection connection_; |
| 964 StrictMock<MockConnectionVisitor> visitor_; | 978 StrictMock<MockConnectionVisitor> visitor_; |
| 965 | 979 |
| 966 QuicPacketHeader header_; | 980 QuicPacketHeader header_; |
| 967 QuicStreamFrame frame1_; | 981 QuicStreamFrame frame1_; |
| 968 QuicStreamFrame frame2_; | 982 QuicStreamFrame frame2_; |
| 969 scoped_ptr<QuicAckFrame> outgoing_ack_; | 983 scoped_ptr<QuicAckFrame> outgoing_ack_; |
| 970 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; | 984 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; |
| 971 QuicSequenceNumberLength sequence_number_length_; | 985 QuicSequenceNumberLength sequence_number_length_; |
| 972 QuicConnectionIdLength connection_id_length_; | 986 QuicConnectionIdLength connection_id_length_; |
| (...skipping 2943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3916 | 3930 |
| 3917 MockQuicConnectionDebugVisitor* debug_visitor = | 3931 MockQuicConnectionDebugVisitor* debug_visitor = |
| 3918 new MockQuicConnectionDebugVisitor(); | 3932 new MockQuicConnectionDebugVisitor(); |
| 3919 connection_.set_debug_visitor(debug_visitor); | 3933 connection_.set_debug_visitor(debug_visitor); |
| 3920 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 3934 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 3921 connection_.OnPacketHeader(header); | 3935 connection_.OnPacketHeader(header); |
| 3922 } | 3936 } |
| 3923 | 3937 |
| 3924 TEST_P(QuicConnectionTest, Pacing) { | 3938 TEST_P(QuicConnectionTest, Pacing) { |
| 3925 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 3939 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), |
| 3926 writer_.get(), true, version()); | 3940 factory_, /* is_server= */ true, version()); |
| 3927 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 3941 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), |
| 3928 writer_.get(), false, version()); | 3942 factory_, /* is_server= */ false, version()); |
| 3929 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 3943 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
| 3930 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3944 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3931 } | 3945 } |
| 3932 | 3946 |
| 3933 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { | 3947 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
| 3934 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3948 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3935 | 3949 |
| 3936 // Send a WINDOW_UPDATE frame. | 3950 // Send a WINDOW_UPDATE frame. |
| 3937 QuicWindowUpdateFrame window_update; | 3951 QuicWindowUpdateFrame window_update; |
| 3938 window_update.stream_id = 3; | 3952 window_update.stream_id = 3; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3949 QuicBlockedFrame blocked; | 3963 QuicBlockedFrame blocked; |
| 3950 blocked.stream_id = 3; | 3964 blocked.stream_id = 3; |
| 3951 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3965 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3952 ProcessFramePacket(QuicFrame(&blocked)); | 3966 ProcessFramePacket(QuicFrame(&blocked)); |
| 3953 EXPECT_TRUE(ack_alarm->IsSet()); | 3967 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3954 } | 3968 } |
| 3955 | 3969 |
| 3956 } // namespace | 3970 } // namespace |
| 3957 } // namespace test | 3971 } // namespace test |
| 3958 } // namespace net | 3972 } // namespace net |
| OLD | NEW |