Chromium Code Reviews| Index: chromeos/dbus/fake_shill_manager_client.cc |
| diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc |
| index d3ad56641aa07e74879092b1a6ad95559420655a..c6ec5bc837f88ef1cc1054add12d1f6213d1b394 100644 |
| --- a/chromeos/dbus/fake_shill_manager_client.cc |
| +++ b/chromeos/dbus/fake_shill_manager_client.cc |
| @@ -5,10 +5,13 @@ |
| #include "chromeos/dbus/fake_shill_manager_client.h" |
| #include "base/bind.h" |
| -#include "base/command_line.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_util.h" |
| #include "base/values.h" |
| #include "chromeos/chromeos_switches.h" |
| +#include "chromeos/dbus/dbus_command_line_helper.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/shill_device_client.h" |
| #include "chromeos/dbus/shill_profile_client.h" |
| @@ -73,17 +76,30 @@ void AppendServicesForType( |
| } |
| } |
| +void UpdatePortalledWifiState(const std::string& service_path) { |
| + DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() |
| + ->SetServiceProperty(service_path, |
| + shill::kStateProperty, |
| + base::StringValue(shill::kStatePortal)); |
| +} |
| + |
| } // namespace |
| FakeShillManagerClient::FakeShillManagerClient() |
| - : weak_ptr_factory_(this) { |
| + : interactive_delay_(0), |
| + weak_ptr_factory_(this) { |
| + ParseCommandLineSwitch(); |
| } |
| FakeShillManagerClient::~FakeShillManagerClient() {} |
| // ShillManagerClient overrides. |
| -void FakeShillManagerClient::Init(dbus::Bus* bus) {} |
| +void FakeShillManagerClient::Init(dbus::Bus* bus) { |
| + // Note: This will occur *before* Init() is called on Service/Device/Profile |
| + // clients. |
| + SetupDefaultEnvironment(); |
|
pneubeck (no reviews)
2014/02/28 09:37:59
IIRC, the idea at some time was that this DefaultE
stevenjb
2014/02/28 17:43:06
Anything that calls InitializeWithStub is going to
|
| +} |
| void FakeShillManagerClient::AddPropertyChangedObserver( |
| ShillPropertyChangedObserver* observer) { |
| @@ -118,7 +134,7 @@ void FakeShillManagerClient::SetProperty(const std::string& name, |
| const base::Closure& callback, |
| const ErrorCallback& error_callback) { |
| stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); |
| - CallNotifyObserversPropertyChanged(name, 0); |
| + CallNotifyObserversPropertyChanged(name); |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| } |
| @@ -133,21 +149,16 @@ void FakeShillManagerClient::RequestScan(const std::string& type, |
| DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| std::string device_path = device_client->GetDevicePathForType(device_type); |
| if (!device_path.empty()) { |
| - device_client->SetDeviceProperty(device_path, |
| - shill::kScanningProperty, |
| - base::FundamentalValue(true)); |
| - } |
| - const int kScanDurationSeconds = 3; |
| - int scan_duration_seconds = kScanDurationSeconds; |
| - if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableStubInteractive)) { |
| - scan_duration_seconds = 0; |
| + device_client->SetDeviceProperty( |
| + device_path, shill::kScanningProperty, base::FundamentalValue(true)); |
| } |
| base::MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&FakeShillManagerClient::ScanCompleted, |
| - weak_ptr_factory_.GetWeakPtr(), device_path, callback), |
| - base::TimeDelta::FromSeconds(scan_duration_seconds)); |
| + weak_ptr_factory_.GetWeakPtr(), |
| + device_path, |
| + callback), |
| + base::TimeDelta::FromSeconds(interactive_delay_)); |
| } |
| void FakeShillManagerClient::EnableTechnology( |
| @@ -156,21 +167,22 @@ void FakeShillManagerClient::EnableTechnology( |
| const ErrorCallback& error_callback) { |
| base::ListValue* enabled_list = NULL; |
| if (!stub_properties_.GetListWithoutPathExpansion( |
| - shill::kEnabledTechnologiesProperty, &enabled_list)) { |
| + shill::kEnabledTechnologiesProperty, &enabled_list)) { |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| base::MessageLoop::current()->PostTask( |
| FROM_HERE, |
| base::Bind(error_callback, "StubError", "Property not found")); |
| return; |
| } |
| - if (CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableStubInteractive)) { |
| - const int kEnableTechnologyDelaySeconds = 3; |
| + if (interactive_delay_) { |
| base::MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
| - weak_ptr_factory_.GetWeakPtr(), type, callback, true), |
| - base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); |
| + weak_ptr_factory_.GetWeakPtr(), |
| + type, |
| + callback, |
| + true), |
| + base::TimeDelta::FromSeconds(interactive_delay_)); |
| } else { |
| SetTechnologyEnabled(type, callback, true); |
| } |
| @@ -182,20 +194,21 @@ void FakeShillManagerClient::DisableTechnology( |
| const ErrorCallback& error_callback) { |
| base::ListValue* enabled_list = NULL; |
| if (!stub_properties_.GetListWithoutPathExpansion( |
| - shill::kEnabledTechnologiesProperty, &enabled_list)) { |
| + shill::kEnabledTechnologiesProperty, &enabled_list)) { |
| base::MessageLoop::current()->PostTask( |
| FROM_HERE, |
| base::Bind(error_callback, "StubError", "Property not found")); |
| return; |
| } |
| - if (CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableStubInteractive)) { |
| - const int kDisableTechnologyDelaySeconds = 3; |
| + if (interactive_delay_) { |
| base::MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
| - weak_ptr_factory_.GetWeakPtr(), type, callback, false), |
| - base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); |
| + weak_ptr_factory_.GetWeakPtr(), |
| + type, |
| + callback, |
| + false), |
| + base::TimeDelta::FromSeconds(interactive_delay_)); |
| } else { |
| SetTechnologyEnabled(type, callback, false); |
| } |
| @@ -306,8 +319,8 @@ void FakeShillManagerClient::VerifyAndEncryptData( |
| const std::string& data, |
| const StringCallback& callback, |
| const ErrorCallback& error_callback) { |
| - base::MessageLoop::current()->PostTask(FROM_HERE, |
| - base::Bind(callback, "encrypted_data")); |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(callback, "encrypted_data")); |
| } |
| void FakeShillManagerClient::ConnectToBestServices( |
| @@ -322,71 +335,87 @@ ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { |
| // ShillManagerClient::TestInterface overrides. |
| void FakeShillManagerClient::AddDevice(const std::string& device_path) { |
| - if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( |
| - base::Value::CreateStringValue(device_path))) { |
| - CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
| + if (GetListProperty(shill::kDevicesProperty) |
| + ->AppendIfNotPresent(base::Value::CreateStringValue(device_path))) { |
| + CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| } |
| } |
| void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { |
| base::StringValue device_path_value(device_path); |
| - if (GetListProperty(shill::kDevicesProperty)->Remove( |
| - device_path_value, NULL)) { |
| - CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
| + if (GetListProperty(shill::kDevicesProperty) |
| + ->Remove(device_path_value, NULL)) { |
| + CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| } |
| } |
| void FakeShillManagerClient::ClearDevices() { |
| GetListProperty(shill::kDevicesProperty)->Clear(); |
| - CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
| + CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| } |
| void FakeShillManagerClient::AddTechnology(const std::string& type, |
| bool enabled) { |
| - if (GetListProperty(shill::kAvailableTechnologiesProperty)-> |
| - AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| - CallNotifyObserversPropertyChanged( |
| - shill::kAvailableTechnologiesProperty, 0); |
| + if (GetListProperty(shill::kAvailableTechnologiesProperty) |
| + ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| + CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
| } |
| if (enabled && |
| - GetListProperty(shill::kEnabledTechnologiesProperty)-> |
| - AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| - CallNotifyObserversPropertyChanged( |
| - shill::kEnabledTechnologiesProperty, 0); |
| + GetListProperty(shill::kEnabledTechnologiesProperty) |
| + ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| + CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| } |
| } |
| void FakeShillManagerClient::RemoveTechnology(const std::string& type) { |
| base::StringValue type_value(type); |
| - if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( |
| - type_value, NULL)) { |
| - CallNotifyObserversPropertyChanged( |
| - shill::kAvailableTechnologiesProperty, 0); |
| + if (GetListProperty(shill::kAvailableTechnologiesProperty) |
| + ->Remove(type_value, NULL)) { |
| + CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
| } |
| - if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( |
| - type_value, NULL)) { |
| - CallNotifyObserversPropertyChanged( |
| - shill::kEnabledTechnologiesProperty, 0); |
| + if (GetListProperty(shill::kEnabledTechnologiesProperty) |
| + ->Remove(type_value, NULL)) { |
| + CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| } |
| } |
| void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, |
| bool initializing) { |
| if (initializing) { |
| - if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> |
| - AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| + if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
| + ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| CallNotifyObserversPropertyChanged( |
| - shill::kUninitializedTechnologiesProperty, 0); |
| + shill::kUninitializedTechnologiesProperty); |
| } |
| } else { |
| - if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( |
| - base::StringValue(type), NULL)) { |
| + if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
| + ->Remove(base::StringValue(type), NULL)) { |
| CallNotifyObserversPropertyChanged( |
| - shill::kUninitializedTechnologiesProperty, 0); |
| + shill::kUninitializedTechnologiesProperty); |
| } |
| } |
| } |
| +void FakeShillManagerClient::AddGeoNetwork( |
| + const std::string& technology, |
| + const base::DictionaryValue& network) { |
| + base::ListValue* list_value = NULL; |
| + if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, |
| + &list_value)) { |
| + list_value = new base::ListValue; |
| + stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
| + } |
| + list_value->Append(network.DeepCopy()); |
| +} |
| + |
| +void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
| + const char* key = shill::kProfilesProperty; |
| + if (GetListProperty(key) |
| + ->AppendIfNotPresent(new base::StringValue(profile_path))) { |
| + CallNotifyObserversPropertyChanged(key); |
| + } |
| +} |
| + |
| void FakeShillManagerClient::ClearProperties() { |
| stub_properties_.Clear(); |
| } |
| @@ -399,9 +428,9 @@ void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
| base::Value::CreateStringValue(service_path)); |
| // If visible, add to Services and notify if new. |
| if (add_to_visible_list && |
| - GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
| - base::Value::CreateStringValue(service_path))) { |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| + GetListProperty(shill::kServicesProperty) |
| + ->AppendIfNotPresent(base::Value::CreateStringValue(service_path))) { |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| } |
| if (add_to_watch_list) |
| AddServiceToWatchList(service_path); |
| @@ -410,16 +439,15 @@ void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
| void FakeShillManagerClient::RemoveManagerService( |
| const std::string& service_path) { |
| base::StringValue service_path_value(service_path); |
| - if (GetListProperty(shill::kServicesProperty)->Remove( |
| - service_path_value, NULL)) { |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| + if (GetListProperty(shill::kServicesProperty) |
| + ->Remove(service_path_value, NULL)) { |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| } |
| - GetListProperty(shill::kServiceCompleteListProperty)->Remove( |
| - service_path_value, NULL); |
| - if (GetListProperty(shill::kServiceWatchListProperty)->Remove( |
| - service_path_value, NULL)) { |
| - CallNotifyObserversPropertyChanged( |
| - shill::kServiceWatchListProperty, 0); |
| + GetListProperty(shill::kServiceCompleteListProperty) |
| + ->Remove(service_path_value, NULL); |
| + if (GetListProperty(shill::kServiceWatchListProperty) |
| + ->Remove(service_path_value, NULL)) { |
| + CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| } |
| } |
| @@ -427,8 +455,8 @@ void FakeShillManagerClient::ClearManagerServices() { |
| GetListProperty(shill::kServicesProperty)->Clear(); |
| GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
| GetListProperty(shill::kServiceWatchListProperty)->Clear(); |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| - CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| + CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| } |
| void FakeShillManagerClient::SortManagerServices() { |
| @@ -454,38 +482,33 @@ void FakeShillManagerClient::SortManagerServices() { |
| for (size_t i = 0; i < inactive_services.size(); ++i) |
| service_list->AppendString(inactive_services[i]); |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| } |
| -void FakeShillManagerClient::AddGeoNetwork( |
| - const std::string& technology, |
| - const base::DictionaryValue& network) { |
| - base::ListValue* list_value = NULL; |
| - if (!stub_geo_networks_.GetListWithoutPathExpansion( |
| - technology, &list_value)) { |
| - list_value = new base::ListValue; |
| - stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
| - } |
| - list_value->Append(network.DeepCopy()); |
| + |
| +int FakeShillManagerClient::GetInteractiveDelay() const { |
| + return interactive_delay_; |
| } |
| -void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
| - const char* key = shill::kProfilesProperty; |
| - if (GetListProperty(key)->AppendIfNotPresent( |
| - new base::StringValue(profile_path))) { |
| - CallNotifyObserversPropertyChanged(key, 0); |
| - } |
| +std::string FakeShillManagerClient::GetInitialState( |
| + const std::string& type) const { |
| + std::map<std::string, std::string>::const_iterator iter = |
| + shill_initial_state_map_.find(type); |
| + if (iter == shill_initial_state_map_.end()) |
| + return shill::kStateOffline; // Not available |
| + return iter->second; |
| } |
| +// Private methods |
| + |
| void FakeShillManagerClient::AddServiceToWatchList( |
| const std::string& service_path) { |
| // Remove and insert the service, moving it to the front of the watch list. |
| - GetListProperty(shill::kServiceWatchListProperty)->Remove( |
| - base::StringValue(service_path), NULL); |
| - GetListProperty(shill::kServiceWatchListProperty)->Insert( |
| - 0, base::Value::CreateStringValue(service_path)); |
| - CallNotifyObserversPropertyChanged( |
| - shill::kServiceWatchListProperty, 0); |
| + GetListProperty(shill::kServiceWatchListProperty) |
| + ->Remove(base::StringValue(service_path), NULL); |
| + GetListProperty(shill::kServiceWatchListProperty) |
| + ->Insert(0, base::Value::CreateStringValue(service_path)); |
| + CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| } |
| void FakeShillManagerClient::PassStubProperties( |
| @@ -508,22 +531,16 @@ void FakeShillManagerClient::PassStubGeoNetworks( |
| } |
| void FakeShillManagerClient::CallNotifyObserversPropertyChanged( |
| - const std::string& property, |
| - int delay_ms) { |
| + const std::string& property) { |
| // Avoid unnecessary delayed task if we have no observers (e.g. during |
| // initial setup). |
| if (!observer_list_.might_have_observers()) |
| return; |
| - if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableStubInteractive)) { |
| - delay_ms = 0; |
| - } |
| - base::MessageLoop::current()->PostDelayedTask( |
| + base::MessageLoop::current()->PostTask( |
| FROM_HERE, |
| base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, |
| weak_ptr_factory_.GetWeakPtr(), |
| - property), |
| - base::TimeDelta::FromMilliseconds(delay_ms)); |
| + property)); |
| } |
| void FakeShillManagerClient::NotifyObserversPropertyChanged( |
| @@ -593,12 +610,11 @@ void FakeShillManagerClient::SetTechnologyEnabled( |
| enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
| else |
| enabled_list->Remove(base::StringValue(type), NULL); |
| - CallNotifyObserversPropertyChanged( |
| - shill::kEnabledTechnologiesProperty, 0 /* already delayed */); |
| + CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| // May affect available services |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| - CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| + CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| } |
| base::ListValue* FakeShillManagerClient::GetEnabledServiceList( |
| @@ -638,9 +654,277 @@ void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
| shill::kScanningProperty, |
| base::FundamentalValue(false)); |
| } |
| - CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| - CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
| + CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| + CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| } |
| +void FakeShillManagerClient::ParseCommandLineSwitch() { |
| + if (dbus_command_line_helper::ParseOptions( |
| + switches::kShillStub, |
| + base::Bind(&FakeShillManagerClient::ParseOption, |
| + base::Unretained(this)))) |
| + return; |
| + // Default setup |
| + SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); |
| + SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); |
| + SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); |
| + SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); |
| +} |
| + |
| +bool FakeShillManagerClient::ParseOption(const std::string& arg0, |
| + const std::string& arg1) { |
| + if (arg0 == "interactive") { |
| + int seconds = 3; |
| + if (!arg1.empty()) |
| + base::StringToInt(arg1, &seconds); |
| + interactive_delay_ = seconds; |
| + return true; |
| + } |
| + return SetInitialNetworkState(arg0, arg1); |
| +} |
| + |
| +bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, |
| + std::string state_arg) { |
| + std::string state; |
| + state_arg = StringToLowerASCII(state_arg); |
| + if (state_arg == "0" || state_arg == "off" || state_arg == "inactive" || |
| + state_arg == shill::kStateIdle) |
| + state = shill::kStateIdle; // Enabled but not connected |
| + else if (state_arg == "disabled" || state_arg == "disconnect") |
| + state = shill::kStateDisconnect; // Diabled but available |
| + else if (state_arg == "none" || state_arg == "offline") |
| + state = shill::kStateOffline; // Not available |
| + else if (state_arg == "portal") |
| + state = shill::kStatePortal; // Connected to portal |
| + else if (state_arg == "active" || state_arg == "activated") |
| + state = shill::kActivationStateActivated; // Connected and activated |
| + else |
| + state = shill::kStateOnline; // Connected |
| + |
| + std::string type; |
| + type_arg = StringToLowerASCII(type_arg); |
| + if (type_arg == "ethernet" || type_arg == "eth") { |
| + if (state == shill::kStateIdle || state == shill::kStateDisconnect) |
| + state = shill::kStateOffline; // No unconnected or disabled ethernet. |
| + shill_initial_state_map_[shill::kTypeEthernet] = state; |
| + } else if (type_arg == "wifi") { |
| + shill_initial_state_map_[shill::kTypeWifi] = state; |
| + } else if (type_arg == "cellular") { |
| + shill_initial_state_map_[shill::kTypeCellular] = state; |
| + } else if (type_arg == "wireless") { |
| + shill_initial_state_map_[shill::kTypeWifi] = state; |
| + shill_initial_state_map_[shill::kTypeCellular] = state; |
| + } else if (type_arg == "wimax") { |
| + shill_initial_state_map_[shill::kTypeWimax] = state; |
| + } else if (type_arg == "vpn") { |
| + shill_initial_state_map_[shill::kTypeVPN] = state; |
| + } else { |
| + LOG(WARNING) << "Unrecognized Shill network type: " << type_arg; |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +void FakeShillManagerClient::SetupDefaultEnvironment() { |
| + DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
| + ShillServiceClient::TestInterface* services = |
| + dbus_manager->GetShillServiceClient()->GetTestInterface(); |
| + ShillProfileClient::TestInterface* profiles = |
| + dbus_manager->GetShillProfileClient()->GetTestInterface(); |
| + ShillDeviceClient::TestInterface* devices = |
| + dbus_manager->GetShillDeviceClient()->GetTestInterface(); |
| + if (!services || !profiles || !devices) |
| + return; |
| + |
| + const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); |
| + profiles->AddProfile(shared_profile, std::string()); |
| + |
| + const bool add_to_visible = true; |
| + const bool add_to_watchlist = true; |
| + |
| + bool enabled, portaled; |
| + std::string state; |
| + |
| + // Ethernet. No service is not added unless connected. |
| + state = ParseInitialState(shill::kTypeEthernet, &enabled, &portaled); |
| + if (state == shill::kStateOnline) { |
| + AddTechnology(shill::kTypeEthernet, enabled); |
| + devices->AddDevice( |
| + "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); |
| + services->AddService("eth1", "eth1", |
| + shill::kTypeEthernet, |
| + state, |
| + add_to_visible, add_to_watchlist); |
| + profiles->AddService(shared_profile, "eth1"); |
| + } |
| + |
| + // Wifi |
| + state = ParseInitialState(shill::kTypeWifi, &enabled, &portaled); |
| + if (state != shill::kStateOffline) { |
| + AddTechnology(shill::kTypeWifi, enabled); |
| + devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); |
| + |
| + services->AddService("wifi1", |
| + "wifi1", |
| + shill::kTypeWifi, |
| + state, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty("wifi1", |
| + shill::kSecurityProperty, |
| + base::StringValue(shill::kSecurityWep)); |
| + profiles->AddService(shared_profile, "wifi1"); |
| + |
| + services->AddService("wifi2", |
| + "wifi2_PSK", |
| + shill::kTypeWifi, |
| + shill::kStateIdle, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty("wifi2", |
| + shill::kSecurityProperty, |
| + base::StringValue(shill::kSecurityPsk)); |
| + |
| + base::FundamentalValue strength_value(80); |
| + services->SetServiceProperty( |
| + "wifi2", shill::kSignalStrengthProperty, strength_value); |
| + profiles->AddService(shared_profile, "wifi2"); |
| + |
| + if (portaled) { |
| + services->AddService("portalled_wifi", |
| + "Portalled Wifi", |
| + shill::kTypeWifi, |
| + shill::kStatePortal, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty("portalled_wifi", |
| + shill::kSecurityProperty, |
| + base::StringValue(shill::kSecurityNone)); |
| + services->SetConnectBehavior("portalled_wifi", |
| + base::Bind(&UpdatePortalledWifiState, |
| + "portalled_wifi")); |
| + services->SetServiceProperty("portalled_wifi", |
| + shill::kConnectableProperty, |
| + base::FundamentalValue(true)); |
| + profiles->AddService(shared_profile, "portalled_wifi"); |
| + } |
| + } |
| + |
| + // Wimax |
| + state = ParseInitialState(shill::kTypeWimax, &enabled, &portaled); |
| + if (state != shill::kStateOffline) { |
| + AddTechnology(shill::kTypeWimax, enabled); |
| + devices->AddDevice( |
| + "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
| + |
| + services->AddService("wimax1", |
| + "wimax1", |
| + shill::kTypeWimax, |
| + state, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty( |
| + "wimax1", shill::kConnectableProperty, base::FundamentalValue(true)); |
| + } |
| + |
| + // Cellular |
| + state = ParseInitialState(shill::kTypeCellular, &enabled, &portaled); |
| + if (state != shill::kStateOffline) { |
| + bool activated = false; |
| + if (state == shill::kActivationStateActivated) { |
| + activated = true; |
| + state = shill::kStateIdle; |
| + } |
| + AddTechnology(shill::kTypeCellular, enabled); |
| + devices->AddDevice( |
| + "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
| + devices->SetDeviceProperty("/device/cellular1", |
| + shill::kCarrierProperty, |
| + base::StringValue(shill::kCarrierSprint)); |
| + |
| + services->AddService("cellular1", |
| + "cellular1", |
| + shill::kTypeCellular, |
| + state, |
| + add_to_visible, add_to_watchlist); |
| + base::StringValue technology_value(shill::kNetworkTechnologyGsm); |
| + services->SetServiceProperty( |
| + "cellular1", shill::kNetworkTechnologyProperty, technology_value); |
| + |
| + if (activated) { |
| + services->SetServiceProperty( |
| + "cellular1", |
| + shill::kActivationStateProperty, |
| + base::StringValue(shill::kActivationStateActivated)); |
| + services->SetServiceProperty("cellular1", |
| + shill::kConnectableProperty, |
| + base::FundamentalValue(true)); |
| + } else { |
| + services->SetServiceProperty( |
| + "cellular1", |
| + shill::kActivationStateProperty, |
| + base::StringValue(shill::kActivationStateNotActivated)); |
| + } |
| + |
| + services->SetServiceProperty("cellular1", |
| + shill::kRoamingStateProperty, |
| + base::StringValue(shill::kRoamingStateHome)); |
| + } |
| + |
| + // VPN |
| + state = ParseInitialState(shill::kTypeVPN, &enabled, &portaled); |
| + if (state != shill::kStateOffline) { |
| + // Set the "Provider" dictionary properties. Note: when setting these in |
| + // Shill, "Provider.Type", etc keys are used, but when reading the values |
| + // "Provider" . "Type", etc keys are used. Here we are setting the values |
| + // that will be read (by the UI, tests, etc). |
| + base::DictionaryValue provider_properties; |
| + provider_properties.SetString(shill::kTypeProperty, |
| + shill::kProviderOpenVpn); |
| + provider_properties.SetString(shill::kHostProperty, "vpn_host"); |
| + |
| + services->AddService("vpn1", |
| + "vpn1", |
| + shill::kTypeVPN, |
| + state, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty( |
| + "vpn1", shill::kProviderProperty, provider_properties); |
| + profiles->AddService(shared_profile, "vpn1"); |
| + |
| + services->AddService("vpn2", |
| + "vpn2", |
| + shill::kTypeVPN, |
| + shill::kStateIdle, |
| + add_to_visible, add_to_watchlist); |
| + services->SetServiceProperty( |
| + "vpn2", shill::kProviderProperty, provider_properties); |
| + } |
| + |
| + SortManagerServices(); |
| +} |
| + |
| +std::string FakeShillManagerClient::ParseInitialState(const std::string& type, |
| + bool* enabled, |
| + bool* portaled) { |
| + std::string state = GetInitialState(type); |
| + if (state == shill::kStateDisconnect) { |
| + *enabled = false; |
| + *portaled = false; |
| + return shill::kStateIdle; |
| + } |
| + if (state == shill::kStatePortal) { |
| + if (type != shill::kTypeWifi) |
| + LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| + *enabled = true; |
| + *portaled = true; |
| + return shill::kStateIdle; |
| + } |
| + if (state == shill::kActivationStateActivated && |
| + type != shill::kTypeCellular) { |
| + LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| + state = shill::kStateIdle; |
| + } |
| + *enabled = true; |
| + *portaled = false; |
| + return state; |
| +} |
| + |
| } // namespace chromeos |