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 { |
| 22 class NiceMockPacketWriterFactory |
| 23 : public QuicConnection::PacketWriterFactory { |
| 24 public: |
| 25 NiceMockPacketWriterFactory() {} |
| 26 virtual ~NiceMockPacketWriterFactory() {} |
| 27 |
| 28 virtual QuicPacketWriter* Create( |
| 29 QuicConnection* /*connection*/) const override { |
| 30 return new testing::NiceMock<MockPacketWriter>(); |
| 31 } |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); |
| 35 }; |
| 36 } // namespace |
| 37 |
21 MockConnection::MockConnection(bool is_server) | 38 MockConnection::MockConnection(bool is_server) |
22 : QuicConnection(kTestConnectionId, | 39 : QuicConnection(kTestConnectionId, |
23 IPEndPoint(net::test::Loopback4(), kTestPort), | 40 IPEndPoint(net::test::Loopback4(), kTestPort), |
24 new testing::NiceMock<MockHelper>(), | 41 new testing::NiceMock<MockHelper>(), |
25 new testing::NiceMock<MockPacketWriter>(), | 42 NiceMockPacketWriterFactory(), |
26 true /* owns_writer */, | 43 /* owns_writer= */ true, |
27 is_server, QuicSupportedVersions()), | 44 is_server, QuicSupportedVersions()), |
28 helper_(helper()) { | 45 helper_(helper()) { |
29 } | 46 } |
30 | 47 |
31 MockConnection::MockConnection(IPEndPoint address, | 48 MockConnection::MockConnection(IPEndPoint address, |
32 bool is_server) | 49 bool is_server) |
33 : QuicConnection(kTestConnectionId, address, | 50 : QuicConnection(kTestConnectionId, address, |
34 new testing::NiceMock<MockHelper>(), | 51 new testing::NiceMock<MockHelper>(), |
35 new testing::NiceMock<MockPacketWriter>(), | 52 NiceMockPacketWriterFactory(), |
36 true /* owns_writer */, | 53 /* owns_writer= */ true, |
37 is_server, QuicSupportedVersions()), | 54 is_server, QuicSupportedVersions()), |
38 helper_(helper()) { | 55 helper_(helper()) { |
39 } | 56 } |
40 | 57 |
41 MockConnection::MockConnection(QuicConnectionId connection_id, | 58 MockConnection::MockConnection(QuicConnectionId connection_id, |
42 bool is_server) | 59 bool is_server) |
43 : QuicConnection(connection_id, | 60 : QuicConnection(connection_id, |
44 IPEndPoint(net::test::Loopback4(), kTestPort), | 61 IPEndPoint(net::test::Loopback4(), kTestPort), |
45 new testing::NiceMock<MockHelper>(), | 62 new testing::NiceMock<MockHelper>(), |
46 new testing::NiceMock<MockPacketWriter>(), | 63 NiceMockPacketWriterFactory(), |
47 true /* owns_writer */, | 64 /* owns_writer= */ true, |
48 is_server, QuicSupportedVersions()), | 65 is_server, QuicSupportedVersions()), |
49 helper_(helper()) { | 66 helper_(helper()) { |
50 } | 67 } |
51 | 68 |
52 MockConnection::MockConnection(bool is_server, | 69 MockConnection::MockConnection(bool is_server, |
53 const QuicVersionVector& supported_versions) | 70 const QuicVersionVector& supported_versions) |
54 : QuicConnection(kTestConnectionId, | 71 : QuicConnection(kTestConnectionId, |
55 IPEndPoint(net::test::Loopback4(), kTestPort), | 72 IPEndPoint(net::test::Loopback4(), kTestPort), |
56 new testing::NiceMock<MockHelper>(), | 73 new testing::NiceMock<MockHelper>(), |
57 new testing::NiceMock<MockPacketWriter>(), | 74 NiceMockPacketWriterFactory(), |
58 true /* owns_writer */, | 75 /* owns_writer= */ true, |
59 is_server, QuicSupportedVersions()), | 76 is_server, QuicSupportedVersions()), |
60 helper_(helper()) { | 77 helper_(helper()) { |
61 } | 78 } |
62 | 79 |
63 MockConnection::~MockConnection() { | 80 MockConnection::~MockConnection() { |
64 } | 81 } |
65 | 82 |
66 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 83 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
67 static_cast<MockHelper*>(helper())->AdvanceTime(delta); | 84 static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
68 } | 85 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 122 |
106 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() { | 123 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() { |
107 } | 124 } |
108 | 125 |
109 MockAckNotifierDelegate::MockAckNotifierDelegate() { | 126 MockAckNotifierDelegate::MockAckNotifierDelegate() { |
110 } | 127 } |
111 | 128 |
112 MockAckNotifierDelegate::~MockAckNotifierDelegate() { | 129 MockAckNotifierDelegate::~MockAckNotifierDelegate() { |
113 } | 130 } |
114 | 131 |
| 132 TestWriterFactory::TestWriterFactory() : current_writer_(NULL) {} |
| 133 TestWriterFactory::~TestWriterFactory() {} |
| 134 |
| 135 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer, |
| 136 QuicConnection* connection) { |
| 137 return new PerConnectionPacketWriter(this, writer, connection); |
| 138 } |
| 139 |
| 140 void TestWriterFactory::OnPacketSent(WriteResult result) { |
| 141 if (current_writer_ != NULL) { |
| 142 current_writer_->connection()->OnPacketSent(result); |
| 143 current_writer_ = NULL; |
| 144 } |
| 145 } |
| 146 |
| 147 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) { |
| 148 if (current_writer_ == writer) { |
| 149 current_writer_ = NULL; |
| 150 } |
| 151 } |
| 152 |
| 153 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter( |
| 154 TestWriterFactory* factory, |
| 155 QuicPacketWriter* writer, |
| 156 QuicConnection* connection) |
| 157 : QuicPerConnectionPacketWriter(writer, connection), |
| 158 factory_(factory) { |
| 159 } |
| 160 |
| 161 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() { |
| 162 factory_->Unregister(this); |
| 163 } |
| 164 |
| 165 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket( |
| 166 const char* buffer, |
| 167 size_t buf_len, |
| 168 const IPAddressNumber& self_address, |
| 169 const IPEndPoint& peer_address) { |
| 170 // A DCHECK(factory_current_writer_ == NULL) would be wrong here -- this class |
| 171 // may be used in a setting where connection()->OnPacketSent() is called in a |
| 172 // different way, so TestWriterFactory::OnPacketSent might never be called. |
| 173 factory_->current_writer_ = this; |
| 174 return QuicPerConnectionPacketWriter::WritePacket(buffer, |
| 175 buf_len, |
| 176 self_address, |
| 177 peer_address); |
| 178 } |
| 179 |
115 } // namespace test | 180 } // namespace test |
116 } // namespace tools | 181 } // namespace tools |
117 } // namespace net | 182 } // namespace net |
OLD | NEW |