1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
#define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
#include <string>
#include "base/strings/string_piece.h"
#include "net/quic/quic_connection.h"
#include "net/quic/quic_session.h"
#include "net/quic/quic_spdy_decompressor.h"
#include "net/spdy/spdy_framer.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace net {
class EpollServer;
class IPEndPoint;
namespace tools {
namespace test {
std::string SerializeUncompressedHeaders(const SpdyHeaderBlock& headers);
class MockConnection : public QuicConnection {
public:
// Uses a QuicConnectionHelper created with fd and eps.
MockConnection(QuicGuid guid,
IPEndPoint address,
int fd,
EpollServer* eps,
bool is_server);
// Uses a MockHelper.
MockConnection(QuicGuid guid, IPEndPoint address, bool is_server);
MockConnection(QuicGuid guid,
IPEndPoint address,
QuicConnectionHelperInterface* helper, bool is_server);
virtual ~MockConnection();
// If the constructor that uses a MockHelper has been used then this method
// will advance the time of the MockClock.
void AdvanceTime(QuicTime::Delta delta);
MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address,
const IPEndPoint& peer_address,
const QuicEncryptedPacket& packet));
MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error));
MOCK_METHOD2(SendConnectionCloseWithDetails, void(
QuicErrorCode error,
const std::string& details));
MOCK_METHOD2(SendRstStream, void(QuicStreamId id,
QuicRstStreamErrorCode error));
MOCK_METHOD3(SendGoAway, void(QuicErrorCode error,
QuicStreamId last_good_stream_id,
const std::string& reason));
MOCK_METHOD0(OnCanWrite, bool());
void ReallyProcessUdpPacket(const IPEndPoint& self_address,
const IPEndPoint& peer_address,
const QuicEncryptedPacket& packet) {
return QuicConnection::ProcessUdpPacket(self_address, peer_address, packet);
}
virtual bool OnProtocolVersionMismatch(QuicVersion version) { return false; }
private:
const bool has_mock_helper_;
DISALLOW_COPY_AND_ASSIGN(MockConnection);
};
class TestDecompressorVisitor : public QuicSpdyDecompressor::Visitor {
public:
virtual ~TestDecompressorVisitor() {}
virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE;
virtual void OnDecompressionError() OVERRIDE;
std::string data() { return data_; }
bool error() { return error_; }
private:
std::string data_;
bool error_;
};
class TestSession : public QuicSession {
public:
TestSession(QuicConnection* connection,
const QuicConfig& config,
bool is_server);
virtual ~TestSession();
MOCK_METHOD1(CreateIncomingReliableStream,
ReliableQuicStream*(QuicStreamId id));
MOCK_METHOD0(CreateOutgoingReliableStream, ReliableQuicStream*());
void SetCryptoStream(QuicCryptoStream* stream);
virtual QuicCryptoStream* GetCryptoStream();
private:
QuicCryptoStream* crypto_stream_;
DISALLOW_COPY_AND_ASSIGN(TestSession);
};
} // namespace test
} // namespace tools
} // namespace net
#endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
|