| OLD | NEW |
| 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_epoll_connection_helper.h" | 5 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 #include "net/quic/crypto/quic_decrypter.h" | 8 #include "net/quic/crypto/quic_decrypter.h" |
| 9 #include "net/quic/crypto/quic_encrypter.h" | 9 #include "net/quic/crypto/quic_encrypter.h" |
| 10 #include "net/quic/crypto/quic_random.h" | 10 #include "net/quic/crypto/quic_random.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const bool kHasData = true; | 32 const bool kHasData = true; |
| 33 | 33 |
| 34 class TestConnectionHelper : public QuicEpollConnectionHelper { | 34 class TestConnectionHelper : public QuicEpollConnectionHelper { |
| 35 public: | 35 public: |
| 36 TestConnectionHelper(int fd, EpollServer* eps) | 36 TestConnectionHelper(int fd, EpollServer* eps) |
| 37 : QuicEpollConnectionHelper(fd, eps) { | 37 : QuicEpollConnectionHelper(fd, eps) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, | 40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, |
| 41 int* error) OVERRIDE { | 41 int* error) OVERRIDE { |
| 42 QuicFramer framer(kQuicVersion1, | 42 QuicFramer framer(kQuicVersion1, QuicTime::Zero(), true); |
| 43 QuicDecrypter::Create(kNULL), | |
| 44 QuicEncrypter::Create(kNULL), | |
| 45 QuicTime::Zero(), | |
| 46 true); | |
| 47 FramerVisitorCapturingFrames visitor; | 43 FramerVisitorCapturingFrames visitor; |
| 48 framer.set_visitor(&visitor); | 44 framer.set_visitor(&visitor); |
| 49 EXPECT_TRUE(framer.ProcessPacket(packet)); | 45 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 50 header_ = *visitor.header(); | 46 header_ = *visitor.header(); |
| 51 *error = 0; | 47 *error = 0; |
| 52 return packet.length(); | 48 return packet.length(); |
| 53 } | 49 } |
| 54 | 50 |
| 55 QuicPacketHeader* header() { return &header_; } | 51 QuicPacketHeader* header() { return &header_; } |
| 56 | 52 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 70 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 75 } | 71 } |
| 76 | 72 |
| 77 using QuicConnection::SendOrQueuePacket; | 73 using QuicConnection::SendOrQueuePacket; |
| 78 }; | 74 }; |
| 79 | 75 |
| 80 class QuicConnectionHelperTest : public ::testing::Test { | 76 class QuicConnectionHelperTest : public ::testing::Test { |
| 81 protected: | 77 protected: |
| 82 QuicConnectionHelperTest() | 78 QuicConnectionHelperTest() |
| 83 : guid_(42), | 79 : guid_(42), |
| 84 framer_(kQuicVersion1, | 80 framer_(kQuicVersion1, QuicTime::Zero(), false), |
| 85 QuicDecrypter::Create(kNULL), | |
| 86 QuicEncrypter::Create(kNULL), | |
| 87 QuicTime::Zero(), | |
| 88 false), | |
| 89 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), | 81 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), |
| 90 helper_(new TestConnectionHelper(0, &epoll_server_)), | 82 helper_(new TestConnectionHelper(0, &epoll_server_)), |
| 91 connection_(guid_, IPEndPoint(), helper_), | 83 connection_(guid_, IPEndPoint(), helper_), |
| 92 frame1_(1, false, 0, data1) { | 84 frame1_(1, false, 0, data1) { |
| 93 connection_.set_visitor(&visitor_); | 85 connection_.set_visitor(&visitor_); |
| 94 connection_.SetSendAlgorithm(send_algorithm_); | 86 connection_.SetSendAlgorithm(send_algorithm_); |
| 95 epoll_server_.set_timeout_in_us(-1); | 87 epoll_server_.set_timeout_in_us(-1); |
| 96 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( | 88 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( |
| 97 QuicTime::Delta::Zero())); | 89 QuicTime::Delta::Zero())); |
| 98 } | 90 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 EXPECT_EQ(kDefaultTimeoutUs + 5000, epoll_server_.NowInUsec()); | 171 EXPECT_EQ(kDefaultTimeoutUs + 5000, epoll_server_.NowInUsec()); |
| 180 EXPECT_FALSE(connection_.connected()); | 172 EXPECT_FALSE(connection_.connected()); |
| 181 } | 173 } |
| 182 | 174 |
| 183 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { | 175 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { |
| 184 // Test that if we send a packet with a delay, it ends up queued. | 176 // Test that if we send a packet with a delay, it ends up queued. |
| 185 QuicPacket* packet = ConstructDataPacket(1, 0); | 177 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 186 EXPECT_CALL( | 178 EXPECT_CALL( |
| 187 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( | 179 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( |
| 188 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 180 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 189 connection_.SendOrQueuePacket(1, packet, 0, | 181 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, |
| 190 HAS_RETRANSMITTABLE_DATA); | 182 HAS_RETRANSMITTABLE_DATA); |
| 191 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); | 183 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); |
| 192 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 184 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 193 | 185 |
| 194 // Advance the clock to fire the alarm, and configure the scheduler | 186 // Advance the clock to fire the alarm, and configure the scheduler |
| 195 // to permit the packet to be sent. | 187 // to permit the packet to be sent. |
| 196 EXPECT_CALL( | 188 EXPECT_CALL( |
| 197 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( | 189 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( |
| 198 testing::Return(QuicTime::Delta::Zero())); | 190 testing::Return(QuicTime::Delta::Zero())); |
| 199 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); | 191 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); |
| 200 epoll_server_.AdvanceByAndCallCallbacks(1); | 192 epoll_server_.AdvanceByAndCallCallbacks(1); |
| 201 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 193 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 202 } | 194 } |
| 203 | 195 |
| 204 } // namespace | 196 } // namespace |
| 205 } // namespace test | 197 } // namespace test |
| 206 } // namespace tools | 198 } // namespace tools |
| 207 } // namespace net | 199 } // namespace net |
| OLD | NEW |