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

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

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto ToT Created 6 years, 4 months 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/end_to_end_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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
225 class NiceMockPacketWriterFactory
226 : public QuicConnection::PacketWriterFactory {
227 public:
228 virtual ~NiceMockPacketWriterFactory() {}
229
230 virtual QuicPacketWriter* Create(
231 QuicConnection* /*connection*/) const override {
232 return new testing::NiceMock<MockPacketWriter>();
233 }
234 };
235 } // namespace
236
224 MockConnection::MockConnection(bool is_server) 237 MockConnection::MockConnection(bool is_server)
225 : QuicConnection(kTestConnectionId, 238 : QuicConnection(kTestConnectionId,
226 IPEndPoint(TestPeerIPAddress(), kTestPort), 239 IPEndPoint(TestPeerIPAddress(), kTestPort),
227 new testing::NiceMock<MockHelper>(), 240 new testing::NiceMock<MockHelper>(),
228 new testing::NiceMock<MockPacketWriter>(), 241 NiceMockPacketWriterFactory(),
229 true /* owns_writer */, 242 /* owns_writer= */ true,
230 is_server, QuicSupportedVersions()), 243 is_server, QuicSupportedVersions()),
231 helper_(helper()) { 244 helper_(helper()) {
232 } 245 }
233 246
234 MockConnection::MockConnection(IPEndPoint address, 247 MockConnection::MockConnection(IPEndPoint address,
235 bool is_server) 248 bool is_server)
236 : QuicConnection(kTestConnectionId, address, 249 : QuicConnection(kTestConnectionId, address,
237 new testing::NiceMock<MockHelper>(), 250 new testing::NiceMock<MockHelper>(),
238 new testing::NiceMock<MockPacketWriter>(), 251 NiceMockPacketWriterFactory(),
239 true /* owns_writer */, 252 /* owns_writer= */ true,
240 is_server, QuicSupportedVersions()), 253 is_server, QuicSupportedVersions()),
241 helper_(helper()) { 254 helper_(helper()) {
242 } 255 }
243 256
244 MockConnection::MockConnection(QuicConnectionId connection_id, 257 MockConnection::MockConnection(QuicConnectionId connection_id,
245 bool is_server) 258 bool is_server)
246 : QuicConnection(connection_id, 259 : QuicConnection(connection_id,
247 IPEndPoint(TestPeerIPAddress(), kTestPort), 260 IPEndPoint(TestPeerIPAddress(), kTestPort),
248 new testing::NiceMock<MockHelper>(), 261 new testing::NiceMock<MockHelper>(),
249 new testing::NiceMock<MockPacketWriter>(), 262 NiceMockPacketWriterFactory(),
250 true /* owns_writer */, 263 /* owns_writer= */ true,
251 is_server, QuicSupportedVersions()), 264 is_server, QuicSupportedVersions()),
252 helper_(helper()) { 265 helper_(helper()) {
253 } 266 }
254 267
255 MockConnection::MockConnection(bool is_server, 268 MockConnection::MockConnection(bool is_server,
256 const QuicVersionVector& supported_versions) 269 const QuicVersionVector& supported_versions)
257 : QuicConnection(kTestConnectionId, 270 : QuicConnection(kTestConnectionId,
258 IPEndPoint(TestPeerIPAddress(), kTestPort), 271 IPEndPoint(TestPeerIPAddress(), kTestPort),
259 new testing::NiceMock<MockHelper>(), 272 new testing::NiceMock<MockHelper>(),
260 new testing::NiceMock<MockPacketWriter>(), 273 NiceMockPacketWriterFactory(),
261 true /* owns_writer */, 274 /* owns_writer= */ true,
262 is_server, supported_versions), 275 is_server, supported_versions),
263 helper_(helper()) { 276 helper_(helper()) {
264 } 277 }
265 278
266 MockConnection::~MockConnection() { 279 MockConnection::~MockConnection() {
267 } 280 }
268 281
269 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 282 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
270 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 283 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
271 } 284 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 kInitialSessionFlowControlWindowForTest); 612 kInitialSessionFlowControlWindowForTest);
600 return config; 613 return config;
601 } 614 }
602 615
603 QuicVersionVector SupportedVersions(QuicVersion version) { 616 QuicVersionVector SupportedVersions(QuicVersion version) {
604 QuicVersionVector versions; 617 QuicVersionVector versions;
605 versions.push_back(version); 618 versions.push_back(version);
606 return versions; 619 return versions;
607 } 620 }
608 621
622 TestWriterFactory::TestWriterFactory() : current_writer_(NULL) {}
623 TestWriterFactory::~TestWriterFactory() {}
624
625 QuicPacketWriter* TestWriterFactory::Create(QuicServerPacketWriter* writer,
626 QuicConnection* connection) {
627 return new PerConnectionPacketWriter(this, writer, connection);
628 }
629
630 void TestWriterFactory::OnPacketSent(WriteResult result) {
631 if (current_writer_ != NULL) {
632 current_writer_->connection()->OnPacketSent(result);
633 current_writer_ = NULL;
634 }
635 }
636
637 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) {
638 if (current_writer_ == writer) {
639 current_writer_ = NULL;
640 }
641 }
642
643 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter(
644 TestWriterFactory* factory,
645 QuicServerPacketWriter* writer,
646 QuicConnection* connection)
647 : QuicPerConnectionPacketWriter(writer, connection),
648 factory_(factory) {
649 }
650
651 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() {
652 factory_->Unregister(this);
653 }
654
655 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket(
656 const char* buffer,
657 size_t buf_len,
658 const IPAddressNumber& self_address,
659 const IPEndPoint& peer_address) {
660 // A DCHECK(factory_current_writer_ == NULL) would be wrong here -- this class
661 // may be used in a setting where connection()->OnPacketSent() is called in a
662 // different way, so TestWriterFactory::OnPacketSent might never be called.
663 factory_->current_writer_ = this;
664 return QuicPerConnectionPacketWriter::WritePacket(buffer,
665 buf_len,
666 self_address,
667 peer_address);
668 }
669
609 } // namespace test 670 } // namespace test
610 } // namespace net 671 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/end_to_end_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698