| 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 "content/browser/renderer_host/p2p/socket_host_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 | 8 |
| 9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
| 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
| 11 #include "net/socket/stream_socket.h" | 11 #include "net/socket/stream_socket.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using ::testing::_; | 15 using ::testing::_; |
| 16 using ::testing::DeleteArg; | 16 using ::testing::DeleteArg; |
| 17 using ::testing::DoAll; | 17 using ::testing::DoAll; |
| 18 using ::testing::Return; | 18 using ::testing::Return; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 class P2PSocketHostTcpTest : public testing::Test { | 22 class P2PSocketHostTcpTest : public testing::Test { |
| 23 protected: | 23 protected: |
| 24 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
| 25 EXPECT_CALL(sender_, Send( | 25 EXPECT_CALL(sender_, Send( |
| 26 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) | 26 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) |
| 27 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 27 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 28 | 28 |
| 29 socket_host_.reset(new P2PSocketHostTcp(&sender_, 0)); | 29 socket_host_.reset(new P2PSocketHostTcp(&sender_, 0, |
| 30 P2P_SOCKET_TCP_CLIENT)); |
| 30 socket_ = new FakeSocket(&sent_data_); | 31 socket_ = new FakeSocket(&sent_data_); |
| 31 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); | 32 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); |
| 32 socket_host_->socket_.reset(socket_); | 33 socket_host_->socket_.reset(socket_); |
| 33 | 34 |
| 34 dest_ = ParseAddress(kTestIpAddress1, kTestPort1); | 35 dest_ = ParseAddress(kTestIpAddress1, kTestPort1); |
| 35 | 36 |
| 36 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); | 37 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); |
| 37 | 38 |
| 38 socket_host_->remote_address_ = dest_; | 39 socket_host_->remote_address_ = dest_; |
| 39 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; | 40 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 59 net::IPEndPoint dest2_; | 60 net::IPEndPoint dest2_; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 class P2PSocketHostStunTcpTest : public testing::Test { | 63 class P2PSocketHostStunTcpTest : public testing::Test { |
| 63 protected: | 64 protected: |
| 64 virtual void SetUp() OVERRIDE { | 65 virtual void SetUp() OVERRIDE { |
| 65 EXPECT_CALL(sender_, Send( | 66 EXPECT_CALL(sender_, Send( |
| 66 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) | 67 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) |
| 67 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 68 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 68 | 69 |
| 69 socket_host_.reset(new P2PSocketHostStunTcp(&sender_, 0)); | 70 socket_host_.reset(new P2PSocketHostStunTcp(&sender_, 0, |
| 71 P2P_SOCKET_STUN_TCP_CLIENT)); |
| 70 socket_ = new FakeSocket(&sent_data_); | 72 socket_ = new FakeSocket(&sent_data_); |
| 71 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); | 73 socket_->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); |
| 72 socket_host_->socket_.reset(socket_); | 74 socket_host_->socket_.reset(socket_); |
| 73 | 75 |
| 74 dest_ = ParseAddress(kTestIpAddress1, kTestPort1); | 76 dest_ = ParseAddress(kTestIpAddress1, kTestPort1); |
| 75 | 77 |
| 76 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); | 78 local_address_ = ParseAddress(kTestLocalIpAddress, kTestPort1); |
| 77 | 79 |
| 78 socket_host_->remote_address_ = dest_; | 80 socket_host_->remote_address_ = dest_; |
| 79 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; | 81 socket_host_->state_ = P2PSocketHost::STATE_CONNECTING; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 message_loop.RunUntilIdle(); | 361 message_loop.RunUntilIdle(); |
| 360 | 362 |
| 361 std::string expected_data; | 363 std::string expected_data; |
| 362 expected_data.append(packet1.begin(), packet1.end()); | 364 expected_data.append(packet1.begin(), packet1.end()); |
| 363 expected_data.append(packet2.begin(), packet2.end()); | 365 expected_data.append(packet2.begin(), packet2.end()); |
| 364 | 366 |
| 365 EXPECT_EQ(expected_data, sent_data_); | 367 EXPECT_EQ(expected_data, sent_data_); |
| 366 } | 368 } |
| 367 | 369 |
| 368 } // namespace content | 370 } // namespace content |
| OLD | NEW |