Add ClearControlFrame() to quic_test_utils.
This function does not have to live in a class and does not need seven identical
definitions.
gfe-relnote: n/a, test-only refactoring.
PiperOrigin-RevId: 254999491
Change-Id: I1173acb47388e3a5ca010c927c4e886d3b6ab387
diff --git a/quic/core/http/quic_spdy_session_test.cc b/quic/core/http/quic_spdy_session_test.cc
index 1819f40..a9540ea 100644
--- a/quic/core/http/quic_spdy_session_test.cc
+++ b/quic/core/http/quic_spdy_session_test.cc
@@ -254,11 +254,6 @@
return consumed;
}
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
-
QuicConsumedData SendLargeFakeData(QuicStream* stream, int bytes) {
DCHECK(writev_consumes_all_data_);
return WritevData(stream, stream->id(), bytes, 0, FIN);
@@ -322,12 +317,12 @@
void CloseStream(QuicStreamId id) {
if (!VersionHasIetfQuicFrames(transport_version())) {
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
} else {
// V99 has two frames, RST_STREAM and STOP_SENDING
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
}
EXPECT_CALL(*connection_, OnStreamReset(id, _));
session_.CloseStream(id);
@@ -887,7 +882,7 @@
InSequence s;
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream2, OnCanWrite()).WillOnce(Invoke([this, stream2]() {
session_.SendStreamData(stream2);
}));
@@ -985,7 +980,7 @@
return;
}
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
EXPECT_TRUE(session_.goaway_sent());
session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
@@ -1182,10 +1177,10 @@
EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
if (VersionHasIetfQuicFrames(transport_version())) {
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
} else {
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
}
for (QuicStreamId i = 0;
!crypto_stream->flow_controller()->IsBlocked() && i < 1000u; i++) {
@@ -1255,7 +1250,7 @@
QuicStreamId stream_id = 5;
// Write until the header stream is flow control blocked.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
SpdyHeaderBlock headers;
SimpleRandom random;
while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) {
@@ -1308,7 +1303,7 @@
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
if (!VersionHasIetfQuicFrames(transport_version())) {
// For version99 the call to OnStreamReset happens as a result of receiving
// the STOP_SENDING, so set up the EXPECT there.
@@ -1566,12 +1561,12 @@
// EXPECT_EQ(1u, session_.GetNumOpenStreams());
if (!VersionHasIetfQuicFrames(transport_version())) {
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
} else {
// V99 has two frames, RST_STREAM and STOP_SENDING
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
}
// Close the stream only if not version 99. If we are version 99
// then closing the stream opens up the available stream id space,
@@ -1978,7 +1973,7 @@
EXPECT_CALL(*stream2, OnCanWrite());
EXPECT_CALL(*stream2, HasPendingRetransmission()).WillOnce(Return(false));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream2, OnCanWrite());
EXPECT_CALL(*stream6, OnCanWrite());
session_.OnCanWrite();
@@ -1994,7 +1989,7 @@
TestStream* stream4 = session_.CreateOutgoingBidirectionalStream();
TestStream* stream6 = session_.CreateOutgoingBidirectionalStream();
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
session_.SendWindowUpdate(stream2->id(), 9);
QuicStreamFrame frame1(stream2->id(), false, 0, 9);
@@ -2010,7 +2005,7 @@
EXPECT_CALL(*stream2, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream4, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*stream6, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*send_algorithm, OnApplicationLimited(_));
diff --git a/quic/core/quic_control_frame_manager_test.cc b/quic/core/quic_control_frame_manager_test.cc
index ccddadd..216ba74 100644
--- a/quic/core/quic_control_frame_manager_test.cc
+++ b/quic/core/quic_control_frame_manager_test.cc
@@ -11,6 +11,7 @@
using testing::_;
using testing::InSequence;
+using testing::Invoke;
using testing::Return;
using testing::StrictMock;
@@ -31,10 +32,6 @@
class QuicControlFrameManagerTest : public QuicTest {
public:
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
bool SaveControlFrame(const QuicFrame& frame) {
frame_ = frame;
return true;
@@ -103,8 +100,7 @@
InSequence s;
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(3)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, SendControlFrame(_)).WillOnce(Return(false));
// Send control frames 1, 2, 3.
manager_->OnCanWrite();
@@ -139,8 +135,7 @@
// Send control frames 4, 5.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
manager_->WritePing();
EXPECT_FALSE(manager_->WillingToWrite());
@@ -151,8 +146,7 @@
InSequence s;
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(3)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, SendControlFrame(_)).WillOnce(Return(false));
// Send control frames 1, 2, 3.
manager_->OnCanWrite();
@@ -169,8 +163,7 @@
// Retransmit control frames 1, 3.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
EXPECT_FALSE(manager_->HasPendingRetransmission());
EXPECT_TRUE(manager_->WillingToWrite());
@@ -178,8 +171,7 @@
// Send control frames 4, 5, and 6.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(number_of_frames_ - 2u)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
manager_->WritePing();
EXPECT_FALSE(manager_->WillingToWrite());
@@ -191,8 +183,7 @@
// Send control frames 1, 2, 3, 4.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(number_of_frames_)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
// Ack control frame 2.
@@ -203,7 +194,7 @@
// Retransmit control frame 3.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
EXPECT_TRUE(manager_->RetransmitControlFrame(QuicFrame(&window_update_)));
// Retransmit control frame 4, and connection is write blocked.
@@ -215,7 +206,7 @@
Initialize();
InSequence s;
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, SendControlFrame(_)).WillOnce(Return(false));
// Send control frame 1.
manager_->OnCanWrite();
@@ -227,8 +218,7 @@
// Verify only the buffered frames are sent.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(number_of_frames_ - 1)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
EXPECT_FALSE(manager_->HasPendingRetransmission());
EXPECT_FALSE(manager_->WillingToWrite());
@@ -247,8 +237,7 @@
InSequence s;
// Flush all buffered control frames.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
// Mark all 3 window updates as lost.
@@ -280,8 +269,7 @@
InSequence s;
// Flush all buffered control frames.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
// Mark all 3 window updates as lost.
@@ -294,8 +282,7 @@
// Verify all 3 window updates get retransmitted.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(3)
- .WillRepeatedly(
- Invoke(this, &QuicControlFrameManagerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
manager_->OnCanWrite();
EXPECT_FALSE(manager_->HasPendingRetransmission());
EXPECT_FALSE(manager_->WillingToWrite());
diff --git a/quic/core/quic_flow_controller_test.cc b/quic/core/quic_flow_controller_test.cc
index 771b2e2..299f922 100644
--- a/quic/core/quic_flow_controller_test.cc
+++ b/quic/core/quic_flow_controller_test.cc
@@ -16,6 +16,7 @@
#include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h"
using testing::_;
+using testing::Invoke;
namespace quic {
namespace test {
@@ -45,11 +46,6 @@
should_auto_tune_receive_window_, &session_flow_controller_);
}
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
-
protected:
QuicStreamId stream_id_ = 1234;
QuicByteCount send_window_ = kInitialSessionFlowControlWindowForTest;
@@ -243,7 +239,7 @@
// This test will generate two WINDOW_UPDATE frames.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(this, &QuicFlowControllerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_FALSE(flow_controller_->auto_tune_receive_window());
// Make sure clock is inititialized.
@@ -353,7 +349,7 @@
// This test will generate two WINDOW_UPDATE frames.
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(this, &QuicFlowControllerTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_FALSE(flow_controller_->auto_tune_receive_window());
// Make sure clock is inititialized.
diff --git a/quic/core/quic_session_test.cc b/quic/core/quic_session_test.cc
index 3e7159d..5ea8633 100644
--- a/quic/core/quic_session_test.cc
+++ b/quic/core/quic_session_test.cc
@@ -280,11 +280,6 @@
return consumed;
}
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
-
bool SaveFrame(const QuicFrame& frame) {
save_frame_ = frame;
DeleteFrame(&const_cast<QuicFrame&>(frame));
@@ -371,10 +366,10 @@
// Once for the RST_STREAM, Once for the STOP_SENDING
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
} else {
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
}
EXPECT_CALL(*connection_, OnStreamReset(id, _));
}
@@ -1118,7 +1113,7 @@
InSequence s;
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream2, OnCanWrite()).WillOnce(Invoke([this, stream2]() {
session_.SendStreamData(stream2);
}));
@@ -1201,7 +1196,7 @@
return;
}
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
EXPECT_TRUE(session_.goaway_sent());
session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
@@ -1422,7 +1417,7 @@
EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
for (QuicStreamId i = 0;
!crypto_stream->flow_controller()->IsBlocked() && i < 1000u; i++) {
EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
@@ -1467,7 +1462,7 @@
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, OnStreamReset(stream->id(), _));
QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream->id(),
@@ -1674,11 +1669,11 @@
// Expect two control frames, RST STREAM and STOP SENDING
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
} else {
// Expect one control frame, just RST STREAM
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
}
// Close stream. Should not make new streams available since
// the stream is not finished.
@@ -1934,7 +1929,7 @@
QUIC_STREAM_CANCELLED, 1234);
// Just for the RST_STREAM
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
if (VersionHasIetfQuicFrames(transport_version())) {
EXPECT_CALL(*connection_,
OnStreamReset(stream2->id(), QUIC_STREAM_CANCELLED));
@@ -1962,7 +1957,7 @@
// Once for the RST_STREAM, once for the STOP_SENDING
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(2)
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
} else {
// Just for the RST_STREAM
EXPECT_CALL(*connection_, SendControlFrame(_)).Times(1);
@@ -2100,7 +2095,7 @@
EXPECT_CALL(*stream2, OnCanWrite());
EXPECT_CALL(*stream2, HasPendingRetransmission()).WillOnce(Return(false));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream2, OnCanWrite());
EXPECT_CALL(*stream6, OnCanWrite());
session_.OnCanWrite();
@@ -2116,7 +2111,7 @@
TestStream* stream4 = session_.CreateOutgoingBidirectionalStream();
TestStream* stream6 = session_.CreateOutgoingBidirectionalStream();
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
session_.SendWindowUpdate(stream2->id(), 9);
QuicStreamFrame frame1(stream2->id(), false, 0, 9);
@@ -2132,7 +2127,7 @@
EXPECT_CALL(*stream2, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
EXPECT_CALL(*stream4, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*stream6, RetransmitStreamData(_, _, _)).WillOnce(Return(true));
EXPECT_CALL(*send_algorithm, OnApplicationLimited(_));
@@ -2245,7 +2240,7 @@
// Reset stream2 locally.
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillRepeatedly(Invoke(&session_, &TestSession::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
EXPECT_CALL(*connection_, OnStreamReset(stream2->id(), _));
stream2->Reset(QUIC_STREAM_CANCELLED);
diff --git a/quic/core/quic_stream_id_manager_test.cc b/quic/core/quic_stream_id_manager_test.cc
index 9f5969e..30ff954 100644
--- a/quic/core/quic_stream_id_manager_test.cc
+++ b/quic/core/quic_stream_id_manager_test.cc
@@ -77,11 +77,6 @@
const QuicFrame& save_frame() { return save_frame_; }
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
-
TestQuicStream* CreateOutgoingBidirectionalStream() {
if (!CanOpenNextOutgoingBidirectionalStream()) {
return nullptr;
diff --git a/quic/core/quic_stream_test.cc b/quic/core/quic_stream_test.cc
index 4c5dac7..45fae55 100644
--- a/quic/core/quic_stream_test.cc
+++ b/quic/core/quic_stream_test.cc
@@ -121,11 +121,6 @@
return QuicConsumedData(1, false);
}
- bool ClearControlFrame(const QuicFrame& frame) {
- DeleteFrame(&const_cast<QuicFrame&>(frame));
- return true;
- }
-
bool ClearResetStreamFrame(const QuicFrame& frame) {
EXPECT_EQ(RST_STREAM_FRAME, frame.type);
DeleteFrame(&const_cast<QuicFrame&>(frame));
@@ -610,7 +605,7 @@
.Times(0);
EXPECT_CALL(*connection_, SendControlFrame(_))
.Times(AtLeast(1))
- .WillRepeatedly(Invoke(this, &QuicStreamTest::ClearControlFrame));
+ .WillRepeatedly(Invoke(&ClearControlFrame));
std::string data(1000, 'x');
for (QuicStreamOffset offset = 0;
@@ -1493,7 +1488,7 @@
EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
.WillRepeatedly(Invoke(MockQuicSession::ConsumeData));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(this, &QuicStreamTest::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
std::string data(1024, '.');
stream_->WriteOrBufferData(data, false, nullptr);
EXPECT_FALSE(HasWriteBlockedStreams());
@@ -1519,7 +1514,7 @@
EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
.WillRepeatedly(Invoke(MockQuicSession::ConsumeData));
EXPECT_CALL(*connection_, SendControlFrame(_))
- .WillOnce(Invoke(this, &QuicStreamTest::ClearControlFrame));
+ .WillOnce(Invoke(&ClearControlFrame));
stream_->WriteOrBufferData(data, false, nullptr);
EXPECT_FALSE(HasWriteBlockedStreams());