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

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 1783783003: Add a QuicCompressedCertsCache instance to QuicDispatcher, plumbing to QuicServerSessionBase but no… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116273065
Patch Set: Created 4 years, 9 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/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_server_session_base.h » ('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/tools/quic/quic_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 using testing::_; 43 using testing::_;
44 44
45 namespace net { 45 namespace net {
46 namespace test { 46 namespace test {
47 namespace { 47 namespace {
48 48
49 class TestQuicSpdyServerSession : public QuicServerSessionBase { 49 class TestQuicSpdyServerSession : public QuicServerSessionBase {
50 public: 50 public:
51 TestQuicSpdyServerSession(const QuicConfig& config, 51 TestQuicSpdyServerSession(const QuicConfig& config,
52 QuicConnection* connection, 52 QuicConnection* connection,
53 const QuicCryptoServerConfig* crypto_config) 53 const QuicCryptoServerConfig* crypto_config,
54 : QuicServerSessionBase(config, connection, nullptr, crypto_config), 54 QuicCompressedCertsCache* compressed_certs_cache)
55 : QuicServerSessionBase(config,
56 connection,
57 nullptr,
58 crypto_config,
59 compressed_certs_cache),
55 crypto_stream_(QuicServerSessionBase::GetCryptoStream()) {} 60 crypto_stream_(QuicServerSessionBase::GetCryptoStream()) {}
56 ~TestQuicSpdyServerSession() override{}; 61 ~TestQuicSpdyServerSession() override{};
57 62
58 MOCK_METHOD2(OnConnectionClosed, 63 MOCK_METHOD2(OnConnectionClosed,
59 void(QuicErrorCode error, ConnectionCloseSource source)); 64 void(QuicErrorCode error, ConnectionCloseSource source));
60 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); 65 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id));
61 MOCK_METHOD1(CreateOutgoingDynamicStream, 66 MOCK_METHOD1(CreateOutgoingDynamicStream,
62 QuicSpdyStream*(SpdyPriority priority)); 67 QuicSpdyStream*(SpdyPriority priority));
63 68
64 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( 69 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 QuicDispatcher* dispatcher_; 125 QuicDispatcher* dispatcher_;
121 }; 126 };
122 127
123 QuicServerSessionBase* CreateSession( 128 QuicServerSessionBase* CreateSession(
124 QuicDispatcher* dispatcher, 129 QuicDispatcher* dispatcher,
125 const QuicConfig& config, 130 const QuicConfig& config,
126 QuicConnectionId connection_id, 131 QuicConnectionId connection_id,
127 const IPEndPoint& client_address, 132 const IPEndPoint& client_address,
128 MockConnectionHelper* helper, 133 MockConnectionHelper* helper,
129 const QuicCryptoServerConfig* crypto_config, 134 const QuicCryptoServerConfig* crypto_config,
135 QuicCompressedCertsCache* compressed_certs_cache,
130 TestQuicSpdyServerSession** session) { 136 TestQuicSpdyServerSession** session) {
131 MockServerConnection* connection = 137 MockServerConnection* connection =
132 new MockServerConnection(connection_id, helper, dispatcher); 138 new MockServerConnection(connection_id, helper, dispatcher);
133 *session = new TestQuicSpdyServerSession(config, connection, crypto_config); 139 *session = new TestQuicSpdyServerSession(config, connection, crypto_config,
140 compressed_certs_cache);
134 connection->set_visitor(*session); 141 connection->set_visitor(*session);
135 ON_CALL(*connection, SendConnectionCloseWithDetails(_, _)) 142 ON_CALL(*connection, SendConnectionCloseWithDetails(_, _))
136 .WillByDefault(WithoutArgs(Invoke( 143 .WillByDefault(WithoutArgs(Invoke(
137 connection, &MockServerConnection::UnregisterOnConnectionClosed))); 144 connection, &MockServerConnection::UnregisterOnConnectionClosed)));
138 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), 145 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()),
139 ProcessUdpPacket(_, client_address, _)); 146 ProcessUdpPacket(_, client_address, _));
140 147
141 return *session; 148 return *session;
142 } 149 }
143 150
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 TestQuicSpdyServerSession* session1_; 256 TestQuicSpdyServerSession* session1_;
250 TestQuicSpdyServerSession* session2_; 257 TestQuicSpdyServerSession* session2_;
251 string data_; 258 string data_;
252 }; 259 };
253 260
254 TEST_F(QuicDispatcherTest, ProcessPackets) { 261 TEST_F(QuicDispatcherTest, ProcessPackets) {
255 IPEndPoint client_address(net::test::Loopback4(), 1); 262 IPEndPoint client_address(net::test::Loopback4(), 1);
256 server_address_ = IPEndPoint(net::test::Any4(), 5); 263 server_address_ = IPEndPoint(net::test::Any4(), 5);
257 264
258 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 265 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
259 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, 266 .WillOnce(testing::Return(CreateSession(
260 client_address, &mock_helper_, 267 &dispatcher_, config_, 1, client_address, &mock_helper_,
261 &crypto_config_, &session1_))); 268 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
269 &session1_)));
262 ProcessPacket(client_address, 1, true, false, "foo"); 270 ProcessPacket(client_address, 1, true, false, "foo");
263 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 271 EXPECT_EQ(client_address, dispatcher_.current_client_address());
264 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 272 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
265 273
266 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) 274 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address))
267 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 2, 275 .WillOnce(testing::Return(CreateSession(
268 client_address, &mock_helper_, 276 &dispatcher_, config_, 2, client_address, &mock_helper_,
269 &crypto_config_, &session2_))); 277 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
278 &session2_)));
270 ProcessPacket(client_address, 2, true, false, "bar"); 279 ProcessPacket(client_address, 2, true, false, "bar");
271 280
272 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 281 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
273 ProcessUdpPacket(_, _, _)) 282 ProcessUdpPacket(_, _, _))
274 .Times(1) 283 .Times(1)
275 .WillOnce(testing::WithArgs<2>( 284 .WillOnce(testing::WithArgs<2>(
276 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 285 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
277 ProcessPacket(client_address, 1, false, false, "eep"); 286 ProcessPacket(client_address, 1, false, false, "eep");
278 } 287 }
279 288
280 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { 289 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
281 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true); 290 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true);
282 IPEndPoint client_address(net::test::Loopback4(), 1); 291 IPEndPoint client_address(net::test::Loopback4(), 1);
283 server_address_ = IPEndPoint(net::test::Any4(), 5); 292 server_address_ = IPEndPoint(net::test::Any4(), 5);
284 293
285 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); 294 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
286 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); 295 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
287 ProcessPacket(client_address, 1, true, version, "foo", 296 ProcessPacket(client_address, 1, true, version, "foo",
288 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 297 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
289 } 298 }
290 299
291 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) { 300 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) {
292 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false); 301 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false);
293 IPEndPoint client_address(net::test::Loopback4(), 1); 302 IPEndPoint client_address(net::test::Loopback4(), 1);
294 server_address_ = IPEndPoint(net::test::Any4(), 5); 303 server_address_ = IPEndPoint(net::test::Any4(), 5);
295 304
296 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 305 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
297 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, 306 .WillOnce(testing::Return(CreateSession(
298 client_address, &mock_helper_, 307 &dispatcher_, config_, 1, client_address, &mock_helper_,
299 &crypto_config_, &session1_))); 308 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
309 &session1_)));
300 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); 310 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
301 ProcessPacket(client_address, 1, true, version, "foo", 311 ProcessPacket(client_address, 1, true, version, "foo",
302 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 312 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
303 } 313 }
304 314
305 TEST_F(QuicDispatcherTest, Shutdown) { 315 TEST_F(QuicDispatcherTest, Shutdown) {
306 IPEndPoint client_address(net::test::Loopback4(), 1); 316 IPEndPoint client_address(net::test::Loopback4(), 1);
307 317
308 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 318 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
309 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, 319 .WillOnce(testing::Return(CreateSession(
310 client_address, &mock_helper_, 320 &dispatcher_, config_, 1, client_address, &mock_helper_,
311 &crypto_config_, &session1_))); 321 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
322 &session1_)));
312 323
313 ProcessPacket(client_address, 1, true, false, "foo"); 324 ProcessPacket(client_address, 1, true, false, "foo");
314 325
315 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 326 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
316 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _)); 327 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _));
317 328
318 dispatcher_.Shutdown(); 329 dispatcher_.Shutdown();
319 } 330 }
320 331
321 TEST_F(QuicDispatcherTest, TimeWaitListManager) { 332 TEST_F(QuicDispatcherTest, TimeWaitListManager) {
322 CreateTimeWaitListManager(); 333 CreateTimeWaitListManager();
323 334
324 // Create a new session. 335 // Create a new session.
325 IPEndPoint client_address(net::test::Loopback4(), 1); 336 IPEndPoint client_address(net::test::Loopback4(), 1);
326 QuicConnectionId connection_id = 1; 337 QuicConnectionId connection_id = 1;
327 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 338 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address))
328 .WillOnce(testing::Return( 339 .WillOnce(testing::Return(CreateSession(
329 CreateSession(&dispatcher_, config_, connection_id, client_address, 340 &dispatcher_, config_, connection_id, client_address, &mock_helper_,
330 &mock_helper_, &crypto_config_, &session1_))); 341 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
342 &session1_)));
331 ProcessPacket(client_address, connection_id, true, false, "foo"); 343 ProcessPacket(client_address, connection_id, true, false, "foo");
332 344
333 // Close the connection by sending public reset packet. 345 // Close the connection by sending public reset packet.
334 QuicPublicResetPacket packet; 346 QuicPublicResetPacket packet;
335 packet.public_header.connection_id = connection_id; 347 packet.public_header.connection_id = connection_id;
336 packet.public_header.reset_flag = true; 348 packet.public_header.reset_flag = true;
337 packet.public_header.version_flag = false; 349 packet.public_header.version_flag = false;
338 packet.rejected_packet_number = 19191; 350 packet.rejected_packet_number = 19191;
339 packet.nonce_proof = 132232; 351 packet.nonce_proof = 132232;
340 scoped_ptr<QuicEncryptedPacket> encrypted( 352 scoped_ptr<QuicEncryptedPacket> encrypted(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 !GetParam().crypto_handshake_successful && 476 !GetParam().crypto_handshake_successful &&
465 GetParam().client_supports_statelesss_rejects; 477 GetParam().client_supports_statelesss_rejects;
466 } 478 }
467 479
468 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on 480 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on
469 // the test parameters. 481 // the test parameters.
470 QuicServerSessionBase* CreateSessionBasedOnTestParams( 482 QuicServerSessionBase* CreateSessionBasedOnTestParams(
471 QuicConnectionId connection_id, 483 QuicConnectionId connection_id,
472 const IPEndPoint& client_address) { 484 const IPEndPoint& client_address) {
473 CreateSession(&dispatcher_, config_, connection_id, client_address, 485 CreateSession(&dispatcher_, config_, connection_id, client_address,
474 &mock_helper_, &crypto_config_, &session1_); 486 &mock_helper_, &crypto_config_,
487 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_);
475 488
476 crypto_stream1_ = new MockQuicCryptoServerStream(crypto_config_, session1_); 489 crypto_stream1_ = new MockQuicCryptoServerStream(crypto_config_, session1_);
477 session1_->SetCryptoStream(crypto_stream1_); 490 session1_->SetCryptoStream(crypto_stream1_);
478 crypto_stream1_->set_handshake_confirmed_for_testing( 491 crypto_stream1_->set_handshake_confirmed_for_testing(
479 GetParam().crypto_handshake_successful); 492 GetParam().crypto_handshake_successful);
480 crypto_stream1_->SetPeerSupportsStatelessRejects( 493 crypto_stream1_->SetPeerSupportsStatelessRejects(
481 GetParam().client_supports_statelesss_rejects); 494 GetParam().client_supports_statelesss_rejects);
482 return session1_; 495 return session1_;
483 } 496 }
484 497
(...skipping 13 matching lines...) Expand all
498 .Times(0); 511 .Times(0);
499 ProcessPacket(client_address, 1, true, false, "foo"); 512 ProcessPacket(client_address, 1, true, false, "foo");
500 } 513 }
501 514
502 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { 515 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
503 IPEndPoint client_address(net::test::Loopback4(), 1); 516 IPEndPoint client_address(net::test::Loopback4(), 1);
504 QuicConnectionId connection_id = 1; 517 QuicConnectionId connection_id = 1;
505 server_address_ = IPEndPoint(net::test::Any4(), 5); 518 server_address_ = IPEndPoint(net::test::Any4(), 5);
506 519
507 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 520 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
508 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, 521 .WillOnce(testing::Return(CreateSession(
509 client_address, &mock_helper_, 522 &dispatcher_, config_, 1, client_address, &mock_helper_,
510 &crypto_config_, &session1_))); 523 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
524 &session1_)));
511 // A packet whose packet number is the largest that is allowed to start a 525 // A packet whose packet number is the largest that is allowed to start a
512 // connection. 526 // connection.
513 ProcessPacket(client_address, connection_id, true, false, "data", 527 ProcessPacket(client_address, connection_id, true, false, "data",
514 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 528 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
515 kDefaultPathId, 529 kDefaultPathId,
516 QuicDispatcher::kMaxReasonableInitialPacketNumber); 530 QuicDispatcher::kMaxReasonableInitialPacketNumber);
517 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 531 EXPECT_EQ(client_address, dispatcher_.current_client_address());
518 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 532 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
519 } 533 }
520 534
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 660
647 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { 661 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
648 public: 662 public:
649 void SetUp() override { 663 void SetUp() override {
650 writer_ = new BlockingWriter; 664 writer_ = new BlockingWriter;
651 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 665 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_);
652 666
653 IPEndPoint client_address(net::test::Loopback4(), 1); 667 IPEndPoint client_address(net::test::Loopback4(), 1);
654 668
655 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 669 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
656 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, 670 .WillOnce(testing::Return(CreateSession(
657 client_address, &helper_, 671 &dispatcher_, config_, 1, client_address, &helper_, &crypto_config_,
658 &crypto_config_, &session1_))); 672 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
659 ProcessPacket(client_address, 1, true, false, "foo"); 673 ProcessPacket(client_address, 1, true, false, "foo");
660 674
661 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 675 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
662 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 2, 676 .WillOnce(testing::Return(CreateSession(
663 client_address, &helper_, 677 &dispatcher_, config_, 2, client_address, &helper_, &crypto_config_,
664 &crypto_config_, &session2_))); 678 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_)));
665 ProcessPacket(client_address, 2, true, false, "bar"); 679 ProcessPacket(client_address, 2, true, false, "bar");
666 680
667 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); 681 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_);
668 } 682 }
669 683
670 void TearDown() override { 684 void TearDown() override {
671 EXPECT_CALL(*connection1(), 685 EXPECT_CALL(*connection1(),
672 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _)); 686 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _));
673 EXPECT_CALL(*connection2(), 687 EXPECT_CALL(*connection2(),
674 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _)); 688 SendConnectionCloseWithDetails(QUIC_PEER_GOING_AWAY, _));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 829
816 // And we'll resume where we left off when we get another call. 830 // And we'll resume where we left off when we get another call.
817 EXPECT_CALL(*connection2(), OnCanWrite()); 831 EXPECT_CALL(*connection2(), OnCanWrite());
818 dispatcher_.OnCanWrite(); 832 dispatcher_.OnCanWrite();
819 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 833 EXPECT_FALSE(dispatcher_.HasPendingWrites());
820 } 834 }
821 835
822 } // namespace 836 } // namespace
823 } // namespace test 837 } // namespace test
824 } // namespace net 838 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_server_session_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698