| 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 #include "net/tools/quic/test_tools/quic_test_utils.h" | 5 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 6 | 6 |
| 7 #include "base/sha1.h" | 7 #include "base/sha1.h" |
| 8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
| 9 #include "net/quic/test_tools/quic_connection_peer.h" | 9 #include "net/quic/test_tools/quic_connection_peer.h" |
| 10 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
| 11 #include "net/tools/quic/quic_epoll_connection_helper.h" | 11 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 12 | 12 |
| 13 using base::StringPiece; | 13 using base::StringPiece; |
| 14 using net::test::kInitialFlowControlWindowForTest; | 14 using net::test::kInitialFlowControlWindowForTest; |
| 15 using net::test::MockHelper; | 15 using net::test::MockHelper; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 namespace tools { | 18 namespace tools { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 MockConnection::MockConnection(bool is_server) | 21 MockConnection::MockConnection(bool is_server) |
| 22 : QuicConnection(kTestConnectionId, | 22 : QuicConnection(kTestConnectionId, |
| 23 IPEndPoint(net::test::Loopback4(), kTestPort), | 23 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 24 new testing::NiceMock<MockHelper>(), | 24 new testing::NiceMock<MockHelper>(), |
| 25 new testing::NiceMock<MockPacketWriter>(), | 25 new testing::NiceMock<MockPacketWriter>(), |
| 26 is_server, QuicSupportedVersions(), | 26 is_server, |
| 27 QuicSupportedVersions(), |
| 27 kInitialFlowControlWindowForTest), | 28 kInitialFlowControlWindowForTest), |
| 28 writer_(net::test::QuicConnectionPeer::GetWriter(this)), | 29 writer_(net::test::QuicConnectionPeer::GetWriter(this)), |
| 29 helper_(helper()) { | 30 helper_(helper()) { |
| 30 } | 31 } |
| 31 | 32 |
| 32 MockConnection::MockConnection(IPEndPoint address, | 33 MockConnection::MockConnection(IPEndPoint address, bool is_server) |
| 33 bool is_server) | 34 : QuicConnection(kTestConnectionId, |
| 34 : QuicConnection(kTestConnectionId, address, | 35 address, |
| 35 new testing::NiceMock<MockHelper>(), | 36 new testing::NiceMock<MockHelper>(), |
| 36 new testing::NiceMock<MockPacketWriter>(), | 37 new testing::NiceMock<MockPacketWriter>(), |
| 37 is_server, QuicSupportedVersions(), | 38 is_server, |
| 39 QuicSupportedVersions(), |
| 38 kInitialFlowControlWindowForTest), | 40 kInitialFlowControlWindowForTest), |
| 39 writer_(net::test::QuicConnectionPeer::GetWriter(this)), | 41 writer_(net::test::QuicConnectionPeer::GetWriter(this)), |
| 40 helper_(helper()) { | 42 helper_(helper()) { |
| 41 } | 43 } |
| 42 | 44 |
| 43 MockConnection::MockConnection(QuicConnectionId connection_id, | 45 MockConnection::MockConnection(QuicConnectionId connection_id, bool is_server) |
| 44 bool is_server) | |
| 45 : QuicConnection(connection_id, | 46 : QuicConnection(connection_id, |
| 46 IPEndPoint(net::test::Loopback4(), kTestPort), | 47 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 47 new testing::NiceMock<MockHelper>(), | 48 new testing::NiceMock<MockHelper>(), |
| 48 new testing::NiceMock<MockPacketWriter>(), | 49 new testing::NiceMock<MockPacketWriter>(), |
| 49 is_server, QuicSupportedVersions(), | 50 is_server, |
| 51 QuicSupportedVersions(), |
| 50 kInitialFlowControlWindowForTest), | 52 kInitialFlowControlWindowForTest), |
| 51 writer_(net::test::QuicConnectionPeer::GetWriter(this)), | 53 writer_(net::test::QuicConnectionPeer::GetWriter(this)), |
| 52 helper_(helper()) { | 54 helper_(helper()) { |
| 53 } | 55 } |
| 54 | 56 |
| 55 MockConnection::MockConnection(bool is_server, | 57 MockConnection::MockConnection(bool is_server, |
| 56 const QuicVersionVector& supported_versions) | 58 const QuicVersionVector& supported_versions) |
| 57 : QuicConnection(kTestConnectionId, | 59 : QuicConnection(kTestConnectionId, |
| 58 IPEndPoint(net::test::Loopback4(), kTestPort), | 60 IPEndPoint(net::test::Loopback4(), kTestPort), |
| 59 new testing::NiceMock<MockHelper>(), | 61 new testing::NiceMock<MockHelper>(), |
| 60 new testing::NiceMock<MockPacketWriter>(), | 62 new testing::NiceMock<MockPacketWriter>(), |
| 61 is_server, QuicSupportedVersions(), | 63 is_server, |
| 64 QuicSupportedVersions(), |
| 62 kInitialFlowControlWindowForTest), | 65 kInitialFlowControlWindowForTest), |
| 63 writer_(net::test::QuicConnectionPeer::GetWriter(this)), | 66 writer_(net::test::QuicConnectionPeer::GetWriter(this)), |
| 64 helper_(helper()) { | 67 helper_(helper()) { |
| 65 } | 68 } |
| 66 | 69 |
| 67 MockConnection::~MockConnection() { | 70 MockConnection::~MockConnection() { |
| 68 } | 71 } |
| 69 | 72 |
| 70 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 73 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
| 71 static_cast<MockHelper*>(helper())->AdvanceTime(delta); | 74 static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
| 72 } | 75 } |
| 73 | 76 |
| 74 uint64 SimpleRandom::RandUint64() { | 77 uint64 SimpleRandom::RandUint64() { |
| 75 unsigned char hash[base::kSHA1Length]; | 78 unsigned char hash[base::kSHA1Length]; |
| 76 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), | 79 base::SHA1HashBytes( |
| 77 hash); | 80 reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), hash); |
| 78 memcpy(&seed_, hash, sizeof(seed_)); | 81 memcpy(&seed_, hash, sizeof(seed_)); |
| 79 return seed_; | 82 return seed_; |
| 80 } | 83 } |
| 81 | 84 |
| 82 TestSession::TestSession(QuicConnection* connection, | 85 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) |
| 83 const QuicConfig& config) | 86 : QuicSession(connection, config), crypto_stream_(NULL) { |
| 84 : QuicSession(connection, config), | |
| 85 crypto_stream_(NULL) { | |
| 86 } | 87 } |
| 87 | 88 |
| 88 TestSession::~TestSession() {} | 89 TestSession::~TestSession() { |
| 90 } |
| 89 | 91 |
| 90 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { | 92 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 91 crypto_stream_ = stream; | 93 crypto_stream_ = stream; |
| 92 } | 94 } |
| 93 | 95 |
| 94 QuicCryptoStream* TestSession::GetCryptoStream() { | 96 QuicCryptoStream* TestSession::GetCryptoStream() { |
| 95 return crypto_stream_; | 97 return crypto_stream_; |
| 96 } | 98 } |
| 97 | 99 |
| 98 MockPacketWriter::MockPacketWriter() { | 100 MockPacketWriter::MockPacketWriter() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 109 | 111 |
| 110 MockAckNotifierDelegate::MockAckNotifierDelegate() { | 112 MockAckNotifierDelegate::MockAckNotifierDelegate() { |
| 111 } | 113 } |
| 112 | 114 |
| 113 MockAckNotifierDelegate::~MockAckNotifierDelegate() { | 115 MockAckNotifierDelegate::~MockAckNotifierDelegate() { |
| 114 } | 116 } |
| 115 | 117 |
| 116 } // namespace test | 118 } // namespace test |
| 117 } // namespace tools | 119 } // namespace tools |
| 118 } // namespace net | 120 } // namespace net |
| OLD | NEW |