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 <stddef.h> | 5 #include <stddef.h> |
6 #include <string> | 6 #include <string> |
7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 congestion_control_tag)); | 154 congestion_control_tag)); |
155 } | 155 } |
156 } | 156 } |
157 } | 157 } |
158 } | 158 } |
159 return params; | 159 return params; |
160 } | 160 } |
161 | 161 |
162 class ServerDelegate : public PacketDroppingTestWriter::Delegate { | 162 class ServerDelegate : public PacketDroppingTestWriter::Delegate { |
163 public: | 163 public: |
164 explicit ServerDelegate(QuicDispatcher* dispatcher) | 164 ServerDelegate(TestWriterFactory* writer_factory, |
165 : dispatcher_(dispatcher) {} | 165 QuicDispatcher* dispatcher) |
| 166 : writer_factory_(writer_factory), |
| 167 dispatcher_(dispatcher) {} |
166 virtual ~ServerDelegate() {} | 168 virtual ~ServerDelegate() {} |
| 169 virtual void OnPacketSent(WriteResult result) override { |
| 170 writer_factory_->OnPacketSent(result); |
| 171 } |
167 virtual void OnCanWrite() OVERRIDE { dispatcher_->OnCanWrite(); } | 172 virtual void OnCanWrite() OVERRIDE { dispatcher_->OnCanWrite(); } |
168 private: | 173 private: |
| 174 TestWriterFactory* writer_factory_; |
169 QuicDispatcher* dispatcher_; | 175 QuicDispatcher* dispatcher_; |
170 }; | 176 }; |
171 | 177 |
172 class ClientDelegate : public PacketDroppingTestWriter::Delegate { | 178 class ClientDelegate : public PacketDroppingTestWriter::Delegate { |
173 public: | 179 public: |
174 explicit ClientDelegate(QuicClient* client) : client_(client) {} | 180 explicit ClientDelegate(QuicClient* client) : client_(client) {} |
175 virtual ~ClientDelegate() {} | 181 virtual ~ClientDelegate() {} |
| 182 virtual void OnPacketSent(WriteResult result) OVERRIDE {} |
176 virtual void OnCanWrite() OVERRIDE { | 183 virtual void OnCanWrite() OVERRIDE { |
177 EpollEvent event(EPOLLOUT, false); | 184 EpollEvent event(EPOLLOUT, false); |
178 client_->OnEvent(client_->fd(), &event); | 185 client_->OnEvent(client_->fd(), &event); |
179 } | 186 } |
180 private: | 187 private: |
181 QuicClient* client_; | 188 QuicClient* client_; |
182 }; | 189 }; |
183 | 190 |
184 class EndToEndTest : public ::testing::TestWithParam<TestParams> { | 191 class EndToEndTest : public ::testing::TestWithParam<TestParams> { |
185 protected: | 192 protected: |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 client_writer_->Initialize( | 322 client_writer_->Initialize( |
316 reinterpret_cast<QuicEpollConnectionHelper*>( | 323 reinterpret_cast<QuicEpollConnectionHelper*>( |
317 QuicConnectionPeer::GetHelper( | 324 QuicConnectionPeer::GetHelper( |
318 client_->client()->session()->connection())), | 325 client_->client()->session()->connection())), |
319 new ClientDelegate(client_->client())); | 326 new ClientDelegate(client_->client())); |
320 return client_->client()->connected(); | 327 return client_->client()->connected(); |
321 } | 328 } |
322 | 329 |
323 virtual void SetUp() OVERRIDE { | 330 virtual void SetUp() OVERRIDE { |
324 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 331 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
325 // and QuicDispatcher when Initialize() is executed. | 332 // and TestWriterFactory when Initialize() is executed. |
326 client_writer_ = new PacketDroppingTestWriter(); | 333 client_writer_ = new PacketDroppingTestWriter(); |
327 server_writer_ = new PacketDroppingTestWriter(); | 334 server_writer_ = new PacketDroppingTestWriter(); |
328 } | 335 } |
329 | 336 |
330 virtual void TearDown() OVERRIDE { | 337 virtual void TearDown() OVERRIDE { |
331 StopServer(); | 338 StopServer(); |
332 } | 339 } |
333 | 340 |
334 void StartServer() { | 341 void StartServer() { |
335 server_thread_.reset( | 342 server_thread_.reset( |
336 new ServerThread( | 343 new ServerThread( |
337 new QuicServer(server_config_, server_supported_versions_), | 344 new QuicServer(server_config_, server_supported_versions_), |
338 server_address_, | 345 server_address_, |
339 strike_register_no_startup_period_)); | 346 strike_register_no_startup_period_)); |
340 server_thread_->Initialize(); | 347 server_thread_->Initialize(); |
341 server_address_ = IPEndPoint(server_address_.address(), | 348 server_address_ = IPEndPoint(server_address_.address(), |
342 server_thread_->GetPort()); | 349 server_thread_->GetPort()); |
343 QuicDispatcher* dispatcher = | 350 QuicDispatcher* dispatcher = |
344 QuicServerPeer::GetDispatcher(server_thread_->server()); | 351 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 352 TestWriterFactory* packet_writer_factory = new TestWriterFactory(); |
| 353 QuicDispatcherPeer::SetPacketWriterFactory(dispatcher, |
| 354 packet_writer_factory); |
345 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 355 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
346 server_writer_->Initialize( | 356 server_writer_->Initialize( |
347 QuicDispatcherPeer::GetHelper(dispatcher), | 357 QuicDispatcherPeer::GetHelper(dispatcher), |
348 new ServerDelegate(dispatcher)); | 358 new ServerDelegate(packet_writer_factory, dispatcher)); |
349 server_thread_->Start(); | 359 server_thread_->Start(); |
350 server_started_ = true; | 360 server_started_ = true; |
351 } | 361 } |
352 | 362 |
353 void StopServer() { | 363 void StopServer() { |
354 if (!server_started_) | 364 if (!server_started_) |
355 return; | 365 return; |
356 if (server_thread_.get()) { | 366 if (server_thread_.get()) { |
357 server_thread_->Quit(); | 367 server_thread_->Quit(); |
358 server_thread_->Join(); | 368 server_thread_->Join(); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 ASSERT_TRUE(Initialize()); | 1153 ASSERT_TRUE(Initialize()); |
1144 | 1154 |
1145 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1155 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
1146 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1156 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1147 | 1157 |
1148 WrongAddressWriter* writer = new WrongAddressWriter(); | 1158 WrongAddressWriter* writer = new WrongAddressWriter(); |
1149 | 1159 |
1150 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); | 1160 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); |
1151 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), | 1161 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), |
1152 writer, | 1162 writer, |
1153 true /* owns_writer */); | 1163 /* owns_writer= */ true); |
1154 | 1164 |
1155 client_->SendSynchronousRequest("/bar"); | 1165 client_->SendSynchronousRequest("/bar"); |
1156 | 1166 |
1157 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1167 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
1158 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 1168 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
1159 } | 1169 } |
1160 | 1170 |
1161 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { | 1171 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { |
1162 // Tests that the client's port can change during an established QUIC | 1172 // Tests that the client's port can change during an established QUIC |
1163 // connection, and that doing so does not result in the connection being | 1173 // connection, and that doing so does not result in the connection being |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 QuicSession* session = dispatcher->session_map().begin()->second; | 1389 QuicSession* session = dispatcher->session_map().begin()->second; |
1380 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( | 1390 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( |
1381 session).size()); | 1391 session).size()); |
1382 server_thread_->Resume(); | 1392 server_thread_->Resume(); |
1383 } | 1393 } |
1384 | 1394 |
1385 } // namespace | 1395 } // namespace |
1386 } // namespace test | 1396 } // namespace test |
1387 } // namespace tools | 1397 } // namespace tools |
1388 } // namespace net | 1398 } // namespace net |
OLD | NEW |