summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/shill_manager_client_stub.h
blob: 1eb666de82c97239e284ca222259e3fc08948e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_STUB_H_
#define CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_STUB_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback.h"
#include "chromeos/dbus/shill_manager_client.h"

namespace chromeos {

// A stub implementation of ShillManagerClient.
// Implemented: Stub devices and services for NetworkStateManager tests.
// Implemented: Stub cellular device entry for SMS tests.
class ShillManagerClientStub : public ShillManagerClient,
                               public ShillManagerClient::TestInterface {
 public:
  ShillManagerClientStub();
  virtual ~ShillManagerClientStub();

  // ShillManagerClient overrides.
  virtual void AddPropertyChangedObserver(
      ShillPropertyChangedObserver* observer) OVERRIDE;
  virtual void RemovePropertyChangedObserver(
      ShillPropertyChangedObserver* observer) OVERRIDE;
  virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE;
  virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE;
  virtual void GetNetworksForGeolocation(
      const DictionaryValueCallback& callback) OVERRIDE;
  virtual void SetProperty(const std::string& name,
                           const base::Value& value,
                           const base::Closure& callback,
                           const ErrorCallback& error_callback) OVERRIDE;
  virtual void RequestScan(const std::string& type,
                           const base::Closure& callback,
                           const ErrorCallback& error_callback) OVERRIDE;
  virtual void EnableTechnology(
      const std::string& type,
      const base::Closure& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void DisableTechnology(
      const std::string& type,
      const base::Closure& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void ConfigureService(
      const base::DictionaryValue& properties,
      const ObjectPathCallback& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void GetService(
      const base::DictionaryValue& properties,
      const ObjectPathCallback& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void VerifyDestination(const std::string& certificate,
                                 const std::string& public_key,
                                 const std::string& nonce,
                                 const std::string& signed_data,
                                 const std::string& device_serial,
                                 const BooleanCallback& callback,
                                 const ErrorCallback& error_callback) OVERRIDE;
  virtual void VerifyAndEncryptCredentials(
      const std::string& certificate,
      const std::string& public_key,
      const std::string& nonce,
      const std::string& signed_data,
      const std::string& device_serial,
      const std::string& service_path,
      const StringCallback& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void VerifyAndEncryptData(
      const std::string& certificate,
      const std::string& public_key,
      const std::string& nonce,
      const std::string& signed_data,
      const std::string& device_serial,
      const std::string& data,
      const StringCallback& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual void ConnectToBestServices(
      const base::Closure& callback,
      const ErrorCallback& error_callback) OVERRIDE;
  virtual ShillManagerClient::TestInterface* GetTestInterface() OVERRIDE;

  // ShillManagerClient::TestInterface overrides.

  virtual void AddDevice(const std::string& device_path) OVERRIDE;
  virtual void RemoveDevice(const std::string& device_path) OVERRIDE;
  virtual void ClearDevices() OVERRIDE;
  virtual void ClearServices() OVERRIDE;
  virtual void AddService(const std::string& service_path,
                          bool add_to_watch_list) OVERRIDE;
  virtual void AddServiceAtIndex(const std::string& service_path,
                                 size_t index,
                                 bool add_to_watch_list) OVERRIDE;
  virtual void RemoveService(const std::string& service_path) OVERRIDE;
  virtual void AddTechnology(const std::string& type, bool enabled) OVERRIDE;
  virtual void RemoveTechnology(const std::string& type) OVERRIDE;
  virtual void ClearProperties() OVERRIDE;
  virtual void AddGeoNetwork(const std::string& technology,
                             const base::DictionaryValue& network) OVERRIDE;

 private:
  void AddServiceToWatchList(const std::string& service_path);
  void SetDefaultProperties();
  void PassStubProperties(const DictionaryValueCallback& callback) const;
  void PassStubGeoNetworks(const DictionaryValueCallback& callback) const;
  void CallNotifyObserversPropertyChanged(const std::string& property,
                                          int delay_ms);
  void NotifyObserversPropertyChanged(const std::string& property);
  base::ListValue* GetListProperty(const std::string& property);
  bool TechnologyEnabled(const std::string& type) const;
  base::ListValue* GetEnabledServiceList(const std::string& property) const;

  // Dictionary of property name -> property value
  base::DictionaryValue stub_properties_;
  // Dictionary of technology -> list of property dictionaries
  base::DictionaryValue stub_geo_networks_;

  ObserverList<ShillPropertyChangedObserver> observer_list_;

  // Note: This should remain the last member so it'll be destroyed and
  // invalidate its weak pointers before any other members are destroyed.
  base::WeakPtrFactory<ShillManagerClientStub> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ShillManagerClientStub);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_STUB_H_