[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / net / tools / quic / test_tools / quic_test_utils.cc
blob69b571d8667b2f5067ce20f46840c15be8a715f8
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
3 // found in the LICENSE file.
5 #include "net/tools/quic/test_tools/quic_test_utils.h"
7 #include "net/quic/quic_connection.h"
8 #include "net/quic/test_tools/quic_connection_peer.h"
9 #include "net/quic/test_tools/quic_test_utils.h"
10 #include "net/tools/epoll_server/epoll_server.h"
11 #include "net/tools/quic/quic_epoll_connection_helper.h"
13 using base::StringPiece;
14 using net::test::MakeAckFrame;
15 using net::test::MockHelper;
16 using net::test::QuicConnectionPeer;
17 using testing::_;
18 using testing::AnyNumber;
19 using testing::Invoke;
21 namespace net {
22 namespace tools {
23 namespace test {
25 QuicAckFrame MakeAckFrameWithNackRanges(
26 size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked) {
27 QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked);
28 // Add enough missing packets to get num_nack_ranges nack ranges.
29 for (QuicPacketSequenceNumber i = 1; i < 2 * num_nack_ranges; i += 2) {
30 ack.missing_packets.insert(least_unacked + i);
32 return ack;
35 MockPacketWriter::MockPacketWriter() {
38 MockPacketWriter::~MockPacketWriter() {
41 MockQuicServerSessionVisitor::MockQuicServerSessionVisitor() {
44 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() {
47 MockAckNotifierDelegate::MockAckNotifierDelegate() {
50 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
53 TestWriterFactory::TestWriterFactory() : current_writer_(nullptr) {}
54 TestWriterFactory::~TestWriterFactory() {}
56 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer,
57 QuicConnection* connection) {
58 return new PerConnectionPacketWriter(this, writer, connection);
61 void TestWriterFactory::OnPacketSent(WriteResult result) {
62 if (current_writer_ != nullptr && result.status == WRITE_STATUS_ERROR) {
63 current_writer_->connection()->OnWriteError(result.error_code);
64 current_writer_ = nullptr;
68 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) {
69 if (current_writer_ == writer) {
70 current_writer_ = nullptr;
74 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter(
75 TestWriterFactory* factory,
76 QuicPacketWriter* writer,
77 QuicConnection* connection)
78 : QuicPerConnectionPacketWriter(writer, connection),
79 factory_(factory) {
82 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() {
83 factory_->Unregister(this);
86 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket(
87 const char* buffer,
88 size_t buf_len,
89 const IPAddressNumber& self_address,
90 const IPEndPoint& peer_address) {
91 // A DCHECK(factory_current_writer_ == nullptr) would be wrong here -- this
92 // class may be used in a setting where connection()->OnPacketSent() is called
93 // in a different way, so TestWriterFactory::OnPacketSent might never be
94 // called.
95 factory_->current_writer_ = this;
96 return QuicPerConnectionPacketWriter::WritePacket(buffer, buf_len,
97 self_address, peer_address);
100 MockTimeWaitListManager::MockTimeWaitListManager(
101 QuicPacketWriter* writer,
102 QuicServerSessionVisitor* visitor,
103 QuicConnectionHelperInterface* helper)
104 : QuicTimeWaitListManager(writer, visitor, helper,
105 QuicSupportedVersions()) {
106 // Though AddConnectionIdToTimeWait is mocked, we want to retain its
107 // functionality.
108 EXPECT_CALL(*this, AddConnectionIdToTimeWait(_, _, _, _)).Times(AnyNumber());
109 ON_CALL(*this, AddConnectionIdToTimeWait(_, _, _, _))
110 .WillByDefault(
111 Invoke(this, &MockTimeWaitListManager::
112 QuicTimeWaitListManager_AddConnectionIdToTimeWait));
115 MockTimeWaitListManager::~MockTimeWaitListManager() {
118 } // namespace test
119 } // namespace tools
120 } // namespace net