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

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

Issue 180953008: Doing a best-effort attempt to send connection close packet for open (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/test_tools/quic_test_utils.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/quic_utils.h" 14 #include "net/quic/quic_utils.h"
15 #include "net/quic/test_tools/quic_test_utils.h" 15 #include "net/quic/test_tools/quic_test_utils.h"
16 #include "net/tools/epoll_server/epoll_server.h" 16 #include "net/tools/epoll_server/epoll_server.h"
17 #include "net/tools/quic/quic_packet_writer_wrapper.h" 17 #include "net/tools/quic/quic_packet_writer_wrapper.h"
18 #include "net/tools/quic/quic_time_wait_list_manager.h" 18 #include "net/tools/quic/quic_time_wait_list_manager.h"
19 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" 19 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h"
20 #include "net/tools/quic/test_tools/quic_test_utils.h" 20 #include "net/tools/quic/test_tools/quic_test_utils.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using base::StringPiece; 24 using base::StringPiece;
25 using net::EpollServer; 25 using net::EpollServer;
26 using net::test::MockSession; 26 using net::test::MockSession;
27 using net::test::ConstructEncryptedPacket;
27 using net::tools::test::MockConnection; 28 using net::tools::test::MockConnection;
28 using std::make_pair; 29 using std::make_pair;
29 using testing::_; 30 using testing::_;
30 using testing::DoAll; 31 using testing::DoAll;
31 using testing::Invoke; 32 using testing::Invoke;
32 using testing::InSequence; 33 using testing::InSequence;
33 using testing::WithoutArgs; 34 using testing::WithoutArgs;
34 35
35 namespace net { 36 namespace net {
36 namespace tools { 37 namespace tools {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 virtual ~QuicDispatcherTest() {} 102 virtual ~QuicDispatcherTest() {}
102 103
103 MockConnection* connection1() { 104 MockConnection* connection1() {
104 return reinterpret_cast<MockConnection*>(session1_->connection()); 105 return reinterpret_cast<MockConnection*>(session1_->connection());
105 } 106 }
106 107
107 MockConnection* connection2() { 108 MockConnection* connection2() {
108 return reinterpret_cast<MockConnection*>(session2_->connection()); 109 return reinterpret_cast<MockConnection*>(session2_->connection());
109 } 110 }
110 111
111 QuicEncryptedPacket* ConstructEncryptedPacket(
112 QuicConnectionId connection_id,
113 bool version_flag,
114 bool reset_flag,
115 QuicPacketSequenceNumber sequence_number,
116 const string& data) {
117 QuicPacketHeader header;
118 header.public_header.connection_id = connection_id;
119 header.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID;
120 header.public_header.version_flag = version_flag;
121 header.public_header.reset_flag = reset_flag;
122 header.public_header.sequence_number_length = PACKET_6BYTE_SEQUENCE_NUMBER;
123 header.packet_sequence_number = sequence_number;
124 header.entropy_flag = false;
125 header.entropy_hash = 0;
126 header.fec_flag = false;
127 header.is_in_fec_group = NOT_IN_FEC_GROUP;
128 header.fec_group = 0;
129 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data));
130 QuicFrame frame(&stream_frame);
131 QuicFrames frames;
132 frames.push_back(frame);
133 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false);
134 scoped_ptr<QuicPacket> packet(
135 framer.BuildUnsizedDataPacket(header, frames).packet);
136 EXPECT_TRUE(packet != NULL);
137 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE,
138 sequence_number,
139 *packet);
140 EXPECT_TRUE(encrypted != NULL);
141 data_ = string(encrypted->data(), encrypted->length());
142 return encrypted;
143 }
144
145 void ProcessPacket(IPEndPoint addr, 112 void ProcessPacket(IPEndPoint addr,
146 QuicConnectionId connection_id, 113 QuicConnectionId connection_id,
147 bool has_version_flag, 114 bool has_version_flag,
148 const string& data) { 115 const string& data) {
149 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( 116 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
150 connection_id, has_version_flag, false, 1, data)); 117 connection_id, has_version_flag, false, 1, data));
118 data_ = string(packet->data(), packet->length());
151 dispatcher_.ProcessPacket(IPEndPoint(), addr, *packet.get()); 119 dispatcher_.ProcessPacket(IPEndPoint(), addr, *packet.get());
152 } 120 }
153 121
154 void ValidatePacket(const QuicEncryptedPacket& packet) { 122 void ValidatePacket(const QuicEncryptedPacket& packet) {
155 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); 123 EXPECT_EQ(data_.length(), packet.AsStringPiece().length());
156 EXPECT_EQ(data_, packet.AsStringPiece()); 124 EXPECT_EQ(data_, packet.AsStringPiece());
157 } 125 }
158 126
159 EpollServer eps_; 127 EpollServer eps_;
160 QuicConfig config_; 128 QuicConfig config_;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // And we'll resume where we left off when we get another call. 435 // And we'll resume where we left off when we get another call.
468 EXPECT_CALL(*connection2(), OnCanWrite()); 436 EXPECT_CALL(*connection2(), OnCanWrite());
469 dispatcher_.OnCanWrite(); 437 dispatcher_.OnCanWrite();
470 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 438 EXPECT_FALSE(dispatcher_.HasPendingWrites());
471 } 439 }
472 440
473 } // namespace 441 } // namespace
474 } // namespace test 442 } // namespace test
475 } // namespace tools 443 } // namespace tools
476 } // namespace net 444 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698