| 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/tools/quic/test_tools/quic_test_utils.h" | 5 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_connection.h" | 7 #include "net/quic/quic_connection.h" |
| 8 #include "net/quic/test_tools/quic_connection_peer.h" | 8 #include "net/quic/test_tools/quic_connection_peer.h" |
| 9 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
| 10 #include "net/tools/quic/quic_epoll_connection_helper.h" | 10 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 11 | 11 |
| 12 using base::StringPiece; | 12 using base::StringPiece; |
| 13 using net::test::MakeAckFrame; | 13 using net::test::MakeAckFrame; |
| 14 using net::test::MockHelper; | 14 using net::test::MockHelper; |
| 15 using net::test::QuicConnectionPeer; | 15 using net::test::QuicConnectionPeer; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 namespace tools { | 18 namespace tools { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 namespace { | 21 QuicPacketWriter* NiceMockPacketWriterFactory::Create( |
| 22 class NiceMockPacketWriterFactory | 22 QuicConnection* /*connection*/) const { |
| 23 : public QuicConnection::PacketWriterFactory { | 23 return new testing::NiceMock<MockPacketWriter>(); |
| 24 public: | 24 } |
| 25 NiceMockPacketWriterFactory() {} | |
| 26 ~NiceMockPacketWriterFactory() override {} | |
| 27 | |
| 28 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override { | |
| 29 return new testing::NiceMock<MockPacketWriter>(); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); | |
| 34 }; | |
| 35 } // namespace | |
| 36 | 25 |
| 37 MockConnection::MockConnection(bool is_server) | 26 MockConnection::MockConnection(bool is_server) |
| 38 : QuicConnection(kTestConnectionId, | 27 : QuicConnection(kTestConnectionId, |
| 39 IPEndPoint(net::test::Loopback4(), kTestPort), | 28 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 40 new testing::NiceMock<MockHelper>(), | 29 new testing::NiceMock<MockHelper>(), |
| 41 NiceMockPacketWriterFactory(), | 30 NiceMockPacketWriterFactory(), |
| 42 /* owns_writer= */ true, | 31 /* owns_writer= */ true, |
| 43 is_server, QuicSupportedVersions()), | 32 is_server, |
| 33 /* is_secure= */ false, |
| 34 QuicSupportedVersions()), |
| 44 helper_(helper()) { | 35 helper_(helper()) { |
| 45 } | 36 } |
| 46 | 37 |
| 38 MockConnection::MockConnection(bool is_server, bool is_secure) |
| 39 : QuicConnection(kTestConnectionId, |
| 40 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 41 new testing::NiceMock<MockHelper>(), |
| 42 NiceMockPacketWriterFactory(), |
| 43 /* owns_writer= */ true, |
| 44 is_server, |
| 45 is_secure, |
| 46 QuicSupportedVersions()), |
| 47 helper_(helper()) { |
| 48 } |
| 49 |
| 47 MockConnection::MockConnection(IPEndPoint address, | 50 MockConnection::MockConnection(IPEndPoint address, |
| 48 bool is_server) | 51 bool is_server) |
| 49 : QuicConnection(kTestConnectionId, address, | 52 : QuicConnection(kTestConnectionId, address, |
| 50 new testing::NiceMock<MockHelper>(), | 53 new testing::NiceMock<MockHelper>(), |
| 51 NiceMockPacketWriterFactory(), | 54 NiceMockPacketWriterFactory(), |
| 52 /* owns_writer= */ true, | 55 /* owns_writer= */ true, |
| 53 is_server, QuicSupportedVersions()), | 56 is_server, |
| 57 /* is_secure= */ false, |
| 58 QuicSupportedVersions()), |
| 54 helper_(helper()) { | 59 helper_(helper()) { |
| 55 } | 60 } |
| 56 | 61 |
| 57 MockConnection::MockConnection(QuicConnectionId connection_id, | 62 MockConnection::MockConnection(QuicConnectionId connection_id, |
| 58 bool is_server) | 63 bool is_server) |
| 59 : QuicConnection(connection_id, | 64 : QuicConnection(connection_id, |
| 60 IPEndPoint(net::test::Loopback4(), kTestPort), | 65 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 61 new testing::NiceMock<MockHelper>(), | 66 new testing::NiceMock<MockHelper>(), |
| 62 NiceMockPacketWriterFactory(), | 67 NiceMockPacketWriterFactory(), |
| 63 /* owns_writer= */ true, | 68 /* owns_writer= */ true, |
| 64 is_server, QuicSupportedVersions()), | 69 is_server, |
| 70 /* is_secure= */ false, |
| 71 QuicSupportedVersions()), |
| 65 helper_(helper()) { | 72 helper_(helper()) { |
| 66 } | 73 } |
| 67 | 74 |
| 68 MockConnection::MockConnection(bool is_server, | 75 MockConnection::MockConnection(bool is_server, |
| 69 const QuicVersionVector& supported_versions) | 76 const QuicVersionVector& supported_versions) |
| 70 : QuicConnection(kTestConnectionId, | 77 : QuicConnection(kTestConnectionId, |
| 71 IPEndPoint(net::test::Loopback4(), kTestPort), | 78 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 72 new testing::NiceMock<MockHelper>(), | 79 new testing::NiceMock<MockHelper>(), |
| 73 NiceMockPacketWriterFactory(), | 80 NiceMockPacketWriterFactory(), |
| 74 /* owns_writer= */ true, | 81 /* owns_writer= */ true, |
| 75 is_server, QuicSupportedVersions()), | 82 is_server, |
| 83 /* is_secure= */ false, |
| 84 supported_versions), |
| 76 helper_(helper()) { | 85 helper_(helper()) { |
| 77 } | 86 } |
| 78 | 87 |
| 79 MockConnection::~MockConnection() { | 88 MockConnection::~MockConnection() { |
| 80 } | 89 } |
| 81 | 90 |
| 82 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 91 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
| 83 static_cast<MockHelper*>(helper())->AdvanceTime(delta); | 92 static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
| 84 } | 93 } |
| 85 | 94 |
| 86 QuicAckFrame MakeAckFrameWithNackRanges( | 95 QuicAckFrame MakeAckFrameWithNackRanges( |
| 87 size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked) { | 96 size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked) { |
| 88 QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked); | 97 QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked); |
| 89 // Add enough missing packets to get num_nack_ranges nack ranges. | 98 // Add enough missing packets to get num_nack_ranges nack ranges. |
| 90 for (QuicPacketSequenceNumber i = 1; i < 2 * num_nack_ranges; i += 2) { | 99 for (QuicPacketSequenceNumber i = 1; i < 2 * num_nack_ranges; i += 2) { |
| 91 ack.missing_packets.insert(least_unacked + i); | 100 ack.missing_packets.insert(least_unacked + i); |
| 92 } | 101 } |
| 93 return ack; | 102 return ack; |
| 94 } | 103 } |
| 95 | 104 |
| 96 TestSession::TestSession(QuicConnection* connection, | 105 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) |
| 97 const QuicConfig& config) | 106 : QuicSession(connection, config), |
| 98 : QuicSession(connection, config, /*is_secure=*/false), | |
| 99 crypto_stream_(nullptr) { | 107 crypto_stream_(nullptr) { |
| 100 InitializeSession(); | 108 InitializeSession(); |
| 101 } | 109 } |
| 102 | 110 |
| 103 TestSession::~TestSession() {} | 111 TestSession::~TestSession() {} |
| 104 | 112 |
| 105 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { | 113 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 106 crypto_stream_ = stream; | 114 crypto_stream_ = stream; |
| 107 } | 115 } |
| 108 | 116 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 factory_->current_writer_ = this; | 181 factory_->current_writer_ = this; |
| 174 return QuicPerConnectionPacketWriter::WritePacket(buffer, | 182 return QuicPerConnectionPacketWriter::WritePacket(buffer, |
| 175 buf_len, | 183 buf_len, |
| 176 self_address, | 184 self_address, |
| 177 peer_address); | 185 peer_address); |
| 178 } | 186 } |
| 179 | 187 |
| 180 } // namespace test | 188 } // namespace test |
| 181 } // namespace tools | 189 } // namespace tools |
| 182 } // namespace net | 190 } // namespace net |
| OLD | NEW |