| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromium_socket_factory.h" | 5 #include "remoting/protocol/chromium_socket_factory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include <memory> |
| 11 |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/webrtc/base/asyncpacketsocket.h" | 16 #include "third_party/webrtc/base/asyncpacketsocket.h" |
| 16 #include "third_party/webrtc/base/socketaddress.h" | 17 #include "third_party/webrtc/base/socketaddress.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 namespace protocol { | 20 namespace protocol { |
| 20 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 run_loop_.Run(); | 58 run_loop_.Run(); |
| 58 } | 59 } |
| 59 EXPECT_EQ(test_packet, last_packet_); | 60 EXPECT_EQ(test_packet, last_packet_); |
| 60 EXPECT_EQ(sender->GetLocalAddress(), last_address_); | 61 EXPECT_EQ(sender->GetLocalAddress(), last_address_); |
| 61 } | 62 } |
| 62 | 63 |
| 63 protected: | 64 protected: |
| 64 base::MessageLoopForIO message_loop_; | 65 base::MessageLoopForIO message_loop_; |
| 65 base::RunLoop run_loop_; | 66 base::RunLoop run_loop_; |
| 66 | 67 |
| 67 scoped_ptr<rtc::PacketSocketFactory> socket_factory_; | 68 std::unique_ptr<rtc::PacketSocketFactory> socket_factory_; |
| 68 scoped_ptr<rtc::AsyncPacketSocket> socket_; | 69 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
| 69 | 70 |
| 70 std::string last_packet_; | 71 std::string last_packet_; |
| 71 rtc::SocketAddress last_address_; | 72 rtc::SocketAddress last_address_; |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 TEST_F(ChromiumSocketFactoryTest, SendAndReceive) { | 75 TEST_F(ChromiumSocketFactoryTest, SendAndReceive) { |
| 75 scoped_ptr<rtc::AsyncPacketSocket> sending_socket( | 76 std::unique_ptr<rtc::AsyncPacketSocket> sending_socket( |
| 76 socket_factory_->CreateUdpSocket( | 77 socket_factory_->CreateUdpSocket(rtc::SocketAddress("127.0.0.1", 0), 0, |
| 77 rtc::SocketAddress("127.0.0.1", 0), 0, 0)); | 78 0)); |
| 78 ASSERT_TRUE(sending_socket.get() != nullptr); | 79 ASSERT_TRUE(sending_socket.get() != nullptr); |
| 79 EXPECT_EQ(sending_socket->GetState(), | 80 EXPECT_EQ(sending_socket->GetState(), |
| 80 rtc::AsyncPacketSocket::STATE_BOUND); | 81 rtc::AsyncPacketSocket::STATE_BOUND); |
| 81 | 82 |
| 82 VerifyCanSendAndReceive(sending_socket.get()); | 83 VerifyCanSendAndReceive(sending_socket.get()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 TEST_F(ChromiumSocketFactoryTest, SetOptions) { | 86 TEST_F(ChromiumSocketFactoryTest, SetOptions) { |
| 86 EXPECT_EQ(0, socket_->SetOption(rtc::Socket::OPT_SNDBUF, 4096)); | 87 EXPECT_EQ(0, socket_->SetOption(rtc::Socket::OPT_SNDBUF, 4096)); |
| 87 EXPECT_EQ(0, socket_->SetOption(rtc::Socket::OPT_RCVBUF, 4096)); | 88 EXPECT_EQ(0, socket_->SetOption(rtc::Socket::OPT_RCVBUF, 4096)); |
| 88 } | 89 } |
| 89 | 90 |
| 90 TEST_F(ChromiumSocketFactoryTest, PortRange) { | 91 TEST_F(ChromiumSocketFactoryTest, PortRange) { |
| 91 const uint16_t kMinPort = 12400; | 92 const uint16_t kMinPort = 12400; |
| 92 const uint16_t kMaxPort = 12410; | 93 const uint16_t kMaxPort = 12410; |
| 93 socket_.reset(socket_factory_->CreateUdpSocket( | 94 socket_.reset(socket_factory_->CreateUdpSocket( |
| 94 rtc::SocketAddress("127.0.0.1", 0), kMaxPort, kMaxPort)); | 95 rtc::SocketAddress("127.0.0.1", 0), kMaxPort, kMaxPort)); |
| 95 ASSERT_TRUE(socket_.get() != nullptr); | 96 ASSERT_TRUE(socket_.get() != nullptr); |
| 96 EXPECT_EQ(socket_->GetState(), rtc::AsyncPacketSocket::STATE_BOUND); | 97 EXPECT_EQ(socket_->GetState(), rtc::AsyncPacketSocket::STATE_BOUND); |
| 97 EXPECT_GE(socket_->GetLocalAddress().port(), kMinPort); | 98 EXPECT_GE(socket_->GetLocalAddress().port(), kMinPort); |
| 98 EXPECT_LE(socket_->GetLocalAddress().port(), kMaxPort); | 99 EXPECT_LE(socket_->GetLocalAddress().port(), kMaxPort); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TEST_F(ChromiumSocketFactoryTest, TransientError) { | 102 TEST_F(ChromiumSocketFactoryTest, TransientError) { |
| 102 scoped_ptr<rtc::AsyncPacketSocket> sending_socket( | 103 std::unique_ptr<rtc::AsyncPacketSocket> sending_socket( |
| 103 socket_factory_->CreateUdpSocket( | 104 socket_factory_->CreateUdpSocket(rtc::SocketAddress("127.0.0.1", 0), 0, |
| 104 rtc::SocketAddress("127.0.0.1", 0), 0, 0)); | 105 0)); |
| 105 std::string test_packet("TEST"); | 106 std::string test_packet("TEST"); |
| 106 | 107 |
| 107 // Try sending a packet to an IPv6 address from a socket that's bound to an | 108 // Try sending a packet to an IPv6 address from a socket that's bound to an |
| 108 // IPv4 address. This send is expected to fail, but the socket should still be | 109 // IPv4 address. This send is expected to fail, but the socket should still be |
| 109 // functional. | 110 // functional. |
| 110 sending_socket->SendTo(test_packet.data(), test_packet.size(), | 111 sending_socket->SendTo(test_packet.data(), test_packet.size(), |
| 111 rtc::SocketAddress("::1", 0), | 112 rtc::SocketAddress("::1", 0), |
| 112 rtc::PacketOptions()); | 113 rtc::PacketOptions()); |
| 113 | 114 |
| 114 // Verify that socket is still usable. | 115 // Verify that socket is still usable. |
| 115 VerifyCanSendAndReceive(sending_socket.get()); | 116 VerifyCanSendAndReceive(sending_socket.get()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 } // namespace protocol | 119 } // namespace protocol |
| 119 } // namespace remoting | 120 } // namespace remoting |
| OLD | NEW |