| 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 DatagramServerSocket { |
| 16 public: | 16 public: |
| 17 explicit MockMDnsDatagramServerSocket(AddressFamily address_family); | 17 explicit MockMDnsDatagramServerSocket(AddressFamily address_family); |
| 18 ~MockMDnsDatagramServerSocket(); | 18 ~MockMDnsDatagramServerSocket(); |
| 19 | 19 |
| 20 // DatagramServerSocket implementation: | 20 // DatagramServerSocket implementation: |
| 21 MOCK_METHOD1(Listen, int(const IPEndPoint& address)); | 21 MOCK_METHOD1(Listen, int(const IPEndPoint& address)); |
| 22 | 22 |
| 23 MOCK_METHOD1(ListenInternal, int(const std::string& address)); | 23 MOCK_METHOD1(ListenInternal, int(const std::string& address)); |
| 24 | 24 |
| 25 MOCK_METHOD4(RecvFrom, int(IOBuffer* buffer, int size, | 25 MOCK_METHOD4(RecvFrom, |
| 26 IPEndPoint* address, | 26 int(IOBuffer* buffer, |
| 27 const CompletionCallback& callback)); | 27 int size, |
| 28 IPEndPoint* address, |
| 29 const CompletionCallback& callback)); |
| 28 | 30 |
| 29 virtual int SendTo(IOBuffer* buf, int buf_len, const IPEndPoint& address, | 31 virtual int SendTo(IOBuffer* buf, |
| 32 int buf_len, |
| 33 const IPEndPoint& address, |
| 30 const CompletionCallback& callback) OVERRIDE; | 34 const CompletionCallback& callback) OVERRIDE; |
| 31 | 35 |
| 32 MOCK_METHOD3(SendToInternal, int(const std::string& packet, | 36 MOCK_METHOD3(SendToInternal, |
| 33 const std::string address, | 37 int(const std::string& packet, |
| 34 const CompletionCallback& callback)); | 38 const std::string address, |
| 39 const CompletionCallback& callback)); |
| 35 | 40 |
| 36 MOCK_METHOD1(SetReceiveBufferSize, int(int32 size)); | 41 MOCK_METHOD1(SetReceiveBufferSize, int(int32 size)); |
| 37 MOCK_METHOD1(SetSendBufferSize, int(int32 size)); | 42 MOCK_METHOD1(SetSendBufferSize, int(int32 size)); |
| 38 | 43 |
| 39 MOCK_METHOD0(Close, void()); | 44 MOCK_METHOD0(Close, void()); |
| 40 | 45 |
| 41 MOCK_CONST_METHOD1(GetPeerAddress, int(IPEndPoint* address)); | 46 MOCK_CONST_METHOD1(GetPeerAddress, int(IPEndPoint* address)); |
| 42 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 47 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 43 MOCK_CONST_METHOD0(NetLog, const BoundNetLog&()); | 48 MOCK_CONST_METHOD0(NetLog, const BoundNetLog&()); |
| 44 | 49 |
| 45 MOCK_METHOD0(AllowAddressReuse, void()); | 50 MOCK_METHOD0(AllowAddressReuse, void()); |
| 46 MOCK_METHOD0(AllowBroadcast, void()); | 51 MOCK_METHOD0(AllowBroadcast, void()); |
| 47 | 52 |
| 48 MOCK_CONST_METHOD1(JoinGroup, int(const IPAddressNumber& group_address)); | 53 MOCK_CONST_METHOD1(JoinGroup, int(const IPAddressNumber& group_address)); |
| 49 MOCK_CONST_METHOD1(LeaveGroup, int(const IPAddressNumber& address)); | 54 MOCK_CONST_METHOD1(LeaveGroup, int(const IPAddressNumber& address)); |
| 50 | 55 |
| 51 MOCK_METHOD1(SetMulticastInterface, int(uint32 interface_index)); | 56 MOCK_METHOD1(SetMulticastInterface, int(uint32 interface_index)); |
| 52 MOCK_METHOD1(SetMulticastTimeToLive, int(int ttl)); | 57 MOCK_METHOD1(SetMulticastTimeToLive, int(int ttl)); |
| 53 MOCK_METHOD1(SetMulticastLoopbackMode, int(bool loopback)); | 58 MOCK_METHOD1(SetMulticastLoopbackMode, int(bool loopback)); |
| 54 | 59 |
| 55 MOCK_METHOD1(SetDiffServCodePoint, int(DiffServCodePoint dscp)); | 60 MOCK_METHOD1(SetDiffServCodePoint, int(DiffServCodePoint dscp)); |
| 56 | 61 |
| 57 MOCK_METHOD0(DetachFromThread, void()); | 62 MOCK_METHOD0(DetachFromThread, void()); |
| 58 | 63 |
| 59 void SetResponsePacket(std::string response_packet); | 64 void SetResponsePacket(std::string response_packet); |
| 60 | 65 |
| 61 int HandleRecvNow(IOBuffer* buffer, int size, IPEndPoint* address, | 66 int HandleRecvNow(IOBuffer* buffer, |
| 67 int size, |
| 68 IPEndPoint* address, |
| 62 const CompletionCallback& callback); | 69 const CompletionCallback& callback); |
| 63 | 70 |
| 64 int HandleRecvLater(IOBuffer* buffer, int size, IPEndPoint* address, | 71 int HandleRecvLater(IOBuffer* buffer, |
| 72 int size, |
| 73 IPEndPoint* address, |
| 65 const CompletionCallback& callback); | 74 const CompletionCallback& callback); |
| 66 | 75 |
| 67 private: | 76 private: |
| 68 std::string response_packet_; | 77 std::string response_packet_; |
| 69 IPEndPoint local_address_; | 78 IPEndPoint local_address_; |
| 70 }; | 79 }; |
| 71 | 80 |
| 72 class MockMDnsSocketFactory : public MDnsSocketFactory { | 81 class MockMDnsSocketFactory : public MDnsSocketFactory { |
| 73 public: | 82 public: |
| 74 MockMDnsSocketFactory(); | 83 MockMDnsSocketFactory(); |
| 75 virtual ~MockMDnsSocketFactory(); | 84 virtual ~MockMDnsSocketFactory(); |
| 76 | 85 |
| 77 virtual void CreateSockets( | 86 virtual void CreateSockets( |
| 78 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE; | 87 ScopedVector<DatagramServerSocket>* sockets) OVERRIDE; |
| 79 | 88 |
| 80 void SimulateReceive(const uint8* packet, int size); | 89 void SimulateReceive(const uint8* packet, int size); |
| 81 | 90 |
| 82 MOCK_METHOD1(OnSendTo, void(const std::string&)); | 91 MOCK_METHOD1(OnSendTo, void(const std::string&)); |
| 83 | 92 |
| 84 private: | 93 private: |
| 85 int SendToInternal(const std::string& packet, const std::string& address, | 94 int SendToInternal(const std::string& packet, |
| 95 const std::string& address, |
| 86 const CompletionCallback& callback); | 96 const CompletionCallback& callback); |
| 87 | 97 |
| 88 // The latest receive callback is always saved, since the MDnsConnection | 98 // The latest receive callback is always saved, since the MDnsConnection |
| 89 // does not care which socket a packet is received on. | 99 // does not care which socket a packet is received on. |
| 90 int RecvFromInternal(IOBuffer* buffer, int size, | 100 int RecvFromInternal(IOBuffer* buffer, |
| 101 int size, |
| 91 IPEndPoint* address, | 102 IPEndPoint* address, |
| 92 const CompletionCallback& callback); | 103 const CompletionCallback& callback); |
| 93 | 104 |
| 94 void CreateSocket(AddressFamily address_family, | 105 void CreateSocket(AddressFamily address_family, |
| 95 ScopedVector<DatagramServerSocket>* sockets); | 106 ScopedVector<DatagramServerSocket>* sockets); |
| 96 | 107 |
| 97 scoped_refptr<IOBuffer> recv_buffer_; | 108 scoped_refptr<IOBuffer> recv_buffer_; |
| 98 int recv_buffer_size_; | 109 int recv_buffer_size_; |
| 99 CompletionCallback recv_callback_; | 110 CompletionCallback recv_callback_; |
| 100 }; | 111 }; |
| 101 | 112 |
| 102 } // namespace net | 113 } // namespace net |
| 103 | 114 |
| 104 #endif // NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ | 115 #endif // NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_ |
| OLD | NEW |