OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/quic/p2p/quic_p2p_session.h" | 5 #include "net/quic/p2p/quic_p2p_session.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/quic/crypto/quic_random.h" | 18 #include "net/quic/crypto/quic_random.h" |
19 #include "net/quic/p2p/quic_p2p_crypto_config.h" | 19 #include "net/quic/p2p/quic_p2p_crypto_config.h" |
20 #include "net/quic/p2p/quic_p2p_stream.h" | 20 #include "net/quic/p2p/quic_p2p_stream.h" |
| 21 #include "net/quic/quic_chromium_alarm_factory.h" |
21 #include "net/quic/quic_chromium_connection_helper.h" | 22 #include "net/quic/quic_chromium_connection_helper.h" |
22 #include "net/quic/quic_chromium_packet_writer.h" | 23 #include "net/quic/quic_chromium_packet_writer.h" |
23 #include "net/quic/test_tools/quic_session_peer.h" | 24 #include "net/quic/test_tools/quic_session_peer.h" |
24 #include "net/socket/socket.h" | 25 #include "net/socket/socket.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 }; | 190 }; |
190 | 191 |
191 } // namespace | 192 } // namespace |
192 | 193 |
193 class QuicP2PSessionTest : public ::testing::Test { | 194 class QuicP2PSessionTest : public ::testing::Test { |
194 public: | 195 public: |
195 void OnWriteResult(int result); | 196 void OnWriteResult(int result); |
196 | 197 |
197 protected: | 198 protected: |
198 QuicP2PSessionTest() | 199 QuicP2PSessionTest() |
199 : quic_helper_(base::ThreadTaskRunnerHandle::Get().get(), | 200 : quic_helper_(&quic_clock_, |
200 &quic_clock_, | 201 QuicRandom::GetInstance()), |
201 QuicRandom::GetInstance()) { | 202 alarm_factory_(base::ThreadTaskRunnerHandle::Get().get(), |
| 203 &quic_clock_) { |
202 // Simulate out-of-bound config handshake. | 204 // Simulate out-of-bound config handshake. |
203 CryptoHandshakeMessage hello_message; | 205 CryptoHandshakeMessage hello_message; |
204 config_.ToHandshakeMessage(&hello_message); | 206 config_.ToHandshakeMessage(&hello_message); |
205 std::string error_detail; | 207 std::string error_detail; |
206 EXPECT_EQ(QUIC_NO_ERROR, | 208 EXPECT_EQ(QUIC_NO_ERROR, |
207 config_.ProcessPeerHello(hello_message, CLIENT, &error_detail)); | 209 config_.ProcessPeerHello(hello_message, CLIENT, &error_detail)); |
208 } | 210 } |
209 | 211 |
210 void CreateSessions() { | 212 void CreateSessions() { |
211 std::unique_ptr<FakeP2PDatagramSocket> socket1(new FakeP2PDatagramSocket()); | 213 std::unique_ptr<FakeP2PDatagramSocket> socket1(new FakeP2PDatagramSocket()); |
(...skipping 11 matching lines...) Expand all Loading... |
223 Perspective::IS_CLIENT); | 225 Perspective::IS_CLIENT); |
224 } | 226 } |
225 | 227 |
226 std::unique_ptr<QuicP2PSession> CreateP2PSession( | 228 std::unique_ptr<QuicP2PSession> CreateP2PSession( |
227 std::unique_ptr<Socket> socket, | 229 std::unique_ptr<Socket> socket, |
228 QuicP2PCryptoConfig crypto_config, | 230 QuicP2PCryptoConfig crypto_config, |
229 Perspective perspective) { | 231 Perspective perspective) { |
230 QuicChromiumPacketWriter* writer = | 232 QuicChromiumPacketWriter* writer = |
231 new QuicChromiumPacketWriter(socket.get()); | 233 new QuicChromiumPacketWriter(socket.get()); |
232 std::unique_ptr<QuicConnection> quic_connection1(new QuicConnection( | 234 std::unique_ptr<QuicConnection> quic_connection1(new QuicConnection( |
233 0, IPEndPoint(IPAddress::IPv4AllZeros(), 0), &quic_helper_, writer, | 235 0, IPEndPoint(IPAddress::IPv4AllZeros(), 0), &quic_helper_, &alarm_facto
ry_, writer, |
234 true /* owns_writer */, perspective, QuicSupportedVersions())); | 236 true /* owns_writer */, perspective, QuicSupportedVersions())); |
235 writer->SetConnection(quic_connection1.get()); | 237 writer->SetConnection(quic_connection1.get()); |
236 | 238 |
237 std::unique_ptr<QuicP2PSession> result( | 239 std::unique_ptr<QuicP2PSession> result( |
238 new QuicP2PSession(config_, crypto_config, std::move(quic_connection1), | 240 new QuicP2PSession(config_, crypto_config, std::move(quic_connection1), |
239 std::move(socket))); | 241 std::move(socket))); |
240 result->Initialize(); | 242 result->Initialize(); |
241 return result; | 243 return result; |
242 } | 244 } |
243 | 245 |
244 void TestStreamConnection(QuicP2PSession* from_session, | 246 void TestStreamConnection(QuicP2PSession* from_session, |
245 QuicP2PSession* to_session, | 247 QuicP2PSession* to_session, |
246 QuicStreamId expected_stream_id); | 248 QuicStreamId expected_stream_id); |
247 | 249 |
248 QuicClock quic_clock_; | 250 QuicClock quic_clock_; |
249 QuicChromiumConnectionHelper quic_helper_; | 251 QuicChromiumConnectionHelper quic_helper_; |
| 252 QuicChromiumAlarmFactory alarm_factory_; |
250 QuicConfig config_; | 253 QuicConfig config_; |
251 | 254 |
252 base::WeakPtr<FakeP2PDatagramSocket> socket1_; | 255 base::WeakPtr<FakeP2PDatagramSocket> socket1_; |
253 std::unique_ptr<QuicP2PSession> session1_; | 256 std::unique_ptr<QuicP2PSession> session1_; |
254 | 257 |
255 base::WeakPtr<FakeP2PDatagramSocket> socket2_; | 258 base::WeakPtr<FakeP2PDatagramSocket> socket2_; |
256 std::unique_ptr<QuicP2PSession> session2_; | 259 std::unique_ptr<QuicP2PSession> session2_; |
257 }; | 260 }; |
258 | 261 |
259 void QuicP2PSessionTest::OnWriteResult(int result) { | 262 void QuicP2PSessionTest::OnWriteResult(int result) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 EXPECT_TRUE(stream_delegate.is_closed()); | 393 EXPECT_TRUE(stream_delegate.is_closed()); |
391 EXPECT_EQ(QUIC_PACKET_READ_ERROR, stream_delegate.error()); | 394 EXPECT_EQ(QUIC_PACKET_READ_ERROR, stream_delegate.error()); |
392 EXPECT_TRUE(session_delegate.is_closed()); | 395 EXPECT_TRUE(session_delegate.is_closed()); |
393 EXPECT_EQ(QUIC_PACKET_READ_ERROR, session_delegate.error()); | 396 EXPECT_EQ(QUIC_PACKET_READ_ERROR, session_delegate.error()); |
394 | 397 |
395 // Verify that the socket was destroyed. | 398 // Verify that the socket was destroyed. |
396 EXPECT_FALSE(socket1_); | 399 EXPECT_FALSE(socket1_); |
397 } | 400 } |
398 | 401 |
399 } // namespace net | 402 } // namespace net |
OLD | NEW |