| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 14 #include "net/quic/congestion_control/send_algorithm_interface.h" | 15 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 15 #include "net/quic/quic_ack_notifier.h" | 16 #include "net/quic/quic_ack_notifier.h" |
| 16 #include "net/quic/quic_connection.h" | 17 #include "net/quic/quic_connection.h" |
| 17 #include "net/quic/quic_framer.h" | 18 #include "net/quic/quic_framer.h" |
| 18 #include "net/quic/quic_session.h" | 19 #include "net/quic/quic_session.h" |
| 19 #include "net/quic/quic_spdy_decompressor.h" | 20 #include "net/quic/quic_spdy_decompressor.h" |
| 20 #include "net/quic/test_tools/mock_clock.h" | 21 #include "net/quic/test_tools/mock_clock.h" |
| 21 #include "net/quic/test_tools/mock_random.h" | 22 #include "net/quic/test_tools/mock_random.h" |
| 22 #include "net/spdy/spdy_framer.h" | 23 #include "net/spdy/spdy_framer.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 | 27 |
| 27 namespace test { | 28 namespace test { |
| 28 | 29 |
| 29 static const QuicGuid kTestGuid = 42; | 30 static const QuicConnectionId kTestConnectionId = 42; |
| 30 static const int kTestPort = 123; | 31 static const int kTestPort = 123; |
| 31 | 32 |
| 32 // Returns the test peer IP address. | 33 // Returns the test peer IP address. |
| 33 IPAddressNumber TestPeerIPAddress(); | 34 IPAddressNumber TestPeerIPAddress(); |
| 34 | 35 |
| 35 // Upper limit on versions we support. | 36 // Upper limit on versions we support. |
| 36 QuicVersion QuicVersionMax(); | 37 QuicVersion QuicVersionMax(); |
| 37 | 38 |
| 38 // Lower limit on versions we support. | 39 // Lower limit on versions we support. |
| 39 QuicVersion QuicVersionMin(); | 40 QuicVersion QuicVersionMin(); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE; | 266 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE; |
| 266 void AdvanceTime(QuicTime::Delta delta); | 267 void AdvanceTime(QuicTime::Delta delta); |
| 267 | 268 |
| 268 private: | 269 private: |
| 269 MockClock clock_; | 270 MockClock clock_; |
| 270 MockRandom random_generator_; | 271 MockRandom random_generator_; |
| 271 }; | 272 }; |
| 272 | 273 |
| 273 class MockConnection : public QuicConnection { | 274 class MockConnection : public QuicConnection { |
| 274 public: | 275 public: |
| 275 // Uses a MockHelper, GUID of 42, and 127.0.0.1:123. | 276 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123. |
| 276 explicit MockConnection(bool is_server); | 277 explicit MockConnection(bool is_server); |
| 277 | 278 |
| 278 // Uses a MockHelper, GUID of 42. | 279 // Uses a MockHelper, ConnectionId of 42. |
| 279 MockConnection(IPEndPoint address, bool is_server); | 280 MockConnection(IPEndPoint address, bool is_server); |
| 280 | 281 |
| 281 // Uses a MockHelper, and 127.0.0.1:123 | 282 // Uses a MockHelper, and 127.0.0.1:123 |
| 282 MockConnection(QuicGuid guid, bool is_server); | 283 MockConnection(QuicConnectionId connection_id, bool is_server); |
| 283 | 284 |
| 284 // Uses a Mock helper, GUID of 42, and 127.0.0.1:123. | 285 // Uses a Mock helper, ConnectionId of 42, and 127.0.0.1:123. |
| 285 MockConnection(bool is_server, const QuicVersionVector& supported_versions); | 286 MockConnection(bool is_server, const QuicVersionVector& supported_versions); |
| 286 | 287 |
| 287 virtual ~MockConnection(); | 288 virtual ~MockConnection(); |
| 288 | 289 |
| 289 // If the constructor that uses a MockHelper has been used then this method | 290 // If the constructor that uses a MockHelper has been used then this method |
| 290 // will advance the time of the MockClock. | 291 // will advance the time of the MockClock. |
| 291 void AdvanceTime(QuicTime::Delta delta); | 292 void AdvanceTime(QuicTime::Delta delta); |
| 292 | 293 |
| 293 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, | 294 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, |
| 294 const IPEndPoint& peer_address, | 295 const IPEndPoint& peer_address, |
| 295 const QuicEncryptedPacket& packet)); | 296 const QuicEncryptedPacket& packet)); |
| 296 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); | 297 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); |
| 297 MOCK_METHOD2(SendConnectionCloseWithDetails, void(QuicErrorCode error, | 298 MOCK_METHOD2(SendConnectionCloseWithDetails, void(QuicErrorCode error, |
| 298 const string& details)); | 299 const string& details)); |
| 299 MOCK_METHOD3(SendRstStream, void(QuicStreamId id, | 300 MOCK_METHOD3(SendRstStream, void(QuicStreamId id, |
| 300 QuicRstStreamErrorCode error, | 301 QuicRstStreamErrorCode error, |
| 301 QuicStreamOffset bytes_written)); | 302 QuicStreamOffset bytes_written)); |
| 302 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, | 303 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, |
| 303 QuicStreamId last_good_stream_id, | 304 QuicStreamId last_good_stream_id, |
| 304 const string& reason)); | 305 const string& reason)); |
| 306 MOCK_METHOD1(SendBlocked, void(QuicStreamId id)); |
| 307 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id, |
| 308 QuicStreamOffset byte_offset)); |
| 305 MOCK_METHOD0(OnCanWrite, void()); | 309 MOCK_METHOD0(OnCanWrite, void()); |
| 306 | 310 |
| 307 void ProcessUdpPacketInternal(const IPEndPoint& self_address, | 311 void ProcessUdpPacketInternal(const IPEndPoint& self_address, |
| 308 const IPEndPoint& peer_address, | 312 const IPEndPoint& peer_address, |
| 309 const QuicEncryptedPacket& packet) { | 313 const QuicEncryptedPacket& packet) { |
| 310 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); | 314 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); |
| 311 } | 315 } |
| 312 | 316 |
| 313 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { | 317 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { |
| 314 return false; | 318 return false; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 MOCK_CONST_METHOD0(BandwidthEstimate, QuicBandwidth(void)); | 434 MOCK_CONST_METHOD0(BandwidthEstimate, QuicBandwidth(void)); |
| 431 MOCK_METHOD1(UpdateRtt, void(QuicTime::Delta rtt_sample)); | 435 MOCK_METHOD1(UpdateRtt, void(QuicTime::Delta rtt_sample)); |
| 432 MOCK_CONST_METHOD0(SmoothedRtt, QuicTime::Delta(void)); | 436 MOCK_CONST_METHOD0(SmoothedRtt, QuicTime::Delta(void)); |
| 433 MOCK_CONST_METHOD0(RetransmissionDelay, QuicTime::Delta(void)); | 437 MOCK_CONST_METHOD0(RetransmissionDelay, QuicTime::Delta(void)); |
| 434 MOCK_CONST_METHOD0(GetCongestionWindow, QuicByteCount()); | 438 MOCK_CONST_METHOD0(GetCongestionWindow, QuicByteCount()); |
| 435 | 439 |
| 436 private: | 440 private: |
| 437 DISALLOW_COPY_AND_ASSIGN(MockSendAlgorithm); | 441 DISALLOW_COPY_AND_ASSIGN(MockSendAlgorithm); |
| 438 }; | 442 }; |
| 439 | 443 |
| 444 class MockLossAlgorithm : public LossDetectionInterface { |
| 445 public: |
| 446 MockLossAlgorithm(); |
| 447 virtual ~MockLossAlgorithm(); |
| 448 |
| 449 MOCK_METHOD5(DetectLostPackets, |
| 450 SequenceNumberSet(const QuicUnackedPacketMap& unacked_packets, |
| 451 const QuicTime& time, |
| 452 QuicPacketSequenceNumber largest_observed, |
| 453 QuicTime::Delta srtt, |
| 454 QuicTime::Delta latest_rtt)); |
| 455 MOCK_CONST_METHOD0(GetLossTimeout, QuicTime()); |
| 456 }; |
| 457 |
| 440 class TestEntropyCalculator : | 458 class TestEntropyCalculator : |
| 441 public QuicReceivedEntropyHashCalculatorInterface { | 459 public QuicReceivedEntropyHashCalculatorInterface { |
| 442 public: | 460 public: |
| 443 TestEntropyCalculator(); | 461 TestEntropyCalculator(); |
| 444 virtual ~TestEntropyCalculator(); | 462 virtual ~TestEntropyCalculator(); |
| 445 | 463 |
| 446 virtual QuicPacketEntropyHash EntropyHash( | 464 virtual QuicPacketEntropyHash EntropyHash( |
| 447 QuicPacketSequenceNumber sequence_number) const OVERRIDE; | 465 QuicPacketSequenceNumber sequence_number) const OVERRIDE; |
| 448 }; | 466 }; |
| 449 | 467 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 479 | 497 |
| 480 protected: | 498 protected: |
| 481 // Object is ref counted. | 499 // Object is ref counted. |
| 482 virtual ~MockAckNotifierDelegate(); | 500 virtual ~MockAckNotifierDelegate(); |
| 483 }; | 501 }; |
| 484 | 502 |
| 485 } // namespace test | 503 } // namespace test |
| 486 } // namespace net | 504 } // namespace net |
| 487 | 505 |
| 488 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 506 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |