From 4b667c1bc4ade7722b443029637f9b5961e423cc Mon Sep 17 00:00:00 2001 From: "stevenjb@chromium.org" Date: Wed, 14 May 2014 22:05:33 +0000 Subject: Improve functionality of FakeShillProfileClient Note: The fake shill client behaviors are tested by the higher level tests that use them. They may be reaching a complexity level that merits explicit testing, but it's not clear whether or not that would actually be a win. These changes are being added to support https://codereview.chromium.org/275543005/. BUG=none R=pneubeck@chromium.org Review URL: https://codereview.chromium.org/284673004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270486 0039d316-1c4b-4281-b951-d872f2087c98 --- chromeos/dbus/fake_shill_service_client.cc | 67 ++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 7 deletions(-) (limited to 'chromeos/dbus/fake_shill_service_client.cc') diff --git a/chromeos/dbus/fake_shill_service_client.cc b/chromeos/dbus/fake_shill_service_client.cc index ef4ffe6..da3a810 100644 --- a/chromeos/dbus/fake_shill_service_client.cc +++ b/chromeos/dbus/fake_shill_service_client.cc @@ -13,6 +13,7 @@ #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_device_client.h" #include "chromeos/dbus/shill_manager_client.h" +#include "chromeos/dbus/shill_profile_client.h" #include "chromeos/dbus/shill_property_changed_observer.h" #include "chromeos/network/shill_property_util.h" #include "dbus/bus.h" @@ -309,12 +310,14 @@ void FakeShillServiceClient::AddService(const std::string& service_path, const std::string& state, bool add_to_visible_list, bool add_to_watch_list) { - AddServiceWithIPConfig(service_path, name, type, state, "", + AddServiceWithIPConfig(service_path, "" /* guid */, name, + type, state, "" /* ipconfig_path */, add_to_visible_list, add_to_watch_list); } void FakeShillServiceClient::AddServiceWithIPConfig( const std::string& service_path, + const std::string& guid, const std::string& name, const std::string& type, const std::string& state, @@ -330,27 +333,59 @@ void FakeShillServiceClient::AddServiceWithIPConfig( base::DictionaryValue* properties = GetModifiableServiceProperties(service_path, true); connect_behavior_.erase(service_path); + + std::string profile_path; + base::DictionaryValue profile_properties; + if (DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> + GetService(service_path, &profile_path, &profile_properties)) { + properties->SetWithoutPathExpansion( + shill::kProfileProperty, + new base::StringValue(profile_path)); + } + + // If |guid| is provided, set Service.GUID to that. Otherwise if a GUID is + // stored in a profile entry, use that. Otherwise leave it blank. Shill does + // not enforce a valid guid, we do that at the NetworkStateHandler layer. + std::string guid_to_set = guid; + if (guid_to_set.empty()) { + profile_properties.GetStringWithoutPathExpansion( + shill::kGuidProperty, &guid_to_set); + } + if (!guid_to_set.empty()) { + properties->SetWithoutPathExpansion(shill::kGuidProperty, + new base::StringValue(guid_to_set)); + } shill_property_util::SetSSID(name, properties); properties->SetWithoutPathExpansion( shill::kNameProperty, - base::Value::CreateStringValue(name)); + new base::StringValue(name)); properties->SetWithoutPathExpansion( shill::kDeviceProperty, - base::Value::CreateStringValue(device_path)); + new base::StringValue(device_path)); properties->SetWithoutPathExpansion( shill::kTypeProperty, - base::Value::CreateStringValue(type)); + new base::StringValue(type)); properties->SetWithoutPathExpansion( shill::kStateProperty, - base::Value::CreateStringValue(state)); + new base::StringValue(state)); if (!ipconfig_path.empty()) { properties->SetWithoutPathExpansion( shill::kIPConfigProperty, - base::Value::CreateStringValue(ipconfig_path)); + new base::StringValue(ipconfig_path)); + } + if (type == shill::kTypeWifi) { + properties->SetWithoutPathExpansion( + shill::kSecurityProperty, + new base::StringValue(shill::kSecurityNone)); } DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> SortManagerServices(); + + if (!profile_path.empty()) { + DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> + UpdateService(profile_path, service_path); + } } void FakeShillServiceClient::RemoveService(const std::string& service_path) { @@ -390,6 +425,24 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path, dict->MergeDictionary(&new_properties); + // Add or update the profile entry. + if (property == shill::kProfileProperty) { + std::string profile_path; + if (value.GetAsString(&profile_path)) { + DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> + AddService(profile_path, service_path); + } else { + LOG(ERROR) << "Profile value is not a String!"; + } + } else { + std::string profile_path; + if (dict->GetStringWithoutPathExpansion( + shill::kProfileProperty, &profile_path) && !profile_path.empty()) { + DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> + UpdateService(profile_path, service_path); + } + } + // Notify the Manager if the state changed (affects DefaultService). if (property == shill::kStateProperty) { std::string state; @@ -503,7 +556,7 @@ void FakeShillServiceClient::SetOtherServicesOffline( continue; properties->SetWithoutPathExpansion( shill::kStateProperty, - base::Value::CreateStringValue(shill::kStateIdle)); + new base::StringValue(shill::kStateIdle)); } } -- cgit v1.1