| Index: net/tools/quic/test_tools/quic_test_utils.cc
|
| diff --git a/net/tools/quic/test_tools/quic_test_utils.cc b/net/tools/quic/test_tools/quic_test_utils.cc
|
| index 255fbc0a3c12ac141385365230e56ab8dded92a1..1e691f9459cf20d4dcaf171bd3267becff14de96 100644
|
| --- a/net/tools/quic/test_tools/quic_test_utils.cc
|
| +++ b/net/tools/quic/test_tools/quic_test_utils.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "net/tools/quic/test_tools/quic_test_utils.h"
|
|
|
| +#include "base/memory/singleton.h"
|
| #include "net/quic/quic_connection.h"
|
| #include "net/quic/test_tools/quic_connection_peer.h"
|
| #include "net/quic/test_tools/quic_test_utils.h"
|
| @@ -18,12 +19,34 @@ namespace net {
|
| namespace tools {
|
| namespace test {
|
|
|
| +namespace {
|
| +class NiceMockPacketWriterFactory
|
| + : public QuicConnection::PacketWriterFactory {
|
| + public:
|
| + virtual ~NiceMockPacketWriterFactory() {}
|
| +
|
| + static NiceMockPacketWriterFactory* GetInstance() {
|
| + return Singleton<NiceMockPacketWriterFactory>::get();
|
| + }
|
| +
|
| + virtual QuicPacketWriter* Create(
|
| + QuicConnection* /*connection*/) const override {
|
| + return new testing::NiceMock<MockPacketWriter>();
|
| + }
|
| +
|
| + private:
|
| + friend struct DefaultSingletonTraits<NiceMockPacketWriterFactory>;
|
| + NiceMockPacketWriterFactory() {}
|
| + DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory);
|
| +};
|
| +} // namespace
|
| +
|
| MockConnection::MockConnection(bool is_server)
|
| : QuicConnection(kTestConnectionId,
|
| IPEndPoint(net::test::Loopback4(), kTestPort),
|
| new testing::NiceMock<MockHelper>(),
|
| - new testing::NiceMock<MockPacketWriter>(),
|
| - true /* owns_writer */,
|
| + *NiceMockPacketWriterFactory::GetInstance(),
|
| + /* owns_writer= */ true,
|
| is_server, QuicSupportedVersions()),
|
| helper_(helper()) {
|
| }
|
| @@ -32,8 +55,8 @@ MockConnection::MockConnection(IPEndPoint address,
|
| bool is_server)
|
| : QuicConnection(kTestConnectionId, address,
|
| new testing::NiceMock<MockHelper>(),
|
| - new testing::NiceMock<MockPacketWriter>(),
|
| - true /* owns_writer */,
|
| + *NiceMockPacketWriterFactory::GetInstance(),
|
| + /* owns_writer= */ true,
|
| is_server, QuicSupportedVersions()),
|
| helper_(helper()) {
|
| }
|
| @@ -43,8 +66,8 @@ MockConnection::MockConnection(QuicConnectionId connection_id,
|
| : QuicConnection(connection_id,
|
| IPEndPoint(net::test::Loopback4(), kTestPort),
|
| new testing::NiceMock<MockHelper>(),
|
| - new testing::NiceMock<MockPacketWriter>(),
|
| - true /* owns_writer */,
|
| + *NiceMockPacketWriterFactory::GetInstance(),
|
| + /* owns_writer= */ true,
|
| is_server, QuicSupportedVersions()),
|
| helper_(helper()) {
|
| }
|
| @@ -54,8 +77,8 @@ MockConnection::MockConnection(bool is_server,
|
| : QuicConnection(kTestConnectionId,
|
| IPEndPoint(net::test::Loopback4(), kTestPort),
|
| new testing::NiceMock<MockHelper>(),
|
| - new testing::NiceMock<MockPacketWriter>(),
|
| - true /* owns_writer */,
|
| + *NiceMockPacketWriterFactory::GetInstance(),
|
| + /* owns_writer= */ true,
|
| is_server, QuicSupportedVersions()),
|
| helper_(helper()) {
|
| }
|
| @@ -112,6 +135,54 @@ MockAckNotifierDelegate::MockAckNotifierDelegate() {
|
| MockAckNotifierDelegate::~MockAckNotifierDelegate() {
|
| }
|
|
|
| +TestWriterFactory::TestWriterFactory() : current_writer_(NULL) {}
|
| +TestWriterFactory::~TestWriterFactory() {}
|
| +
|
| +QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer,
|
| + QuicConnection* connection) {
|
| + return new PerConnectionPacketWriter(this, writer, connection);
|
| +}
|
| +
|
| +void TestWriterFactory::OnPacketSent(WriteResult result) {
|
| + if (current_writer_ != NULL) {
|
| + current_writer_->connection()->OnPacketSent(result);
|
| + current_writer_ = NULL;
|
| + }
|
| +}
|
| +
|
| +void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) {
|
| + if (current_writer_ == writer) {
|
| + current_writer_ = NULL;
|
| + }
|
| +}
|
| +
|
| +TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter(
|
| + TestWriterFactory* factory,
|
| + QuicPacketWriter* writer,
|
| + QuicConnection* connection)
|
| + : QuicPerConnectionPacketWriter(writer, connection),
|
| + factory_(factory) {
|
| +}
|
| +
|
| +TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() {
|
| + factory_->Unregister(this);
|
| +}
|
| +
|
| +WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket(
|
| + const char* buffer,
|
| + size_t buf_len,
|
| + const IPAddressNumber& self_address,
|
| + const IPEndPoint& peer_address) {
|
| + // A DCHECK(factory_current_writer_ == NULL) would be wrong here -- this class
|
| + // may be used in a setting where connection()->OnPacketSent() is called in a
|
| + // different way, so TestWriterFactory::OnPacketSent might never be called.
|
| + factory_->current_writer_ = this;
|
| + return QuicPerConnectionPacketWriter::WritePacket(buffer,
|
| + buf_len,
|
| + self_address,
|
| + peer_address);
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace tools
|
| } // namespace net
|
|
|