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