Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / net / dns / mock_mdns_socket_factory.h
blobc1536bc18c5561bbcee32b76c30126719bbeed01
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.
5 #ifndef NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_
6 #define NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_
8 #include <string>
10 #include "net/dns/mdns_client_impl.h"
11 #include "testing/gmock/include/gmock/gmock.h"
13 namespace net {
15 class MockMDnsDatagramServerSocket : public DatagramServerSocket {
16 public:
17 explicit MockMDnsDatagramServerSocket(AddressFamily address_family);
18 ~MockMDnsDatagramServerSocket() override;
20 // DatagramServerSocket implementation:
21 MOCK_METHOD1(Listen, int(const IPEndPoint& address));
23 MOCK_METHOD1(ListenInternal, int(const std::string& address));
25 MOCK_METHOD4(RecvFrom, int(IOBuffer* buffer, int size,
26 IPEndPoint* address,
27 const CompletionCallback& callback));
29 int SendTo(IOBuffer* buf,
30 int buf_len,
31 const IPEndPoint& address,
32 const CompletionCallback& callback) override;
34 MOCK_METHOD3(SendToInternal, int(const std::string& packet,
35 const std::string address,
36 const CompletionCallback& callback));
38 MOCK_METHOD1(SetReceiveBufferSize, int(int32 size));
39 MOCK_METHOD1(SetSendBufferSize, int(int32 size));
41 MOCK_METHOD0(Close, void());
43 MOCK_CONST_METHOD1(GetPeerAddress, int(IPEndPoint* address));
44 int GetLocalAddress(IPEndPoint* address) const override;
45 MOCK_CONST_METHOD0(NetLog, const BoundNetLog&());
47 MOCK_METHOD0(AllowAddressReuse, void());
48 MOCK_METHOD0(AllowBroadcast, void());
50 MOCK_CONST_METHOD1(JoinGroup, int(const IPAddressNumber& group_address));
51 MOCK_CONST_METHOD1(LeaveGroup, int(const IPAddressNumber& address));
53 MOCK_METHOD1(SetMulticastInterface, int(uint32 interface_index));
54 MOCK_METHOD1(SetMulticastTimeToLive, int(int ttl));
55 MOCK_METHOD1(SetMulticastLoopbackMode, int(bool loopback));
57 MOCK_METHOD1(SetDiffServCodePoint, int(DiffServCodePoint dscp));
59 MOCK_METHOD0(DetachFromThread, void());
61 void SetResponsePacket(std::string response_packet);
63 int HandleRecvNow(IOBuffer* buffer, int size, IPEndPoint* address,
64 const CompletionCallback& callback);
66 int HandleRecvLater(IOBuffer* buffer, int size, IPEndPoint* address,
67 const CompletionCallback& callback);
69 private:
70 std::string response_packet_;
71 IPEndPoint local_address_;
74 class MockMDnsSocketFactory : public MDnsSocketFactory {
75 public:
76 MockMDnsSocketFactory();
77 ~MockMDnsSocketFactory() override;
79 void CreateSockets(ScopedVector<DatagramServerSocket>* sockets) override;
81 void SimulateReceive(const uint8* packet, int size);
83 MOCK_METHOD1(OnSendTo, void(const std::string&));
85 private:
86 int SendToInternal(const std::string& packet, const std::string& address,
87 const CompletionCallback& callback);
89 // The latest receive callback is always saved, since the MDnsConnection
90 // does not care which socket a packet is received on.
91 int RecvFromInternal(IOBuffer* buffer, int size,
92 IPEndPoint* address,
93 const CompletionCallback& callback);
95 void CreateSocket(AddressFamily address_family,
96 ScopedVector<DatagramServerSocket>* sockets);
98 scoped_refptr<IOBuffer> recv_buffer_;
99 int recv_buffer_size_;
100 CompletionCallback recv_callback_;
103 } // namespace net
105 #endif // NET_DNS_MOCK_MDNS_SOCKET_FACTORY_H_