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_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return reinterpret_cast<MockConnection*>(session1_->connection()); | 113 return reinterpret_cast<MockConnection*>(session1_->connection()); |
114 } | 114 } |
115 | 115 |
116 MockConnection* connection2() { | 116 MockConnection* connection2() { |
117 return reinterpret_cast<MockConnection*>(session2_->connection()); | 117 return reinterpret_cast<MockConnection*>(session2_->connection()); |
118 } | 118 } |
119 | 119 |
120 void ProcessPacket(IPEndPoint client_address, | 120 void ProcessPacket(IPEndPoint client_address, |
121 QuicConnectionId connection_id, | 121 QuicConnectionId connection_id, |
122 bool has_version_flag, | 122 bool has_version_flag, |
123 const string& data) { | 123 const std::string& data) { |
124 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 124 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
125 connection_id, has_version_flag, false, 1, data)); | 125 connection_id, has_version_flag, false, 1, data)); |
126 data_ = string(packet->data(), packet->length()); | 126 data_ = std::string(packet->data(), packet->length()); |
127 dispatcher_.ProcessPacket(server_address_, client_address, *packet); | 127 dispatcher_.ProcessPacket(server_address_, client_address, *packet); |
128 } | 128 } |
129 | 129 |
130 void ValidatePacket(const QuicEncryptedPacket& packet) { | 130 void ValidatePacket(const QuicEncryptedPacket& packet) { |
131 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); | 131 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); |
132 EXPECT_EQ(data_, packet.AsStringPiece()); | 132 EXPECT_EQ(data_, packet.AsStringPiece()); |
133 } | 133 } |
134 | 134 |
135 EpollServer eps_; | 135 EpollServer eps_; |
136 QuicConfig config_; | 136 QuicConfig config_; |
137 QuicCryptoServerConfig crypto_config_; | 137 QuicCryptoServerConfig crypto_config_; |
138 IPEndPoint server_address_; | 138 IPEndPoint server_address_; |
139 TestDispatcher dispatcher_; | 139 TestDispatcher dispatcher_; |
140 MockSession* session1_; | 140 MockSession* session1_; |
141 MockSession* session2_; | 141 MockSession* session2_; |
142 string data_; | 142 std::string data_; |
143 }; | 143 }; |
144 | 144 |
145 TEST_F(QuicDispatcherTest, ProcessPackets) { | 145 TEST_F(QuicDispatcherTest, ProcessPackets) { |
146 IPEndPoint client_address(net::test::Loopback4(), 1); | 146 IPEndPoint client_address(net::test::Loopback4(), 1); |
147 IPAddressNumber any4; | 147 IPAddressNumber any4; |
148 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); | 148 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); |
149 server_address_ = IPEndPoint(any4, 5); | 149 server_address_ = IPEndPoint(any4, 5); |
150 | 150 |
151 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)) | 151 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)) |
152 .WillOnce(testing::Return(CreateSession( | 152 .WillOnce(testing::Return(CreateSession( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, | 249 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, |
250 time_wait_list_manager); | 250 time_wait_list_manager); |
251 | 251 |
252 IPEndPoint client_address(net::test::Loopback4(), 1); | 252 IPEndPoint client_address(net::test::Loopback4(), 1); |
253 QuicConnectionId connection_id = 1; | 253 QuicConnectionId connection_id = 1; |
254 // Dispatcher forwards all packets for this connection_id to the time wait | 254 // Dispatcher forwards all packets for this connection_id to the time wait |
255 // list manager. | 255 // list manager. |
256 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); | 256 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); |
257 EXPECT_CALL(*time_wait_list_manager, | 257 EXPECT_CALL(*time_wait_list_manager, |
258 ProcessPacket(_, _, connection_id, _, _)).Times(1); | 258 ProcessPacket(_, _, connection_id, _, _)).Times(1); |
259 string data = "foo"; | 259 std::string data = "foo"; |
260 ProcessPacket(client_address, connection_id, false, "foo"); | 260 ProcessPacket(client_address, connection_id, false, "foo"); |
261 } | 261 } |
262 | 262 |
263 class BlockingWriter : public QuicPacketWriterWrapper { | 263 class BlockingWriter : public QuicPacketWriterWrapper { |
264 public: | 264 public: |
265 BlockingWriter() : write_blocked_(false) {} | 265 BlockingWriter() : write_blocked_(false) {} |
266 | 266 |
267 bool IsWriteBlocked() const override { return write_blocked_; } | 267 bool IsWriteBlocked() const override { return write_blocked_; } |
268 void SetWritable() override { write_blocked_ = false; } | 268 void SetWritable() override { write_blocked_ = false; } |
269 | 269 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // And we'll resume where we left off when we get another call. | 451 // And we'll resume where we left off when we get another call. |
452 EXPECT_CALL(*connection2(), OnCanWrite()); | 452 EXPECT_CALL(*connection2(), OnCanWrite()); |
453 dispatcher_.OnCanWrite(); | 453 dispatcher_.OnCanWrite(); |
454 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 454 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
455 } | 455 } |
456 | 456 |
457 } // namespace | 457 } // namespace |
458 } // namespace test | 458 } // namespace test |
459 } // namespace tools | 459 } // namespace tools |
460 } // namespace net | 460 } // namespace net |
OLD | NEW |