1 // Copyright 2018 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 CHROME_BROWSER_CHROMEOS_SMB_CLIENT_DISCOVERY_FAKE_NETBIOS_CLIENT_H_
6 #define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_DISCOVERY_FAKE_NETBIOS_CLIENT_H_
7 
8 #include <map>
9 #include <vector>
10 
11 #include "chrome/browser/chromeos/smb_client/discovery/netbios_client_interface.h"
12 
13 namespace net {
14 
15 class IPAddress;
16 class IPEndPoint;
17 
18 }  // namespace net
19 
20 namespace chromeos {
21 namespace smb_client {
22 
23 // FakeNetBiosClient is used for testing the NetBiosHostLocator.
24 // FakeNetBiosClient is constructed with a map of IPs -> Packets to simulate
25 // responses received from the Name Request. When ExecuteNameRequest is called,
26 // the NetBiosResponseCallback will be run with each entry in the |fake_data_|
27 // map. The |broadcast_address| and |transaction_id| parameters on
28 // ExecuteNameRequest are ignored.
29 class FakeNetBiosClient : public NetBiosClientInterface {
30  public:
31   FakeNetBiosClient();
32   explicit FakeNetBiosClient(
33       std::map<net::IPEndPoint, std::vector<uint8_t>> fake_data);
34 
35   ~FakeNetBiosClient() override;
36 
37   // NetBiosClientInterface override.
38   void ExecuteNameRequest(const net::IPAddress& broadcast_address,
39                           uint16_t transaction_id,
40                           NetBiosResponseCallback callback) override;
41 
42  private:
43   std::map<net::IPEndPoint, std::vector<uint8_t>> fake_data_;
44 
45   DISALLOW_COPY_AND_ASSIGN(FakeNetBiosClient);
46 };
47 
48 }  // namespace smb_client
49 }  // namespace chromeos
50 
51 #endif  // CHROME_BROWSER_CHROMEOS_SMB_CLIENT_DISCOVERY_FAKE_NETBIOS_CLIENT_H_
52