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