Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: net/quic/test_tools/quic_test_utils.cc

Issue 1433433003: Rename MockHelper to the more descriptive (and more consistent with other Mock classes) MockConnect… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@106414015
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/quic_client_session_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic/test_tools/quic_test_utils.h" 5 #include "net/quic/test_tools/quic_test_utils.h"
6 6
7 #include "base/sha1.h" 7 #include "base/sha1.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/quic/crypto/crypto_framer.h" 10 #include "net/quic/crypto/crypto_framer.h"
(...skipping 15 matching lines...) Expand all
26 using std::max; 26 using std::max;
27 using std::min; 27 using std::min;
28 using std::string; 28 using std::string;
29 using testing::Invoke; 29 using testing::Invoke;
30 using testing::_; 30 using testing::_;
31 31
32 namespace net { 32 namespace net {
33 namespace test { 33 namespace test {
34 namespace { 34 namespace {
35 35
36 // No-op alarm implementation used by MockHelper. 36 // No-op alarm implementation used by MockConnectionHelper.
37 class TestAlarm : public QuicAlarm { 37 class TestAlarm : public QuicAlarm {
38 public: 38 public:
39 explicit TestAlarm(QuicAlarm::Delegate* delegate) 39 explicit TestAlarm(QuicAlarm::Delegate* delegate)
40 : QuicAlarm(delegate) { 40 : QuicAlarm(delegate) {
41 } 41 }
42 42
43 void SetImpl() override {} 43 void SetImpl() override {}
44 void CancelImpl() override {} 44 void CancelImpl() override {}
45 }; 45 };
46 46
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 198
199 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) { 199 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) {
200 return true; 200 return true;
201 } 201 }
202 202
203 MockConnectionVisitor::MockConnectionVisitor() {} 203 MockConnectionVisitor::MockConnectionVisitor() {}
204 204
205 MockConnectionVisitor::~MockConnectionVisitor() {} 205 MockConnectionVisitor::~MockConnectionVisitor() {}
206 206
207 MockHelper::MockHelper() {} 207 MockConnectionHelper::MockConnectionHelper() {}
208 208
209 MockHelper::~MockHelper() {} 209 MockConnectionHelper::~MockConnectionHelper() {}
210 210
211 const QuicClock* MockHelper::GetClock() const { 211 const QuicClock* MockConnectionHelper::GetClock() const { return &clock_; }
212 return &clock_;
213 }
214 212
215 QuicRandom* MockHelper::GetRandomGenerator() { 213 QuicRandom* MockConnectionHelper::GetRandomGenerator() {
216 return &random_generator_; 214 return &random_generator_;
217 } 215 }
218 216
219 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { 217 QuicAlarm* MockConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
220 return new TestAlarm(delegate); 218 return new TestAlarm(delegate);
221 } 219 }
222 220
223 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 221 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) {
224 clock_.AdvanceTime(delta); 222 clock_.AdvanceTime(delta);
225 } 223 }
226 224
227 QuicPacketWriter* NiceMockPacketWriterFactory::Create( 225 QuicPacketWriter* NiceMockPacketWriterFactory::Create(
228 QuicConnection* /*connection*/) const { 226 QuicConnection* /*connection*/) const {
229 return new testing::NiceMock<MockPacketWriter>(); 227 return new testing::NiceMock<MockPacketWriter>();
230 } 228 }
231 229
232 MockConnection::MockConnection(MockHelper* helper, Perspective perspective) 230 MockConnection::MockConnection(MockConnectionHelper* helper,
231 Perspective perspective)
233 : MockConnection(kTestConnectionId, 232 : MockConnection(kTestConnectionId,
234 IPEndPoint(TestPeerIPAddress(), kTestPort), 233 IPEndPoint(TestPeerIPAddress(), kTestPort),
235 helper, 234 helper,
236 perspective, 235 perspective,
237 QuicSupportedVersions()) {} 236 QuicSupportedVersions()) {}
238 237
239 MockConnection::MockConnection(IPEndPoint address, 238 MockConnection::MockConnection(IPEndPoint address,
240 MockHelper* helper, 239 MockConnectionHelper* helper,
241 Perspective perspective) 240 Perspective perspective)
242 : MockConnection(kTestConnectionId, 241 : MockConnection(kTestConnectionId,
243 address, 242 address,
244 helper, 243 helper,
245 perspective, 244 perspective,
246 QuicSupportedVersions()) {} 245 QuicSupportedVersions()) {}
247 246
248 MockConnection::MockConnection(QuicConnectionId connection_id, 247 MockConnection::MockConnection(QuicConnectionId connection_id,
249 MockHelper* helper, 248 MockConnectionHelper* helper,
250 Perspective perspective) 249 Perspective perspective)
251 : MockConnection(connection_id, 250 : MockConnection(connection_id,
252 IPEndPoint(TestPeerIPAddress(), kTestPort), 251 IPEndPoint(TestPeerIPAddress(), kTestPort),
253 helper, 252 helper,
254 perspective, 253 perspective,
255 QuicSupportedVersions()) {} 254 QuicSupportedVersions()) {}
256 255
257 MockConnection::MockConnection(MockHelper* helper, 256 MockConnection::MockConnection(MockConnectionHelper* helper,
258 Perspective perspective, 257 Perspective perspective,
259 const QuicVersionVector& supported_versions) 258 const QuicVersionVector& supported_versions)
260 : MockConnection(kTestConnectionId, 259 : MockConnection(kTestConnectionId,
261 IPEndPoint(TestPeerIPAddress(), kTestPort), 260 IPEndPoint(TestPeerIPAddress(), kTestPort),
262 helper, 261 helper,
263 perspective, 262 perspective,
264 supported_versions) {} 263 supported_versions) {}
265 264
266 MockConnection::MockConnection(QuicConnectionId connection_id, 265 MockConnection::MockConnection(QuicConnectionId connection_id,
267 IPEndPoint address, 266 IPEndPoint address,
268 MockHelper* helper, 267 MockConnectionHelper* helper,
269 Perspective perspective, 268 Perspective perspective,
270 const QuicVersionVector& supported_versions) 269 const QuicVersionVector& supported_versions)
271 : QuicConnection(connection_id, 270 : QuicConnection(connection_id,
272 address, 271 address,
273 helper, 272 helper,
274 NiceMockPacketWriterFactory(), 273 NiceMockPacketWriterFactory(),
275 /* owns_writer= */ true, 274 /* owns_writer= */ true,
276 perspective, 275 perspective,
277 supported_versions) { 276 supported_versions) {
278 ON_CALL(*this, OnError(_)) 277 ON_CALL(*this, OnError(_))
279 .WillByDefault( 278 .WillByDefault(
280 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); 279 Invoke(this, &PacketSavingConnection::QuicConnection_OnError));
281 } 280 }
282 281
283 MockConnection::~MockConnection() {} 282 MockConnection::~MockConnection() {}
284 283
285 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 284 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
286 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 285 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta);
287 } 286 }
288 287
289 PacketSavingConnection::PacketSavingConnection(MockHelper* helper, 288 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper,
290 Perspective perspective) 289 Perspective perspective)
291 : MockConnection(helper, perspective) {} 290 : MockConnection(helper, perspective) {}
292 291
293 PacketSavingConnection::PacketSavingConnection( 292 PacketSavingConnection::PacketSavingConnection(
294 MockHelper* helper, 293 MockConnectionHelper* helper,
295 Perspective perspective, 294 Perspective perspective,
296 const QuicVersionVector& supported_versions) 295 const QuicVersionVector& supported_versions)
297 : MockConnection(helper, perspective, supported_versions) {} 296 : MockConnection(helper, perspective, supported_versions) {}
298 297
299 PacketSavingConnection::~PacketSavingConnection() { 298 PacketSavingConnection::~PacketSavingConnection() {
300 STLDeleteElements(&encrypted_packets_); 299 STLDeleteElements(&encrypted_packets_);
301 } 300 }
302 301
303 void PacketSavingConnection::SendOrQueuePacket(QueuedPacket packet) { 302 void PacketSavingConnection::SendOrQueuePacket(QueuedPacket packet) {
304 if (!packet.serialized_packet.packet->owns_buffer()) { 303 if (!packet.serialized_packet.packet->owns_buffer()) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 buffer, buf_len, self_address, peer_address); 747 buffer, buf_len, self_address, peer_address);
749 } 748 }
750 749
751 MockQuicConnectionDebugVisitor::MockQuicConnectionDebugVisitor() {} 750 MockQuicConnectionDebugVisitor::MockQuicConnectionDebugVisitor() {}
752 751
753 MockQuicConnectionDebugVisitor::~MockQuicConnectionDebugVisitor() {} 752 MockQuicConnectionDebugVisitor::~MockQuicConnectionDebugVisitor() {}
754 753
755 void CreateClientSessionForTest(QuicServerId server_id, 754 void CreateClientSessionForTest(QuicServerId server_id,
756 bool supports_stateless_rejects, 755 bool supports_stateless_rejects,
757 QuicTime::Delta connection_start_time, 756 QuicTime::Delta connection_start_time,
758 MockHelper* helper, 757 MockConnectionHelper* helper,
759 QuicCryptoClientConfig* crypto_client_config, 758 QuicCryptoClientConfig* crypto_client_config,
760 PacketSavingConnection** client_connection, 759 PacketSavingConnection** client_connection,
761 TestQuicSpdyClientSession** client_session) { 760 TestQuicSpdyClientSession** client_session) {
762 CHECK(crypto_client_config); 761 CHECK(crypto_client_config);
763 CHECK(client_connection); 762 CHECK(client_connection);
764 CHECK(client_session); 763 CHECK(client_session);
765 CHECK(!connection_start_time.IsZero()) 764 CHECK(!connection_start_time.IsZero())
766 << "Connections must start at non-zero times, otherwise the " 765 << "Connections must start at non-zero times, otherwise the "
767 << "strike-register will be unhappy."; 766 << "strike-register will be unhappy.";
768 767
769 QuicConfig config = supports_stateless_rejects 768 QuicConfig config = supports_stateless_rejects
770 ? DefaultQuicConfigStatelessRejects() 769 ? DefaultQuicConfigStatelessRejects()
771 : DefaultQuicConfig(); 770 : DefaultQuicConfig();
772 *client_connection = 771 *client_connection =
773 new PacketSavingConnection(helper, Perspective::IS_CLIENT); 772 new PacketSavingConnection(helper, Perspective::IS_CLIENT);
774 *client_session = new TestQuicSpdyClientSession( 773 *client_session = new TestQuicSpdyClientSession(
775 *client_connection, config, server_id, crypto_client_config); 774 *client_connection, config, server_id, crypto_client_config);
776 (*client_connection)->AdvanceTime(connection_start_time); 775 (*client_connection)->AdvanceTime(connection_start_time);
777 } 776 }
778 777
779 void CreateServerSessionForTest(QuicServerId server_id, 778 void CreateServerSessionForTest(QuicServerId server_id,
780 QuicTime::Delta connection_start_time, 779 QuicTime::Delta connection_start_time,
781 MockHelper* helper, 780 MockConnectionHelper* helper,
782 QuicCryptoServerConfig* server_crypto_config, 781 QuicCryptoServerConfig* server_crypto_config,
783 PacketSavingConnection** server_connection, 782 PacketSavingConnection** server_connection,
784 TestQuicSpdyServerSession** server_session) { 783 TestQuicSpdyServerSession** server_session) {
785 CHECK(server_crypto_config); 784 CHECK(server_crypto_config);
786 CHECK(server_connection); 785 CHECK(server_connection);
787 CHECK(server_session); 786 CHECK(server_session);
788 CHECK(!connection_start_time.IsZero()) 787 CHECK(!connection_start_time.IsZero())
789 << "Connections must start at non-zero times, otherwise the " 788 << "Connections must start at non-zero times, otherwise the "
790 << "strike-register will be unhappy."; 789 << "strike-register will be unhappy.";
791 790
792 *server_connection = 791 *server_connection =
793 new PacketSavingConnection(helper, Perspective::IS_SERVER); 792 new PacketSavingConnection(helper, Perspective::IS_SERVER);
794 *server_session = new TestQuicSpdyServerSession( 793 *server_session = new TestQuicSpdyServerSession(
795 *server_connection, DefaultQuicConfig(), server_crypto_config); 794 *server_connection, DefaultQuicConfig(), server_crypto_config);
796 795
797 // We advance the clock initially because the default time is zero and the 796 // We advance the clock initially because the default time is zero and the
798 // strike register worries that we've just overflowed a uint32 time. 797 // strike register worries that we've just overflowed a uint32 time.
799 (*server_connection)->AdvanceTime(connection_start_time); 798 (*server_connection)->AdvanceTime(connection_start_time);
800 } 799 }
801 800
802 QuicStreamId QuicClientDataStreamId(int i) { 801 QuicStreamId QuicClientDataStreamId(int i) {
803 return kClientDataStreamId1 + 2 * i; 802 return kClientDataStreamId1 + 2 * i;
804 } 803 }
805 804
806 } // namespace test 805 } // namespace test
807 } // namespace net 806 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/quic_client_session_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698