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 // Common utilities for Quic tests | 5 // Common utilities for Quic tests |
6 | 6 |
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 private: | 313 private: |
314 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | 314 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); |
315 }; | 315 }; |
316 | 316 |
317 class MockConnectionHelper : public QuicConnectionHelperInterface { | 317 class MockConnectionHelper : public QuicConnectionHelperInterface { |
318 public: | 318 public: |
319 MockConnectionHelper(); | 319 MockConnectionHelper(); |
320 ~MockConnectionHelper() override; | 320 ~MockConnectionHelper() override; |
321 const QuicClock* GetClock() const override; | 321 const QuicClock* GetClock() const override; |
322 QuicRandom* GetRandomGenerator() override; | 322 QuicRandom* GetRandomGenerator() override; |
| 323 QuicBufferAllocator* GetBufferAllocator() override; |
| 324 void AdvanceTime(QuicTime::Delta delta); |
| 325 |
| 326 private: |
| 327 MockClock clock_; |
| 328 MockRandom random_generator_; |
| 329 SimpleBufferAllocator buffer_allocator_; |
| 330 |
| 331 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); |
| 332 }; |
| 333 |
| 334 class MockAlarmFactory : public QuicAlarmFactory { |
| 335 public: |
323 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; | 336 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
324 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( | 337 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( |
325 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, | 338 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
326 QuicConnectionArena* arena) override; | 339 QuicConnectionArena* arena) override; |
327 QuicBufferAllocator* GetBufferAllocator() override; | |
328 void AdvanceTime(QuicTime::Delta delta); | |
329 | 340 |
330 // No-op alarm implementation | 341 // No-op alarm implementation |
331 class TestAlarm : public QuicAlarm { | 342 class TestAlarm : public QuicAlarm { |
332 public: | 343 public: |
333 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) | 344 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) |
334 : QuicAlarm(std::move(delegate)) {} | 345 : QuicAlarm(std::move(delegate)) {} |
335 | 346 |
336 void SetImpl() override {} | 347 void SetImpl() override {} |
337 void CancelImpl() override {} | 348 void CancelImpl() override {} |
338 | 349 |
339 using QuicAlarm::Fire; | 350 using QuicAlarm::Fire; |
340 }; | 351 }; |
341 | 352 |
342 void FireAlarm(QuicAlarm* alarm) { | 353 void FireAlarm(QuicAlarm* alarm) { |
343 reinterpret_cast<TestAlarm*>(alarm)->Fire(); | 354 reinterpret_cast<TestAlarm*>(alarm)->Fire(); |
344 } | 355 } |
345 | |
346 private: | |
347 MockClock clock_; | |
348 MockRandom random_generator_; | |
349 SimpleBufferAllocator buffer_allocator_; | |
350 | |
351 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); | |
352 }; | 356 }; |
353 | 357 |
354 class MockConnection : public QuicConnection { | 358 class MockConnection : public QuicConnection { |
355 public: | 359 public: |
356 // Uses a ConnectionId of 42 and 127.0.0.1:123. | 360 // Uses a ConnectionId of 42 and 127.0.0.1:123. |
357 MockConnection(MockConnectionHelper* helper, Perspective perspective); | 361 MockConnection(MockConnectionHelper* helper, |
| 362 MockAlarmFactory* alarm_factory, |
| 363 Perspective perspective); |
358 | 364 |
359 // Uses a ConnectionId of 42. | 365 // Uses a ConnectionId of 42. |
360 MockConnection(IPEndPoint address, | 366 MockConnection(IPEndPoint address, |
361 MockConnectionHelper* helper, | 367 MockConnectionHelper* helper, |
| 368 MockAlarmFactory* alarm_factory, |
362 Perspective perspective); | 369 Perspective perspective); |
363 | 370 |
364 // Uses 127.0.0.1:123. | 371 // Uses 127.0.0.1:123. |
365 MockConnection(QuicConnectionId connection_id, | 372 MockConnection(QuicConnectionId connection_id, |
366 MockConnectionHelper* helper, | 373 MockConnectionHelper* helper, |
| 374 MockAlarmFactory* alarm_factory, |
367 Perspective perspective); | 375 Perspective perspective); |
368 | 376 |
369 // Uses a ConnectionId of 42, and 127.0.0.1:123. | 377 // Uses a ConnectionId of 42, and 127.0.0.1:123. |
370 MockConnection(MockConnectionHelper* helper, | 378 MockConnection(MockConnectionHelper* helper, |
| 379 MockAlarmFactory* alarm_factory, |
371 Perspective perspective, | 380 Perspective perspective, |
372 const QuicVersionVector& supported_versions); | 381 const QuicVersionVector& supported_versions); |
373 | 382 |
374 MockConnection(QuicConnectionId connection_id, | 383 MockConnection(QuicConnectionId connection_id, |
375 IPEndPoint address, | 384 IPEndPoint address, |
376 MockConnectionHelper* helper, | 385 MockConnectionHelper* helper, |
| 386 MockAlarmFactory* alarm_factory, |
377 Perspective perspective, | 387 Perspective perspective, |
378 const QuicVersionVector& supported_versions); | 388 const QuicVersionVector& supported_versions); |
379 | 389 |
380 ~MockConnection() override; | 390 ~MockConnection() override; |
381 | 391 |
382 // If the constructor that uses a MockConnectionHelper has been used then | 392 // If the constructor that uses a MockConnectionHelper has been used then |
383 // this method | 393 // this method |
384 // will advance the time of the MockClock. | 394 // will advance the time of the MockClock. |
385 void AdvanceTime(QuicTime::Delta delta); | 395 void AdvanceTime(QuicTime::Delta delta); |
386 | 396 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 const std::string& reason) { | 440 const std::string& reason) { |
431 QuicConnection::SendGoAway(error, last_good_stream_id, reason); | 441 QuicConnection::SendGoAway(error, last_good_stream_id, reason); |
432 } | 442 } |
433 | 443 |
434 private: | 444 private: |
435 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 445 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
436 }; | 446 }; |
437 | 447 |
438 class PacketSavingConnection : public MockConnection { | 448 class PacketSavingConnection : public MockConnection { |
439 public: | 449 public: |
440 PacketSavingConnection(MockConnectionHelper* helper, Perspective perspective); | 450 PacketSavingConnection(MockConnectionHelper* helper, |
| 451 MockAlarmFactory* alarm_factory, |
| 452 Perspective perspective); |
441 | 453 |
442 PacketSavingConnection(MockConnectionHelper* helper, | 454 PacketSavingConnection(MockConnectionHelper* helper, |
| 455 MockAlarmFactory* alarm_factory, |
443 Perspective perspective, | 456 Perspective perspective, |
444 const QuicVersionVector& supported_versions); | 457 const QuicVersionVector& supported_versions); |
445 | 458 |
446 ~PacketSavingConnection() override; | 459 ~PacketSavingConnection() override; |
447 | 460 |
448 void SendOrQueuePacket(SerializedPacket* packet) override; | 461 void SendOrQueuePacket(SerializedPacket* packet) override; |
449 | 462 |
450 std::vector<QuicEncryptedPacket*> encrypted_packets_; | 463 std::vector<QuicEncryptedPacket*> encrypted_packets_; |
451 | 464 |
452 private: | 465 private: |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 // client_connection: Pointer reference for newly created | 809 // client_connection: Pointer reference for newly created |
797 // connection. This object will be owned by the | 810 // connection. This object will be owned by the |
798 // client_session. | 811 // client_session. |
799 // client_session: Pointer reference for the newly created client | 812 // client_session: Pointer reference for the newly created client |
800 // session. The new object will be owned by the caller. | 813 // session. The new object will be owned by the caller. |
801 void CreateClientSessionForTest(QuicServerId server_id, | 814 void CreateClientSessionForTest(QuicServerId server_id, |
802 bool supports_stateless_rejects, | 815 bool supports_stateless_rejects, |
803 QuicTime::Delta connection_start_time, | 816 QuicTime::Delta connection_start_time, |
804 QuicVersionVector supported_versions, | 817 QuicVersionVector supported_versions, |
805 MockConnectionHelper* helper, | 818 MockConnectionHelper* helper, |
| 819 MockAlarmFactory* alarm_factory, |
806 QuicCryptoClientConfig* crypto_client_config, | 820 QuicCryptoClientConfig* crypto_client_config, |
807 PacketSavingConnection** client_connection, | 821 PacketSavingConnection** client_connection, |
808 TestQuicSpdyClientSession** client_session); | 822 TestQuicSpdyClientSession** client_session); |
809 | 823 |
810 // Creates a server session for testing. | 824 // Creates a server session for testing. |
811 // | 825 // |
812 // server_id: The server id associated with this stream. | 826 // server_id: The server id associated with this stream. |
813 // connection_start_time: The time to set for the connection clock. | 827 // connection_start_time: The time to set for the connection clock. |
814 // Needed for strike-register nonce verification. The server | 828 // Needed for strike-register nonce verification. The server |
815 // connection_start_time should be synchronized witht the client | 829 // connection_start_time should be synchronized witht the client |
816 // start time, otherwise nonce verification will fail. | 830 // start time, otherwise nonce verification will fail. |
817 // supported_versions: Set of QUIC versions this server supports. | 831 // supported_versions: Set of QUIC versions this server supports. |
818 // helper: Pointer to the MockConnectionHelper to use for the session. | 832 // helper: Pointer to the MockConnectionHelper to use for the session. |
819 // crypto_server_config: Pointer to the crypto server config. | 833 // crypto_server_config: Pointer to the crypto server config. |
820 // server_connection: Pointer reference for newly created | 834 // server_connection: Pointer reference for newly created |
821 // connection. This object will be owned by the | 835 // connection. This object will be owned by the |
822 // server_session. | 836 // server_session. |
823 // server_session: Pointer reference for the newly created server | 837 // server_session: Pointer reference for the newly created server |
824 // session. The new object will be owned by the caller. | 838 // session. The new object will be owned by the caller. |
825 void CreateServerSessionForTest( | 839 void CreateServerSessionForTest( |
826 QuicServerId server_id, | 840 QuicServerId server_id, |
827 QuicTime::Delta connection_start_time, | 841 QuicTime::Delta connection_start_time, |
828 QuicVersionVector supported_versions, | 842 QuicVersionVector supported_versions, |
829 MockConnectionHelper* helper, | 843 MockConnectionHelper* helper, |
| 844 MockAlarmFactory* alarm_factory, |
830 QuicCryptoServerConfig* crypto_server_config, | 845 QuicCryptoServerConfig* crypto_server_config, |
831 QuicCompressedCertsCache* compressed_certs_cache, | 846 QuicCompressedCertsCache* compressed_certs_cache, |
832 PacketSavingConnection** server_connection, | 847 PacketSavingConnection** server_connection, |
833 TestQuicSpdyServerSession** server_session); | 848 TestQuicSpdyServerSession** server_session); |
834 | 849 |
835 // Helper to generate client side stream ids, generalizes | 850 // Helper to generate client side stream ids, generalizes |
836 // kClientDataStreamId1 etc. above. | 851 // kClientDataStreamId1 etc. above. |
837 QuicStreamId QuicClientDataStreamId(int i); | 852 QuicStreamId QuicClientDataStreamId(int i); |
838 | 853 |
839 } // namespace test | 854 } // namespace test |
840 } // namespace net | 855 } // namespace net |
841 | 856 |
842 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 857 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |