Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1614)

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 127633002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_time_wait_list_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "net/quic/crypto/quic_crypto_server_config.h" 11 #include "net/quic/crypto/quic_crypto_server_config.h"
12 #include "net/quic/crypto/quic_random.h" 12 #include "net/quic/crypto/quic_random.h"
13 #include "net/quic/quic_crypto_stream.h" 13 #include "net/quic/quic_crypto_stream.h"
14 #include "net/quic/test_tools/quic_test_utils.h" 14 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/quic/test_tools/quic_test_writer.h"
15 #include "net/tools/epoll_server/epoll_server.h" 16 #include "net/tools/epoll_server/epoll_server.h"
16 #include "net/tools/quic/quic_time_wait_list_manager.h" 17 #include "net/tools/quic/quic_time_wait_list_manager.h"
17 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" 18 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h"
18 #include "net/tools/quic/test_tools/quic_test_utils.h" 19 #include "net/tools/quic/test_tools/quic_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using base::StringPiece; 23 using base::StringPiece;
23 using net::EpollServer; 24 using net::EpollServer;
24 using net::test::MockSession; 25 using net::test::MockSession;
26 using net::test::QuicTestWriter;
25 using net::tools::test::MockConnection; 27 using net::tools::test::MockConnection;
26 using std::make_pair; 28 using std::make_pair;
27 using testing::_; 29 using testing::_;
28 using testing::DoAll; 30 using testing::DoAll;
29 using testing::Invoke; 31 using testing::Invoke;
30 using testing::InSequence; 32 using testing::InSequence;
31 using testing::Return; 33 using testing::Return;
32 using testing::WithoutArgs; 34 using testing::WithoutArgs;
33 35
34 namespace net { 36 namespace net {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 IPEndPoint addr(net::test::Loopback4(), 1); 265 IPEndPoint addr(net::test::Loopback4(), 1);
264 QuicGuid guid = 1; 266 QuicGuid guid = 1;
265 // Dispatcher forwards all packets for this guid to the time wait list 267 // Dispatcher forwards all packets for this guid to the time wait list
266 // manager. 268 // manager.
267 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); 269 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0);
268 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1); 270 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1);
269 string data = "foo"; 271 string data = "foo";
270 ProcessPacket(addr, guid, false, "foo"); 272 ProcessPacket(addr, guid, false, "foo");
271 } 273 }
272 274
275 class BlockingWriter : public QuicTestWriter {
276 public:
277 BlockingWriter() : write_blocked_(false) {}
278
279 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; }
280 virtual void SetWritable() OVERRIDE { write_blocked_ = false; }
281 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { return false; }
282
283 virtual WriteResult WritePacket(
284 const char* buffer, size_t buf_len, const IPAddressNumber& self_address,
285 const IPEndPoint& peer_address,
286 QuicBlockedWriterInterface* blocked_writer) OVERRIDE {
287 if (write_blocked_) {
288 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN);
289 } else {
290 return writer()->WritePacket(buffer, buf_len, self_address, peer_address,
291 blocked_writer);
292 }
293 }
294
295 bool write_blocked_;
296 };
297
273 class QuicWriteBlockedListTest : public QuicDispatcherTest { 298 class QuicWriteBlockedListTest : public QuicDispatcherTest {
274 public: 299 public:
275 virtual void SetUp() { 300 virtual void SetUp() {
301 writer_ = new BlockingWriter;
302 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_);
303
276 IPEndPoint addr(net::test::Loopback4(), 1); 304 IPEndPoint addr(net::test::Loopback4(), 1);
277 305
278 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) 306 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr))
279 .WillOnce(testing::Return(CreateSession( 307 .WillOnce(testing::Return(CreateSession(
280 &dispatcher_, 1, addr, &session1_))); 308 &dispatcher_, 1, addr, &session1_)));
281 ProcessPacket(addr, 1, true, "foo"); 309 ProcessPacket(addr, 1, true, "foo");
282 310
283 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) 311 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr))
284 .WillOnce(testing::Return(CreateSession( 312 .WillOnce(testing::Return(CreateSession(
285 &dispatcher_, 2, addr, &session2_))); 313 &dispatcher_, 2, addr, &session2_)));
286 ProcessPacket(addr, 2, true, "bar"); 314 ProcessPacket(addr, 2, true, "bar");
287 315
288 blocked_list_ = dispatcher_.write_blocked_list(); 316 blocked_list_ = dispatcher_.write_blocked_list();
289 } 317 }
290 318
291 virtual void TearDown() { 319 virtual void TearDown() {
292 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); 320 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY));
293 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); 321 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY));
294 dispatcher_.Shutdown(); 322 dispatcher_.Shutdown();
295 } 323 }
296 324
297 bool SetBlocked() { 325 bool SetBlocked() {
298 QuicDispatcherPeer::SetWriteBlocked(&dispatcher_); 326 writer_->write_blocked_ = true;;
299 return true; 327 return true;
300 } 328 }
301 329
302 protected: 330 protected:
331 BlockingWriter* writer_;
303 QuicDispatcher::WriteBlockedList* blocked_list_; 332 QuicDispatcher::WriteBlockedList* blocked_list_;
304 }; 333 };
305 334
306 TEST_F(QuicWriteBlockedListTest, BasicOnCanWrite) { 335 TEST_F(QuicWriteBlockedListTest, BasicOnCanWrite) {
307 // No OnCanWrite calls because no connections are blocked. 336 // No OnCanWrite calls because no connections are blocked.
308 dispatcher_.OnCanWrite(); 337 dispatcher_.OnCanWrite();
309 338
310 // Register connection 1 for events, and make sure it's nofitied. 339 // Register connection 1 for events, and make sure it's nofitied.
311 blocked_list_->insert(make_pair(connection1(), true)); 340 blocked_list_->insert(make_pair(connection1(), true));
312 EXPECT_CALL(*connection1(), OnCanWrite()); 341 EXPECT_CALL(*connection1(), OnCanWrite());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 442
414 // And we'll resume where we left off when we get another call. 443 // And we'll resume where we left off when we get another call.
415 EXPECT_CALL(*connection2(), OnCanWrite()); 444 EXPECT_CALL(*connection2(), OnCanWrite());
416 dispatcher_.OnCanWrite(); 445 dispatcher_.OnCanWrite();
417 } 446 }
418 447
419 } // namespace 448 } // namespace
420 } // namespace test 449 } // namespace test
421 } // namespace tools 450 } // namespace tools
422 } // namespace net 451 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_time_wait_list_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698