Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromeos / dbus / fake_shill_device_client.h
blob4dc0b54dfe553e2b1be944cfdb4ce838999152ec
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 CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/shill_device_client.h"
16 namespace chromeos {
18 // A fake implementation of ShillDeviceClient.
19 // Implemented: Stub cellular device for SMS testing.
20 class CHROMEOS_EXPORT FakeShillDeviceClient
21 : public ShillDeviceClient,
22 public ShillDeviceClient::TestInterface {
23 public:
24 FakeShillDeviceClient();
25 ~FakeShillDeviceClient() override;
27 // ShillDeviceClient overrides
28 void Init(dbus::Bus* bus) override;
29 void AddPropertyChangedObserver(
30 const dbus::ObjectPath& device_path,
31 ShillPropertyChangedObserver* observer) override;
32 void RemovePropertyChangedObserver(
33 const dbus::ObjectPath& device_path,
34 ShillPropertyChangedObserver* observer) override;
35 void GetProperties(const dbus::ObjectPath& device_path,
36 const DictionaryValueCallback& callback) override;
37 void ProposeScan(const dbus::ObjectPath& device_path,
38 const VoidDBusMethodCallback& callback) override;
39 void SetProperty(const dbus::ObjectPath& device_path,
40 const std::string& name,
41 const base::Value& value,
42 const base::Closure& callback,
43 const ErrorCallback& error_callback) override;
44 void ClearProperty(const dbus::ObjectPath& device_path,
45 const std::string& name,
46 const VoidDBusMethodCallback& callback) override;
47 void AddIPConfig(const dbus::ObjectPath& device_path,
48 const std::string& method,
49 const ObjectPathDBusMethodCallback& callback) override;
50 void RequirePin(const dbus::ObjectPath& device_path,
51 const std::string& pin,
52 bool require,
53 const base::Closure& callback,
54 const ErrorCallback& error_callback) override;
55 void EnterPin(const dbus::ObjectPath& device_path,
56 const std::string& pin,
57 const base::Closure& callback,
58 const ErrorCallback& error_callback) override;
59 void UnblockPin(const dbus::ObjectPath& device_path,
60 const std::string& puk,
61 const std::string& pin,
62 const base::Closure& callback,
63 const ErrorCallback& error_callback) override;
64 void ChangePin(const dbus::ObjectPath& device_path,
65 const std::string& old_pin,
66 const std::string& new_pin,
67 const base::Closure& callback,
68 const ErrorCallback& error_callback) override;
69 void Register(const dbus::ObjectPath& device_path,
70 const std::string& network_id,
71 const base::Closure& callback,
72 const ErrorCallback& error_callback) override;
73 void SetCarrier(const dbus::ObjectPath& device_path,
74 const std::string& carrier,
75 const base::Closure& callback,
76 const ErrorCallback& error_callback) override;
77 void Reset(const dbus::ObjectPath& device_path,
78 const base::Closure& callback,
79 const ErrorCallback& error_callback) override;
80 void PerformTDLSOperation(const dbus::ObjectPath& device_path,
81 const std::string& operation,
82 const std::string& peer,
83 const StringCallback& callback,
84 const ErrorCallback& error_callback) override;
85 void AddWakeOnPacketConnection(
86 const dbus::ObjectPath& device_path,
87 const net::IPEndPoint& ip_endpoint,
88 const base::Closure& callback,
89 const ErrorCallback& error_callback) override;
90 void RemoveWakeOnPacketConnection(
91 const dbus::ObjectPath& device_path,
92 const net::IPEndPoint& ip_endpoint,
93 const base::Closure& callback,
94 const ErrorCallback& error_callback) override;
95 void RemoveAllWakeOnPacketConnections(
96 const dbus::ObjectPath& device_path,
97 const base::Closure& callback,
98 const ErrorCallback& error_callback) override;
100 ShillDeviceClient::TestInterface* GetTestInterface() override;
102 // ShillDeviceClient::TestInterface overrides.
103 void AddDevice(const std::string& device_path,
104 const std::string& type,
105 const std::string& name) override;
106 void RemoveDevice(const std::string& device_path) override;
107 void ClearDevices() override;
108 void SetDeviceProperty(const std::string& device_path,
109 const std::string& name,
110 const base::Value& value) override;
111 std::string GetDevicePathForType(const std::string& type) override;
112 void SetTDLSBusyCount(int count) override;
113 void SetTDLSState(const std::string& state) override;
114 void SetSimLocked(const std::string& device_path, bool locked) override;
116 static const char kDefaultSimPin[];
117 static const int kSimPinRetryCount;
119 private:
120 struct SimLockStatus {
121 std::string type = "";
122 int retries_left = 0;
123 bool lock_enabled = true;
125 typedef base::ObserverList<ShillPropertyChangedObserver> PropertyObserverList;
127 SimLockStatus GetSimLockStatus(const std::string& device_path);
128 void SetSimLockStatus(const std::string& device_path,
129 const SimLockStatus& status);
130 bool SimTryPin(const std::string& device_path, const std::string& pin);
131 bool SimTryPuk(const std::string& device_path, const std::string& pin);
132 void PassStubDeviceProperties(const dbus::ObjectPath& device_path,
133 const DictionaryValueCallback& callback) const;
135 // Posts a task to run a void callback with status code |status|.
136 void PostVoidCallback(const VoidDBusMethodCallback& callback,
137 DBusMethodCallStatus status);
139 void SetPropertyInternal(const dbus::ObjectPath& device_path,
140 const std::string& name,
141 const base::Value& value,
142 const base::Closure& callback,
143 const ErrorCallback& error_callback);
145 void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path,
146 const std::string& property);
147 base::DictionaryValue* GetDeviceProperties(const std::string& device_path);
148 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path);
150 // Dictionary of <device_name, Dictionary>.
151 base::DictionaryValue stub_devices_;
152 // Observer list for each device.
153 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_;
155 // Number of times to return InProgress for TDLS. Set to -1 to emulate
156 // TDLS failure.
157 int initial_tdls_busy_count_;
159 // Current TDLS busy count.
160 int tdls_busy_count_;
162 // Fake state for TDLS.
163 std::string tdls_state_;
165 // Wake on packet connections for each device.
166 std::map<dbus::ObjectPath, std::set<net::IPEndPoint> >
167 wake_on_packet_connections_;
169 // Current SIM PIN per device path.
170 std::map<std::string, std::string> sim_pin_;
172 // Note: This should remain the last member so it'll be destroyed and
173 // invalidate its weak pointers before any other members are destroyed.
174 base::WeakPtrFactory<FakeShillDeviceClient> weak_ptr_factory_;
176 DISALLOW_COPY_AND_ASSIGN(FakeShillDeviceClient);
179 } // namespace chromeos
181 #endif // CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_