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