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 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
6 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 6 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "net/quic/quic_connection.h" | 11 #include "net/quic/quic_connection.h" |
12 #include "net/quic/quic_packet_writer.h" | 12 #include "net/quic/quic_packet_writer.h" |
13 #include "net/quic/quic_session.h" | 13 #include "net/quic/quic_session.h" |
14 #include "net/quic/quic_spdy_decompressor.h" | 14 #include "net/quic/quic_spdy_decompressor.h" |
15 #include "net/spdy/spdy_framer.h" | 15 #include "net/spdy/spdy_framer.h" |
16 #include "net/tools/quic/quic_server_session.h" | 16 #include "net/tools/quic/quic_server_session.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 class EpollServer; | 21 class EpollServer; |
22 class IPEndPoint; | 22 class IPEndPoint; |
23 | 23 |
24 namespace tools { | 24 namespace tools { |
25 namespace test { | 25 namespace test { |
26 | 26 |
27 // Upper limit on versions we support. | 27 static const QuicGuid kTestGuid = 42; |
28 QuicVersion QuicVersionMax(); | 28 static const int kTestPort = 123; |
29 | |
30 // Lower limit on versions we support. | |
31 QuicVersion QuicVersionMin(); | |
32 | 29 |
33 // Simple random number generator used to compute random numbers suitable | 30 // Simple random number generator used to compute random numbers suitable |
34 // for pseudo-randomly dropping packets in tests. It works by computing | 31 // for pseudo-randomly dropping packets in tests. It works by computing |
35 // the sha1 hash of the current seed, and using the first 64 bits as | 32 // the sha1 hash of the current seed, and using the first 64 bits as |
36 // the next random number, and the next seed. | 33 // the next random number, and the next seed. |
37 class SimpleRandom { | 34 class SimpleRandom { |
38 public: | 35 public: |
39 SimpleRandom() : seed_(0) {} | 36 SimpleRandom() : seed_(0) {} |
40 | 37 |
41 // Returns a random number in the range [0, kuint64max]. | 38 // Returns a random number in the range [0, kuint64max]. |
42 uint64 RandUint64(); | 39 uint64 RandUint64(); |
43 | 40 |
44 void set_seed(uint64 seed) { seed_ = seed; } | 41 void set_seed(uint64 seed) { seed_ = seed; } |
45 | 42 |
46 private: | 43 private: |
47 uint64 seed_; | 44 uint64 seed_; |
48 }; | 45 }; |
49 | 46 |
50 class MockConnection : public QuicConnection { | 47 class MockConnection : public QuicConnection { |
51 public: | 48 public: |
52 // Uses a QuicConnectionHelper created with fd and eps. | 49 // Uses a MockHelper, GUID of 42, and 127.0.0.1:123. |
| 50 explicit MockConnection(bool is_server); |
| 51 |
| 52 // Uses a MockHelper, GUID of 42. |
| 53 MockConnection(IPEndPoint address, |
| 54 bool is_server); |
| 55 |
| 56 // Uses a MockHelper, and 127.0.0.1:123 |
53 MockConnection(QuicGuid guid, | 57 MockConnection(QuicGuid guid, |
54 IPEndPoint address, | |
55 int fd, | |
56 EpollServer* eps, | |
57 bool is_server); | 58 bool is_server); |
58 // Uses a MockHelper. | 59 |
59 MockConnection(QuicGuid guid, IPEndPoint address, bool is_server); | |
60 MockConnection(QuicGuid guid, | |
61 IPEndPoint address, | |
62 QuicConnectionHelperInterface* helper, | |
63 QuicPacketWriter* writer, | |
64 bool is_server); | |
65 virtual ~MockConnection(); | 60 virtual ~MockConnection(); |
66 | 61 |
67 // If the constructor that uses a MockHelper has been used then this method | 62 // If the constructor that uses a MockHelper has been used then this method |
68 // will advance the time of the MockClock. | 63 // will advance the time of the MockClock. |
69 void AdvanceTime(QuicTime::Delta delta); | 64 void AdvanceTime(QuicTime::Delta delta); |
70 | 65 |
71 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, | 66 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, |
72 const IPEndPoint& peer_address, | 67 const IPEndPoint& peer_address, |
73 const QuicEncryptedPacket& packet)); | 68 const QuicEncryptedPacket& packet)); |
74 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); | 69 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); |
75 MOCK_METHOD2(SendConnectionCloseWithDetails, void( | 70 MOCK_METHOD2(SendConnectionCloseWithDetails, void( |
76 QuicErrorCode error, | 71 QuicErrorCode error, |
77 const std::string& details)); | 72 const std::string& details)); |
78 MOCK_METHOD2(SendRstStream, void(QuicStreamId id, | 73 MOCK_METHOD2(SendRstStream, void(QuicStreamId id, |
79 QuicRstStreamErrorCode error)); | 74 QuicRstStreamErrorCode error)); |
80 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, | 75 MOCK_METHOD3(SendGoAway, void(QuicErrorCode error, |
81 QuicStreamId last_good_stream_id, | 76 QuicStreamId last_good_stream_id, |
82 const std::string& reason)); | 77 const std::string& reason)); |
83 MOCK_METHOD0(OnCanWrite, bool()); | 78 MOCK_METHOD0(OnCanWrite, bool()); |
84 | 79 |
85 void ReallyProcessUdpPacket(const IPEndPoint& self_address, | 80 void ReallyProcessUdpPacket(const IPEndPoint& self_address, |
86 const IPEndPoint& peer_address, | 81 const IPEndPoint& peer_address, |
87 const QuicEncryptedPacket& packet) { | 82 const QuicEncryptedPacket& packet) { |
88 return QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); | 83 return QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); |
89 } | 84 } |
90 | 85 |
91 virtual bool OnProtocolVersionMismatch(QuicVersion version) { return false; } | 86 virtual bool OnProtocolVersionMismatch(QuicVersion version) { return false; } |
92 | 87 |
93 private: | 88 private: |
94 const bool has_mock_helper_; | |
95 scoped_ptr<QuicPacketWriter> writer_; | 89 scoped_ptr<QuicPacketWriter> writer_; |
96 scoped_ptr<QuicConnectionHelperInterface> helper_; | 90 scoped_ptr<QuicConnectionHelperInterface> helper_; |
97 | 91 |
98 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 92 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
99 }; | 93 }; |
100 | 94 |
101 class TestSession : public QuicSession { | 95 class TestSession : public QuicSession { |
102 public: | 96 public: |
103 TestSession(QuicConnection* connection, | 97 TestSession(QuicConnection* connection, |
104 const QuicConfig& config, | 98 const QuicConfig& config, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 virtual ~MockAckNotifierDelegate(); | 152 virtual ~MockAckNotifierDelegate(); |
159 | 153 |
160 MOCK_METHOD0(OnAckNotification, void()); | 154 MOCK_METHOD0(OnAckNotification, void()); |
161 }; | 155 }; |
162 | 156 |
163 } // namespace test | 157 } // namespace test |
164 } // namespace tools | 158 } // namespace tools |
165 } // namespace net | 159 } // namespace net |
166 | 160 |
167 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 161 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |