| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using testing::StrictMock; | 34 using testing::StrictMock; |
| 35 using testing::Truly; | 35 using testing::Truly; |
| 36 | 36 |
| 37 namespace net { | 37 namespace net { |
| 38 namespace tools { | 38 namespace tools { |
| 39 namespace test { | 39 namespace test { |
| 40 | 40 |
| 41 class QuicTimeWaitListManagerPeer { | 41 class QuicTimeWaitListManagerPeer { |
| 42 public: | 42 public: |
| 43 static bool ShouldSendResponse(QuicTimeWaitListManager* manager, | 43 static bool ShouldSendResponse(QuicTimeWaitListManager* manager, |
| 44 int received_packet_count) { | 44 int received_packet_count) { |
| 45 return manager->ShouldSendResponse(received_packet_count); | 45 return manager->ShouldSendResponse(received_packet_count); |
| 46 } | 46 } |
| 47 | 47 |
| 48 static QuicTime::Delta time_wait_period(QuicTimeWaitListManager* manager) { | 48 static QuicTime::Delta time_wait_period(QuicTimeWaitListManager* manager) { |
| 49 return manager->kTimeWaitPeriod_; | 49 return manager->kTimeWaitPeriod_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static QuicVersion GetQuicVersionFromGuid(QuicTimeWaitListManager* manager, | 52 static QuicVersion GetQuicVersionFromGuid(QuicTimeWaitListManager* manager, |
| 53 QuicGuid guid) { | 53 QuicGuid guid) { |
| 54 return manager->GetQuicVersionFromGuid(guid); | 54 return manager->GetQuicVersionFromGuid(guid); |
| 55 } | 55 } |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 class TestTimeWaitListManager : public QuicTimeWaitListManager { | |
| 61 public: | |
| 62 TestTimeWaitListManager(QuicPacketWriter* writer, | |
| 63 EpollServer* epoll_server) | |
| 64 : QuicTimeWaitListManager(writer, epoll_server, QuicSupportedVersions()) { | |
| 65 } | |
| 66 }; | |
| 67 | |
| 68 class MockFakeTimeEpollServer : public FakeTimeEpollServer { | 60 class MockFakeTimeEpollServer : public FakeTimeEpollServer { |
| 69 public: | 61 public: |
| 70 MOCK_METHOD2(RegisterAlarm, void(int64 timeout_in_us, | 62 MOCK_METHOD2(RegisterAlarm, void(int64 timeout_in_us, |
| 71 EpollAlarmCallbackInterface* alarm)); | 63 EpollAlarmCallbackInterface* alarm)); |
| 72 }; | 64 }; |
| 73 | 65 |
| 74 class QuicTimeWaitListManagerTest : public testing::Test { | 66 class QuicTimeWaitListManagerTest : public testing::Test { |
| 75 protected: | 67 protected: |
| 76 QuicTimeWaitListManagerTest() | 68 QuicTimeWaitListManagerTest() |
| 77 : time_wait_list_manager_( | 69 : time_wait_list_manager_(&writer_, &visitor_, |
| 78 &writer_, &epoll_server_, QuicSupportedVersions()), | 70 &epoll_server_, QuicSupportedVersions()), |
| 79 framer_(QuicSupportedVersions(), QuicTime::Zero(), true), | 71 framer_(QuicSupportedVersions(), QuicTime::Zero(), true), |
| 80 guid_(45), | 72 guid_(45), |
| 81 writer_is_blocked_(false) {} | 73 writer_is_blocked_(false) {} |
| 82 | 74 |
| 83 virtual ~QuicTimeWaitListManagerTest() {} | 75 virtual ~QuicTimeWaitListManagerTest() {} |
| 84 | 76 |
| 85 virtual void SetUp() { | 77 virtual void SetUp() { |
| 86 EXPECT_CALL(writer_, IsWriteBlocked()) | 78 EXPECT_CALL(writer_, IsWriteBlocked()) |
| 87 .WillRepeatedly(ReturnPointee(&writer_is_blocked_)); | 79 .WillRepeatedly(ReturnPointee(&writer_is_blocked_)); |
| 88 EXPECT_CALL(writer_, IsWriteBlockedDataBuffered()) | 80 EXPECT_CALL(writer_, IsWriteBlockedDataBuffered()) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 EXPECT_TRUE(packet != NULL); | 127 EXPECT_TRUE(packet != NULL); |
| 136 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(ENCRYPTION_NONE, | 128 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(ENCRYPTION_NONE, |
| 137 sequence_number, | 129 sequence_number, |
| 138 *packet); | 130 *packet); |
| 139 EXPECT_TRUE(encrypted != NULL); | 131 EXPECT_TRUE(encrypted != NULL); |
| 140 return encrypted; | 132 return encrypted; |
| 141 } | 133 } |
| 142 | 134 |
| 143 NiceMock<MockFakeTimeEpollServer> epoll_server_; | 135 NiceMock<MockFakeTimeEpollServer> epoll_server_; |
| 144 StrictMock<MockPacketWriter> writer_; | 136 StrictMock<MockPacketWriter> writer_; |
| 137 StrictMock<MockQuicServerSessionVisitor> visitor_; |
| 145 QuicTimeWaitListManager time_wait_list_manager_; | 138 QuicTimeWaitListManager time_wait_list_manager_; |
| 146 QuicFramer framer_; | 139 QuicFramer framer_; |
| 147 QuicGuid guid_; | 140 QuicGuid guid_; |
| 148 IPEndPoint server_address_; | 141 IPEndPoint server_address_; |
| 149 IPEndPoint client_address_; | 142 IPEndPoint client_address_; |
| 150 bool writer_is_blocked_; | 143 bool writer_is_blocked_; |
| 151 }; | 144 }; |
| 152 | 145 |
| 153 class ValidatePublicResetPacketPredicate | 146 class ValidatePublicResetPacketPredicate |
| 154 : public MatcherInterface<const std::tr1::tuple<const char*, int> > { | 147 : public MatcherInterface<const std::tr1::tuple<const char*, int> > { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // write block for the next packet. | 293 // write block for the next packet. |
| 301 EXPECT_CALL(writer_, WritePacket(_, _, | 294 EXPECT_CALL(writer_, WritePacket(_, _, |
| 302 server_address_.address(), | 295 server_address_.address(), |
| 303 client_address_, | 296 client_address_, |
| 304 &time_wait_list_manager_)) | 297 &time_wait_list_manager_)) |
| 305 .With(Args<0, 1>(PublicResetPacketEq(guid, | 298 .With(Args<0, 1>(PublicResetPacketEq(guid, |
| 306 sequence_number))) | 299 sequence_number))) |
| 307 .WillOnce(DoAll( | 300 .WillOnce(DoAll( |
| 308 Assign(&writer_is_blocked_, true), | 301 Assign(&writer_is_blocked_, true), |
| 309 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); | 302 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); |
| 303 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 310 ProcessPacket(guid, sequence_number); | 304 ProcessPacket(guid, sequence_number); |
| 311 // 3rd packet. No public reset should be sent; | 305 // 3rd packet. No public reset should be sent; |
| 312 ProcessPacket(guid, sequence_number); | 306 ProcessPacket(guid, sequence_number); |
| 313 | 307 |
| 314 // write packet should not be called since we are write blocked but the | 308 // write packet should not be called since we are write blocked but the |
| 315 // should be queued. | 309 // should be queued. |
| 316 QuicGuid other_guid = 2; | 310 QuicGuid other_guid = 2; |
| 317 AddGuid(other_guid); | 311 AddGuid(other_guid); |
| 318 QuicPacketSequenceNumber other_sequence_number = 23423; | 312 QuicPacketSequenceNumber other_sequence_number = 23423; |
| 319 scoped_ptr<QuicEncryptedPacket> other_packet( | 313 scoped_ptr<QuicEncryptedPacket> other_packet( |
| 320 ConstructEncryptedPacket( | 314 ConstructEncryptedPacket( |
| 321 ENCRYPTION_NONE, other_guid, other_sequence_number)); | 315 ENCRYPTION_NONE, other_guid, other_sequence_number)); |
| 322 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) | 316 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) |
| 323 .Times(0); | 317 .Times(0); |
| 318 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 324 ProcessPacket(other_guid, other_sequence_number); | 319 ProcessPacket(other_guid, other_sequence_number); |
| 325 | 320 |
| 326 // Now expect all the write blocked public reset packets to be sent again. | 321 // Now expect all the write blocked public reset packets to be sent again. |
| 327 writer_is_blocked_ = false; | 322 writer_is_blocked_ = false; |
| 328 EXPECT_CALL(writer_, WritePacket(_, _, | 323 EXPECT_CALL(writer_, WritePacket(_, _, |
| 329 server_address_.address(), | 324 server_address_.address(), |
| 330 client_address_, | 325 client_address_, |
| 331 &time_wait_list_manager_)) | 326 &time_wait_list_manager_)) |
| 332 .With(Args<0, 1>(PublicResetPacketEq(guid, | 327 .With(Args<0, 1>(PublicResetPacketEq(guid, |
| 333 sequence_number))) | 328 sequence_number))) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 360 &time_wait_list_manager_, kGuid2)); | 355 &time_wait_list_manager_, kGuid2)); |
| 361 EXPECT_EQ(net::test::QuicVersionMax(), | 356 EXPECT_EQ(net::test::QuicVersionMax(), |
| 362 QuicTimeWaitListManagerPeer::GetQuicVersionFromGuid( | 357 QuicTimeWaitListManagerPeer::GetQuicVersionFromGuid( |
| 363 &time_wait_list_manager_, kGuid3)); | 358 &time_wait_list_manager_, kGuid3)); |
| 364 } | 359 } |
| 365 | 360 |
| 366 } // namespace | 361 } // namespace |
| 367 } // namespace test | 362 } // namespace test |
| 368 } // namespace tools | 363 } // namespace tools |
| 369 } // namespace net | 364 } // namespace net |
| OLD | NEW |