blob: d60fe11f6a2ab3b7c6a8e3810f22e81fc1a08d3a [file] [log] [blame]
[email protected]9b85bb822013-10-21 10:00:171// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]4a5ddd2052013-02-14 23:54:002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]9b85bb822013-10-21 10:00:175#ifndef CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_
6#define CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_
[email protected]4a5ddd2052013-02-14 23:54:007
8#include <map>
Hidehiko Abe5a138a22017-10-05 16:22:219#include <memory>
[email protected]4a5ddd2052013-02-14 23:54:0010#include <string>
Hidehiko Abe5a138a22017-10-05 16:22:2111#include <vector>
[email protected]4a5ddd2052013-02-14 23:54:0012
[email protected]4a5ddd2052013-02-14 23:54:0013#include "base/callback.h"
Steven Bennettsab7b68e2019-01-07 19:14:4314#include "base/component_export.h"
avi6e1a22d2015-12-21 03:43:2015#include "base/macros.h"
[email protected]4a5ddd2052013-02-14 23:54:0016#include "base/memory/weak_ptr.h"
[email protected]4a5ddd2052013-02-14 23:54:0017#include "chromeos/dbus/shill_service_client.h"
18
19namespace chromeos {
20
[email protected]9b85bb822013-10-21 10:00:1721// A fake implementation of ShillServiceClient. This works in close coordination
22// with FakeShillManagerClient and is not intended to be used independently.
Steven Bennettsab7b68e2019-01-07 19:14:4323class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeShillServiceClient
[email protected]4d201ec2014-03-05 19:54:4024 : public ShillServiceClient,
[email protected]9b85bb822013-10-21 10:00:1725 public ShillServiceClient::TestInterface {
[email protected]4a5ddd2052013-02-14 23:54:0026 public:
[email protected]9b85bb822013-10-21 10:00:1727 FakeShillServiceClient();
dcheng0280cb62015-01-16 07:37:5028 ~FakeShillServiceClient() override;
[email protected]4a5ddd2052013-02-14 23:54:0029
[email protected]c5fd5362013-08-27 12:23:0430 // ShillServiceClient overrides
dcheng0280cb62015-01-16 07:37:5031 void Init(dbus::Bus* bus) override;
32 void AddPropertyChangedObserver(
[email protected]4a5ddd2052013-02-14 23:54:0033 const dbus::ObjectPath& service_path,
mostynb4f4cf142014-10-06 13:57:5234 ShillPropertyChangedObserver* observer) override;
dcheng0280cb62015-01-16 07:37:5035 void RemovePropertyChangedObserver(
[email protected]4a5ddd2052013-02-14 23:54:0036 const dbus::ObjectPath& service_path,
mostynb4f4cf142014-10-06 13:57:5237 ShillPropertyChangedObserver* observer) override;
dcheng0280cb62015-01-16 07:37:5038 void GetProperties(const dbus::ObjectPath& service_path,
39 const DictionaryValueCallback& callback) override;
40 void SetProperty(const dbus::ObjectPath& service_path,
41 const std::string& name,
42 const base::Value& value,
43 const base::Closure& callback,
44 const ErrorCallback& error_callback) override;
45 void SetProperties(const dbus::ObjectPath& service_path,
46 const base::DictionaryValue& properties,
47 const base::Closure& callback,
48 const ErrorCallback& error_callback) override;
49 void ClearProperty(const dbus::ObjectPath& service_path,
50 const std::string& name,
51 const base::Closure& callback,
52 const ErrorCallback& error_callback) override;
53 void ClearProperties(const dbus::ObjectPath& service_path,
54 const std::vector<std::string>& names,
55 const ListValueCallback& callback,
mostynb4f4cf142014-10-06 13:57:5256 const ErrorCallback& error_callback) override;
dcheng0280cb62015-01-16 07:37:5057 void Connect(const dbus::ObjectPath& service_path,
58 const base::Closure& callback,
59 const ErrorCallback& error_callback) override;
60 void Disconnect(const dbus::ObjectPath& service_path,
61 const base::Closure& callback,
62 const ErrorCallback& error_callback) override;
63 void Remove(const dbus::ObjectPath& service_path,
64 const base::Closure& callback,
65 const ErrorCallback& error_callback) override;
66 void ActivateCellularModem(const dbus::ObjectPath& service_path,
67 const std::string& carrier,
68 const base::Closure& callback,
69 const ErrorCallback& error_callback) override;
70 void CompleteCellularActivation(const dbus::ObjectPath& service_path,
71 const base::Closure& callback,
72 const ErrorCallback& error_callback) override;
73 void GetLoadableProfileEntries(
[email protected]7c8fd5642013-07-02 22:24:3074 const dbus::ObjectPath& service_path,
mostynb4f4cf142014-10-06 13:57:5275 const DictionaryValueCallback& callback) override;
dcheng0280cb62015-01-16 07:37:5076 ShillServiceClient::TestInterface* GetTestInterface() override;
[email protected]4a5ddd2052013-02-14 23:54:0077
78 // ShillServiceClient::TestInterface overrides.
dcheng0280cb62015-01-16 07:37:5079 void AddService(const std::string& service_path,
80 const std::string& guid,
81 const std::string& name,
82 const std::string& type,
83 const std::string& state,
84 bool visible) override;
85 void AddServiceWithIPConfig(const std::string& service_path,
86 const std::string& guid,
87 const std::string& name,
88 const std::string& type,
89 const std::string& state,
90 const std::string& ipconfig_path,
91 bool visible) override;
92 base::DictionaryValue* SetServiceProperties(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 void RemoveService(const std::string& service_path) override;
99 bool SetServiceProperty(const std::string& service_path,
100 const std::string& property,
101 const base::Value& value) override;
102 const base::DictionaryValue* GetServiceProperties(
mostynb4f4cf142014-10-06 13:57:52103 const std::string& service_path) const override;
dcheng0280cb62015-01-16 07:37:50104 void ClearServices() override;
105 void SetConnectBehavior(const std::string& service_path,
106 const base::Closure& behavior) override;
[email protected]4a5ddd2052013-02-14 23:54:00107
108 private:
Trent Apteda250ec3ab2018-08-19 08:52:19109 typedef base::ObserverList<ShillPropertyChangedObserver>::Unchecked
110 PropertyObserverList;
[email protected]4a5ddd2052013-02-14 23:54:00111
[email protected]4a5ddd2052013-02-14 23:54:00112 void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path,
113 const std::string& property);
[email protected]fde8b322013-02-28 17:44:24114 base::DictionaryValue* GetModifiableServiceProperties(
[email protected]54287ec2013-09-23 18:40:02115 const std::string& service_path,
116 bool create_if_missing);
[email protected]4a5ddd2052013-02-14 23:54:00117 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path);
[email protected]783aa24d2013-08-06 23:54:38118 void SetOtherServicesOffline(const std::string& service_path);
[email protected]5fd84cc92013-08-14 02:35:50119 void SetCellularActivated(const dbus::ObjectPath& service_path,
120 const ErrorCallback& error_callback);
[email protected]54287ec2013-09-23 18:40:02121 void ContinueConnect(const std::string& service_path);
[email protected]4a5ddd2052013-02-14 23:54:00122
123 base::DictionaryValue stub_services_;
[email protected]54287ec2013-09-23 18:40:02124
125 // Per network service, stores a closure that is executed on each connection
126 // attempt. The callback can for example modify the services properties in
127 // order to simulate a connection failure.
128 std::map<std::string, base::Closure> connect_behavior_;
129
[email protected]4a5ddd2052013-02-14 23:54:00130 // Observer list for each service.
avi8194ad62016-09-20 16:58:36131 std::map<dbus::ObjectPath, std::unique_ptr<PropertyObserverList>>
132 observer_list_;
[email protected]4a5ddd2052013-02-14 23:54:00133
134 // Note: This should remain the last member so it'll be destroyed and
135 // invalidate its weak pointers before any other members are destroyed.
[email protected]9b85bb822013-10-21 10:00:17136 base::WeakPtrFactory<FakeShillServiceClient> weak_ptr_factory_;
[email protected]4a5ddd2052013-02-14 23:54:00137
[email protected]9b85bb822013-10-21 10:00:17138 DISALLOW_COPY_AND_ASSIGN(FakeShillServiceClient);
[email protected]4a5ddd2052013-02-14 23:54:00139};
140
141} // namespace chromeos
142
[email protected]9b85bb822013-10-21 10:00:17143#endif // CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_