diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 18:40:02 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 18:40:02 +0000 |
commit | 54287eca61baef29d064fc87987b9f7202ef433b (patch) | |
tree | 8c73a3542e65cb5f202ad6e834553e454b9381c6 /chromeos | |
parent | f6f42607f926da1bb0534e6384260ebb23fce008 (diff) | |
download | chromium_src-54287eca61baef29d064fc87987b9f7202ef433b.zip chromium_src-54287eca61baef29d064fc87987b9f7202ef433b.tar.gz chromium_src-54287eca61baef29d064fc87987b9f7202ef433b.tar.bz2 |
Refactor the setup of Shill*Stubs' default environment.
This change untangles some of the Shill*Stubs' implementation from the setup of a default network environment. In particular the setup function has now access to all Shill*Stubs during this setup.
This also correctly adds stub networks with status 'online' to a profile, so that the respective FavoriteState is created.
BUG=126870
R=stevenjb@chromium.org
Review URL: https://codereview.chromium.org/24150004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/chromeos.gyp | 2 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.cc | 26 | ||||
-rw-r--r-- | chromeos/dbus/shill_device_client_stub.cc | 21 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client_stub.cc | 16 | ||||
-rw-r--r-- | chromeos/dbus/shill_profile_client_stub.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/shill_profile_client_stub.h | 2 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client.h | 7 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client_stub.cc | 214 | ||||
-rw-r--r-- | chromeos/dbus/shill_service_client_stub.h | 18 | ||||
-rw-r--r-- | chromeos/dbus/shill_stub_helper.cc | 198 | ||||
-rw-r--r-- | chromeos/dbus/shill_stub_helper.h | 28 | ||||
-rw-r--r-- | chromeos/network/network_configuration_handler_unittest.cc | 6 |
12 files changed, 317 insertions, 225 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 0d6f689..3dc7a82 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -137,6 +137,8 @@ 'dbus/shill_service_client.h', 'dbus/shill_service_client_stub.cc', 'dbus/shill_service_client_stub.h', + 'dbus/shill_stub_helper.cc', + 'dbus/shill_stub_helper.h', 'dbus/ibus/ibus_client.cc', 'dbus/ibus/ibus_client.h', 'dbus/ibus/ibus_component.cc', diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index 09313ef..2dbe58d 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -23,12 +23,6 @@ #include "chromeos/dbus/dbus_thread_manager_observer.h" #include "chromeos/dbus/debug_daemon_client.h" #include "chromeos/dbus/gsm_sms_client.h" -#include "chromeos/dbus/shill_device_client.h" -#include "chromeos/dbus/shill_ipconfig_client.h" -#include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/dbus/shill_profile_client.h" -#include "chromeos/dbus/shill_service_client.h" -#include "chromeos/dbus/system_clock_client.h" #include "chromeos/dbus/ibus/ibus_client.h" #include "chromeos/dbus/ibus/ibus_engine_factory_service.h" #include "chromeos/dbus/ibus/ibus_engine_service.h" @@ -40,7 +34,14 @@ #include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_policy_controller.h" #include "chromeos/dbus/session_manager_client.h" +#include "chromeos/dbus/shill_device_client.h" +#include "chromeos/dbus/shill_ipconfig_client.h" +#include "chromeos/dbus/shill_manager_client.h" +#include "chromeos/dbus/shill_profile_client.h" +#include "chromeos/dbus/shill_service_client.h" +#include "chromeos/dbus/shill_stub_helper.h" #include "chromeos/dbus/sms_client.h" +#include "chromeos/dbus/system_clock_client.h" #include "chromeos/dbus/update_engine_client.h" #include "dbus/bus.h" #include "dbus/dbus_statistics.h" @@ -92,23 +93,12 @@ class DBusThreadManagerImpl : public DBusThreadManager { InitClient(cros_disks_client_.get()); InitClient(cryptohome_client_.get()); InitClient(debug_daemon_client_.get()); - - // Initialization order of the Stub implementations of the Shill clients - // matters; stub clients may only have initialization dependencies on - // clients previously initialized. InitClient(shill_manager_client_.get()); InitClient(shill_device_client_.get()); InitClient(shill_ipconfig_client_.get()); InitClient(shill_service_client_.get()); InitClient(shill_profile_client_.get()); InitClient(gsm_sms_client_.get()); - - // If the Service client has a TestInterface, add the default services. - ShillServiceClient::TestInterface* service_client_test = - DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); - if (service_client_test) - service_client_test->AddDefaultServices(); - InitClient(image_burner_client_.get()); InitClient(introspectable_client_.get()); InitClient(modem_messaging_client_.get()); @@ -124,6 +114,8 @@ class DBusThreadManagerImpl : public DBusThreadManager { power_policy_controller_.reset( new PowerPolicyController(this, power_manager_client_.get())); + shill_stub_helper::SetupDefaultEnvironment(); + // This must be called after the list of clients so they've each had a // chance to register with their object managers. system_bus_->GetManagedObjects(); diff --git a/chromeos/dbus/shill_device_client_stub.cc b/chromeos/dbus/shill_device_client_stub.cc index a32febd..c58ed23 100644 --- a/chromeos/dbus/shill_device_client_stub.cc +++ b/chromeos/dbus/shill_device_client_stub.cc @@ -39,9 +39,7 @@ ShillDeviceClientStub::~ShillDeviceClientStub() { // ShillDeviceClient overrides. -void ShillDeviceClientStub::Init(dbus::Bus* bus) { - SetDefaultProperties(); -} +void ShillDeviceClientStub::Init(dbus::Bus* bus) {} void ShillDeviceClientStub::AddPropertyChangedObserver( const dbus::ObjectPath& device_path, @@ -234,23 +232,6 @@ std::string ShillDeviceClientStub::GetDevicePathForType( return std::string(); } -void ShillDeviceClientStub::SetDefaultProperties() { - // Add a wifi device. - AddDevice("stub_wifi_device1", flimflam::kTypeWifi, "/device/wifi1"); - - // Add a cellular device. Used in SMS stub. - AddDevice("stub_cellular_device1", flimflam::kTypeCellular, - "/device/cellular1"); - base::DictionaryValue* properties = - GetDeviceProperties("stub_cellular_device1"); - properties->SetStringWithoutPathExpansion(flimflam::kCarrierProperty, - shill::kCarrierSprint); - - // Add a wimax device. - AddDevice("stub_wimax_device1", flimflam::kTypeWimax, - "/device/wimax1"); -} - void ShillDeviceClientStub::PassStubDeviceProperties( const dbus::ObjectPath& device_path, const DictionaryValueCallback& callback) const { diff --git a/chromeos/dbus/shill_manager_client_stub.cc b/chromeos/dbus/shill_manager_client_stub.cc index 0614874..cd368df 100644 --- a/chromeos/dbus/shill_manager_client_stub.cc +++ b/chromeos/dbus/shill_manager_client_stub.cc @@ -17,7 +17,6 @@ #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" -#include "dbus/object_proxy.h" #include "dbus/values_util.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -84,9 +83,7 @@ ShillManagerClientStub::~ShillManagerClientStub() {} // ShillManagerClient overrides. -void ShillManagerClientStub::Init(dbus::Bus* bus) { - SetDefaultProperties(); -} +void ShillManagerClientStub::Init(dbus::Bus* bus) {} void ShillManagerClientStub::AddPropertyChangedObserver( ShillPropertyChangedObserver* observer) { @@ -491,17 +488,6 @@ void ShillManagerClientStub::AddServiceToWatchList( flimflam::kServiceWatchListProperty, 0); } -void ShillManagerClientStub::SetDefaultProperties() { - // Stub Technologies. - if (!CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kDisableStubEthernet)) { - AddTechnology(flimflam::kTypeEthernet, true); - } - AddTechnology(flimflam::kTypeWifi, true); - AddTechnology(flimflam::kTypeCellular, true); - AddTechnology(flimflam::kTypeWimax, true); -} - void ShillManagerClientStub::PassStubProperties( const DictionaryValueCallback& callback) const { scoped_ptr<base::DictionaryValue> stub_properties( diff --git a/chromeos/dbus/shill_profile_client_stub.cc b/chromeos/dbus/shill_profile_client_stub.cc index cfa97b7..2f6d431 100644 --- a/chromeos/dbus/shill_profile_client_stub.cc +++ b/chromeos/dbus/shill_profile_client_stub.cc @@ -36,9 +36,6 @@ void PassDictionary( } // namespace -// static -const char ShillProfileClientStub::kSharedProfilePath[] = "/profile/default"; - ShillProfileClientStub::ShillProfileClientStub() { } @@ -47,7 +44,6 @@ ShillProfileClientStub::~ShillProfileClientStub() { } void ShillProfileClientStub::Init(dbus::Bus* bus) { - AddProfile(kSharedProfilePath, std::string()); } void ShillProfileClientStub::AddPropertyChangedObserver( diff --git a/chromeos/dbus/shill_profile_client_stub.h b/chromeos/dbus/shill_profile_client_stub.h index 63a8912..9230491 100644 --- a/chromeos/dbus/shill_profile_client_stub.h +++ b/chromeos/dbus/shill_profile_client_stub.h @@ -53,8 +53,6 @@ class ShillProfileClientStub : public ShillProfileClient, const std::string& service_path) OVERRIDE; virtual void GetProfilePaths(std::vector<std::string>* profiles) OVERRIDE; - static const char kSharedProfilePath[]; - private: struct ProfileProperties; typedef std::map<std::string, ProfileProperties*> ProfileMap; diff --git a/chromeos/dbus/shill_service_client.h b/chromeos/dbus/shill_service_client.h index 64f2557..8e75baf 100644 --- a/chromeos/dbus/shill_service_client.h +++ b/chromeos/dbus/shill_service_client.h @@ -44,10 +44,6 @@ class CHROMEOS_EXPORT ShillServiceClient : public DBusClient { // GetTestInterface(), only implemented in the stub implementation. class TestInterface { public: - // Adds a set of default services. Must be called after all Shill - // clients have been created. - virtual void AddDefaultServices() = 0; - // Adds a Service to the Manager and Service stubs. virtual void AddService(const std::string& service_path, const std::string& name, @@ -78,6 +74,9 @@ class CHROMEOS_EXPORT ShillServiceClient : public DBusClient { // Clears all Services from the Manager and Service stubs. virtual void ClearServices() = 0; + virtual void SetConnectBehavior(const std::string& service_path, + const base::Closure& behavior) = 0; + protected: virtual ~TestInterface() {} }; diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc index 930f935b..25ab4de 100644 --- a/chromeos/dbus/shill_service_client_stub.cc +++ b/chromeos/dbus/shill_service_client_stub.cc @@ -5,6 +5,7 @@ #include "chromeos/dbus/shill_service_client_stub.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "base/stl_util.h" @@ -13,20 +14,16 @@ #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/dbus/shill_profile_client_stub.h" #include "chromeos/dbus/shill_property_changed_observer.h" #include "dbus/bus.h" #include "dbus/message.h" -#include "dbus/object_proxy.h" +#include "dbus/object_path.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { namespace { -const char kStubPortalledWifiPath[] = "portalled_wifi"; -const char kStubPortalledWifiName[] = "Portalled Wifi"; - void ErrorFunction(const std::string& error_name, const std::string& error_message) { LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; @@ -54,15 +51,6 @@ ShillServiceClientStub::~ShillServiceClientStub() { observer_list_.begin(), observer_list_.end()); } -// static -bool ShillServiceClientStub::IsStubPortalledWifiEnabled( - const std::string& path) { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableStubPortalledWifi)) { - return false; - } - return path == kStubPortalledWifiPath; -} // ShillServiceClient overrides. @@ -182,7 +170,7 @@ void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, const base::Closure& callback, const ErrorCallback& error_callback) { VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); - base::DictionaryValue* service_properties; + base::DictionaryValue* service_properties = NULL; if (!stub_services_.GetDictionary( service_path.value(), &service_properties)) { LOG(ERROR) << "Service not found: " << service_path.value(); @@ -201,45 +189,21 @@ void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, flimflam::kStateProperty, associating_value); - // Set Online after a delay. + // Stay Associating until the state is changed again after a delay. base::TimeDelta delay; if (CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kEnableStubInteractive)) { const int kConnectDelaySeconds = 5; delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); } - base::StringValue online_value(flimflam::kStateOnline); - if (service_path.value() == kStubPortalledWifiPath) - online_value = base::StringValue(flimflam::kStatePortal); - std::string passphrase; - service_properties->GetStringWithoutPathExpansion( - flimflam::kPassphraseProperty, &passphrase); - if (passphrase == "failure") - online_value = base::StringValue(flimflam::kStateFailure); base::MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&ShillServiceClientStub::SetProperty, + base::Bind(&ShillServiceClientStub::ContinueConnect, weak_ptr_factory_.GetWeakPtr(), - service_path, - flimflam::kStateProperty, - online_value, - base::Bind(&base::DoNothing), - error_callback), + service_path.value()), delay); + callback.Run(); - // On failure, also set the Error property. - if (passphrase == "failure") { - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&ShillServiceClientStub::SetProperty, - weak_ptr_factory_.GetWeakPtr(), - service_path, - flimflam::kErrorProperty, - base::StringValue(flimflam::kErrorBadPassphrase), - base::Bind(&base::DoNothing), - error_callback), - delay); - } } void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, @@ -283,7 +247,7 @@ void ShillServiceClientStub::ActivateCellularModem( const base::Closure& callback, const ErrorCallback& error_callback) { base::DictionaryValue* service_properties = - GetModifiableServiceProperties(service_path.value()); + GetModifiableServiceProperties(service_path.value(), false); if (!service_properties) { LOG(ERROR) << "Service not found: " << service_path.value(); error_callback.Run("Error.InvalidService", "Invalid Service"); @@ -324,7 +288,7 @@ void ShillServiceClientStub::GetLoadableProfileEntries( scoped_ptr<base::DictionaryValue> result_properties( new base::DictionaryValue); base::DictionaryValue* service_properties = - GetModifiableServiceProperties(service_path.value()); + GetModifiableServiceProperties(service_path.value(), false); if (service_properties) { std::string profile_path; if (service_properties->GetStringWithoutPathExpansion( @@ -378,7 +342,8 @@ void ShillServiceClientStub::AddServiceWithIPConfig( AddManagerService(service_path, add_to_visible_list, add_to_watch_list); base::DictionaryValue* properties = - GetModifiableServiceProperties(service_path); + GetModifiableServiceProperties(service_path, true); + connect_behavior_.erase(service_path); properties->SetWithoutPathExpansion( flimflam::kSSIDProperty, base::Value::CreateStringValue(service_path)); @@ -402,6 +367,7 @@ void ShillServiceClientStub::RemoveService(const std::string& service_path) { RemoveManagerService(service_path); stub_services_.RemoveWithoutPathExpansion(service_path, NULL); + connect_behavior_.erase(service_path); } bool ShillServiceClientStub::SetServiceProperty(const std::string& service_path, @@ -460,112 +426,12 @@ void ShillServiceClientStub::ClearServices() { ClearManagerServices(); stub_services_.Clear(); + connect_behavior_.clear(); } -void ShillServiceClientStub::AddDefaultServices() { - const bool add_to_visible = true; - const bool add_to_watchlist = true; - - if (!CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kDisableStubEthernet)) { - AddService("eth1", "eth1", - flimflam::kTypeEthernet, - flimflam::kStateOnline, - add_to_visible, add_to_watchlist); - } - - // Wifi - - AddService("wifi1", "wifi1", - flimflam::kTypeWifi, - flimflam::kStateOnline, - add_to_visible, add_to_watchlist); - SetServiceProperty("wifi1", - flimflam::kSecurityProperty, - base::StringValue(flimflam::kSecurityWep)); - - AddService("wifi2", "wifi2_PSK", - flimflam::kTypeWifi, - flimflam::kStateIdle, - add_to_visible, add_to_watchlist); - SetServiceProperty("wifi2", - flimflam::kSecurityProperty, - base::StringValue(flimflam::kSecurityPsk)); - base::FundamentalValue strength_value(80); - SetServiceProperty("wifi2", - flimflam::kSignalStrengthProperty, - strength_value); - - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableStubPortalledWifi)) { - AddService(kStubPortalledWifiPath, kStubPortalledWifiName, - flimflam::kTypeWifi, - flimflam::kStatePortal, - add_to_visible, add_to_watchlist); - SetServiceProperty(kStubPortalledWifiPath, - flimflam::kSecurityProperty, - base::StringValue(flimflam::kSecurityNone)); - } - - // Wimax - - AddService("wimax1", "wimax1", - flimflam::kTypeWimax, - flimflam::kStateIdle, - add_to_visible, add_to_watchlist); - SetServiceProperty("wimax1", - flimflam::kConnectableProperty, - base::FundamentalValue(true)); - - // Cellular - - AddService("cellular1", "cellular1", - flimflam::kTypeCellular, - flimflam::kStateIdle, - add_to_visible, add_to_watchlist); - base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); - SetServiceProperty("cellular1", - flimflam::kNetworkTechnologyProperty, - technology_value); - SetServiceProperty("cellular1", - flimflam::kActivationStateProperty, - base::StringValue(flimflam::kActivationStateNotActivated)); - SetServiceProperty("cellular1", - flimflam::kRoamingStateProperty, - base::StringValue(flimflam::kRoamingStateHome)); - - // VPN - - // 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(flimflam::kTypeProperty, - flimflam::kProviderOpenVpn); - provider_properties.SetString(flimflam::kHostProperty, "vpn_host"); - - AddService("vpn1", "vpn1", - flimflam::kTypeVPN, - flimflam::kStateOnline, - add_to_visible, add_to_watchlist); - SetServiceProperty("vpn1", - flimflam::kProviderProperty, - provider_properties); - - AddService("vpn2", "vpn2", - flimflam::kTypeVPN, - flimflam::kStateOffline, - add_to_visible, add_to_watchlist); - SetServiceProperty("vpn2", - flimflam::kProviderProperty, - provider_properties); - - DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> - AddService(ShillProfileClientStub::kSharedProfilePath, "wifi2"); - - DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> - SortManagerServices(); +void ShillServiceClientStub::SetConnectBehavior(const std::string& service_path, + const base::Closure& behavior) { + connect_behavior_[service_path] = behavior; } void ShillServiceClientStub::NotifyObserversPropertyChanged( @@ -589,10 +455,11 @@ void ShillServiceClientStub::NotifyObserversPropertyChanged( } base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties( - const std::string& service_path) { + const std::string& service_path, bool create_if_missing) { base::DictionaryValue* properties = NULL; - if (!stub_services_.GetDictionaryWithoutPathExpansion( - service_path, &properties)) { + if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, + &properties) && + create_if_missing) { properties = new base::DictionaryValue; stub_services_.Set(service_path, properties); } @@ -655,4 +522,45 @@ void ShillServiceClientStub::SetCellularActivated( error_callback); } +void ShillServiceClientStub::ContinueConnect( + const std::string& service_path) { + VLOG(1) << "ShillServiceClientStub::ContinueConnect: " << service_path; + base::DictionaryValue* service_properties = NULL; + if (!stub_services_.GetDictionary(service_path, &service_properties)) { + LOG(ERROR) << "Service not found: " << service_path; + return; + } + + if (ContainsKey(connect_behavior_, service_path)) { + const base::Closure& custom_connect_behavior = + connect_behavior_[service_path]; + custom_connect_behavior.Run(); + return; + } + + // No custom connect behavior set, continue with the default connect behavior. + std::string passphrase; + service_properties->GetStringWithoutPathExpansion( + flimflam::kPassphraseProperty, &passphrase); + if (passphrase == "failure") { + // Simulate a password failure. + SetServiceProperty(service_path, + flimflam::kStateProperty, + base::StringValue(flimflam::kStateFailure)); + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind( + base::IgnoreResult(&ShillServiceClientStub::SetServiceProperty), + weak_ptr_factory_.GetWeakPtr(), + service_path, + flimflam::kErrorProperty, + base::StringValue(flimflam::kErrorBadPassphrase))); + } else { + // Set Online. + SetServiceProperty(service_path, + flimflam::kStateProperty, + base::StringValue(flimflam::kStateOnline)); + } +} + } // namespace chromeos diff --git a/chromeos/dbus/shill_service_client_stub.h b/chromeos/dbus/shill_service_client_stub.h index f2fb91c..810a8ea 100644 --- a/chromeos/dbus/shill_service_client_stub.h +++ b/chromeos/dbus/shill_service_client_stub.h @@ -24,11 +24,6 @@ class ShillServiceClientStub : public ShillServiceClient, ShillServiceClientStub(); virtual ~ShillServiceClientStub(); - // Returns true when stub portalled wifi is enabled and it's service - // path equals to |path|. - CHROMEOS_EXPORT static bool IsStubPortalledWifiEnabled( - const std::string& path); - // ShillServiceClient overrides virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( @@ -80,7 +75,6 @@ class ShillServiceClientStub : public ShillServiceClient, virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE; // ShillServiceClient::TestInterface overrides. - virtual void AddDefaultServices() OVERRIDE; virtual void AddService(const std::string& service_path, const std::string& name, const std::string& type, @@ -101,6 +95,8 @@ class ShillServiceClientStub : public ShillServiceClient, virtual const base::DictionaryValue* GetServiceProperties( const std::string& service_path) const OVERRIDE; virtual void ClearServices() OVERRIDE; + virtual void SetConnectBehavior(const std::string& service_path, + const base::Closure& behavior) OVERRIDE; private: typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; @@ -108,13 +104,21 @@ class ShillServiceClientStub : public ShillServiceClient, void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, const std::string& property); base::DictionaryValue* GetModifiableServiceProperties( - const std::string& service_path); + const std::string& service_path, + bool create_if_missing); PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); void SetOtherServicesOffline(const std::string& service_path); void SetCellularActivated(const dbus::ObjectPath& service_path, const ErrorCallback& error_callback); + void ContinueConnect(const std::string& service_path); base::DictionaryValue stub_services_; + + // Per network service, stores a closure that is executed on each connection + // attempt. The callback can for example modify the services properties in + // order to simulate a connection failure. + std::map<std::string, base::Closure> connect_behavior_; + // Observer list for each service. std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; diff --git a/chromeos/dbus/shill_stub_helper.cc b/chromeos/dbus/shill_stub_helper.cc new file mode 100644 index 0000000..1cbc655 --- /dev/null +++ b/chromeos/dbus/shill_stub_helper.cc @@ -0,0 +1,198 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromeos/dbus/shill_stub_helper.h" + +#include "base/bind.h" +#include "base/command_line.h" +#include "chromeos/chromeos_switches.h" +#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_profile_client_stub.h" +#include "chromeos/dbus/shill_service_client.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { +namespace shill_stub_helper { + +namespace { + +const char kStubPortalledWifiName[] = "Portalled Wifi"; +const char kStubPortalledWifiPath[] = "portalled_wifi"; + +void UpdatePortalledWifiState() { + ShillServiceClient::TestInterface* services = + DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); + + services->SetServiceProperty(kStubPortalledWifiPath, + flimflam::kStateProperty, + base::StringValue(flimflam::kStatePortal)); +} + +} // namespace + +const char kSharedProfilePath[] = "/profile/default"; + +bool IsStubPortalledWifiEnabled(const std::string& path) { + if (!CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kEnableStubPortalledWifi)) { + return false; + } + return path == kStubPortalledWifiPath; +} + +void SetupDefaultEnvironment() { + ShillServiceClient::TestInterface* services = + DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); + ShillProfileClient::TestInterface* profiles = + DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); + ShillManagerClient::TestInterface* manager = + DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); + ShillDeviceClient::TestInterface* devices = + DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); + if (!services || !profiles || !manager | !devices) + return; + + // Stub Technologies. + if (!CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kDisableStubEthernet)) { + manager->AddTechnology(flimflam::kTypeEthernet, true); + } + manager->AddTechnology(flimflam::kTypeWifi, true); + manager->AddTechnology(flimflam::kTypeCellular, true); + manager->AddTechnology(flimflam::kTypeWimax, true); + + profiles->AddProfile(kSharedProfilePath, std::string()); + + // Add a wifi device. + devices->AddDevice("stub_wifi_device1", flimflam::kTypeWifi, "/device/wifi1"); + + // Add a cellular device. Used in SMS stub. + devices->AddDevice( + "stub_cellular_device1", flimflam::kTypeCellular, "/device/cellular1"); + devices->SetDeviceProperty("stub_cellular_device1", + flimflam::kCarrierProperty, + base::StringValue(shill::kCarrierSprint)); + + // Add a wimax device. + devices->AddDevice( + "stub_wimax_device1", flimflam::kTypeWimax, "/device/wimax1"); + + const bool add_to_visible = true; + const bool add_to_watchlist = true; + + if (!CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kDisableStubEthernet)) { + services->AddService("eth1", "eth1", + flimflam::kTypeEthernet, + flimflam::kStateOnline, + add_to_visible, add_to_watchlist); + profiles->AddService(kSharedProfilePath, "eth1"); + } + + // Wifi + + services->AddService("wifi1", + "wifi1", + flimflam::kTypeWifi, + flimflam::kStateOnline, + add_to_visible, add_to_watchlist); + services->SetServiceProperty("wifi1", + flimflam::kSecurityProperty, + base::StringValue(flimflam::kSecurityWep)); + profiles->AddService(kSharedProfilePath, "wifi1"); + + services->AddService("wifi2", + "wifi2_PSK", + flimflam::kTypeWifi, + flimflam::kStateIdle, + add_to_visible, add_to_watchlist); + services->SetServiceProperty("wifi2", + flimflam::kSecurityProperty, + base::StringValue(flimflam::kSecurityPsk)); + base::FundamentalValue strength_value(80); + services->SetServiceProperty( + "wifi2", flimflam::kSignalStrengthProperty, strength_value); + profiles->AddService(kSharedProfilePath, "wifi2"); + + if (CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kEnableStubPortalledWifi)) { + services->AddService(kStubPortalledWifiPath, + kStubPortalledWifiName, + flimflam::kTypeWifi, + flimflam::kStatePortal, + add_to_visible, add_to_watchlist); + services->SetServiceProperty(kStubPortalledWifiPath, + flimflam::kSecurityProperty, + base::StringValue(flimflam::kSecurityNone)); + services->SetConnectBehavior(kStubPortalledWifiPath, + base::Bind(&UpdatePortalledWifiState)); + services->SetServiceProperty(kStubPortalledWifiPath, + flimflam::kConnectableProperty, + base::FundamentalValue(true)); + } + + // Wimax + + services->AddService("wimax1", + "wimax1", + flimflam::kTypeWimax, + flimflam::kStateIdle, + add_to_visible, add_to_watchlist); + services->SetServiceProperty( + "wimax1", flimflam::kConnectableProperty, base::FundamentalValue(true)); + + // Cellular + + services->AddService("cellular1", + "cellular1", + flimflam::kTypeCellular, + flimflam::kStateIdle, + add_to_visible, add_to_watchlist); + base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); + services->SetServiceProperty( + "cellular1", flimflam::kNetworkTechnologyProperty, technology_value); + services->SetServiceProperty( + "cellular1", + flimflam::kActivationStateProperty, + base::StringValue(flimflam::kActivationStateNotActivated)); + services->SetServiceProperty("cellular1", + flimflam::kRoamingStateProperty, + base::StringValue(flimflam::kRoamingStateHome)); + + // VPN + + // 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(flimflam::kTypeProperty, + flimflam::kProviderOpenVpn); + provider_properties.SetString(flimflam::kHostProperty, "vpn_host"); + + services->AddService("vpn1", + "vpn1", + flimflam::kTypeVPN, + flimflam::kStateOnline, + add_to_visible, add_to_watchlist); + services->SetServiceProperty( + "vpn1", flimflam::kProviderProperty, provider_properties); + profiles->AddService(kSharedProfilePath, "vpn1"); + + services->AddService("vpn2", + "vpn2", + flimflam::kTypeVPN, + flimflam::kStateOffline, + add_to_visible, add_to_watchlist); + services->SetServiceProperty( + "vpn2", flimflam::kProviderProperty, provider_properties); + + manager->SortManagerServices(); +} + +} // namespace shill_stub_helper +} // namespace chromeos diff --git a/chromeos/dbus/shill_stub_helper.h b/chromeos/dbus/shill_stub_helper.h new file mode 100644 index 0000000..16c7031 --- /dev/null +++ b/chromeos/dbus/shill_stub_helper.h @@ -0,0 +1,28 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMEOS_DBUS_SHILL_STUB_HELPER_H_ +#define CHROMEOS_DBUS_SHILL_STUB_HELPER_H_ + +#include <string> + +#include "chromeos/chromeos_export.h" + +namespace chromeos { +namespace shill_stub_helper { + +CHROMEOS_EXPORT extern const char kSharedProfilePath[]; + +// Add default devices, services and profiles. This works only if +// DBusThreadManager was initialized with the Shill*ClientStubs. +void SetupDefaultEnvironment(); + +// Returns true when stub portalled wifi is enabled and it's service +// path equals to |path|. +CHROMEOS_EXPORT bool IsStubPortalledWifiEnabled(const std::string& path); + +} // namespace shill_stub_helper +} // namespace chromeos + +#endif // CHROMEOS_DBUS_SHILL_STUB_HELPER_H_ diff --git a/chromeos/network/network_configuration_handler_unittest.cc b/chromeos/network/network_configuration_handler_unittest.cc index 2057bee..b8b019c 100644 --- a/chromeos/network/network_configuration_handler_unittest.cc +++ b/chromeos/network/network_configuration_handler_unittest.cc @@ -12,7 +12,7 @@ #include "chromeos/dbus/mock_shill_manager_client.h" #include "chromeos/dbus/mock_shill_profile_client.h" #include "chromeos/dbus/mock_shill_service_client.h" -#include "chromeos/dbus/shill_profile_client_stub.h" +#include "chromeos/dbus/shill_stub_helper.h" #include "chromeos/network/network_configuration_handler.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" @@ -592,7 +592,7 @@ TEST_F(NetworkConfigurationHandlerStubTest, StubCreateConfiguration) { properties.SetStringWithoutPathExpansion( flimflam::kStateProperty, flimflam::kStateIdle); properties.SetStringWithoutPathExpansion( - flimflam::kProfileProperty, ShillProfileClientStub::kSharedProfilePath); + flimflam::kProfileProperty, shill_stub_helper::kSharedProfilePath); network_configuration_handler_->CreateConfiguration( properties, @@ -612,7 +612,7 @@ TEST_F(NetworkConfigurationHandlerStubTest, StubCreateConfiguration) { EXPECT_TRUE(GetServiceStringProperty( create_service_path_, flimflam::kProfileProperty, &actual_profile)); - EXPECT_EQ(ShillProfileClientStub::kSharedProfilePath, actual_profile); + EXPECT_EQ(shill_stub_helper::kSharedProfilePath, actual_profile); } } // namespace chromeos |