blob: 431cccf3a695a4386d64a7126cbcc8164ff3ccb9 [file] [log] [blame]
[email protected]3c8bd112012-11-07 10:14:591// Copyright (c) 2012 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.
4
5#include "chromeos/network/shill_property_handler.h"
6
7#include <map>
8#include <set>
9#include <string>
10
11#include "base/bind.h"
12#include "base/memory/scoped_ptr.h"
[email protected]f129d2502013-07-17 22:45:5013#include "base/message_loop/message_loop.h"
[email protected]3c8bd112012-11-07 10:14:5914#include "base/values.h"
15#include "chromeos/dbus/dbus_thread_manager.h"
16#include "chromeos/dbus/shill_device_client.h"
[email protected]362fb222013-04-02 23:24:2817#include "chromeos/dbus/shill_ipconfig_client.h"
[email protected]3c8bd112012-11-07 10:14:5918#include "chromeos/dbus/shill_manager_client.h"
[email protected]ce21fc62013-07-03 10:45:5819#include "chromeos/dbus/shill_profile_client.h"
[email protected]3c8bd112012-11-07 10:14:5920#include "chromeos/dbus/shill_service_client.h"
21#include "dbus/object_path.h"
22#include "testing/gtest/include/gtest/gtest.h"
23#include "third_party/cros_system_api/dbus/service_constants.h"
24
25namespace chromeos {
26
27namespace {
28
[email protected]362fb222013-04-02 23:24:2829void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {
30}
31
[email protected]3c8bd112012-11-07 10:14:5932void ErrorCallbackFunction(const std::string& error_name,
33 const std::string& error_message) {
34 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
35}
36
37class TestListener : public internal::ShillPropertyHandler::Listener {
38 public:
[email protected]e925cfd2013-09-13 18:38:3739 TestListener() : technology_list_updates_(0),
40 errors_(0) {
[email protected]3c8bd112012-11-07 10:14:5941 }
42
43 virtual void UpdateManagedList(ManagedState::ManagedType type,
44 const base::ListValue& entries) OVERRIDE {
45 UpdateEntries(GetTypeString(type), entries);
46 }
47
[email protected]3c8bd112012-11-07 10:14:5948 virtual void UpdateManagedStateProperties(
49 ManagedState::ManagedType type,
50 const std::string& path,
51 const base::DictionaryValue& properties) OVERRIDE {
[email protected]ce21fc62013-07-03 10:45:5852 AddInitialPropertyUpdate(GetTypeString(type), path);
[email protected]3c8bd112012-11-07 10:14:5953 }
54
[email protected]4a3ed972013-04-11 22:03:2355 virtual void ProfileListChanged() OVERRIDE {
56 }
57
[email protected]3c8bd112012-11-07 10:14:5958 virtual void UpdateNetworkServiceProperty(
59 const std::string& service_path,
60 const std::string& key,
61 const base::Value& value) OVERRIDE {
[email protected]547396c52013-09-24 07:24:5662 AddPropertyUpdate(shill::kServicesProperty, service_path);
[email protected]3c8bd112012-11-07 10:14:5963 }
64
[email protected]b16d79d72013-02-07 08:14:4665 virtual void UpdateDeviceProperty(
66 const std::string& device_path,
67 const std::string& key,
68 const base::Value& value) OVERRIDE {
[email protected]547396c52013-09-24 07:24:5669 AddPropertyUpdate(shill::kDevicesProperty, device_path);
[email protected]b16d79d72013-02-07 08:14:4670 }
71
[email protected]e925cfd2013-09-13 18:38:3772 virtual void TechnologyListChanged() OVERRIDE {
73 ++technology_list_updates_;
[email protected]3c8bd112012-11-07 10:14:5974 }
75
[email protected]68196e452013-05-31 01:16:3876 virtual void CheckPortalListChanged(
77 const std::string& check_portal_list) OVERRIDE {
78 }
79
[email protected]3c8bd112012-11-07 10:14:5980 virtual void ManagedStateListChanged(
81 ManagedState::ManagedType type) OVERRIDE {
82 AddStateListUpdate(GetTypeString(type));
83 }
84
85 std::vector<std::string>& entries(const std::string& type) {
86 return entries_[type];
87 }
88 std::map<std::string, int>& property_updates(const std::string& type) {
89 return property_updates_[type];
90 }
[email protected]ce21fc62013-07-03 10:45:5891 std::map<std::string, int>& initial_property_updates(
92 const std::string& type) {
93 return initial_property_updates_[type];
94 }
[email protected]3c8bd112012-11-07 10:14:5995 int list_updates(const std::string& type) { return list_updates_[type]; }
[email protected]e925cfd2013-09-13 18:38:3796 int technology_list_updates() { return technology_list_updates_; }
[email protected]3c8bd112012-11-07 10:14:5997 int errors() { return errors_; }
98
99 private:
100 std::string GetTypeString(ManagedState::ManagedType type) {
101 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
[email protected]547396c52013-09-24 07:24:56102 return shill::kServicesProperty;
[email protected]ce21fc62013-07-03 10:45:58103 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) {
104 return shill::kServiceCompleteListProperty;
[email protected]3c8bd112012-11-07 10:14:59105 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
[email protected]547396c52013-09-24 07:24:56106 return shill::kDevicesProperty;
[email protected]3c8bd112012-11-07 10:14:59107 }
108 LOG(ERROR) << "UpdateManagedList called with unrecognized type: " << type;
109 ++errors_;
110 return std::string();
111 }
112
113 void UpdateEntries(const std::string& type, const base::ListValue& entries) {
114 if (type.empty())
115 return;
116 entries_[type].clear();
117 for (base::ListValue::const_iterator iter = entries.begin();
118 iter != entries.end(); ++iter) {
119 std::string path;
120 if ((*iter)->GetAsString(&path))
121 entries_[type].push_back(path);
122 }
123 }
124
125 void AddPropertyUpdate(const std::string& type, const std::string& path) {
126 if (type.empty())
127 return;
128 property_updates(type)[path] += 1;
129 }
130
[email protected]ce21fc62013-07-03 10:45:58131 void AddInitialPropertyUpdate(const std::string& type,
132 const std::string& path) {
133 if (type.empty())
134 return;
135 initial_property_updates(type)[path] += 1;
136 }
137
[email protected]3c8bd112012-11-07 10:14:59138 void AddStateListUpdate(const std::string& type) {
139 if (type.empty())
140 return;
141 list_updates_[type] += 1;
142 }
143
144 // Map of list-type -> paths
145 std::map<std::string, std::vector<std::string> > entries_;
146 // Map of list-type -> map of paths -> update counts
147 std::map<std::string, std::map<std::string, int> > property_updates_;
[email protected]ce21fc62013-07-03 10:45:58148 std::map<std::string, std::map<std::string, int> > initial_property_updates_;
[email protected]3c8bd112012-11-07 10:14:59149 // Map of list-type -> list update counts
150 std::map<std::string, int > list_updates_;
[email protected]e925cfd2013-09-13 18:38:37151 int technology_list_updates_;
[email protected]3c8bd112012-11-07 10:14:59152 int errors_;
153};
154
155} // namespace
156
157class ShillPropertyHandlerTest : public testing::Test {
158 public:
159 ShillPropertyHandlerTest()
160 : manager_test_(NULL),
161 device_test_(NULL),
[email protected]ce21fc62013-07-03 10:45:58162 service_test_(NULL),
163 profile_test_(NULL) {
[email protected]3c8bd112012-11-07 10:14:59164 }
165 virtual ~ShillPropertyHandlerTest() {
166 }
167
168 virtual void SetUp() OVERRIDE {
169 // Initialize DBusThreadManager with a stub implementation.
170 DBusThreadManager::InitializeWithStub();
171 // Get the test interface for manager / device / service and clear the
172 // default stub properties.
173 manager_test_ =
174 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
175 ASSERT_TRUE(manager_test_);
176 device_test_ =
177 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
178 ASSERT_TRUE(device_test_);
179 service_test_ =
180 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
181 ASSERT_TRUE(service_test_);
[email protected]ce21fc62013-07-03 10:45:58182 profile_test_ =
183 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
184 ASSERT_TRUE(profile_test_);
[email protected]362fb222013-04-02 23:24:28185 SetupShillPropertyHandler();
186 message_loop_.RunUntilIdle();
[email protected]3c8bd112012-11-07 10:14:59187 }
188
189 virtual void TearDown() OVERRIDE {
190 shill_property_handler_.reset();
191 listener_.reset();
192 DBusThreadManager::Shutdown();
193 }
194
195 void AddDevice(const std::string& type, const std::string& id) {
196 ASSERT_TRUE(IsValidType(type));
[email protected]b7c377e2013-01-15 10:00:39197 device_test_->AddDevice(id, type, std::string("/device/" + id));
[email protected]3c8bd112012-11-07 10:14:59198 }
199
200 void RemoveDevice(const std::string& id) {
[email protected]3c8bd112012-11-07 10:14:59201 device_test_->RemoveDevice(id);
202 }
203
204 void AddService(const std::string& type,
205 const std::string& id,
206 const std::string& state,
207 bool add_to_watch_list) {
208 ASSERT_TRUE(IsValidType(type));
[email protected]362fb222013-04-02 23:24:28209 service_test_->AddService(id, id, type, state,
[email protected]ce21fc62013-07-03 10:45:58210 true /* visible */, add_to_watch_list);
[email protected]362fb222013-04-02 23:24:28211 }
212
213 void AddServiceWithIPConfig(const std::string& type,
214 const std::string& id,
215 const std::string& state,
216 const std::string& ipconfig_path,
217 bool add_to_watch_list) {
218 ASSERT_TRUE(IsValidType(type));
219 service_test_->AddServiceWithIPConfig(id, id, type, state,
[email protected]ce21fc62013-07-03 10:45:58220 ipconfig_path,
221 true /* visible */,
222 add_to_watch_list);
223 }
224
225 void AddServiceToProfile(const std::string& type,
226 const std::string& id,
227 bool visible) {
[email protected]547396c52013-09-24 07:24:56228 service_test_->AddService(id, id, type, shill::kStateIdle,
[email protected]ce21fc62013-07-03 10:45:58229 visible, false /* watch */);
230 std::vector<std::string> profiles;
231 profile_test_->GetProfilePaths(&profiles);
232 ASSERT_TRUE(profiles.size() > 0);
233 base::DictionaryValue properties; // Empty entry
234 profile_test_->AddService(profiles[0], id);
[email protected]3c8bd112012-11-07 10:14:59235 }
236
237 void RemoveService(const std::string& id) {
[email protected]3c8bd112012-11-07 10:14:59238 service_test_->RemoveService(id);
239 }
240
241 // Call this after any initial Shill client setup
242 void SetupShillPropertyHandler() {
[email protected]1c86dbf2013-03-06 17:42:26243 SetupDefaultShillState();
[email protected]3c8bd112012-11-07 10:14:59244 listener_.reset(new TestListener);
245 shill_property_handler_.reset(
246 new internal::ShillPropertyHandler(listener_.get()));
247 shill_property_handler_->Init();
248 }
249
250 bool IsValidType(const std::string& type) {
[email protected]547396c52013-09-24 07:24:56251 return (type == shill::kTypeEthernet ||
[email protected]184bd2d2013-09-11 20:38:04252 type == shill::kTypeEthernetEap ||
[email protected]547396c52013-09-24 07:24:56253 type == shill::kTypeWifi ||
254 type == shill::kTypeWimax ||
255 type == shill::kTypeBluetooth ||
256 type == shill::kTypeCellular ||
257 type == shill::kTypeVPN);
[email protected]3c8bd112012-11-07 10:14:59258 }
259
260 protected:
[email protected]1c86dbf2013-03-06 17:42:26261 void SetupDefaultShillState() {
262 message_loop_.RunUntilIdle(); // Process any pending updates
263 device_test_->ClearDevices();
[email protected]547396c52013-09-24 07:24:56264 AddDevice(shill::kTypeWifi, "stub_wifi_device1");
265 AddDevice(shill::kTypeCellular, "stub_cellular_device1");
[email protected]1c86dbf2013-03-06 17:42:26266 service_test_->ClearServices();
267 const bool add_to_watchlist = true;
[email protected]547396c52013-09-24 07:24:56268 AddService(shill::kTypeEthernet, "stub_ethernet",
269 shill::kStateOnline, add_to_watchlist);
270 AddService(shill::kTypeWifi, "stub_wifi1",
271 shill::kStateOnline, add_to_watchlist);
272 AddService(shill::kTypeWifi, "stub_wifi2",
273 shill::kStateIdle, add_to_watchlist);
274 AddService(shill::kTypeCellular, "stub_cellular1",
275 shill::kStateIdle, add_to_watchlist);
[email protected]1c86dbf2013-03-06 17:42:26276 }
277
[email protected]df905632013-05-29 23:04:36278 base::MessageLoopForUI message_loop_;
[email protected]3c8bd112012-11-07 10:14:59279 scoped_ptr<TestListener> listener_;
280 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_;
281 ShillManagerClient::TestInterface* manager_test_;
282 ShillDeviceClient::TestInterface* device_test_;
283 ShillServiceClient::TestInterface* service_test_;
[email protected]ce21fc62013-07-03 10:45:58284 ShillProfileClient::TestInterface* profile_test_;
[email protected]3c8bd112012-11-07 10:14:59285
286 private:
287 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest);
288};
289
290TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) {
[email protected]547396c52013-09-24 07:24:56291 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(shill::kTypeWifi));
292 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi));
[email protected]3c8bd112012-11-07 10:14:59293 const size_t kNumShillManagerClientStubImplDevices = 2;
294 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
[email protected]547396c52013-09-24 07:24:56295 listener_->entries(shill::kDevicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59296 const size_t kNumShillManagerClientStubImplServices = 4;
297 EXPECT_EQ(kNumShillManagerClientStubImplServices,
[email protected]547396c52013-09-24 07:24:56298 listener_->entries(shill::kServicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59299
300 EXPECT_EQ(0, listener_->errors());
301}
302
303TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) {
[email protected]e925cfd2013-09-13 18:38:37304 const int initial_technology_updates = 2; // Available and Enabled lists
305 EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates());
[email protected]36c3b892013-08-05 17:04:13306
307 // Remove a technology. Updates both the Available and Enabled lists.
[email protected]547396c52013-09-24 07:24:56308 manager_test_->RemoveTechnology(shill::kTypeWimax);
[email protected]36c3b892013-08-05 17:04:13309 message_loop_.RunUntilIdle();
[email protected]e925cfd2013-09-13 18:38:37310 EXPECT_EQ(initial_technology_updates + 2,
311 listener_->technology_list_updates());
[email protected]36c3b892013-08-05 17:04:13312
[email protected]3c8bd112012-11-07 10:14:59313 // Add a disabled technology.
[email protected]547396c52013-09-24 07:24:56314 manager_test_->AddTechnology(shill::kTypeWimax, false);
[email protected]3c8bd112012-11-07 10:14:59315 message_loop_.RunUntilIdle();
[email protected]e925cfd2013-09-13 18:38:37316 EXPECT_EQ(initial_technology_updates + 3,
317 listener_->technology_list_updates());
[email protected]b15f4932013-04-15 21:09:25318 EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(
[email protected]547396c52013-09-24 07:24:56319 shill::kTypeWimax));
320 EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax));
[email protected]b16d79d72013-02-07 08:14:46321
[email protected]3c8bd112012-11-07 10:14:59322 // Enable the technology.
323 DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
[email protected]547396c52013-09-24 07:24:56324 shill::kTypeWimax,
[email protected]3c8bd112012-11-07 10:14:59325 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
326 message_loop_.RunUntilIdle();
[email protected]e925cfd2013-09-13 18:38:37327 EXPECT_EQ(initial_technology_updates + 4,
328 listener_->technology_list_updates());
[email protected]547396c52013-09-24 07:24:56329 EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax));
[email protected]3c8bd112012-11-07 10:14:59330
331 EXPECT_EQ(0, listener_->errors());
332}
333
334TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) {
[email protected]547396c52013-09-24 07:24:56335 EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty));
[email protected]3c8bd112012-11-07 10:14:59336 const size_t kNumShillManagerClientStubImplDevices = 2;
337 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
[email protected]547396c52013-09-24 07:24:56338 listener_->entries(shill::kDevicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59339 // Add a device.
340 const std::string kTestDevicePath("test_wifi_device1");
[email protected]547396c52013-09-24 07:24:56341 AddDevice(shill::kTypeWifi, kTestDevicePath);
[email protected]3c8bd112012-11-07 10:14:59342 message_loop_.RunUntilIdle();
[email protected]547396c52013-09-24 07:24:56343 EXPECT_EQ(2, listener_->list_updates(shill::kDevicesProperty));
[email protected]3c8bd112012-11-07 10:14:59344 EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1,
[email protected]547396c52013-09-24 07:24:56345 listener_->entries(shill::kDevicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59346 // Device changes are not observed.
347 // Remove a device
348 RemoveDevice(kTestDevicePath);
349 message_loop_.RunUntilIdle();
[email protected]547396c52013-09-24 07:24:56350 EXPECT_EQ(3, listener_->list_updates(shill::kDevicesProperty));
[email protected]3c8bd112012-11-07 10:14:59351 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
[email protected]547396c52013-09-24 07:24:56352 listener_->entries(shill::kDevicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59353
354 EXPECT_EQ(0, listener_->errors());
355}
356
357TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) {
[email protected]547396c52013-09-24 07:24:56358 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
[email protected]3c8bd112012-11-07 10:14:59359 const size_t kNumShillManagerClientStubImplServices = 4;
360 EXPECT_EQ(kNumShillManagerClientStubImplServices,
[email protected]547396c52013-09-24 07:24:56361 listener_->entries(shill::kServicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59362
363 // Add an unwatched service.
364 const std::string kTestServicePath("test_wifi_service1");
[email protected]547396c52013-09-24 07:24:56365 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false);
[email protected]3c8bd112012-11-07 10:14:59366 message_loop_.RunUntilIdle();
[email protected]e36826d92013-05-14 17:23:11367 // Watched and unwatched services trigger a service list update.
[email protected]547396c52013-09-24 07:24:56368 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
[email protected]3c8bd112012-11-07 10:14:59369 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
[email protected]547396c52013-09-24 07:24:56370 listener_->entries(shill::kServicesProperty).size());
[email protected]e36826d92013-05-14 17:23:11371 // Service receives an initial property update.
[email protected]ce21fc62013-07-03 10:45:58372 EXPECT_EQ(1, listener_->initial_property_updates(
[email protected]547396c52013-09-24 07:24:56373 shill::kServicesProperty)[kTestServicePath]);
[email protected]3c8bd112012-11-07 10:14:59374 // Change a property.
375 base::FundamentalValue scan_interval(3);
376 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
377 dbus::ObjectPath(kTestServicePath),
[email protected]547396c52013-09-24 07:24:56378 shill::kScanIntervalProperty,
[email protected]3c8bd112012-11-07 10:14:59379 scan_interval,
380 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
381 message_loop_.RunUntilIdle();
[email protected]e36826d92013-05-14 17:23:11382 // Property change triggers an update.
[email protected]ce21fc62013-07-03 10:45:58383 EXPECT_EQ(1, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56384 shill::kServicesProperty)[kTestServicePath]);
[email protected]3c8bd112012-11-07 10:14:59385
386 // Add the existing service to the watch list.
[email protected]547396c52013-09-24 07:24:56387 AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true);
[email protected]3c8bd112012-11-07 10:14:59388 message_loop_.RunUntilIdle();
[email protected]fa6797e2012-11-28 15:15:44389 // Service list update should be received when watch list changes.
[email protected]547396c52013-09-24 07:24:56390 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
[email protected]fa6797e2012-11-28 15:15:44391 // Number of services shouldn't change.
[email protected]3c8bd112012-11-07 10:14:59392 EXPECT_EQ(kNumShillManagerClientStubImplServices + 1,
[email protected]547396c52013-09-24 07:24:56393 listener_->entries(shill::kServicesProperty).size());
[email protected]fa6797e2012-11-28 15:15:44394
[email protected]3c8bd112012-11-07 10:14:59395 // Change a property.
396 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
397 dbus::ObjectPath(kTestServicePath),
[email protected]547396c52013-09-24 07:24:56398 shill::kScanIntervalProperty,
[email protected]3c8bd112012-11-07 10:14:59399 scan_interval,
400 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
401 message_loop_.RunUntilIdle();
[email protected]fa6797e2012-11-28 15:15:44402 // Property change should trigger another update.
[email protected]ce21fc62013-07-03 10:45:58403 EXPECT_EQ(2, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56404 shill::kServicesProperty)[kTestServicePath]);
[email protected]3c8bd112012-11-07 10:14:59405
406 // Remove a service
407 RemoveService(kTestServicePath);
408 message_loop_.RunUntilIdle();
[email protected]547396c52013-09-24 07:24:56409 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty));
[email protected]3c8bd112012-11-07 10:14:59410 EXPECT_EQ(kNumShillManagerClientStubImplServices,
[email protected]547396c52013-09-24 07:24:56411 listener_->entries(shill::kServicesProperty).size());
[email protected]3c8bd112012-11-07 10:14:59412
413 EXPECT_EQ(0, listener_->errors());
414}
415
[email protected]362fb222013-04-02 23:24:28416TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) {
417 // Set the properties for an IP Config object.
418 const std::string kTestIPConfigPath("test_ip_config_path");
[email protected]a491f162013-07-12 17:12:25419
[email protected]362fb222013-04-02 23:24:28420 base::StringValue ip_address("192.168.1.1");
421 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
422 dbus::ObjectPath(kTestIPConfigPath),
[email protected]547396c52013-09-24 07:24:56423 shill::kAddressProperty, ip_address,
[email protected]362fb222013-04-02 23:24:28424 base::Bind(&DoNothingWithCallStatus));
425 base::ListValue dns_servers;
426 dns_servers.Append(base::Value::CreateStringValue("192.168.1.100"));
427 dns_servers.Append(base::Value::CreateStringValue("192.168.1.101"));
428 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
429 dbus::ObjectPath(kTestIPConfigPath),
[email protected]547396c52013-09-24 07:24:56430 shill::kNameServersProperty, dns_servers,
[email protected]a491f162013-07-12 17:12:25431 base::Bind(&DoNothingWithCallStatus));
432 base::FundamentalValue prefixlen(8);
433 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
434 dbus::ObjectPath(kTestIPConfigPath),
[email protected]547396c52013-09-24 07:24:56435 shill::kPrefixlenProperty, prefixlen,
[email protected]a491f162013-07-12 17:12:25436 base::Bind(&DoNothingWithCallStatus));
437 base::StringValue gateway("192.0.0.1");
438 DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
439 dbus::ObjectPath(kTestIPConfigPath),
[email protected]547396c52013-09-24 07:24:56440 shill::kGatewayProperty, gateway,
[email protected]362fb222013-04-02 23:24:28441 base::Bind(&DoNothingWithCallStatus));
442 message_loop_.RunUntilIdle();
443
444 // Add a service with an empty ipconfig and then update
445 // its ipconfig property.
446 const std::string kTestServicePath1("test_wifi_service1");
[email protected]547396c52013-09-24 07:24:56447 AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle, true);
[email protected]362fb222013-04-02 23:24:28448 message_loop_.RunUntilIdle();
449 // This is the initial property update.
[email protected]ce21fc62013-07-03 10:45:58450 EXPECT_EQ(1, listener_->initial_property_updates(
[email protected]547396c52013-09-24 07:24:56451 shill::kServicesProperty)[kTestServicePath1]);
[email protected]362fb222013-04-02 23:24:28452 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
453 dbus::ObjectPath(kTestServicePath1),
454 shill::kIPConfigProperty,
455 base::StringValue(kTestIPConfigPath),
456 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
457 message_loop_.RunUntilIdle();
458 // IPConfig property change on the service should trigger property updates for
[email protected]a491f162013-07-12 17:12:25459 // IP Address, DNS, prefixlen, and gateway.
460 EXPECT_EQ(4, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56461 shill::kServicesProperty)[kTestServicePath1]);
[email protected]362fb222013-04-02 23:24:28462
463 // Now, Add a new watched service with the IPConfig already set.
464 const std::string kTestServicePath2("test_wifi_service2");
[email protected]547396c52013-09-24 07:24:56465 AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2,
466 shill::kStateIdle, kTestIPConfigPath, true);
[email protected]362fb222013-04-02 23:24:28467 message_loop_.RunUntilIdle();
[email protected]a491f162013-07-12 17:12:25468 // A watched service with the IPConfig property already set must trigger
469 // property updates for IP Address, DNS, prefixlen, and gateway when added.
470 EXPECT_EQ(4, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56471 shill::kServicesProperty)[kTestServicePath2]);
[email protected]ce21fc62013-07-03 10:45:58472}
473
474TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) {
475 // Initial list updates.
[email protected]547396c52013-09-24 07:24:56476 EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty));
[email protected]ce21fc62013-07-03 10:45:58477 EXPECT_EQ(1, listener_->list_updates(shill::kServiceCompleteListProperty));
478
479 // Add a new entry to the profile only; should trigger a single list update
480 // for both Services and ServiceCompleteList, and a single property update
481 // for ServiceCompleteList.
482 const std::string kTestServicePath1("stub_wifi_profile_only1");
[email protected]547396c52013-09-24 07:24:56483 AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false);
[email protected]ce21fc62013-07-03 10:45:58484 shill_property_handler_->UpdateManagerProperties();
485 message_loop_.RunUntilIdle();
[email protected]547396c52013-09-24 07:24:56486 EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty));
[email protected]ce21fc62013-07-03 10:45:58487 EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty));
488 EXPECT_EQ(0, listener_->initial_property_updates(
[email protected]547396c52013-09-24 07:24:56489 shill::kServicesProperty)[kTestServicePath1]);
[email protected]ce21fc62013-07-03 10:45:58490 EXPECT_EQ(1, listener_->initial_property_updates(
491 shill::kServiceCompleteListProperty)[kTestServicePath1]);
492 EXPECT_EQ(0, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56493 shill::kServicesProperty)[kTestServicePath1]);
[email protected]ce21fc62013-07-03 10:45:58494 EXPECT_EQ(0, listener_->property_updates(
495 shill::kServiceCompleteListProperty)[kTestServicePath1]);
496
497 // Add a new entry to the services and the profile; should also trigger a
498 // single list update for both Services and ServiceCompleteList, and should
499 // trigger tow property updates for Services (one when the Profile propety
500 // changes, and one for the Request) and one ServiceCompleteList change for
501 // the Request.
502 const std::string kTestServicePath2("stub_wifi_profile_only2");
[email protected]547396c52013-09-24 07:24:56503 AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true);
[email protected]ce21fc62013-07-03 10:45:58504 shill_property_handler_->UpdateManagerProperties();
505 message_loop_.RunUntilIdle();
[email protected]547396c52013-09-24 07:24:56506 EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty));
[email protected]ce21fc62013-07-03 10:45:58507 EXPECT_EQ(3, listener_->list_updates(shill::kServiceCompleteListProperty));
508 EXPECT_EQ(1, listener_->initial_property_updates(
[email protected]547396c52013-09-24 07:24:56509 shill::kServicesProperty)[kTestServicePath2]);
[email protected]ce21fc62013-07-03 10:45:58510 EXPECT_EQ(1, listener_->initial_property_updates(
511 shill::kServiceCompleteListProperty)[kTestServicePath2]);
512 // Expect one property update for the Profile property of the Network.
513 EXPECT_EQ(1, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56514 shill::kServicesProperty)[kTestServicePath2]);
[email protected]ce21fc62013-07-03 10:45:58515 EXPECT_EQ(0, listener_->property_updates(
516 shill::kServiceCompleteListProperty)[kTestServicePath2]);
517
518 // Change a property of a Network in a Profile.
519 base::FundamentalValue scan_interval(3);
520 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
521 dbus::ObjectPath(kTestServicePath2),
[email protected]547396c52013-09-24 07:24:56522 shill::kScanIntervalProperty,
[email protected]ce21fc62013-07-03 10:45:58523 scan_interval,
524 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
525 message_loop_.RunUntilIdle();
526 // Property change should trigger an update for the Network only; no
527 // property updates pushed by Shill affect Favorites.
528 EXPECT_EQ(2, listener_->property_updates(
[email protected]547396c52013-09-24 07:24:56529 shill::kServicesProperty)[kTestServicePath2]);
[email protected]ce21fc62013-07-03 10:45:58530 EXPECT_EQ(0, listener_->property_updates(
531 shill::kServiceCompleteListProperty)[kTestServicePath2]);
[email protected]362fb222013-04-02 23:24:28532}
[email protected]3c8bd112012-11-07 10:14:59533
534} // namespace chromeos