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 #include "chromeos/dbus/shill_stub_helper.h"
8 #include "base/command_line.h"
9 #include "chromeos/chromeos_switches.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/shill_device_client.h"
12 #include "chromeos/dbus/shill_manager_client.h"
13 #include "chromeos/dbus/shill_profile_client.h"
14 #include "chromeos/dbus/shill_profile_client_stub.h"
15 #include "chromeos/dbus/shill_service_client.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
19 namespace shill_stub_helper
{
23 const char kDevicePathWifi
[] = "/device/wifi1";
24 const char kDevicePathCellular
[] = "/device/cellular1";
25 const char kDevicePathWimax
[] = "/device/wimax1";
27 const char kStubPortalledWifiName
[] = "Portalled Wifi";
28 const char kStubPortalledWifiPath
[] = "portalled_wifi";
30 void UpdatePortalledWifiState() {
31 ShillServiceClient::TestInterface
* services
=
32 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
34 services
->SetServiceProperty(kStubPortalledWifiPath
,
35 shill::kStateProperty
,
36 base::StringValue(shill::kStatePortal
));
41 const char kSharedProfilePath
[] = "/profile/default";
43 bool IsStubPortalledWifiEnabled(const std::string
& path
) {
44 if (!CommandLine::ForCurrentProcess()->HasSwitch(
45 chromeos::switches::kEnableStubPortalledWifi
)) {
48 return path
== kStubPortalledWifiPath
;
51 void SetupDefaultEnvironment() {
52 ShillServiceClient::TestInterface
* services
=
53 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
54 ShillProfileClient::TestInterface
* profiles
=
55 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
56 ShillManagerClient::TestInterface
* manager
=
57 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
58 ShillDeviceClient::TestInterface
* devices
=
59 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
60 if (!services
|| !profiles
|| !manager
| !devices
)
64 if (!CommandLine::ForCurrentProcess()->HasSwitch(
65 chromeos::switches::kDisableStubEthernet
)) {
66 manager
->AddTechnology(shill::kTypeEthernet
, true);
68 manager
->AddTechnology(shill::kTypeWifi
, true);
69 manager
->AddTechnology(shill::kTypeCellular
, true);
70 manager
->AddTechnology(shill::kTypeWimax
, true);
72 profiles
->AddProfile(kSharedProfilePath
, std::string());
75 devices
->AddDevice(kDevicePathWifi
, shill::kTypeWifi
, "stub_wifi_device1");
77 // Add a cellular device. Used in SMS stub.
79 kDevicePathCellular
, shill::kTypeCellular
, "stub_cellular_device1");
80 devices
->SetDeviceProperty("stub_cellular_device1",
81 shill::kCarrierProperty
,
82 base::StringValue(shill::kCarrierSprint
));
84 // Add a wimax device.
85 devices
->AddDevice(kDevicePathWimax
, shill::kTypeWimax
, "stub_wimax_device1");
87 const bool add_to_visible
= true;
88 const bool add_to_watchlist
= true;
90 if (!CommandLine::ForCurrentProcess()->HasSwitch(
91 chromeos::switches::kDisableStubEthernet
)) {
92 services
->AddService("eth1", "eth1",
95 add_to_visible
, add_to_watchlist
);
96 profiles
->AddService(kSharedProfilePath
, "eth1");
101 services
->AddService("wifi1",
105 add_to_visible
, add_to_watchlist
);
106 services
->SetServiceProperty("wifi1",
107 shill::kSecurityProperty
,
108 base::StringValue(shill::kSecurityWep
));
109 profiles
->AddService(kSharedProfilePath
, "wifi1");
111 services
->AddService("wifi2",
115 add_to_visible
, add_to_watchlist
);
116 services
->SetServiceProperty("wifi2",
117 shill::kSecurityProperty
,
118 base::StringValue(shill::kSecurityPsk
));
119 base::FundamentalValue
strength_value(80);
120 services
->SetServiceProperty(
121 "wifi2", shill::kSignalStrengthProperty
, strength_value
);
122 profiles
->AddService(kSharedProfilePath
, "wifi2");
124 if (CommandLine::ForCurrentProcess()->HasSwitch(
125 chromeos::switches::kEnableStubPortalledWifi
)) {
126 services
->AddService(kStubPortalledWifiPath
,
127 kStubPortalledWifiName
,
130 add_to_visible
, add_to_watchlist
);
131 services
->SetServiceProperty(kStubPortalledWifiPath
,
132 shill::kSecurityProperty
,
133 base::StringValue(shill::kSecurityNone
));
134 services
->SetConnectBehavior(kStubPortalledWifiPath
,
135 base::Bind(&UpdatePortalledWifiState
));
136 services
->SetServiceProperty(kStubPortalledWifiPath
,
137 shill::kConnectableProperty
,
138 base::FundamentalValue(true));
143 services
->AddService("wimax1",
147 add_to_visible
, add_to_watchlist
);
148 services
->SetServiceProperty(
149 "wimax1", shill::kConnectableProperty
, base::FundamentalValue(true));
153 services
->AddService("cellular1",
155 shill::kTypeCellular
,
157 add_to_visible
, add_to_watchlist
);
158 base::StringValue
technology_value(shill::kNetworkTechnologyGsm
);
159 services
->SetServiceProperty(
160 "cellular1", shill::kNetworkTechnologyProperty
, technology_value
);
161 services
->SetServiceProperty(
163 shill::kActivationStateProperty
,
164 base::StringValue(shill::kActivationStateNotActivated
));
165 services
->SetServiceProperty("cellular1",
166 shill::kRoamingStateProperty
,
167 base::StringValue(shill::kRoamingStateHome
));
171 // Set the "Provider" dictionary properties. Note: when setting these in
172 // Shill, "Provider.Type", etc keys are used, but when reading the values
173 // "Provider" . "Type", etc keys are used. Here we are setting the values
174 // that will be read (by the UI, tests, etc).
175 base::DictionaryValue provider_properties
;
176 provider_properties
.SetString(shill::kTypeProperty
, shill::kProviderOpenVpn
);
177 provider_properties
.SetString(shill::kHostProperty
, "vpn_host");
179 services
->AddService("vpn1",
183 add_to_visible
, add_to_watchlist
);
184 services
->SetServiceProperty(
185 "vpn1", shill::kProviderProperty
, provider_properties
);
186 profiles
->AddService(kSharedProfilePath
, "vpn1");
188 services
->AddService("vpn2",
191 shill::kStateOffline
,
192 add_to_visible
, add_to_watchlist
);
193 services
->SetServiceProperty(
194 "vpn2", shill::kProviderProperty
, provider_properties
);
196 manager
->SortManagerServices();
199 std::string
DevicePathForType(const std::string
& type
) {
200 if (type
== shill::kTypeWifi
)
201 return kDevicePathWifi
;
202 if (type
== shill::kTypeCellular
)
203 return kDevicePathCellular
;
204 if (type
== shill::kTypeWimax
)
205 return kDevicePathWimax
;
209 } // namespace shill_stub_helper
210 } // namespace chromeos