Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: net/quic/test_tools/quic_test_utils.h

Issue 1898793003: Make QuicDispatcher's helper and alarm factory arguments unique_ptrs to make ownership clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@119871679
Patch Set: fixing rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 private: 311 private:
312 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); 312 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor);
313 }; 313 };
314 314
315 class MockConnectionHelper : public QuicConnectionHelperInterface { 315 class MockConnectionHelper : public QuicConnectionHelperInterface {
316 public: 316 public:
317 MockConnectionHelper(); 317 MockConnectionHelper();
318 ~MockConnectionHelper() override; 318 ~MockConnectionHelper() override;
319 const QuicClock* GetClock() const override; 319 const QuicClock* GetClock() const override;
320 QuicRandom* GetRandomGenerator() override; 320 QuicRandom* GetRandomGenerator() override;
321 QuicBufferAllocator* GetBufferAllocator() override;
322 void AdvanceTime(QuicTime::Delta delta);
323
324 private:
325 MockClock clock_;
326 MockRandom random_generator_;
327 SimpleBufferAllocator buffer_allocator_;
328
329 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper);
330 };
331
332 class MockAlarmFactory : public QuicAlarmFactory {
333 public:
321 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; 334 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
322 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( 335 QuicArenaScopedPtr<QuicAlarm> CreateAlarm(
323 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, 336 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
324 QuicConnectionArena* arena) override; 337 QuicConnectionArena* arena) override;
325 QuicBufferAllocator* GetBufferAllocator() override;
326 void AdvanceTime(QuicTime::Delta delta);
327 338
328 // No-op alarm implementation 339 // No-op alarm implementation
329 class TestAlarm : public QuicAlarm { 340 class TestAlarm : public QuicAlarm {
330 public: 341 public:
331 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) 342 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate)
332 : QuicAlarm(std::move(delegate)) {} 343 : QuicAlarm(std::move(delegate)) {}
333 344
334 void SetImpl() override {} 345 void SetImpl() override {}
335 void CancelImpl() override {} 346 void CancelImpl() override {}
336 347
337 using QuicAlarm::Fire; 348 using QuicAlarm::Fire;
338 }; 349 };
339 350
340 void FireAlarm(QuicAlarm* alarm) { 351 void FireAlarm(QuicAlarm* alarm) {
341 reinterpret_cast<TestAlarm*>(alarm)->Fire(); 352 reinterpret_cast<TestAlarm*>(alarm)->Fire();
342 } 353 }
343
344 private:
345 MockClock clock_;
346 MockRandom random_generator_;
347 SimpleBufferAllocator buffer_allocator_;
348
349 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper);
350 }; 354 };
351 355
352 class MockConnection : public QuicConnection { 356 class MockConnection : public QuicConnection {
353 public: 357 public:
354 // Uses a ConnectionId of 42 and 127.0.0.1:123. 358 // Uses a ConnectionId of 42 and 127.0.0.1:123.
355 MockConnection(MockConnectionHelper* helper, Perspective perspective); 359 MockConnection(MockConnectionHelper* helper,
360 MockAlarmFactory* alarm_factory,
361 Perspective perspective);
356 362
357 // Uses a ConnectionId of 42. 363 // Uses a ConnectionId of 42.
358 MockConnection(IPEndPoint address, 364 MockConnection(IPEndPoint address,
359 MockConnectionHelper* helper, 365 MockConnectionHelper* helper,
366 MockAlarmFactory* alarm_factory,
360 Perspective perspective); 367 Perspective perspective);
361 368
362 // Uses 127.0.0.1:123. 369 // Uses 127.0.0.1:123.
363 MockConnection(QuicConnectionId connection_id, 370 MockConnection(QuicConnectionId connection_id,
364 MockConnectionHelper* helper, 371 MockConnectionHelper* helper,
372 MockAlarmFactory* alarm_factory,
365 Perspective perspective); 373 Perspective perspective);
366 374
367 // Uses a ConnectionId of 42, and 127.0.0.1:123. 375 // Uses a ConnectionId of 42, and 127.0.0.1:123.
368 MockConnection(MockConnectionHelper* helper, 376 MockConnection(MockConnectionHelper* helper,
377 MockAlarmFactory* alarm_factory,
369 Perspective perspective, 378 Perspective perspective,
370 const QuicVersionVector& supported_versions); 379 const QuicVersionVector& supported_versions);
371 380
372 MockConnection(QuicConnectionId connection_id, 381 MockConnection(QuicConnectionId connection_id,
373 IPEndPoint address, 382 IPEndPoint address,
374 MockConnectionHelper* helper, 383 MockConnectionHelper* helper,
384 MockAlarmFactory* alarm_factory,
375 Perspective perspective, 385 Perspective perspective,
376 const QuicVersionVector& supported_versions); 386 const QuicVersionVector& supported_versions);
377 387
378 ~MockConnection() override; 388 ~MockConnection() override;
379 389
380 // If the constructor that uses a MockConnectionHelper has been used then 390 // If the constructor that uses a MockConnectionHelper has been used then
381 // this method 391 // this method
382 // will advance the time of the MockClock. 392 // will advance the time of the MockClock.
383 void AdvanceTime(QuicTime::Delta delta); 393 void AdvanceTime(QuicTime::Delta delta);
384 394
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 const std::string& reason) { 438 const std::string& reason) {
429 QuicConnection::SendGoAway(error, last_good_stream_id, reason); 439 QuicConnection::SendGoAway(error, last_good_stream_id, reason);
430 } 440 }
431 441
432 private: 442 private:
433 DISALLOW_COPY_AND_ASSIGN(MockConnection); 443 DISALLOW_COPY_AND_ASSIGN(MockConnection);
434 }; 444 };
435 445
436 class PacketSavingConnection : public MockConnection { 446 class PacketSavingConnection : public MockConnection {
437 public: 447 public:
438 PacketSavingConnection(MockConnectionHelper* helper, Perspective perspective); 448 PacketSavingConnection(MockConnectionHelper* helper,
449 MockAlarmFactory* alarm_factory,
450 Perspective perspective);
439 451
440 PacketSavingConnection(MockConnectionHelper* helper, 452 PacketSavingConnection(MockConnectionHelper* helper,
453 MockAlarmFactory* alarm_factory,
441 Perspective perspective, 454 Perspective perspective,
442 const QuicVersionVector& supported_versions); 455 const QuicVersionVector& supported_versions);
443 456
444 ~PacketSavingConnection() override; 457 ~PacketSavingConnection() override;
445 458
446 void SendOrQueuePacket(SerializedPacket* packet) override; 459 void SendOrQueuePacket(SerializedPacket* packet) override;
447 460
448 std::vector<QuicEncryptedPacket*> encrypted_packets_; 461 std::vector<QuicEncryptedPacket*> encrypted_packets_;
449 462
450 private: 463 private:
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // client_connection: Pointer reference for newly created 797 // client_connection: Pointer reference for newly created
785 // connection. This object will be owned by the 798 // connection. This object will be owned by the
786 // client_session. 799 // client_session.
787 // client_session: Pointer reference for the newly created client 800 // client_session: Pointer reference for the newly created client
788 // session. The new object will be owned by the caller. 801 // session. The new object will be owned by the caller.
789 void CreateClientSessionForTest(QuicServerId server_id, 802 void CreateClientSessionForTest(QuicServerId server_id,
790 bool supports_stateless_rejects, 803 bool supports_stateless_rejects,
791 QuicTime::Delta connection_start_time, 804 QuicTime::Delta connection_start_time,
792 QuicVersionVector supported_versions, 805 QuicVersionVector supported_versions,
793 MockConnectionHelper* helper, 806 MockConnectionHelper* helper,
807 MockAlarmFactory* alarm_factory,
794 QuicCryptoClientConfig* crypto_client_config, 808 QuicCryptoClientConfig* crypto_client_config,
795 PacketSavingConnection** client_connection, 809 PacketSavingConnection** client_connection,
796 TestQuicSpdyClientSession** client_session); 810 TestQuicSpdyClientSession** client_session);
797 811
798 // Creates a server session for testing. 812 // Creates a server session for testing.
799 // 813 //
800 // server_id: The server id associated with this stream. 814 // server_id: The server id associated with this stream.
801 // connection_start_time: The time to set for the connection clock. 815 // connection_start_time: The time to set for the connection clock.
802 // Needed for strike-register nonce verification. The server 816 // Needed for strike-register nonce verification. The server
803 // connection_start_time should be synchronized witht the client 817 // connection_start_time should be synchronized witht the client
804 // start time, otherwise nonce verification will fail. 818 // start time, otherwise nonce verification will fail.
805 // supported_versions: Set of QUIC versions this server supports. 819 // supported_versions: Set of QUIC versions this server supports.
806 // helper: Pointer to the MockConnectionHelper to use for the session. 820 // helper: Pointer to the MockConnectionHelper to use for the session.
807 // crypto_server_config: Pointer to the crypto server config. 821 // crypto_server_config: Pointer to the crypto server config.
808 // server_connection: Pointer reference for newly created 822 // server_connection: Pointer reference for newly created
809 // connection. This object will be owned by the 823 // connection. This object will be owned by the
810 // server_session. 824 // server_session.
811 // server_session: Pointer reference for the newly created server 825 // server_session: Pointer reference for the newly created server
812 // session. The new object will be owned by the caller. 826 // session. The new object will be owned by the caller.
813 void CreateServerSessionForTest( 827 void CreateServerSessionForTest(
814 QuicServerId server_id, 828 QuicServerId server_id,
815 QuicTime::Delta connection_start_time, 829 QuicTime::Delta connection_start_time,
816 QuicVersionVector supported_versions, 830 QuicVersionVector supported_versions,
817 MockConnectionHelper* helper, 831 MockConnectionHelper* helper,
832 MockAlarmFactory* alarm_factory,
818 QuicCryptoServerConfig* crypto_server_config, 833 QuicCryptoServerConfig* crypto_server_config,
819 QuicCompressedCertsCache* compressed_certs_cache, 834 QuicCompressedCertsCache* compressed_certs_cache,
820 PacketSavingConnection** server_connection, 835 PacketSavingConnection** server_connection,
821 TestQuicSpdyServerSession** server_session); 836 TestQuicSpdyServerSession** server_session);
822 837
823 // Helper to generate client side stream ids, generalizes 838 // Helper to generate client side stream ids, generalizes
824 // kClientDataStreamId1 etc. above. 839 // kClientDataStreamId1 etc. above.
825 QuicStreamId QuicClientDataStreamId(int i); 840 QuicStreamId QuicClientDataStreamId(int i);
826 841
827 } // namespace test 842 } // namespace test
828 } // namespace net 843 } // namespace net
829 844
830 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 845 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698