| 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/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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 214 } |
| 215 | 215 |
| 216 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { | 216 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { |
| 217 return new TestAlarm(delegate); | 217 return new TestAlarm(delegate); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MockHelper::AdvanceTime(QuicTime::Delta delta) { | 220 void MockHelper::AdvanceTime(QuicTime::Delta delta) { |
| 221 clock_.AdvanceTime(delta); | 221 clock_.AdvanceTime(delta); |
| 222 } | 222 } |
| 223 | 223 |
| 224 namespace { | 224 QuicPacketWriter* NiceMockPacketWriterFactory::Create( |
| 225 class NiceMockPacketWriterFactory | 225 QuicConnection* /*connection*/) const { |
| 226 : public QuicConnection::PacketWriterFactory { | 226 return new testing::NiceMock<MockPacketWriter>(); |
| 227 public: | 227 } |
| 228 NiceMockPacketWriterFactory() {} | |
| 229 ~NiceMockPacketWriterFactory() override {} | |
| 230 | |
| 231 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override { | |
| 232 return new testing::NiceMock<MockPacketWriter>(); | |
| 233 } | |
| 234 | |
| 235 private: | |
| 236 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); | |
| 237 }; | |
| 238 } // namespace | |
| 239 | 228 |
| 240 MockConnection::MockConnection(bool is_server) | 229 MockConnection::MockConnection(bool is_server) |
| 241 : QuicConnection(kTestConnectionId, | 230 : QuicConnection(kTestConnectionId, |
| 242 IPEndPoint(TestPeerIPAddress(), kTestPort), | 231 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 243 new testing::NiceMock<MockHelper>(), | 232 new testing::NiceMock<MockHelper>(), |
| 244 NiceMockPacketWriterFactory(), | 233 NiceMockPacketWriterFactory(), |
| 245 /* owns_writer= */ true, | 234 /* owns_writer= */ true, |
| 246 is_server, QuicSupportedVersions()), | 235 is_server, |
| 236 /* is_secure= */ false, |
| 237 QuicSupportedVersions()), |
| 247 helper_(helper()) { | 238 helper_(helper()) { |
| 248 } | 239 } |
| 249 | 240 |
| 241 MockConnection::MockConnection(bool is_server, bool is_secure) |
| 242 : QuicConnection(kTestConnectionId, |
| 243 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 244 new testing::NiceMock<MockHelper>(), |
| 245 NiceMockPacketWriterFactory(), |
| 246 /* owns_writer= */ true, |
| 247 is_server, |
| 248 is_secure, |
| 249 QuicSupportedVersions()), |
| 250 helper_(helper()) { |
| 251 } |
| 252 |
| 250 MockConnection::MockConnection(IPEndPoint address, | 253 MockConnection::MockConnection(IPEndPoint address, |
| 251 bool is_server) | 254 bool is_server) |
| 252 : QuicConnection(kTestConnectionId, address, | 255 : QuicConnection(kTestConnectionId, address, |
| 253 new testing::NiceMock<MockHelper>(), | 256 new testing::NiceMock<MockHelper>(), |
| 254 NiceMockPacketWriterFactory(), | 257 NiceMockPacketWriterFactory(), |
| 255 /* owns_writer= */ true, | 258 /* owns_writer= */ true, |
| 256 is_server, QuicSupportedVersions()), | 259 is_server, |
| 260 /* is_secure= */ false, |
| 261 QuicSupportedVersions()), |
| 257 helper_(helper()) { | 262 helper_(helper()) { |
| 258 } | 263 } |
| 259 | 264 |
| 260 MockConnection::MockConnection(QuicConnectionId connection_id, | 265 MockConnection::MockConnection(QuicConnectionId connection_id, |
| 261 bool is_server) | 266 bool is_server) |
| 262 : QuicConnection(connection_id, | 267 : QuicConnection(connection_id, |
| 263 IPEndPoint(TestPeerIPAddress(), kTestPort), | 268 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 264 new testing::NiceMock<MockHelper>(), | 269 new testing::NiceMock<MockHelper>(), |
| 265 NiceMockPacketWriterFactory(), | 270 NiceMockPacketWriterFactory(), |
| 266 /* owns_writer= */ true, | 271 /* owns_writer= */ true, |
| 267 is_server, QuicSupportedVersions()), | 272 is_server, |
| 273 /* is_secure= */ false, |
| 274 QuicSupportedVersions()), |
| 268 helper_(helper()) { | 275 helper_(helper()) { |
| 269 } | 276 } |
| 270 | 277 |
| 271 MockConnection::MockConnection(bool is_server, | 278 MockConnection::MockConnection(bool is_server, |
| 272 const QuicVersionVector& supported_versions) | 279 const QuicVersionVector& supported_versions) |
| 273 : QuicConnection(kTestConnectionId, | 280 : QuicConnection(kTestConnectionId, |
| 274 IPEndPoint(TestPeerIPAddress(), kTestPort), | 281 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 275 new testing::NiceMock<MockHelper>(), | 282 new testing::NiceMock<MockHelper>(), |
| 276 NiceMockPacketWriterFactory(), | 283 NiceMockPacketWriterFactory(), |
| 277 /* owns_writer= */ true, | 284 /* owns_writer= */ true, |
| 278 is_server, supported_versions), | 285 is_server, |
| 286 /* is_secure= */ false, |
| 287 supported_versions), |
| 279 helper_(helper()) { | 288 helper_(helper()) { |
| 280 } | 289 } |
| 281 | 290 |
| 282 MockConnection::~MockConnection() { | 291 MockConnection::~MockConnection() { |
| 283 } | 292 } |
| 284 | 293 |
| 285 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 294 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
| 286 static_cast<MockHelper*>(helper())->AdvanceTime(delta); | 295 static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
| 287 } | 296 } |
| 288 | 297 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 309 *packet.serialized_packet.packet); | 318 *packet.serialized_packet.packet); |
| 310 encrypted_packets_.push_back(encrypted); | 319 encrypted_packets_.push_back(encrypted); |
| 311 // Transfer ownership of the packet to the SentPacketManager and the | 320 // Transfer ownership of the packet to the SentPacketManager and the |
| 312 // ack notifier to the AckNotifierManager. | 321 // ack notifier to the AckNotifierManager. |
| 313 sent_packet_manager_.OnPacketSent( | 322 sent_packet_manager_.OnPacketSent( |
| 314 &packet.serialized_packet, 0, QuicTime::Zero(), 1000, | 323 &packet.serialized_packet, 0, QuicTime::Zero(), 1000, |
| 315 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | 324 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
| 316 } | 325 } |
| 317 | 326 |
| 318 MockSession::MockSession(QuicConnection* connection) | 327 MockSession::MockSession(QuicConnection* connection) |
| 319 : QuicSession(connection, DefaultQuicConfig(), /*is_secure=*/false) { | 328 : QuicSession(connection, DefaultQuicConfig()) { |
| 320 InitializeSession(); | 329 InitializeSession(); |
| 321 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 330 ON_CALL(*this, WritevData(_, _, _, _, _, _)) |
| 322 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 331 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 323 } | 332 } |
| 324 | 333 |
| 325 MockSession::~MockSession() { | 334 MockSession::~MockSession() { |
| 326 } | 335 } |
| 327 | 336 |
| 328 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) | 337 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) |
| 329 : QuicSession(connection, config, /*is_secure=*/false), | 338 : QuicSession(connection, config), |
| 330 crypto_stream_(nullptr) { | 339 crypto_stream_(nullptr) { |
| 331 InitializeSession(); | 340 InitializeSession(); |
| 332 } | 341 } |
| 333 | 342 |
| 334 TestSession::~TestSession() {} | 343 TestSession::~TestSession() {} |
| 335 | 344 |
| 336 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { | 345 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 337 crypto_stream_ = stream; | 346 crypto_stream_ = stream; |
| 338 } | 347 } |
| 339 | 348 |
| 340 QuicCryptoStream* TestSession::GetCryptoStream() { | 349 QuicCryptoStream* TestSession::GetCryptoStream() { |
| 341 return crypto_stream_; | 350 return crypto_stream_; |
| 342 } | 351 } |
| 343 | 352 |
| 344 TestClientSession::TestClientSession(QuicConnection* connection, | 353 TestClientSession::TestClientSession(QuicConnection* connection, |
| 345 const QuicConfig& config) | 354 const QuicConfig& config) |
| 346 : QuicClientSessionBase(connection, config, /*is_secure=*/false), | 355 : QuicClientSessionBase(connection, config), |
| 347 crypto_stream_(nullptr) { | 356 crypto_stream_(nullptr) { |
| 348 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber()); | 357 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber()); |
| 349 InitializeSession(); | 358 InitializeSession(); |
| 350 } | 359 } |
| 351 | 360 |
| 352 TestClientSession::~TestClientSession() {} | 361 TestClientSession::~TestClientSession() {} |
| 353 | 362 |
| 354 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { | 363 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 355 crypto_stream_ = stream; | 364 crypto_stream_ = stream; |
| 356 } | 365 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 // called. | 678 // called. |
| 670 factory_->current_writer_ = this; | 679 factory_->current_writer_ = this; |
| 671 return QuicPerConnectionPacketWriter::WritePacket(buffer, | 680 return QuicPerConnectionPacketWriter::WritePacket(buffer, |
| 672 buf_len, | 681 buf_len, |
| 673 self_address, | 682 self_address, |
| 674 peer_address); | 683 peer_address); |
| 675 } | 684 } |
| 676 | 685 |
| 677 } // namespace test | 686 } // namespace test |
| 678 } // namespace net | 687 } // namespace net |
| OLD | NEW |