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 "remoting/protocol/pseudotcp_adapter.h" | 5 #include "remoting/protocol/pseudotcp_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ptr_util.h" |
12 #include "jingle/glue/thread_wrapper.h" | 13 #include "jingle/glue/thread_wrapper.h" |
13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
15 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
16 #include "remoting/protocol/p2p_datagram_socket.h" | 17 #include "remoting/protocol/p2p_datagram_socket.h" |
17 #include "remoting/protocol/p2p_stream_socket.h" | 18 #include "remoting/protocol/p2p_stream_socket.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 protected: | 288 protected: |
288 void SetUp() override { | 289 void SetUp() override { |
289 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 290 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
290 | 291 |
291 host_socket_ = new FakeSocket(); | 292 host_socket_ = new FakeSocket(); |
292 client_socket_ = new FakeSocket(); | 293 client_socket_ = new FakeSocket(); |
293 | 294 |
294 host_socket_->Connect(client_socket_); | 295 host_socket_->Connect(client_socket_); |
295 client_socket_->Connect(host_socket_); | 296 client_socket_->Connect(host_socket_); |
296 | 297 |
297 host_pseudotcp_.reset(new PseudoTcpAdapter(make_scoped_ptr(host_socket_))); | 298 host_pseudotcp_.reset(new PseudoTcpAdapter(base::WrapUnique(host_socket_))); |
298 client_pseudotcp_.reset( | 299 client_pseudotcp_.reset( |
299 new PseudoTcpAdapter(make_scoped_ptr(client_socket_))); | 300 new PseudoTcpAdapter(base::WrapUnique(client_socket_))); |
300 } | 301 } |
301 | 302 |
302 FakeSocket* host_socket_; | 303 FakeSocket* host_socket_; |
303 FakeSocket* client_socket_; | 304 FakeSocket* client_socket_; |
304 | 305 |
305 scoped_ptr<PseudoTcpAdapter> host_pseudotcp_; | 306 std::unique_ptr<PseudoTcpAdapter> host_pseudotcp_; |
306 scoped_ptr<PseudoTcpAdapter> client_pseudotcp_; | 307 std::unique_ptr<PseudoTcpAdapter> client_pseudotcp_; |
307 base::MessageLoop message_loop_; | 308 base::MessageLoop message_loop_; |
308 }; | 309 }; |
309 | 310 |
310 TEST_F(PseudoTcpAdapterTest, DataTransfer) { | 311 TEST_F(PseudoTcpAdapterTest, DataTransfer) { |
311 net::TestCompletionCallback host_connect_cb; | 312 net::TestCompletionCallback host_connect_cb; |
312 net::TestCompletionCallback client_connect_cb; | 313 net::TestCompletionCallback client_connect_cb; |
313 | 314 |
314 int rv1 = host_pseudotcp_->Connect(host_connect_cb.callback()); | 315 int rv1 = host_pseudotcp_->Connect(host_connect_cb.callback()); |
315 int rv2 = client_pseudotcp_->Connect(client_connect_cb.callback()); | 316 int rv2 = client_pseudotcp_->Connect(client_connect_cb.callback()); |
316 | 317 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 client_pseudotcp_.get()); | 362 client_pseudotcp_.get()); |
362 | 363 |
363 tester->Start(); | 364 tester->Start(); |
364 message_loop_.Run(); | 365 message_loop_.Run(); |
365 tester->CheckResults(); | 366 tester->CheckResults(); |
366 } | 367 } |
367 | 368 |
368 class DeleteOnConnected { | 369 class DeleteOnConnected { |
369 public: | 370 public: |
370 DeleteOnConnected(base::MessageLoop* message_loop, | 371 DeleteOnConnected(base::MessageLoop* message_loop, |
371 scoped_ptr<PseudoTcpAdapter>* adapter) | 372 std::unique_ptr<PseudoTcpAdapter>* adapter) |
372 : message_loop_(message_loop), adapter_(adapter) {} | 373 : message_loop_(message_loop), adapter_(adapter) {} |
373 void OnConnected(int error) { | 374 void OnConnected(int error) { |
374 adapter_->reset(); | 375 adapter_->reset(); |
375 message_loop_->PostTask(FROM_HERE, | 376 message_loop_->PostTask(FROM_HERE, |
376 base::MessageLoop::QuitWhenIdleClosure()); | 377 base::MessageLoop::QuitWhenIdleClosure()); |
377 } | 378 } |
378 base::MessageLoop* message_loop_; | 379 base::MessageLoop* message_loop_; |
379 scoped_ptr<PseudoTcpAdapter>* adapter_; | 380 std::unique_ptr<PseudoTcpAdapter>* adapter_; |
380 }; | 381 }; |
381 | 382 |
382 TEST_F(PseudoTcpAdapterTest, DeleteOnConnected) { | 383 TEST_F(PseudoTcpAdapterTest, DeleteOnConnected) { |
383 // This test verifies that deleting the adapter mid-callback doesn't lead | 384 // This test verifies that deleting the adapter mid-callback doesn't lead |
384 // to deleted structures being touched as the stack unrolls, so the failure | 385 // to deleted structures being touched as the stack unrolls, so the failure |
385 // mode is a crash rather than a normal test failure. | 386 // mode is a crash rather than a normal test failure. |
386 net::TestCompletionCallback client_connect_cb; | 387 net::TestCompletionCallback client_connect_cb; |
387 DeleteOnConnected host_delete(&message_loop_, &host_pseudotcp_); | 388 DeleteOnConnected host_delete(&message_loop_, &host_pseudotcp_); |
388 | 389 |
389 host_pseudotcp_->Connect(base::Bind(&DeleteOnConnected::OnConnected, | 390 host_pseudotcp_->Connect(base::Bind(&DeleteOnConnected::OnConnected, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 424 |
424 tester->Start(); | 425 tester->Start(); |
425 message_loop_.Run(); | 426 message_loop_.Run(); |
426 tester->CheckResults(); | 427 tester->CheckResults(); |
427 } | 428 } |
428 | 429 |
429 } // namespace | 430 } // namespace |
430 | 431 |
431 } // namespace protocol | 432 } // namespace protocol |
432 } // namespace remoting | 433 } // namespace remoting |
OLD | NEW |