Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / net / tools / quic / test_tools / quic_test_utils.cc
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
3 // found in the LICENSE file.
4
5 #include "net/tools/quic/test_tools/quic_test_utils.h"
6
7 #include "base/sha1.h"
8 #include "net/quic/quic_connection.h"
9 #include "net/quic/test_tools/quic_connection_peer.h"
10 #include "net/quic/test_tools/quic_test_utils.h"
11 #include "net/tools/quic/quic_epoll_connection_helper.h"
12
13 using base::StringPiece;
14 using net::test::MockHelper;
15
16 namespace net {
17 namespace tools {
18 namespace test {
19
20 MockConnection::MockConnection(bool is_server)
21     : QuicConnection(kTestGuid,
22                      IPEndPoint(net::test::Loopback4(), kTestPort),
23                      new testing::NiceMock<MockHelper>(),
24                      new testing::NiceMock<MockPacketWriter>(),
25                      is_server, QuicSupportedVersions()),
26       writer_(net::test::QuicConnectionPeer::GetWriter(this)),
27       helper_(helper()) {
28 }
29
30 MockConnection::MockConnection(IPEndPoint address,
31                                bool is_server)
32     : QuicConnection(kTestGuid, address,
33                      new testing::NiceMock<MockHelper>(),
34                      new testing::NiceMock<MockPacketWriter>(),
35                      is_server, QuicSupportedVersions()),
36       writer_(net::test::QuicConnectionPeer::GetWriter(this)),
37       helper_(helper()) {
38 }
39
40 MockConnection::MockConnection(QuicGuid guid,
41                                bool is_server)
42     : QuicConnection(guid,
43                      IPEndPoint(net::test::Loopback4(), kTestPort),
44                      new testing::NiceMock<MockHelper>(),
45                      new testing::NiceMock<MockPacketWriter>(),
46                      is_server, QuicSupportedVersions()),
47       writer_(net::test::QuicConnectionPeer::GetWriter(this)),
48       helper_(helper()) {
49 }
50
51 MockConnection::MockConnection(bool is_server,
52                                const QuicVersionVector& supported_versions)
53     : QuicConnection(kTestGuid,
54                      IPEndPoint(net::test::Loopback4(), kTestPort),
55                      new testing::NiceMock<MockHelper>(),
56                      new testing::NiceMock<MockPacketWriter>(),
57                      is_server, supported_versions),
58       writer_(net::test::QuicConnectionPeer::GetWriter(this)),
59       helper_(helper()) {
60 }
61
62 MockConnection::~MockConnection() {
63 }
64
65 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
66   static_cast<MockHelper*>(helper())->AdvanceTime(delta);
67 }
68
69 uint64 SimpleRandom::RandUint64() {
70   unsigned char hash[base::kSHA1Length];
71   base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_),
72                       hash);
73   memcpy(&seed_, hash, sizeof(seed_));
74   return seed_;
75 }
76
77 TestSession::TestSession(QuicConnection* connection,
78                          const QuicConfig& config)
79     : QuicSession(connection, config),
80       crypto_stream_(NULL) {
81 }
82
83 TestSession::~TestSession() {}
84
85 void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
86   crypto_stream_ = stream;
87 }
88
89 QuicCryptoStream* TestSession::GetCryptoStream() {
90   return crypto_stream_;
91 }
92
93 MockPacketWriter::MockPacketWriter() {
94 }
95
96 MockPacketWriter::~MockPacketWriter() {
97 }
98
99 MockQuicServerSessionVisitor::MockQuicServerSessionVisitor() {
100 }
101
102 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() {
103 }
104
105 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
106   data.AppendToString(&data_);
107   return true;
108 }
109
110 void TestDecompressorVisitor::OnDecompressionError() {
111   error_ = true;
112 }
113
114 MockAckNotifierDelegate::MockAckNotifierDelegate() {
115 }
116
117 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
118 }
119
120 }  // namespace test
121 }  // namespace tools
122 }  // namespace net