| 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, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 const IPEndPoint& peer_address)); | 129 const IPEndPoint& peer_address)); |
| 130 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool()); | 130 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool()); |
| 131 MOCK_CONST_METHOD0(IsWriteBlocked, bool()); | 131 MOCK_CONST_METHOD0(IsWriteBlocked, bool()); |
| 132 MOCK_METHOD0(SetWritable, void()); | 132 MOCK_METHOD0(SetWritable, void()); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 class MockQuicServerSessionVisitor : public QuicServerSessionVisitor { | 135 class MockQuicServerSessionVisitor : public QuicServerSessionVisitor { |
| 136 public: | 136 public: |
| 137 MockQuicServerSessionVisitor(); | 137 MockQuicServerSessionVisitor(); |
| 138 virtual ~MockQuicServerSessionVisitor(); | 138 virtual ~MockQuicServerSessionVisitor(); |
| 139 MOCK_METHOD2(OnConnectionClosed, void(QuicGuid guid, QuicErrorCode error)); | 139 MOCK_METHOD2(OnConnectionClosed, void(QuicConnectionId connection_id, |
| 140 QuicErrorCode error)); |
| 140 MOCK_METHOD1(OnWriteBlocked, void(QuicBlockedWriterInterface* writer)); | 141 MOCK_METHOD1(OnWriteBlocked, void(QuicBlockedWriterInterface* writer)); |
| 141 }; | 142 }; |
| 142 | 143 |
| 143 class TestDecompressorVisitor : public QuicSpdyDecompressor::Visitor { | 144 class TestDecompressorVisitor : public QuicSpdyDecompressor::Visitor { |
| 144 public: | 145 public: |
| 145 virtual ~TestDecompressorVisitor() {} | 146 virtual ~TestDecompressorVisitor() {} |
| 146 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; | 147 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; |
| 147 virtual void OnDecompressionError() OVERRIDE; | 148 virtual void OnDecompressionError() OVERRIDE; |
| 148 | 149 |
| 149 std::string data() { return data_; } | 150 std::string data() { return data_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 163 protected: | 164 protected: |
| 164 // Object is ref counted. | 165 // Object is ref counted. |
| 165 virtual ~MockAckNotifierDelegate(); | 166 virtual ~MockAckNotifierDelegate(); |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 } // namespace test | 169 } // namespace test |
| 169 } // namespace tools | 170 } // namespace tools |
| 170 } // namespace net | 171 } // namespace net |
| 171 | 172 |
| 172 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 173 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |