| 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_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 8 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/quic/quic_connection.h" | 13 #include "net/quic/quic_connection.h" |
| 14 #include "net/quic/quic_packet_writer.h" | 14 #include "net/quic/quic_packet_writer.h" |
| 15 #include "net/quic/quic_session.h" | 15 #include "net/quic/quic_session.h" |
| 16 #include "net/quic/quic_spdy_decompressor.h" | 16 #include "net/quic/quic_spdy_decompressor.h" |
| 17 #include "net/spdy/spdy_framer.h" | 17 #include "net/spdy/spdy_framer.h" |
| 18 #include "net/tools/quic/quic_server_session.h" | 18 #include "net/tools/quic/quic_server_session.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class EpollServer; | 23 class EpollServer; |
| 24 class IPEndPoint; | 24 class IPEndPoint; |
| 25 | 25 |
| 26 namespace tools { | 26 namespace tools { |
| 27 namespace test { | 27 namespace test { |
| 28 | 28 |
| 29 static const QuicGuid kTestGuid = 42; | 29 static const QuicConnectionId kTestConnectionId = 42; |
| 30 static const int kTestPort = 123; | 30 static const int kTestPort = 123; |
| 31 | 31 |
| 32 // Simple random number generator used to compute random numbers suitable | 32 // Simple random number generator used to compute random numbers suitable |
| 33 // for pseudo-randomly dropping packets in tests. It works by computing | 33 // for pseudo-randomly dropping packets in tests. It works by computing |
| 34 // the sha1 hash of the current seed, and using the first 64 bits as | 34 // the sha1 hash of the current seed, and using the first 64 bits as |
| 35 // the next random number, and the next seed. | 35 // the next random number, and the next seed. |
| 36 class SimpleRandom { | 36 class SimpleRandom { |
| 37 public: | 37 public: |
| 38 SimpleRandom() : seed_(0) {} | 38 SimpleRandom() : seed_(0) {} |
| 39 | 39 |
| 40 // Returns a random number in the range [0, kuint64max]. | 40 // Returns a random number in the range [0, kuint64max]. |
| 41 uint64 RandUint64(); | 41 uint64 RandUint64(); |
| 42 | 42 |
| 43 void set_seed(uint64 seed) { seed_ = seed; } | 43 void set_seed(uint64 seed) { seed_ = seed; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 uint64 seed_; | 46 uint64 seed_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class MockConnection : public QuicConnection { | 49 class MockConnection : public QuicConnection { |
| 50 public: | 50 public: |
| 51 // Uses a MockHelper, GUID of 42, and 127.0.0.1:123. | 51 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123. |
| 52 explicit MockConnection(bool is_server); | 52 explicit MockConnection(bool is_server); |
| 53 | 53 |
| 54 // Uses a MockHelper, GUID of 42. | 54 // Uses a MockHelper, ConnectionId of 42. |
| 55 MockConnection(IPEndPoint address, bool is_server); | 55 MockConnection(IPEndPoint address, bool is_server); |
| 56 | 56 |
| 57 // Uses a MockHelper, and 127.0.0.1:123 | 57 // Uses a MockHelper, and 127.0.0.1:123 |
| 58 MockConnection(QuicGuid guid, bool is_server); | 58 MockConnection(QuicConnectionId connection_id, bool is_server); |
| 59 | 59 |
| 60 // Uses a Mock helper, GUID of 42, and 127.0.0.1:123. | 60 // Uses a Mock helper, ConnectionId of 42, and 127.0.0.1:123. |
| 61 MockConnection(bool is_server, const QuicVersionVector& supported_versions); | 61 MockConnection(bool is_server, const QuicVersionVector& supported_versions); |
| 62 | 62 |
| 63 virtual ~MockConnection(); | 63 virtual ~MockConnection(); |
| 64 | 64 |
| 65 // If the constructor that uses a MockHelper has been used then this method | 65 // If the constructor that uses a MockHelper has been used then this method |
| 66 // will advance the time of the MockClock. | 66 // will advance the time of the MockClock. |
| 67 void AdvanceTime(QuicTime::Delta delta); | 67 void AdvanceTime(QuicTime::Delta delta); |
| 68 | 68 |
| 69 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, | 69 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, |
| 70 const IPEndPoint& peer_address, | 70 const IPEndPoint& peer_address, |
| 71 const QuicEncryptedPacket& packet)); | 71 const QuicEncryptedPacket& packet)); |
| 72 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); | 72 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); |
| 73 MOCK_METHOD2(SendConnectionCloseWithDetails, void( | 73 MOCK_METHOD2(SendConnectionCloseWithDetails, void( |
| 74 QuicErrorCode error, | 74 QuicErrorCode error, |
| 75 const std::string& details)); | 75 const std::string& details)); |
| 76 MOCK_METHOD3(SendRstStream, void(QuicStreamId id, | 76 MOCK_METHOD3(SendRstStream, void(QuicStreamId id, |
| 77 QuicRstStreamErrorCode error, | 77 QuicRstStreamErrorCode error, |
| 78 QuicStreamOffset bytes_written)); | 78 QuicStreamOffset bytes_written)); |
| 79 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, | 79 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, |
| 80 QuicStreamId last_good_stream_id, | 80 QuicStreamId last_good_stream_id, |
| 81 const std::string& reason)); | 81 const std::string& reason)); |
| 82 MOCK_METHOD1(SendBlocked, void(QuicStreamId id)); |
| 83 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id, |
| 84 QuicStreamOffset byte_offset)); |
| 82 MOCK_METHOD0(OnCanWrite, void()); | 85 MOCK_METHOD0(OnCanWrite, void()); |
| 83 MOCK_CONST_METHOD0(HasPendingWrites, bool()); | 86 MOCK_CONST_METHOD0(HasPendingWrites, bool()); |
| 84 | 87 |
| 85 void ReallyProcessUdpPacket(const IPEndPoint& self_address, | 88 void ReallyProcessUdpPacket(const IPEndPoint& self_address, |
| 86 const IPEndPoint& peer_address, | 89 const IPEndPoint& peer_address, |
| 87 const QuicEncryptedPacket& packet) { | 90 const QuicEncryptedPacket& packet) { |
| 88 return QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); | 91 return QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); |
| 89 } | 92 } |
| 90 | 93 |
| 91 virtual bool OnProtocolVersionMismatch(QuicVersion version) { return false; } | 94 virtual bool OnProtocolVersionMismatch(QuicVersion version) { return false; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const IPEndPoint& peer_address)); | 129 const IPEndPoint& peer_address)); |
| 127 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool()); | 130 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool()); |
| 128 MOCK_CONST_METHOD0(IsWriteBlocked, bool()); | 131 MOCK_CONST_METHOD0(IsWriteBlocked, bool()); |
| 129 MOCK_METHOD0(SetWritable, void()); | 132 MOCK_METHOD0(SetWritable, void()); |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 class MockQuicServerSessionVisitor : public QuicServerSessionVisitor { | 135 class MockQuicServerSessionVisitor : public QuicServerSessionVisitor { |
| 133 public: | 136 public: |
| 134 MockQuicServerSessionVisitor(); | 137 MockQuicServerSessionVisitor(); |
| 135 virtual ~MockQuicServerSessionVisitor(); | 138 virtual ~MockQuicServerSessionVisitor(); |
| 136 MOCK_METHOD2(OnConnectionClosed, void(QuicGuid guid, QuicErrorCode error)); | 139 MOCK_METHOD2(OnConnectionClosed, void(QuicConnectionId connection_id, |
| 140 QuicErrorCode error)); |
| 137 MOCK_METHOD1(OnWriteBlocked, void(QuicBlockedWriterInterface* writer)); | 141 MOCK_METHOD1(OnWriteBlocked, void(QuicBlockedWriterInterface* writer)); |
| 138 }; | 142 }; |
| 139 | 143 |
| 140 class TestDecompressorVisitor : public QuicSpdyDecompressor::Visitor { | 144 class TestDecompressorVisitor : public QuicSpdyDecompressor::Visitor { |
| 141 public: | 145 public: |
| 142 virtual ~TestDecompressorVisitor() {} | 146 virtual ~TestDecompressorVisitor() {} |
| 143 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; | 147 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; |
| 144 virtual void OnDecompressionError() OVERRIDE; | 148 virtual void OnDecompressionError() OVERRIDE; |
| 145 | 149 |
| 146 std::string data() { return data_; } | 150 std::string data() { return data_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 160 protected: | 164 protected: |
| 161 // Object is ref counted. | 165 // Object is ref counted. |
| 162 virtual ~MockAckNotifierDelegate(); | 166 virtual ~MockAckNotifierDelegate(); |
| 163 }; | 167 }; |
| 164 | 168 |
| 165 } // namespace test | 169 } // namespace test |
| 166 } // namespace tools | 170 } // namespace tools |
| 167 } // namespace net | 171 } // namespace net |
| 168 | 172 |
| 169 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 173 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |