| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 client_writer_->Initialize( | 327 client_writer_->Initialize( |
| 321 reinterpret_cast<QuicEpollConnectionHelper*>( | 328 reinterpret_cast<QuicEpollConnectionHelper*>( |
| 322 QuicConnectionPeer::GetHelper( | 329 QuicConnectionPeer::GetHelper( |
| 323 client_->client()->session()->connection())), | 330 client_->client()->session()->connection())), |
| 324 new ClientDelegate(client_->client())); | 331 new ClientDelegate(client_->client())); |
| 325 return client_->client()->connected(); | 332 return client_->client()->connected(); |
| 326 } | 333 } |
| 327 | 334 |
| 328 virtual void SetUp() OVERRIDE { | 335 virtual void SetUp() OVERRIDE { |
| 329 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 336 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
| 330 // and QuicDispatcher when Initialize() is executed. | 337 // and TestWriterFactory when Initialize() is executed. |
| 331 client_writer_ = new PacketDroppingTestWriter(); | 338 client_writer_ = new PacketDroppingTestWriter(); |
| 332 server_writer_ = new PacketDroppingTestWriter(); | 339 server_writer_ = new PacketDroppingTestWriter(); |
| 333 } | 340 } |
| 334 | 341 |
| 335 virtual void TearDown() OVERRIDE { | 342 virtual void TearDown() OVERRIDE { |
| 336 StopServer(); | 343 StopServer(); |
| 337 } | 344 } |
| 338 | 345 |
| 339 void StartServer() { | 346 void StartServer() { |
| 340 server_thread_.reset( | 347 server_thread_.reset( |
| 341 new ServerThread( | 348 new ServerThread( |
| 342 new QuicServer(server_config_, server_supported_versions_), | 349 new QuicServer(server_config_, server_supported_versions_), |
| 343 server_address_, | 350 server_address_, |
| 344 strike_register_no_startup_period_)); | 351 strike_register_no_startup_period_)); |
| 345 server_thread_->Initialize(); | 352 server_thread_->Initialize(); |
| 346 server_address_ = IPEndPoint(server_address_.address(), | 353 server_address_ = IPEndPoint(server_address_.address(), |
| 347 server_thread_->GetPort()); | 354 server_thread_->GetPort()); |
| 348 QuicDispatcher* dispatcher = | 355 QuicDispatcher* dispatcher = |
| 349 QuicServerPeer::GetDispatcher(server_thread_->server()); | 356 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 357 TestWriterFactory* packet_writer_factory = new TestWriterFactory(); |
| 358 QuicDispatcherPeer::SetPacketWriterFactory(dispatcher, |
| 359 packet_writer_factory); |
| 350 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 360 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
| 351 server_writer_->Initialize( | 361 server_writer_->Initialize( |
| 352 QuicDispatcherPeer::GetHelper(dispatcher), | 362 QuicDispatcherPeer::GetHelper(dispatcher), |
| 353 new ServerDelegate(dispatcher)); | 363 new ServerDelegate(packet_writer_factory, dispatcher)); |
| 354 server_thread_->Start(); | 364 server_thread_->Start(); |
| 355 server_started_ = true; | 365 server_started_ = true; |
| 356 } | 366 } |
| 357 | 367 |
| 358 void StopServer() { | 368 void StopServer() { |
| 359 if (!server_started_) | 369 if (!server_started_) |
| 360 return; | 370 return; |
| 361 if (server_thread_.get()) { | 371 if (server_thread_.get()) { |
| 362 server_thread_->Quit(); | 372 server_thread_->Quit(); |
| 363 server_thread_->Join(); | 373 server_thread_->Join(); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 ASSERT_TRUE(Initialize()); | 1158 ASSERT_TRUE(Initialize()); |
| 1149 | 1159 |
| 1150 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1160 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1151 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1161 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1152 | 1162 |
| 1153 WrongAddressWriter* writer = new WrongAddressWriter(); | 1163 WrongAddressWriter* writer = new WrongAddressWriter(); |
| 1154 | 1164 |
| 1155 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); | 1165 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); |
| 1156 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), | 1166 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), |
| 1157 writer, | 1167 writer, |
| 1158 true /* owns_writer */); | 1168 /* owns_writer= */ true); |
| 1159 | 1169 |
| 1160 client_->SendSynchronousRequest("/bar"); | 1170 client_->SendSynchronousRequest("/bar"); |
| 1161 | 1171 |
| 1162 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1172 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 1163 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 1173 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
| 1164 } | 1174 } |
| 1165 | 1175 |
| 1166 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { | 1176 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { |
| 1167 // Tests that the client's port can change during an established QUIC | 1177 // Tests that the client's port can change during an established QUIC |
| 1168 // connection, and that doing so does not result in the connection being | 1178 // 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... |
| 1384 QuicSession* session = dispatcher->session_map().begin()->second; | 1394 QuicSession* session = dispatcher->session_map().begin()->second; |
| 1385 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( | 1395 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( |
| 1386 session).size()); | 1396 session).size()); |
| 1387 server_thread_->Resume(); | 1397 server_thread_->Resume(); |
| 1388 } | 1398 } |
| 1389 | 1399 |
| 1390 } // namespace | 1400 } // namespace |
| 1391 } // namespace test | 1401 } // namespace test |
| 1392 } // namespace tools | 1402 } // namespace tools |
| 1393 } // namespace net | 1403 } // namespace net |
| OLD | NEW |