| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ | 5 #ifndef NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ |
| 6 #define NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ | 6 #define NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "net/dns/mdns_client_impl.h" | 10 #include "net/dns/mdns_client_impl.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 class MockMDnsDatagramServerSocket : public DatagramServerSocket { | 15 class MockMDnsDatagramServerSocket : public MDnsConnection::Socket { |
| 16 public: | 16 public: |
| 17 MockMDnsDatagramServerSocket(); | 17 MockMDnsDatagramServerSocket(); |
| 18 ~MockMDnsDatagramServerSocket(); | 18 ~MockMDnsDatagramServerSocket(); |
| 19 | 19 |
| 20 // DatagramServerSocket implementation: | 20 // MDnsConnection::Socket implementation: |
| 21 int Listen(const IPEndPoint& address); | |
| 22 | |
| 23 MOCK_METHOD1(ListenInternal, int(const std::string& address)); | |
| 24 | |
| 25 MOCK_METHOD4(RecvFrom, int(IOBuffer* buffer, int size, | 21 MOCK_METHOD4(RecvFrom, int(IOBuffer* buffer, int size, |
| 26 IPEndPoint* address, | 22 IPEndPoint* address, |
| 27 const CompletionCallback& callback)); | 23 const CompletionCallback& callback)); |
| 24 int SendTo(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 28 | 25 |
| 29 int SendTo(IOBuffer* buf, int buf_len, const IPEndPoint& address, | 26 MOCK_METHOD2(SendToInternal, int(const std::string& packet, |
| 30 const CompletionCallback& callback); | |
| 31 | |
| 32 MOCK_METHOD3(SendToInternal, int(const std::string& packet, | |
| 33 const std::string address, | |
| 34 const CompletionCallback& callback)); | 27 const CompletionCallback& callback)); |
| 35 | 28 |
| 36 MOCK_METHOD1(SetReceiveBufferSize, bool(int32 size)); | |
| 37 MOCK_METHOD1(SetSendBufferSize, bool(int32 size)); | |
| 38 | |
| 39 MOCK_METHOD0(Close, void()); | |
| 40 | |
| 41 MOCK_CONST_METHOD1(GetPeerAddress, int(IPEndPoint* address)); | |
| 42 MOCK_CONST_METHOD1(GetLocalAddress, int(IPEndPoint* address)); | |
| 43 MOCK_CONST_METHOD0(NetLog, const BoundNetLog&()); | |
| 44 | |
| 45 MOCK_METHOD0(AllowAddressReuse, void()); | |
| 46 MOCK_METHOD0(AllowBroadcast, void()); | |
| 47 | |
| 48 int JoinGroup(const IPAddressNumber& group_address) const; | |
| 49 | |
| 50 MOCK_CONST_METHOD1(JoinGroupInternal, int(const std::string& group)); | |
| 51 | |
| 52 int LeaveGroup(const IPAddressNumber& group_address) const; | |
| 53 | |
| 54 MOCK_CONST_METHOD1(LeaveGroupInternal, int(const std::string& group)); | |
| 55 | |
| 56 MOCK_METHOD1(SetMulticastTimeToLive, int(int ttl)); | |
| 57 | |
| 58 MOCK_METHOD1(SetMulticastLoopbackMode, int(bool loopback)); | |
| 59 | |
| 60 MOCK_METHOD1(SetDiffServCodePoint, int(DiffServCodePoint dscp)); | |
| 61 | |
| 62 void SetResponsePacket(std::string response_packet); | 29 void SetResponsePacket(std::string response_packet); |
| 63 | 30 |
| 64 int HandleRecvNow(IOBuffer* buffer, int size, IPEndPoint* address, | 31 int HandleRecvNow(IOBuffer* buffer, int size, IPEndPoint* address, |
| 65 const CompletionCallback& callback); | 32 const CompletionCallback& callback); |
| 66 | 33 |
| 67 int HandleRecvLater(IOBuffer* buffer, int size, IPEndPoint* address, | 34 int HandleRecvLater(IOBuffer* buffer, int size, IPEndPoint* address, |
| 68 const CompletionCallback& callback); | 35 const CompletionCallback& callback); |
| 69 | 36 |
| 70 private: | 37 private: |
| 71 std::string response_packet_; | 38 std::string response_packet_; |
| 72 }; | 39 }; |
| 73 | 40 |
| 74 class MockMDnsSocketFactory : public MDnsConnection::SocketFactory { | 41 class MockMDnsSocketFactory : public MDnsConnection::SocketFactory { |
| 75 public: | 42 public: |
| 76 MockMDnsSocketFactory(); | 43 MockMDnsSocketFactory(); |
| 77 | |
| 78 virtual ~MockMDnsSocketFactory(); | 44 virtual ~MockMDnsSocketFactory(); |
| 79 | 45 |
| 80 virtual scoped_ptr<DatagramServerSocket> CreateSocket() OVERRIDE; | 46 virtual void CreateSockets( |
| 47 ScopedVector<MDnsConnection::Socket>* sockets) OVERRIDE; |
| 81 | 48 |
| 82 void SimulateReceive(const uint8* packet, int size); | 49 void SimulateReceive(const uint8* packet, int size); |
| 83 | 50 |
| 84 MOCK_METHOD1(OnSendTo, void(const std::string&)); | 51 MOCK_METHOD1(OnSendTo, void(const std::string&)); |
| 85 | 52 |
| 86 private: | 53 private: |
| 87 int SendToInternal(const std::string& packet, const std::string& address, | 54 int SendToInternal(const std::string& packet, |
| 88 const CompletionCallback& callback); | 55 const CompletionCallback& callback); |
| 89 | 56 |
| 90 // The latest receive callback is always saved, since the MDnsConnection | 57 // The latest receive callback is always saved, since the MDnsConnection |
| 91 // does not care which socket a packet is received on. | 58 // does not care which socket a packet is received on. |
| 92 int RecvFromInternal(IOBuffer* buffer, int size, | 59 int RecvFromInternal(IOBuffer* buffer, int size, |
| 93 IPEndPoint* address, | 60 IPEndPoint* address, |
| 94 const CompletionCallback& callback); | 61 const CompletionCallback& callback); |
| 95 | 62 |
| 96 scoped_refptr<IOBuffer> recv_buffer_; | 63 scoped_refptr<IOBuffer> recv_buffer_; |
| 97 int recv_buffer_size_; | 64 int recv_buffer_size_; |
| 98 CompletionCallback recv_callback_; | 65 CompletionCallback recv_callback_; |
| 99 }; | 66 }; |
| 100 | 67 |
| 101 } // namespace net | 68 } // namespace net |
| 102 | 69 |
| 103 #endif // NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ | 70 #endif // NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ |
| OLD | NEW |