[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 1 | // 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] | f129d250 | 2013-07-17 22:45:50 | [diff] [blame] | 13 | #include "base/message_loop/message_loop.h" |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 14 | #include "base/values.h" |
| 15 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 | #include "chromeos/dbus/shill_device_client.h" |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 17 | #include "chromeos/dbus/shill_ipconfig_client.h" |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 18 | #include "chromeos/dbus/shill_manager_client.h" |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 19 | #include "chromeos/dbus/shill_profile_client.h" |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 20 | #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 | |
| 25 | namespace chromeos { |
| 26 | |
| 27 | namespace { |
| 28 | |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 29 | void DoNothingWithCallStatus(DBusMethodCallStatus call_status) { |
| 30 | } |
| 31 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 32 | void ErrorCallbackFunction(const std::string& error_name, |
| 33 | const std::string& error_message) { |
| 34 | LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 35 | } |
| 36 | |
| 37 | class TestListener : public internal::ShillPropertyHandler::Listener { |
| 38 | public: |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 39 | TestListener() : technology_list_updates_(0), |
| 40 | errors_(0) { |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | virtual void UpdateManagedList(ManagedState::ManagedType type, |
| 44 | const base::ListValue& entries) OVERRIDE { |
| 45 | UpdateEntries(GetTypeString(type), entries); |
| 46 | } |
| 47 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 48 | virtual void UpdateManagedStateProperties( |
| 49 | ManagedState::ManagedType type, |
| 50 | const std::string& path, |
| 51 | const base::DictionaryValue& properties) OVERRIDE { |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 52 | AddInitialPropertyUpdate(GetTypeString(type), path); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | 4a3ed97 | 2013-04-11 22:03:23 | [diff] [blame] | 55 | virtual void ProfileListChanged() OVERRIDE { |
| 56 | } |
| 57 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 58 | virtual void UpdateNetworkServiceProperty( |
| 59 | const std::string& service_path, |
| 60 | const std::string& key, |
| 61 | const base::Value& value) OVERRIDE { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 62 | AddPropertyUpdate(shill::kServicesProperty, service_path); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | b16d79d7 | 2013-02-07 08:14:46 | [diff] [blame] | 65 | virtual void UpdateDeviceProperty( |
| 66 | const std::string& device_path, |
| 67 | const std::string& key, |
| 68 | const base::Value& value) OVERRIDE { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 69 | AddPropertyUpdate(shill::kDevicesProperty, device_path); |
[email protected] | b16d79d7 | 2013-02-07 08:14:46 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 72 | virtual void TechnologyListChanged() OVERRIDE { |
| 73 | ++technology_list_updates_; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 74 | } |
| 75 | |
[email protected] | 68196e45 | 2013-05-31 01:16:38 | [diff] [blame] | 76 | virtual void CheckPortalListChanged( |
| 77 | const std::string& check_portal_list) OVERRIDE { |
| 78 | } |
| 79 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 80 | 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 91 | std::map<std::string, int>& initial_property_updates( |
| 92 | const std::string& type) { |
| 93 | return initial_property_updates_[type]; |
| 94 | } |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 95 | int list_updates(const std::string& type) { return list_updates_[type]; } |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 96 | int technology_list_updates() { return technology_list_updates_; } |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 97 | int errors() { return errors_; } |
| 98 | |
| 99 | private: |
| 100 | std::string GetTypeString(ManagedState::ManagedType type) { |
| 101 | if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 102 | return shill::kServicesProperty; |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 103 | } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { |
| 104 | return shill::kServiceCompleteListProperty; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 105 | } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 106 | return shill::kDevicesProperty; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 107 | } |
| 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 131 | 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] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 138 | 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 148 | std::map<std::string, std::map<std::string, int> > initial_property_updates_; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 149 | // Map of list-type -> list update counts |
| 150 | std::map<std::string, int > list_updates_; |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 151 | int technology_list_updates_; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 152 | int errors_; |
| 153 | }; |
| 154 | |
| 155 | } // namespace |
| 156 | |
| 157 | class ShillPropertyHandlerTest : public testing::Test { |
| 158 | public: |
| 159 | ShillPropertyHandlerTest() |
| 160 | : manager_test_(NULL), |
| 161 | device_test_(NULL), |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 162 | service_test_(NULL), |
| 163 | profile_test_(NULL) { |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 164 | } |
| 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 182 | profile_test_ = |
| 183 | DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 184 | ASSERT_TRUE(profile_test_); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 185 | SetupShillPropertyHandler(); |
| 186 | message_loop_.RunUntilIdle(); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 187 | } |
| 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] | b7c377e | 2013-01-15 10:00:39 | [diff] [blame] | 197 | device_test_->AddDevice(id, type, std::string("/device/" + id)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void RemoveDevice(const std::string& id) { |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 201 | 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] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 209 | service_test_->AddService(id, id, type, state, |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 210 | true /* visible */, add_to_watch_list); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 211 | } |
| 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 220 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 228 | service_test_->AddService(id, id, type, shill::kStateIdle, |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 229 | 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] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void RemoveService(const std::string& id) { |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 238 | service_test_->RemoveService(id); |
| 239 | } |
| 240 | |
| 241 | // Call this after any initial Shill client setup |
| 242 | void SetupShillPropertyHandler() { |
[email protected] | 1c86dbf | 2013-03-06 17:42:26 | [diff] [blame] | 243 | SetupDefaultShillState(); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 244 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 251 | return (type == shill::kTypeEthernet || |
[email protected] | 184bd2d | 2013-09-11 20:38:04 | [diff] [blame] | 252 | type == shill::kTypeEthernetEap || |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 253 | type == shill::kTypeWifi || |
| 254 | type == shill::kTypeWimax || |
| 255 | type == shill::kTypeBluetooth || |
| 256 | type == shill::kTypeCellular || |
| 257 | type == shill::kTypeVPN); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | protected: |
[email protected] | 1c86dbf | 2013-03-06 17:42:26 | [diff] [blame] | 261 | void SetupDefaultShillState() { |
| 262 | message_loop_.RunUntilIdle(); // Process any pending updates |
| 263 | device_test_->ClearDevices(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 264 | AddDevice(shill::kTypeWifi, "stub_wifi_device1"); |
| 265 | AddDevice(shill::kTypeCellular, "stub_cellular_device1"); |
[email protected] | 1c86dbf | 2013-03-06 17:42:26 | [diff] [blame] | 266 | service_test_->ClearServices(); |
| 267 | const bool add_to_watchlist = true; |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 268 | 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] | 1c86dbf | 2013-03-06 17:42:26 | [diff] [blame] | 276 | } |
| 277 | |
[email protected] | df90563 | 2013-05-29 23:04:36 | [diff] [blame] | 278 | base::MessageLoopForUI message_loop_; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 279 | 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] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 284 | ShillProfileClient::TestInterface* profile_test_; |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 285 | |
| 286 | private: |
| 287 | DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandlerTest); |
| 288 | }; |
| 289 | |
| 290 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerStub) { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 291 | EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable(shill::kTypeWifi)); |
| 292 | EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWifi)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 293 | const size_t kNumShillManagerClientStubImplDevices = 2; |
| 294 | EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 295 | listener_->entries(shill::kDevicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 296 | const size_t kNumShillManagerClientStubImplServices = 4; |
| 297 | EXPECT_EQ(kNumShillManagerClientStubImplServices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 298 | listener_->entries(shill::kServicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 299 | |
| 300 | EXPECT_EQ(0, listener_->errors()); |
| 301 | } |
| 302 | |
| 303 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerTechnologyChanged) { |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 304 | const int initial_technology_updates = 2; // Available and Enabled lists |
| 305 | EXPECT_EQ(initial_technology_updates, listener_->technology_list_updates()); |
[email protected] | 36c3b89 | 2013-08-05 17:04:13 | [diff] [blame] | 306 | |
| 307 | // Remove a technology. Updates both the Available and Enabled lists. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 308 | manager_test_->RemoveTechnology(shill::kTypeWimax); |
[email protected] | 36c3b89 | 2013-08-05 17:04:13 | [diff] [blame] | 309 | message_loop_.RunUntilIdle(); |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 310 | EXPECT_EQ(initial_technology_updates + 2, |
| 311 | listener_->technology_list_updates()); |
[email protected] | 36c3b89 | 2013-08-05 17:04:13 | [diff] [blame] | 312 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 313 | // Add a disabled technology. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 314 | manager_test_->AddTechnology(shill::kTypeWimax, false); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 315 | message_loop_.RunUntilIdle(); |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 316 | EXPECT_EQ(initial_technology_updates + 3, |
| 317 | listener_->technology_list_updates()); |
[email protected] | b15f493 | 2013-04-15 21:09:25 | [diff] [blame] | 318 | EXPECT_TRUE(shill_property_handler_->IsTechnologyAvailable( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 319 | shill::kTypeWimax)); |
| 320 | EXPECT_FALSE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax)); |
[email protected] | b16d79d7 | 2013-02-07 08:14:46 | [diff] [blame] | 321 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 322 | // Enable the technology. |
| 323 | DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 324 | shill::kTypeWimax, |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 325 | base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 326 | message_loop_.RunUntilIdle(); |
[email protected] | e925cfd | 2013-09-13 18:38:37 | [diff] [blame] | 327 | EXPECT_EQ(initial_technology_updates + 4, |
| 328 | listener_->technology_list_updates()); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 329 | EXPECT_TRUE(shill_property_handler_->IsTechnologyEnabled(shill::kTypeWimax)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 330 | |
| 331 | EXPECT_EQ(0, listener_->errors()); |
| 332 | } |
| 333 | |
| 334 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 335 | EXPECT_EQ(1, listener_->list_updates(shill::kDevicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 336 | const size_t kNumShillManagerClientStubImplDevices = 2; |
| 337 | EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 338 | listener_->entries(shill::kDevicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 339 | // Add a device. |
| 340 | const std::string kTestDevicePath("test_wifi_device1"); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 341 | AddDevice(shill::kTypeWifi, kTestDevicePath); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 342 | message_loop_.RunUntilIdle(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 343 | EXPECT_EQ(2, listener_->list_updates(shill::kDevicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 344 | EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 345 | listener_->entries(shill::kDevicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 346 | // Device changes are not observed. |
| 347 | // Remove a device |
| 348 | RemoveDevice(kTestDevicePath); |
| 349 | message_loop_.RunUntilIdle(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 350 | EXPECT_EQ(3, listener_->list_updates(shill::kDevicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 351 | EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 352 | listener_->entries(shill::kDevicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 353 | |
| 354 | EXPECT_EQ(0, listener_->errors()); |
| 355 | } |
| 356 | |
| 357 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServicePropertyChanged) { |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 358 | EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 359 | const size_t kNumShillManagerClientStubImplServices = 4; |
| 360 | EXPECT_EQ(kNumShillManagerClientStubImplServices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 361 | listener_->entries(shill::kServicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 362 | |
| 363 | // Add an unwatched service. |
| 364 | const std::string kTestServicePath("test_wifi_service1"); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 365 | AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, false); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 366 | message_loop_.RunUntilIdle(); |
[email protected] | e36826d9 | 2013-05-14 17:23:11 | [diff] [blame] | 367 | // Watched and unwatched services trigger a service list update. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 368 | EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 369 | EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 370 | listener_->entries(shill::kServicesProperty).size()); |
[email protected] | e36826d9 | 2013-05-14 17:23:11 | [diff] [blame] | 371 | // Service receives an initial property update. |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 372 | EXPECT_EQ(1, listener_->initial_property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 373 | shill::kServicesProperty)[kTestServicePath]); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 374 | // Change a property. |
| 375 | base::FundamentalValue scan_interval(3); |
| 376 | DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 377 | dbus::ObjectPath(kTestServicePath), |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 378 | shill::kScanIntervalProperty, |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 379 | scan_interval, |
| 380 | base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 381 | message_loop_.RunUntilIdle(); |
[email protected] | e36826d9 | 2013-05-14 17:23:11 | [diff] [blame] | 382 | // Property change triggers an update. |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 383 | EXPECT_EQ(1, listener_->property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 384 | shill::kServicesProperty)[kTestServicePath]); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 385 | |
| 386 | // Add the existing service to the watch list. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 387 | AddService(shill::kTypeWifi, kTestServicePath, shill::kStateIdle, true); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 388 | message_loop_.RunUntilIdle(); |
[email protected] | fa6797e | 2012-11-28 15:15:44 | [diff] [blame] | 389 | // Service list update should be received when watch list changes. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 390 | EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | fa6797e | 2012-11-28 15:15:44 | [diff] [blame] | 391 | // Number of services shouldn't change. |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 392 | EXPECT_EQ(kNumShillManagerClientStubImplServices + 1, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 393 | listener_->entries(shill::kServicesProperty).size()); |
[email protected] | fa6797e | 2012-11-28 15:15:44 | [diff] [blame] | 394 | |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 395 | // Change a property. |
| 396 | DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 397 | dbus::ObjectPath(kTestServicePath), |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 398 | shill::kScanIntervalProperty, |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 399 | scan_interval, |
| 400 | base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 401 | message_loop_.RunUntilIdle(); |
[email protected] | fa6797e | 2012-11-28 15:15:44 | [diff] [blame] | 402 | // Property change should trigger another update. |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 403 | EXPECT_EQ(2, listener_->property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 404 | shill::kServicesProperty)[kTestServicePath]); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 405 | |
| 406 | // Remove a service |
| 407 | RemoveService(kTestServicePath); |
| 408 | message_loop_.RunUntilIdle(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 409 | EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 410 | EXPECT_EQ(kNumShillManagerClientStubImplServices, |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 411 | listener_->entries(shill::kServicesProperty).size()); |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 412 | |
| 413 | EXPECT_EQ(0, listener_->errors()); |
| 414 | } |
| 415 | |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 416 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerIPConfigPropertyChanged) { |
| 417 | // Set the properties for an IP Config object. |
| 418 | const std::string kTestIPConfigPath("test_ip_config_path"); |
[email protected] | a491f16 | 2013-07-12 17:12:25 | [diff] [blame] | 419 | |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 420 | base::StringValue ip_address("192.168.1.1"); |
| 421 | DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( |
| 422 | dbus::ObjectPath(kTestIPConfigPath), |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 423 | shill::kAddressProperty, ip_address, |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 424 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 430 | shill::kNameServersProperty, dns_servers, |
[email protected] | a491f16 | 2013-07-12 17:12:25 | [diff] [blame] | 431 | base::Bind(&DoNothingWithCallStatus)); |
| 432 | base::FundamentalValue prefixlen(8); |
| 433 | DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( |
| 434 | dbus::ObjectPath(kTestIPConfigPath), |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 435 | shill::kPrefixlenProperty, prefixlen, |
[email protected] | a491f16 | 2013-07-12 17:12:25 | [diff] [blame] | 436 | base::Bind(&DoNothingWithCallStatus)); |
| 437 | base::StringValue gateway("192.0.0.1"); |
| 438 | DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty( |
| 439 | dbus::ObjectPath(kTestIPConfigPath), |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 440 | shill::kGatewayProperty, gateway, |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 441 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 447 | AddService(shill::kTypeWifi, kTestServicePath1, shill::kStateIdle, true); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 448 | message_loop_.RunUntilIdle(); |
| 449 | // This is the initial property update. |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 450 | EXPECT_EQ(1, listener_->initial_property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 451 | shill::kServicesProperty)[kTestServicePath1]); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 452 | 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] | a491f16 | 2013-07-12 17:12:25 | [diff] [blame] | 459 | // IP Address, DNS, prefixlen, and gateway. |
| 460 | EXPECT_EQ(4, listener_->property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 461 | shill::kServicesProperty)[kTestServicePath1]); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 462 | |
| 463 | // Now, Add a new watched service with the IPConfig already set. |
| 464 | const std::string kTestServicePath2("test_wifi_service2"); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 465 | AddServiceWithIPConfig(shill::kTypeWifi, kTestServicePath2, |
| 466 | shill::kStateIdle, kTestIPConfigPath, true); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 467 | message_loop_.RunUntilIdle(); |
[email protected] | a491f16 | 2013-07-12 17:12:25 | [diff] [blame] | 468 | // 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 471 | shill::kServicesProperty)[kTestServicePath2]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerServiceCompleteList) { |
| 475 | // Initial list updates. |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 476 | EXPECT_EQ(1, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 477 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 483 | AddServiceToProfile(shill::kTypeWifi, kTestServicePath1, false); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 484 | shill_property_handler_->UpdateManagerProperties(); |
| 485 | message_loop_.RunUntilIdle(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 486 | EXPECT_EQ(2, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 487 | EXPECT_EQ(2, listener_->list_updates(shill::kServiceCompleteListProperty)); |
| 488 | EXPECT_EQ(0, listener_->initial_property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 489 | shill::kServicesProperty)[kTestServicePath1]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 490 | EXPECT_EQ(1, listener_->initial_property_updates( |
| 491 | shill::kServiceCompleteListProperty)[kTestServicePath1]); |
| 492 | EXPECT_EQ(0, listener_->property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 493 | shill::kServicesProperty)[kTestServicePath1]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 494 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 503 | AddServiceToProfile(shill::kTypeWifi, kTestServicePath2, true); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 504 | shill_property_handler_->UpdateManagerProperties(); |
| 505 | message_loop_.RunUntilIdle(); |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 506 | EXPECT_EQ(3, listener_->list_updates(shill::kServicesProperty)); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 507 | EXPECT_EQ(3, listener_->list_updates(shill::kServiceCompleteListProperty)); |
| 508 | EXPECT_EQ(1, listener_->initial_property_updates( |
[email protected] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 509 | shill::kServicesProperty)[kTestServicePath2]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 510 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 514 | shill::kServicesProperty)[kTestServicePath2]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 515 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 522 | shill::kScanIntervalProperty, |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 523 | 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] | 547396c5 | 2013-09-24 07:24:56 | [diff] [blame] | 529 | shill::kServicesProperty)[kTestServicePath2]); |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 530 | EXPECT_EQ(0, listener_->property_updates( |
| 531 | shill::kServiceCompleteListProperty)[kTestServicePath2]); |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 532 | } |
[email protected] | 3c8bd11 | 2012-11-07 10:14:59 | [diff] [blame] | 533 | |
| 534 | } // namespace chromeos |