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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 void MockHelper::AdvanceTime(QuicTime::Delta delta) { | 228 void MockHelper::AdvanceTime(QuicTime::Delta delta) { |
229 clock_.AdvanceTime(delta); | 229 clock_.AdvanceTime(delta); |
230 } | 230 } |
231 | 231 |
232 QuicPacketWriter* NiceMockPacketWriterFactory::Create( | 232 QuicPacketWriter* NiceMockPacketWriterFactory::Create( |
233 QuicConnection* /*connection*/) const { | 233 QuicConnection* /*connection*/) const { |
234 return new testing::NiceMock<MockPacketWriter>(); | 234 return new testing::NiceMock<MockPacketWriter>(); |
235 } | 235 } |
236 | 236 |
237 MockConnection::MockConnection(bool is_server) | 237 MockConnection::MockConnection(Perspective perspective) |
238 : QuicConnection(kTestConnectionId, | 238 : QuicConnection(kTestConnectionId, |
239 IPEndPoint(TestPeerIPAddress(), kTestPort), | 239 IPEndPoint(TestPeerIPAddress(), kTestPort), |
240 new testing::NiceMock<MockHelper>(), | 240 new testing::NiceMock<MockHelper>(), |
241 NiceMockPacketWriterFactory(), | 241 NiceMockPacketWriterFactory(), |
242 /* owns_writer= */ true, | 242 /* owns_writer= */ true, |
243 is_server, | 243 perspective, |
244 /* is_secure= */ false, | 244 /* is_secure= */ false, |
245 QuicSupportedVersions()), | 245 QuicSupportedVersions()), |
246 helper_(helper()) { | 246 helper_(helper()) { |
247 } | 247 } |
248 | 248 |
249 MockConnection::MockConnection(bool is_server, bool is_secure) | 249 MockConnection::MockConnection(Perspective perspective, bool is_secure) |
250 : QuicConnection(kTestConnectionId, | 250 : QuicConnection(kTestConnectionId, |
251 IPEndPoint(TestPeerIPAddress(), kTestPort), | 251 IPEndPoint(TestPeerIPAddress(), kTestPort), |
252 new testing::NiceMock<MockHelper>(), | 252 new testing::NiceMock<MockHelper>(), |
253 NiceMockPacketWriterFactory(), | 253 NiceMockPacketWriterFactory(), |
254 /* owns_writer= */ true, | 254 /* owns_writer= */ true, |
255 is_server, | 255 perspective, |
256 is_secure, | 256 is_secure, |
257 QuicSupportedVersions()), | 257 QuicSupportedVersions()), |
258 helper_(helper()) { | 258 helper_(helper()) { |
259 } | 259 } |
260 | 260 |
261 MockConnection::MockConnection(IPEndPoint address, | 261 MockConnection::MockConnection(IPEndPoint address, Perspective perspective) |
262 bool is_server) | 262 : QuicConnection(kTestConnectionId, |
263 : QuicConnection(kTestConnectionId, address, | 263 address, |
264 new testing::NiceMock<MockHelper>(), | 264 new testing::NiceMock<MockHelper>(), |
265 NiceMockPacketWriterFactory(), | 265 NiceMockPacketWriterFactory(), |
266 /* owns_writer= */ true, | 266 /* owns_writer= */ true, |
267 is_server, | 267 perspective, |
268 /* is_secure= */ false, | 268 /* is_secure= */ false, |
269 QuicSupportedVersions()), | 269 QuicSupportedVersions()), |
270 helper_(helper()) { | 270 helper_(helper()) { |
271 } | 271 } |
272 | 272 |
273 MockConnection::MockConnection(QuicConnectionId connection_id, | 273 MockConnection::MockConnection(QuicConnectionId connection_id, |
274 bool is_server) | 274 Perspective perspective) |
275 : QuicConnection(connection_id, | 275 : QuicConnection(connection_id, |
276 IPEndPoint(TestPeerIPAddress(), kTestPort), | 276 IPEndPoint(TestPeerIPAddress(), kTestPort), |
277 new testing::NiceMock<MockHelper>(), | 277 new testing::NiceMock<MockHelper>(), |
278 NiceMockPacketWriterFactory(), | 278 NiceMockPacketWriterFactory(), |
279 /* owns_writer= */ true, | 279 /* owns_writer= */ true, |
280 is_server, | 280 perspective, |
281 /* is_secure= */ false, | 281 /* is_secure= */ false, |
282 QuicSupportedVersions()), | 282 QuicSupportedVersions()), |
283 helper_(helper()) { | 283 helper_(helper()) { |
284 } | 284 } |
285 | 285 |
286 MockConnection::MockConnection(bool is_server, | 286 MockConnection::MockConnection(Perspective perspective, |
287 const QuicVersionVector& supported_versions) | 287 const QuicVersionVector& supported_versions) |
288 : QuicConnection(kTestConnectionId, | 288 : QuicConnection(kTestConnectionId, |
289 IPEndPoint(TestPeerIPAddress(), kTestPort), | 289 IPEndPoint(TestPeerIPAddress(), kTestPort), |
290 new testing::NiceMock<MockHelper>(), | 290 new testing::NiceMock<MockHelper>(), |
291 NiceMockPacketWriterFactory(), | 291 NiceMockPacketWriterFactory(), |
292 /* owns_writer= */ true, | 292 /* owns_writer= */ true, |
293 is_server, | 293 perspective, |
294 /* is_secure= */ false, | 294 /* is_secure= */ false, |
295 supported_versions), | 295 supported_versions), |
296 helper_(helper()) { | 296 helper_(helper()) { |
297 } | 297 } |
298 | 298 |
299 MockConnection::~MockConnection() { | 299 MockConnection::~MockConnection() { |
300 } | 300 } |
301 | 301 |
302 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 302 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
303 static_cast<MockHelper*>(helper())->AdvanceTime(delta); | 303 static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
304 } | 304 } |
305 | 305 |
306 PacketSavingConnection::PacketSavingConnection(bool is_server) | 306 PacketSavingConnection::PacketSavingConnection(Perspective perspective) |
307 : MockConnection(is_server) { | 307 : MockConnection(perspective) { |
308 } | 308 } |
309 | 309 |
310 PacketSavingConnection::PacketSavingConnection( | 310 PacketSavingConnection::PacketSavingConnection( |
311 bool is_server, | 311 Perspective perspective, |
312 const QuicVersionVector& supported_versions) | 312 const QuicVersionVector& supported_versions) |
313 : MockConnection(is_server, supported_versions) { | 313 : MockConnection(perspective, supported_versions) { |
314 } | 314 } |
315 | 315 |
316 PacketSavingConnection::~PacketSavingConnection() { | 316 PacketSavingConnection::~PacketSavingConnection() { |
317 STLDeleteElements(&encrypted_packets_); | 317 STLDeleteElements(&encrypted_packets_); |
318 } | 318 } |
319 | 319 |
320 void PacketSavingConnection::SendOrQueuePacket(QueuedPacket packet) { | 320 void PacketSavingConnection::SendOrQueuePacket(QueuedPacket packet) { |
321 encrypted_packets_.push_back(packet.serialized_packet.packet); | 321 encrypted_packets_.push_back(packet.serialized_packet.packet); |
322 // Transfer ownership of the packet to the SentPacketManager and the | 322 // Transfer ownership of the packet to the SentPacketManager and the |
323 // ack notifier to the AckNotifierManager. | 323 // ack notifier to the AckNotifierManager. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 hex += mark ? '*' : ' '; | 424 hex += mark ? '*' : ' '; |
425 hex += kHexChars[(*p & 0xf0) >> 4]; | 425 hex += kHexChars[(*p & 0xf0) >> 4]; |
426 hex += kHexChars[*p & 0x0f]; | 426 hex += kHexChars[*p & 0x0f]; |
427 hex += mark ? '*' : ' '; | 427 hex += mark ? '*' : ' '; |
428 } else { | 428 } else { |
429 hex += " "; | 429 hex += " "; |
430 } | 430 } |
431 } | 431 } |
432 hex = hex + " "; | 432 hex = hex + " "; |
433 | 433 |
434 for (const char *p = row; p < row + 4 && p < row + length; ++p) | 434 for (const char* p = row; p < row + 4 && p < row + length; ++p) { |
435 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; | 435 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; |
| 436 } |
436 | 437 |
437 hex = hex + '\n'; | 438 hex = hex + '\n'; |
438 } | 439 } |
439 return hex; | 440 return hex; |
440 } | 441 } |
441 | 442 |
442 } // namespace | 443 } // namespace |
443 | 444 |
444 IPAddressNumber TestPeerIPAddress() { return Loopback4(); } | 445 IPAddressNumber TestPeerIPAddress() { return Loopback4(); } |
445 | 446 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 header.packet_sequence_number = sequence_number; | 496 header.packet_sequence_number = sequence_number; |
496 header.entropy_flag = false; | 497 header.entropy_flag = false; |
497 header.entropy_hash = 0; | 498 header.entropy_hash = 0; |
498 header.fec_flag = false; | 499 header.fec_flag = false; |
499 header.is_in_fec_group = NOT_IN_FEC_GROUP; | 500 header.is_in_fec_group = NOT_IN_FEC_GROUP; |
500 header.fec_group = 0; | 501 header.fec_group = 0; |
501 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data)); | 502 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data)); |
502 QuicFrame frame(&stream_frame); | 503 QuicFrame frame(&stream_frame); |
503 QuicFrames frames; | 504 QuicFrames frames; |
504 frames.push_back(frame); | 505 frames.push_back(frame); |
505 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); | 506 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), |
| 507 Perspective::IS_CLIENT); |
506 scoped_ptr<QuicPacket> packet( | 508 scoped_ptr<QuicPacket> packet( |
507 BuildUnsizedDataPacket(&framer, header, frames)); | 509 BuildUnsizedDataPacket(&framer, header, frames)); |
508 EXPECT_TRUE(packet != nullptr); | 510 EXPECT_TRUE(packet != nullptr); |
509 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE, | 511 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE, |
510 sequence_number, | 512 sequence_number, |
511 *packet); | 513 *packet); |
512 EXPECT_TRUE(encrypted != nullptr); | 514 EXPECT_TRUE(encrypted != nullptr); |
513 return encrypted; | 515 return encrypted; |
514 } | 516 } |
515 | 517 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size()); | 558 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size()); |
557 return true; | 559 return true; |
558 } | 560 } |
559 | 561 |
560 static QuicPacket* ConstructPacketFromHandshakeMessage( | 562 static QuicPacket* ConstructPacketFromHandshakeMessage( |
561 QuicConnectionId connection_id, | 563 QuicConnectionId connection_id, |
562 const CryptoHandshakeMessage& message, | 564 const CryptoHandshakeMessage& message, |
563 bool should_include_version) { | 565 bool should_include_version) { |
564 CryptoFramer crypto_framer; | 566 CryptoFramer crypto_framer; |
565 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); | 567 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); |
566 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false); | 568 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), |
| 569 Perspective::IS_CLIENT); |
567 | 570 |
568 QuicPacketHeader header; | 571 QuicPacketHeader header; |
569 header.public_header.connection_id = connection_id; | 572 header.public_header.connection_id = connection_id; |
570 header.public_header.reset_flag = false; | 573 header.public_header.reset_flag = false; |
571 header.public_header.version_flag = should_include_version; | 574 header.public_header.version_flag = should_include_version; |
572 header.packet_sequence_number = 1; | 575 header.packet_sequence_number = 1; |
573 header.entropy_flag = false; | 576 header.entropy_flag = false; |
574 header.entropy_hash = 0; | 577 header.entropy_hash = 0; |
575 header.fec_flag = false; | 578 header.fec_flag = false; |
576 header.fec_group = 0; | 579 header.fec_group = 0; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 // called. | 694 // called. |
692 factory_->current_writer_ = this; | 695 factory_->current_writer_ = this; |
693 return QuicPerConnectionPacketWriter::WritePacket(buffer, | 696 return QuicPerConnectionPacketWriter::WritePacket(buffer, |
694 buf_len, | 697 buf_len, |
695 self_address, | 698 self_address, |
696 peer_address); | 699 peer_address); |
697 } | 700 } |
698 | 701 |
699 } // namespace test | 702 } // namespace test |
700 } // namespace net | 703 } // namespace net |
OLD | NEW |