| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "extensions/browser/api/socket/tcp_socket.h" | 8 #include "extensions/browser/api/socket/tcp_socket.h" |
| 9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/rand_callback.h" | 13 #include "net/base/rand_callback.h" |
| 14 #include "net/log/net_log_source.h" |
| 14 #include "net/socket/tcp_client_socket.h" | 15 #include "net/socket/tcp_client_socket.h" |
| 15 #include "net/socket/tcp_server_socket.h" | 16 #include "net/socket/tcp_server_socket.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 18 |
| 18 using testing::_; | 19 using testing::_; |
| 19 using testing::DoAll; | 20 using testing::DoAll; |
| 20 using testing::Return; | 21 using testing::Return; |
| 21 using testing::SaveArg; | 22 using testing::SaveArg; |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 class MockTCPSocket : public net::TCPClientSocket { | 26 class MockTCPSocket : public net::TCPClientSocket { |
| 26 public: | 27 public: |
| 27 explicit MockTCPSocket(const net::AddressList& address_list) | 28 explicit MockTCPSocket(const net::AddressList& address_list) |
| 28 : net::TCPClientSocket(address_list, NULL, NULL, net::NetLog::Source()) {} | 29 : net::TCPClientSocket(address_list, NULL, NULL, net::NetLogSource()) {} |
| 29 | 30 |
| 30 MOCK_METHOD3(Read, int(net::IOBuffer* buf, int buf_len, | 31 MOCK_METHOD3(Read, int(net::IOBuffer* buf, int buf_len, |
| 31 const net::CompletionCallback& callback)); | 32 const net::CompletionCallback& callback)); |
| 32 MOCK_METHOD3(Write, int(net::IOBuffer* buf, int buf_len, | 33 MOCK_METHOD3(Write, int(net::IOBuffer* buf, int buf_len, |
| 33 const net::CompletionCallback& callback)); | 34 const net::CompletionCallback& callback)); |
| 34 MOCK_METHOD2(SetKeepAlive, bool(bool enable, int delay)); | 35 MOCK_METHOD2(SetKeepAlive, bool(bool enable, int delay)); |
| 35 MOCK_METHOD1(SetNoDelay, bool(bool no_delay)); | 36 MOCK_METHOD1(SetNoDelay, bool(bool no_delay)); |
| 36 bool IsConnected() const override { | 37 bool IsConnected() const override { |
| 37 return true; | 38 return true; |
| 38 } | 39 } |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(MockTCPSocket); | 42 DISALLOW_COPY_AND_ASSIGN(MockTCPSocket); |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 class MockTCPServerSocket : public net::TCPServerSocket { | 45 class MockTCPServerSocket : public net::TCPServerSocket { |
| 45 public: | 46 public: |
| 46 MockTCPServerSocket() : net::TCPServerSocket(NULL, net::NetLog::Source()) {} | 47 MockTCPServerSocket() : net::TCPServerSocket(NULL, net::NetLogSource()) {} |
| 47 MOCK_METHOD2(Listen, int(const net::IPEndPoint& address, int backlog)); | 48 MOCK_METHOD2(Listen, int(const net::IPEndPoint& address, int backlog)); |
| 48 MOCK_METHOD2(Accept, | 49 MOCK_METHOD2(Accept, |
| 49 int(std::unique_ptr<net::StreamSocket>* socket, | 50 int(std::unique_ptr<net::StreamSocket>* socket, |
| 50 const net::CompletionCallback& callback)); | 51 const net::CompletionCallback& callback)); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(MockTCPServerSocket); | 54 DISALLOW_COPY_AND_ASSIGN(MockTCPServerSocket); |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 class CompleteHandler { | 57 class CompleteHandler { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 248 |
| 248 EXPECT_CALL(handler, OnAcceptMock(_, _)); | 249 EXPECT_CALL(handler, OnAcceptMock(_, _)); |
| 249 | 250 |
| 250 std::string err_msg; | 251 std::string err_msg; |
| 251 EXPECT_EQ(net::OK, socket->Listen("127.0.0.1", 9999, 10, &err_msg)); | 252 EXPECT_EQ(net::OK, socket->Listen("127.0.0.1", 9999, 10, &err_msg)); |
| 252 socket->Accept(base::Bind(&CompleteHandler::OnAccept, | 253 socket->Accept(base::Bind(&CompleteHandler::OnAccept, |
| 253 base::Unretained(&handler))); | 254 base::Unretained(&handler))); |
| 254 } | 255 } |
| 255 | 256 |
| 256 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |