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_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_SHILL_MANAGER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/shill_manager_client.h"
17 // A fake implementation of ShillManagerClient. This works in close coordination
18 // with FakeShillServiceClient. FakeShillDeviceClient, and
19 // FakeShillProfileClient, and is not intended to be used independently.
20 class CHROMEOS_EXPORT FakeShillManagerClient
21 : public ShillManagerClient
,
22 public ShillManagerClient::TestInterface
{
24 FakeShillManagerClient();
25 virtual ~FakeShillManagerClient();
27 // ShillManagerClient overrides
28 virtual void Init(dbus::Bus
* bus
) OVERRIDE
;
29 virtual void AddPropertyChangedObserver(
30 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
31 virtual void RemovePropertyChangedObserver(
32 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
33 virtual void GetProperties(const DictionaryValueCallback
& callback
) OVERRIDE
;
34 virtual void GetNetworksForGeolocation(
35 const DictionaryValueCallback
& callback
) OVERRIDE
;
36 virtual void SetProperty(const std::string
& name
,
37 const base::Value
& value
,
38 const base::Closure
& callback
,
39 const ErrorCallback
& error_callback
) OVERRIDE
;
40 virtual void RequestScan(const std::string
& type
,
41 const base::Closure
& callback
,
42 const ErrorCallback
& error_callback
) OVERRIDE
;
43 virtual void EnableTechnology(
44 const std::string
& type
,
45 const base::Closure
& callback
,
46 const ErrorCallback
& error_callback
) OVERRIDE
;
47 virtual void DisableTechnology(
48 const std::string
& type
,
49 const base::Closure
& callback
,
50 const ErrorCallback
& error_callback
) OVERRIDE
;
51 virtual void ConfigureService(
52 const base::DictionaryValue
& properties
,
53 const ObjectPathCallback
& callback
,
54 const ErrorCallback
& error_callback
) OVERRIDE
;
55 virtual void ConfigureServiceForProfile(
56 const dbus::ObjectPath
& profile_path
,
57 const base::DictionaryValue
& properties
,
58 const ObjectPathCallback
& callback
,
59 const ErrorCallback
& error_callback
) OVERRIDE
;
60 virtual void GetService(
61 const base::DictionaryValue
& properties
,
62 const ObjectPathCallback
& callback
,
63 const ErrorCallback
& error_callback
) OVERRIDE
;
64 virtual void VerifyDestination(const VerificationProperties
& properties
,
65 const BooleanCallback
& callback
,
66 const ErrorCallback
& error_callback
) OVERRIDE
;
67 virtual void VerifyAndEncryptCredentials(
68 const VerificationProperties
& properties
,
69 const std::string
& service_path
,
70 const StringCallback
& callback
,
71 const ErrorCallback
& error_callback
) OVERRIDE
;
72 virtual void VerifyAndEncryptData(
73 const VerificationProperties
& properties
,
74 const std::string
& data
,
75 const StringCallback
& callback
,
76 const ErrorCallback
& error_callback
) OVERRIDE
;
77 virtual void ConnectToBestServices(
78 const base::Closure
& callback
,
79 const ErrorCallback
& error_callback
) OVERRIDE
;
80 virtual ShillManagerClient::TestInterface
* GetTestInterface() OVERRIDE
;
82 // ShillManagerClient::TestInterface overrides.
83 virtual void AddDevice(const std::string
& device_path
) OVERRIDE
;
84 virtual void RemoveDevice(const std::string
& device_path
) OVERRIDE
;
85 virtual void ClearDevices() OVERRIDE
;
86 virtual void AddTechnology(const std::string
& type
, bool enabled
) OVERRIDE
;
87 virtual void RemoveTechnology(const std::string
& type
) OVERRIDE
;
88 virtual void SetTechnologyInitializing(const std::string
& type
,
89 bool initializing
) OVERRIDE
;
90 virtual void AddGeoNetwork(const std::string
& technology
,
91 const base::DictionaryValue
& network
) OVERRIDE
;
92 virtual void AddProfile(const std::string
& profile_path
) OVERRIDE
;
93 virtual void ClearProperties() OVERRIDE
;
94 virtual void SetManagerProperty(const std::string
& key
,
95 const base::Value
& value
) OVERRIDE
;
96 virtual void AddManagerService(const std::string
& service_path
,
97 bool notify_observers
) OVERRIDE
;
98 virtual void RemoveManagerService(const std::string
& service_path
) OVERRIDE
;
99 virtual void ClearManagerServices() OVERRIDE
;
100 virtual void ServiceStateChanged(const std::string
& service_path
,
101 const std::string
& state
) OVERRIDE
;
102 virtual void SortManagerServices(bool notify
) OVERRIDE
;
103 virtual void SetupDefaultEnvironment() OVERRIDE
;
104 virtual int GetInteractiveDelay() const OVERRIDE
;
105 virtual void SetBestServiceToConnect(
106 const std::string
& service_path
) OVERRIDE
;
108 // Constants used for testing.
109 static const char kFakeEthernetNetworkGuid
[];
112 void SetDefaultProperties();
113 void PassStubProperties(const DictionaryValueCallback
& callback
) const;
114 void PassStubGeoNetworks(const DictionaryValueCallback
& callback
) const;
115 void CallNotifyObserversPropertyChanged(const std::string
& property
);
116 void NotifyObserversPropertyChanged(const std::string
& property
);
117 base::ListValue
* GetListProperty(const std::string
& property
);
118 bool TechnologyEnabled(const std::string
& type
) const;
119 void SetTechnologyEnabled(const std::string
& type
,
120 const base::Closure
& callback
,
122 base::ListValue
* GetEnabledServiceList(const std::string
& property
) const;
123 void ScanCompleted(const std::string
& device_path
,
124 const base::Closure
& callback
);
126 // Parses the command line for Shill stub switches and sets initial states.
127 // Uses comma-separated name-value pairs (see SplitStringIntoKeyValuePairs):
128 // interactive={delay} - sets delay in seconds for interactive UI
129 // {wifi,cellular,etc}={on,off,disabled,none} - sets initial state for type
130 void ParseCommandLineSwitch();
131 bool ParseOption(const std::string
& arg0
, const std::string
& arg1
);
132 bool SetInitialNetworkState(std::string type_arg
, std::string state_arg
);
133 std::string
GetInitialStateForType(const std::string
& type
,
136 // Dictionary of property name -> property value
137 base::DictionaryValue stub_properties_
;
139 // Dictionary of technology -> list of property dictionaries
140 base::DictionaryValue stub_geo_networks_
;
142 // Seconds to delay interactive actions
143 int interactive_delay_
;
145 // Initial state for fake services.
146 std::map
<std::string
, std::string
> shill_initial_state_map_
;
147 typedef std::map
<std::string
, base::Value
*> ShillPropertyMap
;
148 typedef std::map
<std::string
, ShillPropertyMap
> DevicePropertyMap
;
149 DevicePropertyMap shill_device_property_map_
;
151 ObserverList
<ShillPropertyChangedObserver
> observer_list_
;
153 // Note: This should remain the last member so it'll be destroyed and
154 // invalidate its weak pointers before any other members are destroyed.
155 base::WeakPtrFactory
<FakeShillManagerClient
> weak_ptr_factory_
;
157 // Track the default service for signaling Manager.DefaultService.
158 std::string default_service_
;
160 // 'Best' service to connect to on ConnectToBestServices() calls.
161 std::string best_service_
;
163 DISALLOW_COPY_AND_ASSIGN(FakeShillManagerClient
);
166 } // namespace chromeos
168 #endif // CHROMEOS_DBUS_FAKE_SHILL_MANAGER_CLIENT_H_