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_SERVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/shill_service_client.h"
19 // A fake implementation of ShillServiceClient. This works in close coordination
20 // with FakeShillManagerClient and is not intended to be used independently.
21 class CHROMEOS_EXPORT FakeShillServiceClient
22 : public ShillServiceClient
,
23 public ShillServiceClient::TestInterface
{
25 FakeShillServiceClient();
26 virtual ~FakeShillServiceClient();
28 // ShillServiceClient overrides
29 virtual void Init(dbus::Bus
* bus
) OVERRIDE
;
30 virtual void AddPropertyChangedObserver(
31 const dbus::ObjectPath
& service_path
,
32 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
33 virtual void RemovePropertyChangedObserver(
34 const dbus::ObjectPath
& service_path
,
35 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
36 virtual void GetProperties(const dbus::ObjectPath
& service_path
,
37 const DictionaryValueCallback
& callback
) OVERRIDE
;
38 virtual void SetProperty(const dbus::ObjectPath
& service_path
,
39 const std::string
& name
,
40 const base::Value
& value
,
41 const base::Closure
& callback
,
42 const ErrorCallback
& error_callback
) OVERRIDE
;
43 virtual void SetProperties(const dbus::ObjectPath
& service_path
,
44 const base::DictionaryValue
& properties
,
45 const base::Closure
& callback
,
46 const ErrorCallback
& error_callback
) OVERRIDE
;
47 virtual void ClearProperty(const dbus::ObjectPath
& service_path
,
48 const std::string
& name
,
49 const base::Closure
& callback
,
50 const ErrorCallback
& error_callback
) OVERRIDE
;
51 virtual void ClearProperties(const dbus::ObjectPath
& service_path
,
52 const std::vector
<std::string
>& names
,
53 const ListValueCallback
& callback
,
54 const ErrorCallback
& error_callback
) OVERRIDE
;
55 virtual void Connect(const dbus::ObjectPath
& service_path
,
56 const base::Closure
& callback
,
57 const ErrorCallback
& error_callback
) OVERRIDE
;
58 virtual void Disconnect(const dbus::ObjectPath
& service_path
,
59 const base::Closure
& callback
,
60 const ErrorCallback
& error_callback
) OVERRIDE
;
61 virtual void Remove(const dbus::ObjectPath
& service_path
,
62 const base::Closure
& callback
,
63 const ErrorCallback
& error_callback
) OVERRIDE
;
64 virtual void ActivateCellularModem(
65 const dbus::ObjectPath
& service_path
,
66 const std::string
& carrier
,
67 const base::Closure
& callback
,
68 const ErrorCallback
& error_callback
) OVERRIDE
;
69 virtual void CompleteCellularActivation(
70 const dbus::ObjectPath
& service_path
,
71 const base::Closure
& callback
,
72 const ErrorCallback
& error_callback
) OVERRIDE
;
73 virtual void GetLoadableProfileEntries(
74 const dbus::ObjectPath
& service_path
,
75 const DictionaryValueCallback
& callback
) OVERRIDE
;
76 virtual ShillServiceClient::TestInterface
* GetTestInterface() OVERRIDE
;
78 // ShillServiceClient::TestInterface overrides.
79 virtual void AddService(const std::string
& service_path
,
80 const std::string
& name
,
81 const std::string
& type
,
82 const std::string
& state
,
83 bool visible
) OVERRIDE
;
84 virtual void AddServiceWithIPConfig(const std::string
& service_path
,
85 const std::string
& guid
,
86 const std::string
& name
,
87 const std::string
& type
,
88 const std::string
& state
,
89 const std::string
& ipconfig_path
,
90 bool visible
) OVERRIDE
;
91 virtual base::DictionaryValue
* SetServiceProperties(
92 const std::string
& service_path
,
93 const std::string
& guid
,
94 const std::string
& name
,
95 const std::string
& type
,
96 const std::string
& state
,
97 bool visible
) OVERRIDE
;
98 virtual void RemoveService(const std::string
& service_path
) OVERRIDE
;
99 virtual bool SetServiceProperty(const std::string
& service_path
,
100 const std::string
& property
,
101 const base::Value
& value
) OVERRIDE
;
102 virtual const base::DictionaryValue
* GetServiceProperties(
103 const std::string
& service_path
) const OVERRIDE
;
104 virtual void ClearServices() OVERRIDE
;
105 virtual void SetConnectBehavior(const std::string
& service_path
,
106 const base::Closure
& behavior
) OVERRIDE
;
109 typedef ObserverList
<ShillPropertyChangedObserver
> PropertyObserverList
;
111 void NotifyObserversPropertyChanged(const dbus::ObjectPath
& service_path
,
112 const std::string
& property
);
113 base::DictionaryValue
* GetModifiableServiceProperties(
114 const std::string
& service_path
,
115 bool create_if_missing
);
116 PropertyObserverList
& GetObserverList(const dbus::ObjectPath
& device_path
);
117 void SetOtherServicesOffline(const std::string
& service_path
);
118 void SetCellularActivated(const dbus::ObjectPath
& service_path
,
119 const ErrorCallback
& error_callback
);
120 void ContinueConnect(const std::string
& service_path
);
122 base::DictionaryValue stub_services_
;
124 // Per network service, stores a closure that is executed on each connection
125 // attempt. The callback can for example modify the services properties in
126 // order to simulate a connection failure.
127 std::map
<std::string
, base::Closure
> connect_behavior_
;
129 // Observer list for each service.
130 std::map
<dbus::ObjectPath
, PropertyObserverList
*> observer_list_
;
132 // Note: This should remain the last member so it'll be destroyed and
133 // invalidate its weak pointers before any other members are destroyed.
134 base::WeakPtrFactory
<FakeShillServiceClient
> weak_ptr_factory_
;
136 DISALLOW_COPY_AND_ASSIGN(FakeShillServiceClient
);
139 } // namespace chromeos
141 #endif // CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_