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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 public: | 100 public: |
101 QuicDispatcherTest() | 101 QuicDispatcherTest() |
102 : crypto_config_(QuicCryptoServerConfig::TESTING, | 102 : crypto_config_(QuicCryptoServerConfig::TESTING, |
103 QuicRandom::GetInstance()), | 103 QuicRandom::GetInstance()), |
104 dispatcher_(config_, crypto_config_, &eps_), | 104 dispatcher_(config_, crypto_config_, &eps_), |
105 session1_(nullptr), | 105 session1_(nullptr), |
106 session2_(nullptr) { | 106 session2_(nullptr) { |
107 dispatcher_.Initialize(1); | 107 dispatcher_.Initialize(1); |
108 } | 108 } |
109 | 109 |
110 virtual ~QuicDispatcherTest() {} | 110 ~QuicDispatcherTest() override {} |
111 | 111 |
112 MockConnection* connection1() { | 112 MockConnection* connection1() { |
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, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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 virtual bool IsWriteBlocked() const override { return write_blocked_; } | 267 bool IsWriteBlocked() const override { return write_blocked_; } |
268 virtual void SetWritable() override { write_blocked_ = false; } | 268 void SetWritable() override { write_blocked_ = false; } |
269 | 269 |
270 virtual WriteResult WritePacket( | 270 WriteResult WritePacket(const char* buffer, |
271 const char* buffer, | 271 size_t buf_len, |
272 size_t buf_len, | 272 const IPAddressNumber& self_client_address, |
273 const IPAddressNumber& self_client_address, | 273 const IPEndPoint& peer_client_address) override { |
274 const IPEndPoint& peer_client_address) override { | |
275 // It would be quite possible to actually implement this method here with | 274 // It would be quite possible to actually implement this method here with |
276 // the fake blocked status, but it would be significantly more work in | 275 // the fake blocked status, but it would be significantly more work in |
277 // Chromium, and since it's not called anyway, don't bother. | 276 // Chromium, and since it's not called anyway, don't bother. |
278 LOG(DFATAL) << "Not supported"; | 277 LOG(DFATAL) << "Not supported"; |
279 return WriteResult(); | 278 return WriteResult(); |
280 } | 279 } |
281 | 280 |
282 bool write_blocked_; | 281 bool write_blocked_; |
283 }; | 282 }; |
284 | 283 |
285 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { | 284 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { |
286 public: | 285 public: |
287 virtual void SetUp() { | 286 void SetUp() override { |
288 writer_ = new BlockingWriter; | 287 writer_ = new BlockingWriter; |
289 QuicDispatcherPeer::SetPacketWriterFactory(&dispatcher_, | 288 QuicDispatcherPeer::SetPacketWriterFactory(&dispatcher_, |
290 new TestWriterFactory()); | 289 new TestWriterFactory()); |
291 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); | 290 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); |
292 | 291 |
293 IPEndPoint client_address(net::test::Loopback4(), 1); | 292 IPEndPoint client_address(net::test::Loopback4(), 1); |
294 | 293 |
295 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) | 294 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) |
296 .WillOnce(testing::Return(CreateSession( | 295 .WillOnce(testing::Return(CreateSession( |
297 &dispatcher_, 1, client_address, &session1_))); | 296 &dispatcher_, 1, client_address, &session1_))); |
298 ProcessPacket(client_address, 1, true, "foo"); | 297 ProcessPacket(client_address, 1, true, "foo"); |
299 | 298 |
300 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) | 299 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) |
301 .WillOnce(testing::Return(CreateSession( | 300 .WillOnce(testing::Return(CreateSession( |
302 &dispatcher_, 2, client_address, &session2_))); | 301 &dispatcher_, 2, client_address, &session2_))); |
303 ProcessPacket(client_address, 2, true, "bar"); | 302 ProcessPacket(client_address, 2, true, "bar"); |
304 | 303 |
305 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); | 304 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); |
306 } | 305 } |
307 | 306 |
308 virtual void TearDown() { | 307 void TearDown() override { |
309 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); | 308 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); |
310 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); | 309 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); |
311 dispatcher_.Shutdown(); | 310 dispatcher_.Shutdown(); |
312 } | 311 } |
313 | 312 |
314 void SetBlocked() { | 313 void SetBlocked() { |
315 writer_->write_blocked_ = true; | 314 writer_->write_blocked_ = true; |
316 } | 315 } |
317 | 316 |
318 void BlockConnection2() { | 317 void BlockConnection2() { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // 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. |
453 EXPECT_CALL(*connection2(), OnCanWrite()); | 452 EXPECT_CALL(*connection2(), OnCanWrite()); |
454 dispatcher_.OnCanWrite(); | 453 dispatcher_.OnCanWrite(); |
455 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 454 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
456 } | 455 } |
457 | 456 |
458 } // namespace | 457 } // namespace |
459 } // namespace test | 458 } // namespace test |
460 } // namespace tools | 459 } // namespace tools |
461 } // namespace net | 460 } // namespace net |
OLD | NEW |