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

Unified Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_dispatcher_test.cc
diff --git a/net/tools/quic/quic_dispatcher_test.cc b/net/tools/quic/quic_dispatcher_test.cc
index fc1e10d59e7c9a02df9ac02d094bff0e9d74ce82..6ef1b16723745d611bbd75394584d07ffccc3f34 100644
--- a/net/tools/quic/quic_dispatcher_test.cc
+++ b/net/tools/quic/quic_dispatcher_test.cc
@@ -97,12 +97,29 @@ QuicSession* CreateSession(QuicDispatcher* dispatcher,
return *session;
}
+class MockTimeWaitListManager : public QuicTimeWaitListManager {
+ public:
+ MockTimeWaitListManager(QuicPacketWriter* writer,
+ QuicServerSessionVisitor* visitor,
+ EpollServer* eps)
+ : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) {
+ }
+
+ MOCK_METHOD5(ProcessPacket,
+ void(const IPEndPoint& server_address,
+ const IPEndPoint& client_address,
+ QuicConnectionId connection_id,
+ QuicPacketSequenceNumber sequence_number,
+ const QuicEncryptedPacket& packet));
+};
+
class QuicDispatcherTest : public ::testing::Test {
public:
QuicDispatcherTest()
: crypto_config_(QuicCryptoServerConfig::TESTING,
QuicRandom::GetInstance()),
dispatcher_(config_, crypto_config_, &eps_),
+ time_wait_list_manager_(nullptr),
session1_(nullptr),
session2_(nullptr) {
dispatcher_.Initialize(1);
@@ -133,11 +150,20 @@ class QuicDispatcherTest : public ::testing::Test {
EXPECT_EQ(data_, packet.AsStringPiece());
}
+ void CreateTimeWaitListManager() {
+ time_wait_list_manager_ = new MockTimeWaitListManager(
+ QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
+ // dispatcher takes the ownership of time_wait_list_manager.
+ QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
+ time_wait_list_manager_);
+ }
+
EpollServer eps_;
QuicConfig config_;
QuicCryptoServerConfig crypto_config_;
IPEndPoint server_address_;
TestDispatcher dispatcher_;
+ MockTimeWaitListManager* time_wait_list_manager_;
MockSession* session1_;
MockSession* session2_;
string data_;
@@ -184,28 +210,9 @@ TEST_F(QuicDispatcherTest, Shutdown) {
dispatcher_.Shutdown();
}
-class MockTimeWaitListManager : public QuicTimeWaitListManager {
- public:
- MockTimeWaitListManager(QuicPacketWriter* writer,
- QuicServerSessionVisitor* visitor,
- EpollServer* eps)
- : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) {
- }
-
- MOCK_METHOD5(ProcessPacket, void(const IPEndPoint& server_address,
- const IPEndPoint& client_address,
- QuicConnectionId connection_id,
- QuicPacketSequenceNumber sequence_number,
- const QuicEncryptedPacket& packet));
-};
-
TEST_F(QuicDispatcherTest, TimeWaitListManager) {
- MockTimeWaitListManager* time_wait_list_manager =
- new MockTimeWaitListManager(
- QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
- // dispatcher takes the ownership of time_wait_list_manager.
- QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
- time_wait_list_manager);
+ CreateTimeWaitListManager();
+
// Create a new session.
IPEndPoint client_address(net::test::Loopback4(), 1);
QuicConnectionId connection_id = 1;
@@ -233,34 +240,44 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
reinterpret_cast<MockConnection*>(session1_->connection()),
&MockConnection::ReallyProcessUdpPacket));
dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted);
- EXPECT_TRUE(time_wait_list_manager->IsConnectionIdInTimeWait(connection_id));
+ EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
// Dispatcher forwards subsequent packets for this connection_id to the time
// wait list manager.
- EXPECT_CALL(*time_wait_list_manager,
+ EXPECT_CALL(*time_wait_list_manager_,
ProcessPacket(_, _, connection_id, _, _)).Times(1);
ProcessPacket(client_address, connection_id, true, "foo");
}
TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) {
- MockTimeWaitListManager* time_wait_list_manager =
- new MockTimeWaitListManager(
- QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
- // dispatcher takes the ownership of time_wait_list_manager.
- QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
- time_wait_list_manager);
+ CreateTimeWaitListManager();
IPEndPoint client_address(net::test::Loopback4(), 1);
QuicConnectionId connection_id = 1;
// Dispatcher forwards all packets for this connection_id to the time wait
// list manager.
EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0);
- EXPECT_CALL(*time_wait_list_manager,
+ EXPECT_CALL(*time_wait_list_manager_,
ProcessPacket(_, _, connection_id, _, _)).Times(1);
string data = "foo";
ProcessPacket(client_address, connection_id, false, "foo");
}
+TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) {
+ CreateTimeWaitListManager();
+
+ IPEndPoint client_address(net::test::Loopback4(), 0);
+ IPAddressNumber any4;
+ CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4));
+ server_address_ = IPEndPoint(any4, 5);
+
+ EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0);
+ EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
+ ProcessPacket(client_address, 1, true, "foo");
+ EXPECT_EQ(client_address, dispatcher_.current_client_address());
+ EXPECT_EQ(server_address_, dispatcher_.current_server_address());
+}
+
class BlockingWriter : public QuicPacketWriterWrapper {
public:
BlockingWriter() : write_blocked_(false) {}
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698