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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 client_writer_->Initialize( | 326 client_writer_->Initialize( |
320 reinterpret_cast<QuicEpollConnectionHelper*>( | 327 reinterpret_cast<QuicEpollConnectionHelper*>( |
321 QuicConnectionPeer::GetHelper( | 328 QuicConnectionPeer::GetHelper( |
322 client_->client()->session()->connection())), | 329 client_->client()->session()->connection())), |
323 new ClientDelegate(client_->client())); | 330 new ClientDelegate(client_->client())); |
324 return client_->client()->connected(); | 331 return client_->client()->connected(); |
325 } | 332 } |
326 | 333 |
327 virtual void SetUp() OVERRIDE { | 334 virtual void SetUp() OVERRIDE { |
328 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 335 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
329 // and QuicDispatcher when Initialize() is executed. | 336 // and TestWriterFactory when Initialize() is executed. |
330 client_writer_ = new PacketDroppingTestWriter(); | 337 client_writer_ = new PacketDroppingTestWriter(); |
331 server_writer_ = new PacketDroppingTestWriter(); | 338 server_writer_ = new PacketDroppingTestWriter(); |
332 } | 339 } |
333 | 340 |
334 virtual void TearDown() OVERRIDE { | 341 virtual void TearDown() OVERRIDE { |
335 StopServer(); | 342 StopServer(); |
336 } | 343 } |
337 | 344 |
338 void StartServer() { | 345 void StartServer() { |
339 server_thread_.reset( | 346 server_thread_.reset( |
340 new ServerThread( | 347 new ServerThread( |
341 new QuicServer(server_config_, server_supported_versions_), | 348 new QuicServer(server_config_, server_supported_versions_), |
342 server_address_, | 349 server_address_, |
343 strike_register_no_startup_period_)); | 350 strike_register_no_startup_period_)); |
344 server_thread_->Initialize(); | 351 server_thread_->Initialize(); |
345 server_address_ = IPEndPoint(server_address_.address(), | 352 server_address_ = IPEndPoint(server_address_.address(), |
346 server_thread_->GetPort()); | 353 server_thread_->GetPort()); |
347 QuicDispatcher* dispatcher = | 354 QuicDispatcher* dispatcher = |
348 QuicServerPeer::GetDispatcher(server_thread_->server()); | 355 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 356 TestWriterFactory* packet_writer_factory = new TestWriterFactory(); |
| 357 QuicDispatcherPeer::SetPacketWriterFactory(dispatcher, |
| 358 packet_writer_factory); |
349 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 359 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
350 server_writer_->Initialize( | 360 server_writer_->Initialize( |
351 QuicDispatcherPeer::GetHelper(dispatcher), | 361 QuicDispatcherPeer::GetHelper(dispatcher), |
352 new ServerDelegate(dispatcher)); | 362 new ServerDelegate(packet_writer_factory, dispatcher)); |
353 server_thread_->Start(); | 363 server_thread_->Start(); |
354 server_started_ = true; | 364 server_started_ = true; |
355 } | 365 } |
356 | 366 |
357 void StopServer() { | 367 void StopServer() { |
358 if (!server_started_) | 368 if (!server_started_) |
359 return; | 369 return; |
360 if (server_thread_.get()) { | 370 if (server_thread_.get()) { |
361 server_thread_->Quit(); | 371 server_thread_->Quit(); |
362 server_thread_->Join(); | 372 server_thread_->Join(); |
(...skipping 780 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 |