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/test_tools/quic_test_utils.h" | 5 #include "net/quic/test_tools/quic_test_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 MockConnectionHelper::~MockConnectionHelper() {} | 194 MockConnectionHelper::~MockConnectionHelper() {} |
195 | 195 |
196 const QuicClock* MockConnectionHelper::GetClock() const { | 196 const QuicClock* MockConnectionHelper::GetClock() const { |
197 return &clock_; | 197 return &clock_; |
198 } | 198 } |
199 | 199 |
200 QuicRandom* MockConnectionHelper::GetRandomGenerator() { | 200 QuicRandom* MockConnectionHelper::GetRandomGenerator() { |
201 return &random_generator_; | 201 return &random_generator_; |
202 } | 202 } |
203 | 203 |
204 QuicAlarm* MockConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { | 204 QuicAlarm* MockAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) { |
205 return new MockConnectionHelper::TestAlarm( | 205 return new MockAlarmFactory::TestAlarm( |
206 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); | 206 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
207 } | 207 } |
208 | 208 |
209 QuicArenaScopedPtr<QuicAlarm> MockConnectionHelper::CreateAlarm( | 209 QuicArenaScopedPtr<QuicAlarm> MockAlarmFactory::CreateAlarm( |
210 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, | 210 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
211 QuicConnectionArena* arena) { | 211 QuicConnectionArena* arena) { |
212 if (arena != nullptr) { | 212 if (arena != nullptr) { |
213 return arena->New<MockConnectionHelper::TestAlarm>(std::move(delegate)); | 213 return arena->New<MockAlarmFactory::TestAlarm>(std::move(delegate)); |
214 } else { | 214 } else { |
215 return QuicArenaScopedPtr<MockConnectionHelper::TestAlarm>( | 215 return QuicArenaScopedPtr<MockAlarmFactory::TestAlarm>( |
216 new TestAlarm(std::move(delegate))); | 216 new TestAlarm(std::move(delegate))); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() { | 220 QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() { |
221 return &buffer_allocator_; | 221 return &buffer_allocator_; |
222 } | 222 } |
223 | 223 |
224 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) { | 224 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) { |
225 clock_.AdvanceTime(delta); | 225 clock_.AdvanceTime(delta); |
226 } | 226 } |
227 | 227 |
228 MockConnection::MockConnection(MockConnectionHelper* helper, | 228 MockConnection::MockConnection(MockConnectionHelper* helper, |
| 229 MockAlarmFactory* alarm_factory, |
229 Perspective perspective) | 230 Perspective perspective) |
230 : MockConnection(kTestConnectionId, | 231 : MockConnection(kTestConnectionId, |
231 IPEndPoint(TestPeerIPAddress(), kTestPort), | 232 IPEndPoint(TestPeerIPAddress(), kTestPort), |
232 helper, | 233 helper, |
| 234 alarm_factory, |
233 perspective, | 235 perspective, |
234 QuicSupportedVersions()) {} | 236 QuicSupportedVersions()) {} |
235 | 237 |
236 MockConnection::MockConnection(IPEndPoint address, | 238 MockConnection::MockConnection(IPEndPoint address, |
237 MockConnectionHelper* helper, | 239 MockConnectionHelper* helper, |
| 240 MockAlarmFactory* alarm_factory, |
238 Perspective perspective) | 241 Perspective perspective) |
239 : MockConnection(kTestConnectionId, | 242 : MockConnection(kTestConnectionId, |
240 address, | 243 address, |
241 helper, | 244 helper, |
| 245 alarm_factory, |
242 perspective, | 246 perspective, |
243 QuicSupportedVersions()) {} | 247 QuicSupportedVersions()) {} |
244 | 248 |
245 MockConnection::MockConnection(QuicConnectionId connection_id, | 249 MockConnection::MockConnection(QuicConnectionId connection_id, |
246 MockConnectionHelper* helper, | 250 MockConnectionHelper* helper, |
| 251 MockAlarmFactory* alarm_factory, |
247 Perspective perspective) | 252 Perspective perspective) |
248 : MockConnection(connection_id, | 253 : MockConnection(connection_id, |
249 IPEndPoint(TestPeerIPAddress(), kTestPort), | 254 IPEndPoint(TestPeerIPAddress(), kTestPort), |
250 helper, | 255 helper, |
| 256 alarm_factory, |
251 perspective, | 257 perspective, |
252 QuicSupportedVersions()) {} | 258 QuicSupportedVersions()) {} |
253 | 259 |
254 MockConnection::MockConnection(MockConnectionHelper* helper, | 260 MockConnection::MockConnection(MockConnectionHelper* helper, |
| 261 MockAlarmFactory* alarm_factory, |
255 Perspective perspective, | 262 Perspective perspective, |
256 const QuicVersionVector& supported_versions) | 263 const QuicVersionVector& supported_versions) |
257 : MockConnection(kTestConnectionId, | 264 : MockConnection(kTestConnectionId, |
258 IPEndPoint(TestPeerIPAddress(), kTestPort), | 265 IPEndPoint(TestPeerIPAddress(), kTestPort), |
259 helper, | 266 helper, |
| 267 alarm_factory, |
260 perspective, | 268 perspective, |
261 supported_versions) {} | 269 supported_versions) {} |
262 | 270 |
263 MockConnection::MockConnection(QuicConnectionId connection_id, | 271 MockConnection::MockConnection(QuicConnectionId connection_id, |
264 IPEndPoint address, | 272 IPEndPoint address, |
265 MockConnectionHelper* helper, | 273 MockConnectionHelper* helper, |
| 274 MockAlarmFactory* alarm_factory, |
266 Perspective perspective, | 275 Perspective perspective, |
267 const QuicVersionVector& supported_versions) | 276 const QuicVersionVector& supported_versions) |
268 : QuicConnection(connection_id, | 277 : QuicConnection(connection_id, |
269 address, | 278 address, |
270 helper, | 279 helper, |
| 280 alarm_factory, |
271 new testing::NiceMock<MockPacketWriter>(), | 281 new testing::NiceMock<MockPacketWriter>(), |
272 /* owns_writer= */ true, | 282 /* owns_writer= */ true, |
273 perspective, | 283 perspective, |
274 supported_versions) { | 284 supported_versions) { |
275 ON_CALL(*this, OnError(_)) | 285 ON_CALL(*this, OnError(_)) |
276 .WillByDefault( | 286 .WillByDefault( |
277 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); | 287 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); |
278 } | 288 } |
279 | 289 |
280 MockConnection::~MockConnection() {} | 290 MockConnection::~MockConnection() {} |
281 | 291 |
282 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 292 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
283 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta); | 293 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta); |
284 } | 294 } |
285 | 295 |
286 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper, | 296 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper, |
| 297 MockAlarmFactory* alarm_factory, |
287 Perspective perspective) | 298 Perspective perspective) |
288 : MockConnection(helper, perspective) {} | 299 : MockConnection(helper, alarm_factory, perspective) {} |
289 | 300 |
290 PacketSavingConnection::PacketSavingConnection( | 301 PacketSavingConnection::PacketSavingConnection( |
291 MockConnectionHelper* helper, | 302 MockConnectionHelper* helper, |
| 303 MockAlarmFactory* alarm_factory, |
292 Perspective perspective, | 304 Perspective perspective, |
293 const QuicVersionVector& supported_versions) | 305 const QuicVersionVector& supported_versions) |
294 : MockConnection(helper, perspective, supported_versions) {} | 306 : MockConnection(helper, alarm_factory, perspective, supported_versions) {} |
295 | 307 |
296 PacketSavingConnection::~PacketSavingConnection() { | 308 PacketSavingConnection::~PacketSavingConnection() { |
297 STLDeleteElements(&encrypted_packets_); | 309 STLDeleteElements(&encrypted_packets_); |
298 } | 310 } |
299 | 311 |
300 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { | 312 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { |
301 encrypted_packets_.push_back(new QuicEncryptedPacket( | 313 encrypted_packets_.push_back(new QuicEncryptedPacket( |
302 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); | 314 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); |
303 // Transfer ownership of the packet to the SentPacketManager and the | 315 // Transfer ownership of the packet to the SentPacketManager and the |
304 // ack notifier to the AckNotifierManager. | 316 // ack notifier to the AckNotifierManager. |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) | 766 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) |
755 : QuicReceivedPacketManager(stats) {} | 767 : QuicReceivedPacketManager(stats) {} |
756 | 768 |
757 MockReceivedPacketManager::~MockReceivedPacketManager() {} | 769 MockReceivedPacketManager::~MockReceivedPacketManager() {} |
758 | 770 |
759 void CreateClientSessionForTest(QuicServerId server_id, | 771 void CreateClientSessionForTest(QuicServerId server_id, |
760 bool supports_stateless_rejects, | 772 bool supports_stateless_rejects, |
761 QuicTime::Delta connection_start_time, | 773 QuicTime::Delta connection_start_time, |
762 QuicVersionVector supported_versions, | 774 QuicVersionVector supported_versions, |
763 MockConnectionHelper* helper, | 775 MockConnectionHelper* helper, |
| 776 MockAlarmFactory* alarm_factory, |
764 QuicCryptoClientConfig* crypto_client_config, | 777 QuicCryptoClientConfig* crypto_client_config, |
765 PacketSavingConnection** client_connection, | 778 PacketSavingConnection** client_connection, |
766 TestQuicSpdyClientSession** client_session) { | 779 TestQuicSpdyClientSession** client_session) { |
767 CHECK(crypto_client_config); | 780 CHECK(crypto_client_config); |
768 CHECK(client_connection); | 781 CHECK(client_connection); |
769 CHECK(client_session); | 782 CHECK(client_session); |
770 CHECK(!connection_start_time.IsZero()) | 783 CHECK(!connection_start_time.IsZero()) |
771 << "Connections must start at non-zero times, otherwise the " | 784 << "Connections must start at non-zero times, otherwise the " |
772 << "strike-register will be unhappy."; | 785 << "strike-register will be unhappy."; |
773 | 786 |
774 QuicConfig config = supports_stateless_rejects | 787 QuicConfig config = supports_stateless_rejects |
775 ? DefaultQuicConfigStatelessRejects() | 788 ? DefaultQuicConfigStatelessRejects() |
776 : DefaultQuicConfig(); | 789 : DefaultQuicConfig(); |
777 *client_connection = new PacketSavingConnection( | 790 *client_connection = new PacketSavingConnection( |
778 helper, Perspective::IS_CLIENT, supported_versions); | 791 helper, alarm_factory, Perspective::IS_CLIENT, supported_versions); |
779 *client_session = new TestQuicSpdyClientSession( | 792 *client_session = new TestQuicSpdyClientSession( |
780 *client_connection, config, server_id, crypto_client_config); | 793 *client_connection, config, server_id, crypto_client_config); |
781 (*client_connection)->AdvanceTime(connection_start_time); | 794 (*client_connection)->AdvanceTime(connection_start_time); |
782 } | 795 } |
783 | 796 |
784 void CreateServerSessionForTest( | 797 void CreateServerSessionForTest( |
785 QuicServerId server_id, | 798 QuicServerId server_id, |
786 QuicTime::Delta connection_start_time, | 799 QuicTime::Delta connection_start_time, |
787 QuicVersionVector supported_versions, | 800 QuicVersionVector supported_versions, |
788 MockConnectionHelper* helper, | 801 MockConnectionHelper* helper, |
| 802 MockAlarmFactory* alarm_factory, |
789 QuicCryptoServerConfig* server_crypto_config, | 803 QuicCryptoServerConfig* server_crypto_config, |
790 QuicCompressedCertsCache* compressed_certs_cache, | 804 QuicCompressedCertsCache* compressed_certs_cache, |
791 PacketSavingConnection** server_connection, | 805 PacketSavingConnection** server_connection, |
792 TestQuicSpdyServerSession** server_session) { | 806 TestQuicSpdyServerSession** server_session) { |
793 CHECK(server_crypto_config); | 807 CHECK(server_crypto_config); |
794 CHECK(server_connection); | 808 CHECK(server_connection); |
795 CHECK(server_session); | 809 CHECK(server_session); |
796 CHECK(!connection_start_time.IsZero()) | 810 CHECK(!connection_start_time.IsZero()) |
797 << "Connections must start at non-zero times, otherwise the " | 811 << "Connections must start at non-zero times, otherwise the " |
798 << "strike-register will be unhappy."; | 812 << "strike-register will be unhappy."; |
799 | 813 |
800 *server_connection = new PacketSavingConnection( | 814 *server_connection = new PacketSavingConnection( |
801 helper, Perspective::IS_SERVER, supported_versions); | 815 helper, alarm_factory, Perspective::IS_SERVER, supported_versions); |
802 *server_session = new TestQuicSpdyServerSession( | 816 *server_session = new TestQuicSpdyServerSession( |
803 *server_connection, DefaultQuicConfig(), server_crypto_config, | 817 *server_connection, DefaultQuicConfig(), server_crypto_config, |
804 compressed_certs_cache); | 818 compressed_certs_cache); |
805 | 819 |
806 // We advance the clock initially because the default time is zero and the | 820 // We advance the clock initially because the default time is zero and the |
807 // strike register worries that we've just overflowed a uint32_t time. | 821 // strike register worries that we've just overflowed a uint32_t time. |
808 (*server_connection)->AdvanceTime(connection_start_time); | 822 (*server_connection)->AdvanceTime(connection_start_time); |
809 } | 823 } |
810 | 824 |
811 QuicStreamId QuicClientDataStreamId(int i) { | 825 QuicStreamId QuicClientDataStreamId(int i) { |
812 return kClientDataStreamId1 + 2 * i; | 826 return kClientDataStreamId1 + 2 * i; |
813 } | 827 } |
814 | 828 |
815 } // namespace test | 829 } // namespace test |
816 } // namespace net | 830 } // namespace net |
OLD | NEW |