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 <string> | 10 #include <string> |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); | 287 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); |
288 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); | 288 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); |
289 MOCK_METHOD1(OnSuccessfulVersionNegotiation, | 289 MOCK_METHOD1(OnSuccessfulVersionNegotiation, |
290 void(const QuicVersion& version)); | 290 void(const QuicVersion& version)); |
291 MOCK_METHOD0(OnConfigNegotiated, void()); | 291 MOCK_METHOD0(OnConfigNegotiated, void()); |
292 | 292 |
293 private: | 293 private: |
294 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | 294 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); |
295 }; | 295 }; |
296 | 296 |
297 class MockHelper : public QuicConnectionHelperInterface { | 297 class MockConnectionHelper : public QuicConnectionHelperInterface { |
298 public: | 298 public: |
299 MockHelper(); | 299 MockConnectionHelper(); |
300 ~MockHelper() override; | 300 ~MockConnectionHelper() override; |
301 const QuicClock* GetClock() const override; | 301 const QuicClock* GetClock() const override; |
302 QuicRandom* GetRandomGenerator() override; | 302 QuicRandom* GetRandomGenerator() override; |
303 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; | 303 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
304 void AdvanceTime(QuicTime::Delta delta); | 304 void AdvanceTime(QuicTime::Delta delta); |
305 | 305 |
306 private: | 306 private: |
307 MockClock clock_; | 307 MockClock clock_; |
308 MockRandom random_generator_; | 308 MockRandom random_generator_; |
309 | 309 |
310 DISALLOW_COPY_AND_ASSIGN(MockHelper); | 310 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); |
311 }; | 311 }; |
312 | 312 |
313 class NiceMockPacketWriterFactory : public QuicConnection::PacketWriterFactory { | 313 class NiceMockPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
314 public: | 314 public: |
315 NiceMockPacketWriterFactory() {} | 315 NiceMockPacketWriterFactory() {} |
316 ~NiceMockPacketWriterFactory() override {} | 316 ~NiceMockPacketWriterFactory() override {} |
317 | 317 |
318 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override; | 318 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override; |
319 | 319 |
320 private: | 320 private: |
321 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); | 321 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); |
322 }; | 322 }; |
323 | 323 |
324 class MockConnection : public QuicConnection { | 324 class MockConnection : public QuicConnection { |
325 public: | 325 public: |
326 // Uses a ConnectionId of 42 and 127.0.0.1:123. | 326 // Uses a ConnectionId of 42 and 127.0.0.1:123. |
327 MockConnection(MockHelper* helper, Perspective perspective); | 327 MockConnection(MockConnectionHelper* helper, Perspective perspective); |
328 | 328 |
329 // Uses a ConnectionId of 42. | 329 // Uses a ConnectionId of 42. |
330 MockConnection(IPEndPoint address, | 330 MockConnection(IPEndPoint address, |
331 MockHelper* helper, | 331 MockConnectionHelper* helper, |
332 Perspective perspective); | 332 Perspective perspective); |
333 | 333 |
334 // Uses 127.0.0.1:123. | 334 // Uses 127.0.0.1:123. |
335 MockConnection(QuicConnectionId connection_id, | 335 MockConnection(QuicConnectionId connection_id, |
336 MockHelper* helper, | 336 MockConnectionHelper* helper, |
337 Perspective perspective); | 337 Perspective perspective); |
338 | 338 |
339 // Uses a ConnectionId of 42, and 127.0.0.1:123. | 339 // Uses a ConnectionId of 42, and 127.0.0.1:123. |
340 MockConnection(MockHelper* helper, | 340 MockConnection(MockConnectionHelper* helper, |
341 Perspective perspective, | 341 Perspective perspective, |
342 const QuicVersionVector& supported_versions); | 342 const QuicVersionVector& supported_versions); |
343 | 343 |
344 MockConnection(QuicConnectionId connection_id, | 344 MockConnection(QuicConnectionId connection_id, |
345 IPEndPoint address, | 345 IPEndPoint address, |
346 MockHelper* helper, | 346 MockConnectionHelper* helper, |
347 Perspective perspective, | 347 Perspective perspective, |
348 const QuicVersionVector& supported_versions); | 348 const QuicVersionVector& supported_versions); |
349 | 349 |
350 ~MockConnection() override; | 350 ~MockConnection() override; |
351 | 351 |
352 // If the constructor that uses a MockHelper has been used then this method | 352 // If the constructor that uses a MockConnectionHelper has been used then |
| 353 // this method |
353 // will advance the time of the MockClock. | 354 // will advance the time of the MockClock. |
354 void AdvanceTime(QuicTime::Delta delta); | 355 void AdvanceTime(QuicTime::Delta delta); |
355 | 356 |
356 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, | 357 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, |
357 const IPEndPoint& peer_address, | 358 const IPEndPoint& peer_address, |
358 const QuicEncryptedPacket& packet)); | 359 const QuicEncryptedPacket& packet)); |
359 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); | 360 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); |
360 MOCK_METHOD2(SendConnectionCloseWithDetails, | 361 MOCK_METHOD2(SendConnectionCloseWithDetails, |
361 void(QuicErrorCode error, const std::string& details)); | 362 void(QuicErrorCode error, const std::string& details)); |
362 MOCK_METHOD2(SendConnectionClosePacket, | 363 MOCK_METHOD2(SendConnectionClosePacket, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 const std::string& reason) { | 398 const std::string& reason) { |
398 QuicConnection::SendGoAway(error, last_good_stream_id, reason); | 399 QuicConnection::SendGoAway(error, last_good_stream_id, reason); |
399 } | 400 } |
400 | 401 |
401 private: | 402 private: |
402 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 403 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
403 }; | 404 }; |
404 | 405 |
405 class PacketSavingConnection : public MockConnection { | 406 class PacketSavingConnection : public MockConnection { |
406 public: | 407 public: |
407 PacketSavingConnection(MockHelper* helper, Perspective perspective); | 408 PacketSavingConnection(MockConnectionHelper* helper, Perspective perspective); |
408 | 409 |
409 PacketSavingConnection(MockHelper* helper, | 410 PacketSavingConnection(MockConnectionHelper* helper, |
410 Perspective perspective, | 411 Perspective perspective, |
411 const QuicVersionVector& supported_versions); | 412 const QuicVersionVector& supported_versions); |
412 | 413 |
413 ~PacketSavingConnection() override; | 414 ~PacketSavingConnection() override; |
414 | 415 |
415 void SendOrQueuePacket(QueuedPacket packet) override; | 416 void SendOrQueuePacket(QueuedPacket packet) override; |
416 | 417 |
417 std::vector<QuicEncryptedPacket*> encrypted_packets_; | 418 std::vector<QuicEncryptedPacket*> encrypted_packets_; |
418 | 419 |
419 private: | 420 private: |
(...skipping 21 matching lines...) Expand all Loading... |
441 base::StringPiece headers_data)); | 442 base::StringPiece headers_data)); |
442 MOCK_METHOD2(OnStreamHeadersPriority, void(QuicStreamId stream_id, | 443 MOCK_METHOD2(OnStreamHeadersPriority, void(QuicStreamId stream_id, |
443 QuicPriority priority)); | 444 QuicPriority priority)); |
444 MOCK_METHOD3(OnStreamHeadersComplete, void(QuicStreamId stream_id, | 445 MOCK_METHOD3(OnStreamHeadersComplete, void(QuicStreamId stream_id, |
445 bool fin, | 446 bool fin, |
446 size_t frame_len)); | 447 size_t frame_len)); |
447 MOCK_METHOD3(SendRstStream, void(QuicStreamId stream_id, | 448 MOCK_METHOD3(SendRstStream, void(QuicStreamId stream_id, |
448 QuicRstStreamErrorCode error, | 449 QuicRstStreamErrorCode error, |
449 QuicStreamOffset bytes_written)); | 450 QuicStreamOffset bytes_written)); |
450 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); | 451 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 452 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); |
451 | 453 |
452 using QuicSession::ActivateStream; | 454 using QuicSession::ActivateStream; |
453 | 455 |
454 private: | 456 private: |
455 scoped_ptr<QuicCryptoStream> crypto_stream_; | 457 scoped_ptr<QuicCryptoStream> crypto_stream_; |
456 | 458 |
457 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); | 459 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); |
458 }; | 460 }; |
459 | 461 |
460 class TestQuicSpdyServerSession : public QuicSpdySession { | 462 class TestQuicSpdyServerSession : public QuicSpdySession { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 }; | 725 }; |
724 | 726 |
725 // Creates a client session for testing. | 727 // Creates a client session for testing. |
726 // | 728 // |
727 // server_id: The server id associated with this stream. | 729 // server_id: The server id associated with this stream. |
728 // supports_stateless_rejects: Does this client support stateless rejects. | 730 // supports_stateless_rejects: Does this client support stateless rejects. |
729 // connection_start_time: The time to set for the connection clock. | 731 // connection_start_time: The time to set for the connection clock. |
730 // Needed for strike-register nonce verification. The client | 732 // Needed for strike-register nonce verification. The client |
731 // connection_start_time should be synchronized witht the server | 733 // connection_start_time should be synchronized witht the server |
732 // start time, otherwise nonce verification will fail. | 734 // start time, otherwise nonce verification will fail. |
733 // helper: Pointer to the MockHelper to use for the session. | 735 // helper: Pointer to the MockConnectionHelper to use for the session. |
734 // crypto_client_config: Pointer to the crypto client config. | 736 // crypto_client_config: Pointer to the crypto client config. |
735 // client_connection: Pointer reference for newly created | 737 // client_connection: Pointer reference for newly created |
736 // connection. This object will be owned by the | 738 // connection. This object will be owned by the |
737 // client_session. | 739 // client_session. |
738 // client_session: Pointer reference for the newly created client | 740 // client_session: Pointer reference for the newly created client |
739 // session. The new object will be owned by the caller. | 741 // session. The new object will be owned by the caller. |
740 void CreateClientSessionForTest(QuicServerId server_id, | 742 void CreateClientSessionForTest(QuicServerId server_id, |
741 bool supports_stateless_rejects, | 743 bool supports_stateless_rejects, |
742 QuicTime::Delta connection_start_time, | 744 QuicTime::Delta connection_start_time, |
743 MockHelper* helper, | 745 MockConnectionHelper* helper, |
744 QuicCryptoClientConfig* crypto_client_config, | 746 QuicCryptoClientConfig* crypto_client_config, |
745 PacketSavingConnection** client_connection, | 747 PacketSavingConnection** client_connection, |
746 TestQuicSpdyClientSession** client_session); | 748 TestQuicSpdyClientSession** client_session); |
747 | 749 |
748 // Creates a server session for testing. | 750 // Creates a server session for testing. |
749 // | 751 // |
750 // server_id: The server id associated with this stream. | 752 // server_id: The server id associated with this stream. |
751 // connection_start_time: The time to set for the connection clock. | 753 // connection_start_time: The time to set for the connection clock. |
752 // Needed for strike-register nonce verification. The server | 754 // Needed for strike-register nonce verification. The server |
753 // connection_start_time should be synchronized witht the client | 755 // connection_start_time should be synchronized witht the client |
754 // start time, otherwise nonce verification will fail. | 756 // start time, otherwise nonce verification will fail. |
755 // helper: Pointer to the MockHelper to use for the session. | 757 // helper: Pointer to the MockConnectionHelper to use for the session. |
756 // crypto_server_config: Pointer to the crypto server config. | 758 // crypto_server_config: Pointer to the crypto server config. |
757 // server_connection: Pointer reference for newly created | 759 // server_connection: Pointer reference for newly created |
758 // connection. This object will be owned by the | 760 // connection. This object will be owned by the |
759 // server_session. | 761 // server_session. |
760 // server_session: Pointer reference for the newly created server | 762 // server_session: Pointer reference for the newly created server |
761 // session. The new object will be owned by the caller. | 763 // session. The new object will be owned by the caller. |
762 void CreateServerSessionForTest(QuicServerId server_id, | 764 void CreateServerSessionForTest(QuicServerId server_id, |
763 QuicTime::Delta connection_start_time, | 765 QuicTime::Delta connection_start_time, |
764 MockHelper* helper, | 766 MockConnectionHelper* helper, |
765 QuicCryptoServerConfig* crypto_server_config, | 767 QuicCryptoServerConfig* crypto_server_config, |
766 PacketSavingConnection** server_connection, | 768 PacketSavingConnection** server_connection, |
767 TestQuicSpdyServerSession** server_session); | 769 TestQuicSpdyServerSession** server_session); |
768 | 770 |
769 // Helper to generate client side stream ids, generalizes | 771 // Helper to generate client side stream ids, generalizes |
770 // kClientDataStreamId1 etc. above. | 772 // kClientDataStreamId1 etc. above. |
771 QuicStreamId QuicClientDataStreamId(int i); | 773 QuicStreamId QuicClientDataStreamId(int i); |
772 | 774 |
773 } // namespace test | 775 } // namespace test |
774 } // namespace net | 776 } // namespace net |
775 | 777 |
776 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 778 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |