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" |
11 #include "net/quic/crypto/crypto_handshake.h" | 11 #include "net/quic/crypto/crypto_handshake.h" |
12 #include "net/quic/crypto/crypto_utils.h" | 12 #include "net/quic/crypto/crypto_utils.h" |
13 #include "net/quic/crypto/null_encrypter.h" | 13 #include "net/quic/crypto/null_encrypter.h" |
14 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
15 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
16 #include "net/quic/quic_data_writer.h" | 16 #include "net/quic/quic_data_writer.h" |
17 #include "net/quic/quic_framer.h" | 17 #include "net/quic/quic_framer.h" |
18 #include "net/quic/quic_packet_creator.h" | 18 #include "net/quic/quic_packet_creator.h" |
19 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
20 #include "net/quic/test_tools/quic_connection_peer.h" | 20 #include "net/quic/test_tools/quic_connection_peer.h" |
21 #include "net/spdy/spdy_frame_builder.h" | 21 #include "net/spdy/spdy_frame_builder.h" |
| 22 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
22 | 23 |
23 using base::StringPiece; | 24 using base::StringPiece; |
24 using std::max; | 25 using std::max; |
25 using std::min; | 26 using std::min; |
26 using std::string; | 27 using std::string; |
27 using testing::AnyNumber; | 28 using testing::AnyNumber; |
28 using testing::_; | 29 using testing::_; |
29 | 30 |
30 namespace net { | 31 namespace net { |
31 namespace test { | 32 namespace test { |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 | 661 |
661 QuicVersionVector SupportedVersions(QuicVersion version) { | 662 QuicVersionVector SupportedVersions(QuicVersion version) { |
662 QuicVersionVector versions; | 663 QuicVersionVector versions; |
663 versions.push_back(version); | 664 versions.push_back(version); |
664 return versions; | 665 return versions; |
665 } | 666 } |
666 | 667 |
667 TestWriterFactory::TestWriterFactory() : current_writer_(nullptr) {} | 668 TestWriterFactory::TestWriterFactory() : current_writer_(nullptr) {} |
668 TestWriterFactory::~TestWriterFactory() {} | 669 TestWriterFactory::~TestWriterFactory() {} |
669 | 670 |
670 QuicPacketWriter* TestWriterFactory::Create(QuicServerPacketWriter* writer, | 671 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer, |
671 QuicConnection* connection) { | 672 QuicConnection* connection) { |
672 return new PerConnectionPacketWriter(this, writer, connection); | 673 return new PerConnectionPacketWriter(this, writer, connection); |
673 } | 674 } |
674 | 675 |
675 void TestWriterFactory::OnPacketSent(WriteResult result) { | 676 void TestWriterFactory::OnPacketSent(WriteResult result) { |
676 if (current_writer_ != nullptr && result.status == WRITE_STATUS_ERROR) { | 677 if (current_writer_ != nullptr && result.status == WRITE_STATUS_ERROR) { |
677 current_writer_->connection()->OnWriteError(result.error_code); | 678 current_writer_->connection()->OnWriteError(result.error_code); |
678 current_writer_ = nullptr; | 679 current_writer_ = nullptr; |
679 } | 680 } |
680 } | 681 } |
681 | 682 |
682 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) { | 683 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) { |
683 if (current_writer_ == writer) { | 684 if (current_writer_ == writer) { |
684 current_writer_ = nullptr; | 685 current_writer_ = nullptr; |
685 } | 686 } |
686 } | 687 } |
687 | 688 |
688 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter( | 689 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter( |
689 TestWriterFactory* factory, | 690 TestWriterFactory* factory, |
690 QuicServerPacketWriter* writer, | 691 QuicPacketWriter* writer, |
691 QuicConnection* connection) | 692 QuicConnection* connection) |
692 : QuicPerConnectionPacketWriter(writer, connection), | 693 : QuicPerConnectionPacketWriter(writer, connection), |
693 factory_(factory) { | 694 factory_(factory) { |
694 } | 695 } |
695 | 696 |
696 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() { | 697 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() { |
697 factory_->Unregister(this); | 698 factory_->Unregister(this); |
698 } | 699 } |
699 | 700 |
700 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket( | 701 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket( |
701 const char* buffer, | 702 const char* buffer, |
702 size_t buf_len, | 703 size_t buf_len, |
703 const IPAddressNumber& self_address, | 704 const IPAddressNumber& self_address, |
704 const IPEndPoint& peer_address) { | 705 const IPEndPoint& peer_address) { |
705 // A DCHECK(factory_current_writer_ == nullptr) would be wrong here -- this | 706 // A DCHECK(factory_current_writer_ == nullptr) would be wrong here -- this |
706 // class may be used in a setting where connection()->OnPacketSent() is called | 707 // class may be used in a setting where connection()->OnPacketSent() is called |
707 // in a different way, so TestWriterFactory::OnPacketSent might never be | 708 // in a different way, so TestWriterFactory::OnPacketSent might never be |
708 // called. | 709 // called. |
709 factory_->current_writer_ = this; | 710 factory_->current_writer_ = this; |
710 return QuicPerConnectionPacketWriter::WritePacket(buffer, | 711 return tools::QuicPerConnectionPacketWriter::WritePacket(buffer, |
711 buf_len, | 712 buf_len, |
712 self_address, | 713 self_address, |
713 peer_address); | 714 peer_address); |
714 } | 715 } |
715 | 716 |
716 } // namespace test | 717 } // namespace test |
717 } // namespace net | 718 } // namespace net |
OLD | NEW |