| 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 23 matching lines...) Expand all Loading... |
| 34 const bool kFromPeer = true; | 34 const bool kFromPeer = true; |
| 35 | 35 |
| 36 class TestWriter : public QuicPacketWriter { | 36 class TestWriter : public QuicPacketWriter { |
| 37 public: | 37 public: |
| 38 // QuicPacketWriter | 38 // QuicPacketWriter |
| 39 virtual WriteResult WritePacket( | 39 virtual WriteResult WritePacket( |
| 40 const char* buffer, size_t buf_len, | 40 const char* buffer, size_t buf_len, |
| 41 const IPAddressNumber& self_address, | 41 const IPAddressNumber& self_address, |
| 42 const IPEndPoint& peer_address, | 42 const IPEndPoint& peer_address, |
| 43 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { | 43 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { |
| 44 QuicFramer framer(QuicVersionMax(), QuicTime::Zero(), true); | 44 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), true); |
| 45 FramerVisitorCapturingFrames visitor; | 45 FramerVisitorCapturingFrames visitor; |
| 46 framer.set_visitor(&visitor); | 46 framer.set_visitor(&visitor); |
| 47 QuicEncryptedPacket packet(buffer, buf_len); | 47 QuicEncryptedPacket packet(buffer, buf_len); |
| 48 EXPECT_TRUE(framer.ProcessPacket(packet)); | 48 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 49 header_ = *visitor.header(); | 49 header_ = *visitor.header(); |
| 50 return WriteResult(WRITE_STATUS_OK, packet.length()); | 50 return WriteResult(WRITE_STATUS_OK, packet.length()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 53 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Returns the header from the last packet written. | 57 // Returns the header from the last packet written. |
| 58 const QuicPacketHeader& header() { return header_; } | 58 const QuicPacketHeader& header() { return header_; } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 QuicPacketHeader header_; | 61 QuicPacketHeader header_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class TestConnection : public QuicConnection { | 64 class TestConnection : public QuicConnection { |
| 65 public: | 65 public: |
| 66 TestConnection(QuicGuid guid, | 66 TestConnection(QuicGuid guid, |
| 67 IPEndPoint address, | 67 IPEndPoint address, |
| 68 QuicEpollConnectionHelper* helper, | 68 QuicEpollConnectionHelper* helper, |
| 69 TestWriter* writer) | 69 TestWriter* writer) |
| 70 : QuicConnection(guid, address, helper, writer, false, QuicVersionMax()) { | 70 : QuicConnection(guid, address, helper, writer, false, |
| 71 QuicSupportedVersions()) { |
| 71 } | 72 } |
| 72 | 73 |
| 73 void SendAck() { | 74 void SendAck() { |
| 74 QuicConnectionPeer::SendAck(this); | 75 QuicConnectionPeer::SendAck(this); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 78 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 78 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 79 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 79 } | 80 } |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 class QuicEpollConnectionHelperTest : public ::testing::Test { | 83 class QuicEpollConnectionHelperTest : public ::testing::Test { |
| 83 protected: | 84 protected: |
| 84 QuicEpollConnectionHelperTest() | 85 QuicEpollConnectionHelperTest() |
| 85 : guid_(42), | 86 : guid_(42), |
| 86 framer_(QuicVersionMax(), QuicTime::Zero(), false), | 87 framer_(QuicSupportedVersions(), QuicTime::Zero(), false), |
| 87 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), | 88 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), |
| 88 helper_(&epoll_server_), | 89 helper_(&epoll_server_), |
| 89 connection_(guid_, IPEndPoint(), &helper_, &writer_), | 90 connection_(guid_, IPEndPoint(), &helper_, &writer_), |
| 90 frame_(3, false, 0, kData) { | 91 frame_(3, false, 0, kData) { |
| 91 connection_.set_visitor(&visitor_); | 92 connection_.set_visitor(&visitor_); |
| 92 connection_.SetSendAlgorithm(send_algorithm_); | 93 connection_.SetSendAlgorithm(send_algorithm_); |
| 93 epoll_server_.set_timeout_in_us(-1); | 94 epoll_server_.set_timeout_in_us(-1); |
| 94 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). | 95 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). |
| 95 WillRepeatedly(Return(QuicTime::Delta::Zero())); | 96 WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 96 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( | 97 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); | 229 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); |
| 229 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); | 230 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
| 230 epoll_server_.AdvanceByAndCallCallbacks(1); | 231 epoll_server_.AdvanceByAndCallCallbacks(1); |
| 231 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 232 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace | 235 } // namespace |
| 235 } // namespace test | 236 } // namespace test |
| 236 } // namespace tools | 237 } // namespace tools |
| 237 } // namespace net | 238 } // namespace net |
| OLD | NEW |