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

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

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto ToT Created 6 years, 4 months 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
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_dispatcher.h » ('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 20 matching lines...) Expand all
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
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
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
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 QuicPacketCreator peer_creator_; 973 QuicPacketCreator peer_creator_;
961 MockEntropyCalculator entropy_calculator_; 974 MockEntropyCalculator entropy_calculator_;
962 975
963 MockSendAlgorithm* send_algorithm_; 976 MockSendAlgorithm* send_algorithm_;
964 MockLossAlgorithm* loss_algorithm_; 977 MockLossAlgorithm* loss_algorithm_;
965 TestReceiveAlgorithm* receive_algorithm_; 978 TestReceiveAlgorithm* receive_algorithm_;
966 MockClock clock_; 979 MockClock clock_;
967 MockRandom random_generator_; 980 MockRandom random_generator_;
968 scoped_ptr<TestConnectionHelper> helper_; 981 scoped_ptr<TestConnectionHelper> helper_;
969 scoped_ptr<TestPacketWriter> writer_; 982 scoped_ptr<TestPacketWriter> writer_;
983 NiceMock<MockPacketWriterFactory> factory_;
970 TestConnection connection_; 984 TestConnection connection_;
971 StrictMock<MockConnectionVisitor> visitor_; 985 StrictMock<MockConnectionVisitor> visitor_;
972 986
973 QuicPacketHeader header_; 987 QuicPacketHeader header_;
974 QuicStreamFrame frame1_; 988 QuicStreamFrame frame1_;
975 QuicStreamFrame frame2_; 989 QuicStreamFrame frame2_;
976 scoped_ptr<QuicAckFrame> outgoing_ack_; 990 scoped_ptr<QuicAckFrame> outgoing_ack_;
977 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; 991 scoped_ptr<QuicStopWaitingFrame> stop_waiting_;
978 QuicSequenceNumberLength sequence_number_length_; 992 QuicSequenceNumberLength sequence_number_length_;
979 QuicConnectionIdLength connection_id_length_; 993 QuicConnectionIdLength connection_id_length_;
(...skipping 2971 matching lines...) Expand 10 before | Expand all | Expand 10 after
3951 new MockQuicConnectionDebugVisitor(); 3965 new MockQuicConnectionDebugVisitor();
3952 connection_.set_debug_visitor(debug_visitor); 3966 connection_.set_debug_visitor(debug_visitor);
3953 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 3967 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
3954 connection_.OnPacketHeader(header); 3968 connection_.OnPacketHeader(header);
3955 } 3969 }
3956 3970
3957 TEST_P(QuicConnectionTest, Pacing) { 3971 TEST_P(QuicConnectionTest, Pacing) {
3958 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); 3972 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true);
3959 3973
3960 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), 3974 TestConnection server(connection_id_, IPEndPoint(), helper_.get(),
3961 writer_.get(), true, version()); 3975 factory_, /* is_server= */ true, version());
3962 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), 3976 TestConnection client(connection_id_, IPEndPoint(), helper_.get(),
3963 writer_.get(), false, version()); 3977 factory_, /* is_server= */ false, version());
3964 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); 3978 EXPECT_FALSE(client.sent_packet_manager().using_pacing());
3965 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 3979 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
3966 } 3980 }
3967 3981
3968 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { 3982 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) {
3969 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3983 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3970 3984
3971 // Send a WINDOW_UPDATE frame. 3985 // Send a WINDOW_UPDATE frame.
3972 QuicWindowUpdateFrame window_update; 3986 QuicWindowUpdateFrame window_update;
3973 window_update.stream_id = 3; 3987 window_update.stream_id = 3;
(...skipping 10 matching lines...) Expand all
3984 QuicBlockedFrame blocked; 3998 QuicBlockedFrame blocked;
3985 blocked.stream_id = 3; 3999 blocked.stream_id = 3;
3986 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4000 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3987 ProcessFramePacket(QuicFrame(&blocked)); 4001 ProcessFramePacket(QuicFrame(&blocked));
3988 EXPECT_TRUE(ack_alarm->IsSet()); 4002 EXPECT_TRUE(ack_alarm->IsSet());
3989 } 4003 }
3990 4004
3991 } // namespace 4005 } // namespace
3992 } // namespace test 4006 } // namespace test
3993 } // namespace net 4007 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698