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

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

Issue 1979763002: Landing Recent QUIC changes until Sun May 8 00:39:29 2016 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/crypto_test_utils.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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; 304 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override;
305 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; 305 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override;
306 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; 306 bool OnBlockedFrame(const QuicBlockedFrame& frame) override;
307 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; 307 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override;
308 void OnPacketComplete() override {} 308 void OnPacketComplete() override {}
309 309
310 private: 310 private:
311 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); 311 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor);
312 }; 312 };
313 313
314 class MockConnectionVisitor : public QuicConnectionVisitorInterface { 314 class MockQuicConnectionVisitor : public QuicConnectionVisitorInterface {
315 public: 315 public:
316 MockConnectionVisitor(); 316 MockQuicConnectionVisitor();
317 ~MockConnectionVisitor() override; 317 ~MockQuicConnectionVisitor() override;
318 318
319 MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame& frame)); 319 MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame& frame));
320 MOCK_METHOD1(OnWindowUpdateFrame, void(const QuicWindowUpdateFrame& frame)); 320 MOCK_METHOD1(OnWindowUpdateFrame, void(const QuicWindowUpdateFrame& frame));
321 MOCK_METHOD1(OnBlockedFrame, void(const QuicBlockedFrame& frame)); 321 MOCK_METHOD1(OnBlockedFrame, void(const QuicBlockedFrame& frame));
322 MOCK_METHOD1(OnRstStream, void(const QuicRstStreamFrame& frame)); 322 MOCK_METHOD1(OnRstStream, void(const QuicRstStreamFrame& frame));
323 MOCK_METHOD1(OnGoAway, void(const QuicGoAwayFrame& frame)); 323 MOCK_METHOD1(OnGoAway, void(const QuicGoAwayFrame& frame));
324 MOCK_METHOD3(OnConnectionClosed, 324 MOCK_METHOD3(OnConnectionClosed,
325 void(QuicErrorCode error, 325 void(QuicErrorCode error,
326 const std::string& error_details, 326 const std::string& error_details,
327 ConnectionCloseSource source)); 327 ConnectionCloseSource source));
328 MOCK_METHOD0(OnWriteBlocked, void()); 328 MOCK_METHOD0(OnWriteBlocked, void());
329 MOCK_METHOD0(OnCanWrite, void()); 329 MOCK_METHOD0(OnCanWrite, void());
330 MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now)); 330 MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now));
331 MOCK_METHOD1(OnConnectionMigration, void(PeerAddressChangeType type)); 331 MOCK_METHOD1(OnConnectionMigration, void(PeerAddressChangeType type));
332 MOCK_METHOD0(OnPathDegrading, void()); 332 MOCK_METHOD0(OnPathDegrading, void());
333 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); 333 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool());
334 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); 334 MOCK_CONST_METHOD0(HasPendingHandshake, bool());
335 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); 335 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool());
336 MOCK_METHOD1(OnSuccessfulVersionNegotiation, 336 MOCK_METHOD1(OnSuccessfulVersionNegotiation,
337 void(const QuicVersion& version)); 337 void(const QuicVersion& version));
338 MOCK_METHOD0(OnConfigNegotiated, void()); 338 MOCK_METHOD0(OnConfigNegotiated, void());
339 MOCK_METHOD0(PostProcessAfterData, void()); 339 MOCK_METHOD0(PostProcessAfterData, void());
340 340
341 private: 341 private:
342 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); 342 DISALLOW_COPY_AND_ASSIGN(MockQuicConnectionVisitor);
343 }; 343 };
344 344
345 class MockConnectionHelper : public QuicConnectionHelperInterface { 345 class MockQuicConnectionHelper : public QuicConnectionHelperInterface {
346 public: 346 public:
347 MockConnectionHelper(); 347 MockQuicConnectionHelper();
348 ~MockConnectionHelper() override; 348 ~MockQuicConnectionHelper() override;
349 const QuicClock* GetClock() const override; 349 const QuicClock* GetClock() const override;
350 QuicRandom* GetRandomGenerator() override; 350 QuicRandom* GetRandomGenerator() override;
351 QuicBufferAllocator* GetBufferAllocator() override; 351 QuicBufferAllocator* GetBufferAllocator() override;
352 void AdvanceTime(QuicTime::Delta delta); 352 void AdvanceTime(QuicTime::Delta delta);
353 353
354 private: 354 private:
355 MockClock clock_; 355 MockClock clock_;
356 MockRandom random_generator_; 356 MockRandom random_generator_;
357 SimpleBufferAllocator buffer_allocator_; 357 SimpleBufferAllocator buffer_allocator_;
358 358
359 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); 359 DISALLOW_COPY_AND_ASSIGN(MockQuicConnectionHelper);
360 }; 360 };
361 361
362 class MockAlarmFactory : public QuicAlarmFactory { 362 class MockAlarmFactory : public QuicAlarmFactory {
363 public: 363 public:
364 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; 364 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
365 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( 365 QuicArenaScopedPtr<QuicAlarm> CreateAlarm(
366 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, 366 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
367 QuicConnectionArena* arena) override; 367 QuicConnectionArena* arena) override;
368 368
369 // No-op alarm implementation 369 // No-op alarm implementation
370 class TestAlarm : public QuicAlarm { 370 class TestAlarm : public QuicAlarm {
371 public: 371 public:
372 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) 372 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate)
373 : QuicAlarm(std::move(delegate)) {} 373 : QuicAlarm(std::move(delegate)) {}
374 374
375 void SetImpl() override {} 375 void SetImpl() override {}
376 void CancelImpl() override {} 376 void CancelImpl() override {}
377 377
378 using QuicAlarm::Fire; 378 using QuicAlarm::Fire;
379 }; 379 };
380 380
381 void FireAlarm(QuicAlarm* alarm) { 381 void FireAlarm(QuicAlarm* alarm) {
382 reinterpret_cast<TestAlarm*>(alarm)->Fire(); 382 reinterpret_cast<TestAlarm*>(alarm)->Fire();
383 } 383 }
384 }; 384 };
385 385
386 class MockConnection : public QuicConnection { 386 class MockQuicConnection : public QuicConnection {
387 public: 387 public:
388 // Uses a ConnectionId of 42 and 127.0.0.1:123. 388 // Uses a ConnectionId of 42 and 127.0.0.1:123.
389 MockConnection(MockConnectionHelper* helper, 389 MockQuicConnection(MockQuicConnectionHelper* helper,
390 MockAlarmFactory* alarm_factory, 390 MockAlarmFactory* alarm_factory,
391 Perspective perspective); 391 Perspective perspective);
392 392
393 // Uses a ConnectionId of 42. 393 // Uses a ConnectionId of 42.
394 MockConnection(IPEndPoint address, 394 MockQuicConnection(IPEndPoint address,
395 MockConnectionHelper* helper, 395 MockQuicConnectionHelper* helper,
396 MockAlarmFactory* alarm_factory, 396 MockAlarmFactory* alarm_factory,
397 Perspective perspective); 397 Perspective perspective);
398 398
399 // Uses 127.0.0.1:123. 399 // Uses 127.0.0.1:123.
400 MockConnection(QuicConnectionId connection_id, 400 MockQuicConnection(QuicConnectionId connection_id,
401 MockConnectionHelper* helper, 401 MockQuicConnectionHelper* helper,
402 MockAlarmFactory* alarm_factory, 402 MockAlarmFactory* alarm_factory,
403 Perspective perspective); 403 Perspective perspective);
404 404
405 // Uses a ConnectionId of 42, and 127.0.0.1:123. 405 // Uses a ConnectionId of 42, and 127.0.0.1:123.
406 MockConnection(MockConnectionHelper* helper, 406 MockQuicConnection(MockQuicConnectionHelper* helper,
407 MockAlarmFactory* alarm_factory, 407 MockAlarmFactory* alarm_factory,
408 Perspective perspective, 408 Perspective perspective,
409 const QuicVersionVector& supported_versions); 409 const QuicVersionVector& supported_versions);
410 410
411 MockConnection(QuicConnectionId connection_id, 411 MockQuicConnection(QuicConnectionId connection_id,
412 IPEndPoint address, 412 IPEndPoint address,
413 MockConnectionHelper* helper, 413 MockQuicConnectionHelper* helper,
414 MockAlarmFactory* alarm_factory, 414 MockAlarmFactory* alarm_factory,
415 Perspective perspective, 415 Perspective perspective,
416 const QuicVersionVector& supported_versions); 416 const QuicVersionVector& supported_versions);
417 417
418 ~MockConnection() override; 418 ~MockQuicConnection() override;
419 419
420 // If the constructor that uses a MockConnectionHelper has been used then 420 // If the constructor that uses a MockQuicConnectionHelper has been used then
421 // this method 421 // this method
422 // will advance the time of the MockClock. 422 // will advance the time of the MockClock.
423 void AdvanceTime(QuicTime::Delta delta); 423 void AdvanceTime(QuicTime::Delta delta);
424 424
425 MOCK_METHOD3(ProcessUdpPacket, 425 MOCK_METHOD3(ProcessUdpPacket,
426 void(const IPEndPoint& self_address, 426 void(const IPEndPoint& self_address,
427 const IPEndPoint& peer_address, 427 const IPEndPoint& peer_address,
428 const QuicReceivedPacket& packet)); 428 const QuicReceivedPacket& packet));
429 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); 429 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error));
430 MOCK_METHOD3(CloseConnection, 430 MOCK_METHOD3(CloseConnection,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 464
465 bool OnProtocolVersionMismatch(QuicVersion version) override { return false; } 465 bool OnProtocolVersionMismatch(QuicVersion version) override { return false; }
466 466
467 void ReallySendGoAway(QuicErrorCode error, 467 void ReallySendGoAway(QuicErrorCode error,
468 QuicStreamId last_good_stream_id, 468 QuicStreamId last_good_stream_id,
469 const std::string& reason) { 469 const std::string& reason) {
470 QuicConnection::SendGoAway(error, last_good_stream_id, reason); 470 QuicConnection::SendGoAway(error, last_good_stream_id, reason);
471 } 471 }
472 472
473 private: 473 private:
474 DISALLOW_COPY_AND_ASSIGN(MockConnection); 474 DISALLOW_COPY_AND_ASSIGN(MockQuicConnection);
475 }; 475 };
476 476
477 class PacketSavingConnection : public MockConnection { 477 class PacketSavingConnection : public MockQuicConnection {
478 public: 478 public:
479 PacketSavingConnection(MockConnectionHelper* helper, 479 PacketSavingConnection(MockQuicConnectionHelper* helper,
480 MockAlarmFactory* alarm_factory, 480 MockAlarmFactory* alarm_factory,
481 Perspective perspective); 481 Perspective perspective);
482 482
483 PacketSavingConnection(MockConnectionHelper* helper, 483 PacketSavingConnection(MockQuicConnectionHelper* helper,
484 MockAlarmFactory* alarm_factory, 484 MockAlarmFactory* alarm_factory,
485 Perspective perspective, 485 Perspective perspective,
486 const QuicVersionVector& supported_versions); 486 const QuicVersionVector& supported_versions);
487 487
488 ~PacketSavingConnection() override; 488 ~PacketSavingConnection() override;
489 489
490 void SendOrQueuePacket(SerializedPacket* packet) override; 490 void SendOrQueuePacket(SerializedPacket* packet) override;
491 491
492 std::vector<QuicEncryptedPacket*> encrypted_packets_; 492 std::vector<QuicEncryptedPacket*> encrypted_packets_;
493 493
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 private: 806 private:
807 DISALLOW_COPY_AND_ASSIGN(MockAckListener); 807 DISALLOW_COPY_AND_ASSIGN(MockAckListener);
808 }; 808 };
809 809
810 class MockNetworkChangeVisitor 810 class MockNetworkChangeVisitor
811 : public QuicSentPacketManager::NetworkChangeVisitor { 811 : public QuicSentPacketManager::NetworkChangeVisitor {
812 public: 812 public:
813 MockNetworkChangeVisitor(); 813 MockNetworkChangeVisitor();
814 ~MockNetworkChangeVisitor() override; 814 ~MockNetworkChangeVisitor() override;
815 815
816 MOCK_METHOD0(OnCongestionWindowChange, void()); 816 MOCK_METHOD0(OnCongestionChange, void());
817 MOCK_METHOD0(OnRttChange, void());
818 MOCK_METHOD0(OnPathDegrading, void()); 817 MOCK_METHOD0(OnPathDegrading, void());
819 818
820 private: 819 private:
821 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); 820 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor);
822 }; 821 };
823 822
824 class MockQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor { 823 class MockQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor {
825 public: 824 public:
826 MockQuicConnectionDebugVisitor(); 825 MockQuicConnectionDebugVisitor();
827 ~MockQuicConnectionDebugVisitor() override; 826 ~MockQuicConnectionDebugVisitor() override;
828 827
829 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&)); 828 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&));
830 829
831 MOCK_METHOD4(OnPacketSent, 830 MOCK_METHOD5(OnPacketSent,
832 void(const SerializedPacket&, 831 void(const SerializedPacket&,
832 QuicPathId,
833 QuicPacketNumber, 833 QuicPacketNumber,
834 TransmissionType, 834 TransmissionType,
835 QuicTime)); 835 QuicTime));
836 836
837 MOCK_METHOD3(OnPacketReceived, 837 MOCK_METHOD3(OnPacketReceived,
838 void(const IPEndPoint&, 838 void(const IPEndPoint&,
839 const IPEndPoint&, 839 const IPEndPoint&,
840 const QuicEncryptedPacket&)); 840 const QuicEncryptedPacket&));
841 841
842 MOCK_METHOD1(OnIncorrectConnectionId, void(QuicConnectionId)); 842 MOCK_METHOD1(OnIncorrectConnectionId, void(QuicConnectionId));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 882
883 // Creates a client session for testing. 883 // Creates a client session for testing.
884 // 884 //
885 // server_id: The server id associated with this stream. 885 // server_id: The server id associated with this stream.
886 // supports_stateless_rejects: Does this client support stateless rejects. 886 // supports_stateless_rejects: Does this client support stateless rejects.
887 // connection_start_time: The time to set for the connection clock. 887 // connection_start_time: The time to set for the connection clock.
888 // Needed for strike-register nonce verification. The client 888 // Needed for strike-register nonce verification. The client
889 // connection_start_time should be synchronized witht the server 889 // connection_start_time should be synchronized witht the server
890 // start time, otherwise nonce verification will fail. 890 // start time, otherwise nonce verification will fail.
891 // supported_versions: Set of QUIC versions this client supports. 891 // supported_versions: Set of QUIC versions this client supports.
892 // helper: Pointer to the MockConnectionHelper to use for the session. 892 // helper: Pointer to the MockQuicConnectionHelper to use for the session.
893 // crypto_client_config: Pointer to the crypto client config. 893 // crypto_client_config: Pointer to the crypto client config.
894 // client_connection: Pointer reference for newly created 894 // client_connection: Pointer reference for newly created
895 // connection. This object will be owned by the 895 // connection. This object will be owned by the
896 // client_session. 896 // client_session.
897 // client_session: Pointer reference for the newly created client 897 // client_session: Pointer reference for the newly created client
898 // session. The new object will be owned by the caller. 898 // session. The new object will be owned by the caller.
899 void CreateClientSessionForTest(QuicServerId server_id, 899 void CreateClientSessionForTest(QuicServerId server_id,
900 bool supports_stateless_rejects, 900 bool supports_stateless_rejects,
901 QuicTime::Delta connection_start_time, 901 QuicTime::Delta connection_start_time,
902 QuicVersionVector supported_versions, 902 QuicVersionVector supported_versions,
903 MockConnectionHelper* helper, 903 MockQuicConnectionHelper* helper,
904 MockAlarmFactory* alarm_factory, 904 MockAlarmFactory* alarm_factory,
905 QuicCryptoClientConfig* crypto_client_config, 905 QuicCryptoClientConfig* crypto_client_config,
906 PacketSavingConnection** client_connection, 906 PacketSavingConnection** client_connection,
907 TestQuicSpdyClientSession** client_session); 907 TestQuicSpdyClientSession** client_session);
908 908
909 // Creates a server session for testing. 909 // Creates a server session for testing.
910 // 910 //
911 // server_id: The server id associated with this stream. 911 // server_id: The server id associated with this stream.
912 // connection_start_time: The time to set for the connection clock. 912 // connection_start_time: The time to set for the connection clock.
913 // Needed for strike-register nonce verification. The server 913 // Needed for strike-register nonce verification. The server
914 // connection_start_time should be synchronized witht the client 914 // connection_start_time should be synchronized witht the client
915 // start time, otherwise nonce verification will fail. 915 // start time, otherwise nonce verification will fail.
916 // supported_versions: Set of QUIC versions this server supports. 916 // supported_versions: Set of QUIC versions this server supports.
917 // helper: Pointer to the MockConnectionHelper to use for the session. 917 // helper: Pointer to the MockQuicConnectionHelper to use for the session.
918 // crypto_server_config: Pointer to the crypto server config. 918 // crypto_server_config: Pointer to the crypto server config.
919 // server_connection: Pointer reference for newly created 919 // server_connection: Pointer reference for newly created
920 // connection. This object will be owned by the 920 // connection. This object will be owned by the
921 // server_session. 921 // server_session.
922 // server_session: Pointer reference for the newly created server 922 // server_session: Pointer reference for the newly created server
923 // session. The new object will be owned by the caller. 923 // session. The new object will be owned by the caller.
924 void CreateServerSessionForTest( 924 void CreateServerSessionForTest(
925 QuicServerId server_id, 925 QuicServerId server_id,
926 QuicTime::Delta connection_start_time, 926 QuicTime::Delta connection_start_time,
927 QuicVersionVector supported_versions, 927 QuicVersionVector supported_versions,
928 MockConnectionHelper* helper, 928 MockQuicConnectionHelper* helper,
929 MockAlarmFactory* alarm_factory, 929 MockAlarmFactory* alarm_factory,
930 QuicCryptoServerConfig* crypto_server_config, 930 QuicCryptoServerConfig* crypto_server_config,
931 QuicCompressedCertsCache* compressed_certs_cache, 931 QuicCompressedCertsCache* compressed_certs_cache,
932 PacketSavingConnection** server_connection, 932 PacketSavingConnection** server_connection,
933 TestQuicSpdyServerSession** server_session); 933 TestQuicSpdyServerSession** server_session);
934 934
935 // Helper to generate client side stream ids, generalizes 935 // Helper to generate client side stream ids, generalizes
936 // kClientDataStreamId1 etc. above. 936 // kClientDataStreamId1 etc. above.
937 QuicStreamId QuicClientDataStreamId(int i); 937 QuicStreamId QuicClientDataStreamId(int i);
938 938
939 } // namespace test 939 } // namespace test
940 } // namespace net 940 } // namespace net
941 941
942 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 942 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.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