diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-10 16:02:49 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-10 16:02:49 +0000 |
commit | 54652d823fd3498a8fa4a294adfb1e5068f24079 (patch) | |
tree | 3910548219aa193f1ab7b19447d3a082d0c0f0d1 /chromeos | |
parent | f3b041e6e425002bc05e0cb729fb4d0b58292d5f (diff) | |
download | chromium_src-54652d823fd3498a8fa4a294adfb1e5068f24079.zip chromium_src-54652d823fd3498a8fa4a294adfb1e5068f24079.tar.gz chromium_src-54652d823fd3498a8fa4a294adfb1e5068f24079.tar.bz2 |
ChromeOS: Remove MockDBusThreadManager.
- Extends FakeDBusThreadManager about DBusClient setters.
- Removes default initialization of DBusClients from FakeDBusThreadManager.
- Replaces all occurrences of MockDBusThreadManager in tests by FakeDBusThreadManager.
- Every test now creates exactly the DBusClients that are required.
- Removes all references to Fake/Stub implementations from the DBusThreadManagerImpl used for production.
Depends on:
https://codereview.chromium.org/50243005/
BUG=275286
TBR=miket@chromium.org,mkwst@chromium.org,rtenneti@chromium.org
Review URL: https://codereview.chromium.org/49773003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/chromeos.gyp | 6 | ||||
-rw-r--r-- | chromeos/cryptohome/system_salt_getter_unittest.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/dbus_client.h | 2 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.cc | 163 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.h | 15 | ||||
-rw-r--r-- | chromeos/dbus/fake_dbus_thread_manager.cc | 356 | ||||
-rw-r--r-- | chromeos/dbus/fake_dbus_thread_manager.h | 205 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_client.h | 3 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager.cc | 162 | ||||
-rw-r--r-- | chromeos/dbus/mock_dbus_thread_manager.h | 178 | ||||
-rw-r--r-- | chromeos/dbus/mock_shill_manager_client.cc | 7 | ||||
-rw-r--r-- | chromeos/dbus/mock_shill_profile_client.cc | 7 | ||||
-rw-r--r-- | chromeos/dbus/power_policy_controller.cc | 19 | ||||
-rw-r--r-- | chromeos/dbus/power_policy_controller.h | 4 | ||||
-rw-r--r-- | chromeos/dbus/power_policy_controller_unittest.cc | 29 | ||||
-rw-r--r-- | chromeos/disks/disk_mount_manager_unittest.cc | 6 | ||||
-rw-r--r-- | chromeos/network/managed_network_configuration_handler_unittest.cc | 129 | ||||
-rw-r--r-- | chromeos/network/network_configuration_handler_unittest.cc | 43 |
18 files changed, 581 insertions, 757 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 778b016..757fb84 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -111,6 +111,8 @@ 'dbus/fake_bluetooth_profile_service_provider.h', 'dbus/fake_cryptohome_client.cc', 'dbus/fake_cryptohome_client.h', + 'dbus/fake_dbus_thread_manager.cc', + 'dbus/fake_dbus_thread_manager.h', 'dbus/fake_gsm_sms_client.cc', 'dbus/fake_gsm_sms_client.h', 'dbus/fake_nfc_adapter_client.cc', @@ -391,8 +393,6 @@ 'cryptohome/mock_async_method_caller.h', 'dbus/mock_cryptohome_client.cc', 'dbus/mock_cryptohome_client.h', - 'dbus/mock_dbus_thread_manager.cc', - 'dbus/mock_dbus_thread_manager.h', 'dbus/mock_session_manager_client.cc', 'dbus/mock_session_manager_client.h', 'dbus/mock_shill_manager_client.cc', @@ -431,8 +431,6 @@ 'sources': [ 'dbus/fake_cros_disks_client.cc', 'dbus/fake_cros_disks_client.h', - 'dbus/fake_dbus_thread_manager.cc', - 'dbus/fake_dbus_thread_manager.h', 'dbus/fake_power_manager_client.cc', 'dbus/fake_power_manager_client.h', 'dbus/fake_session_manager_client.cc', diff --git a/chromeos/cryptohome/system_salt_getter_unittest.cc b/chromeos/cryptohome/system_salt_getter_unittest.cc index 07883a0..f1b5230 100644 --- a/chromeos/cryptohome/system_salt_getter_unittest.cc +++ b/chromeos/cryptohome/system_salt_getter_unittest.cc @@ -26,7 +26,9 @@ class SystemSaltGetterTest : public testing::Test { virtual void SetUp() OVERRIDE { FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager; - fake_cryptohome_client_ = dbus_thread_manager->fake_cryptohome_client(); + fake_cryptohome_client_ = new FakeCryptohomeClient; + dbus_thread_manager->SetCryptohomeClient( + scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); DBusThreadManager::InitializeForTesting(dbus_thread_manager); EXPECT_FALSE(SystemSaltGetter::IsInitialized()); diff --git a/chromeos/dbus/dbus_client.h b/chromeos/dbus/dbus_client.h index c9ac671..94c8059 100644 --- a/chromeos/dbus/dbus_client.h +++ b/chromeos/dbus/dbus_client.h @@ -18,7 +18,7 @@ namespace chromeos { // incorrect calls. Stub clients may lift that restriction however. class DBusClient { protected: - friend class DBusThreadManagerImpl; + friend class DBusThreadManager; virtual ~DBusClient() {} diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index ff0760a..18843dc 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -19,9 +19,11 @@ #include "chromeos/dbus/cras_audio_client.h" #include "chromeos/dbus/cros_disks_client.h" #include "chromeos/dbus/cryptohome_client.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/dbus_thread_manager_observer.h" #include "chromeos/dbus/debug_daemon_client.h" +#include "chromeos/dbus/fake_dbus_thread_manager.h" #include "chromeos/dbus/gsm_sms_client.h" #include "chromeos/dbus/ibus/ibus_client.h" #include "chromeos/dbus/image_burner_client.h" @@ -56,15 +58,7 @@ static bool g_dbus_thread_manager_set_for_testing = false; // The DBusThreadManager implementation used in production. class DBusThreadManagerImpl : public DBusThreadManager { public: - explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) { - DBusClientImplementationType client_type_override = client_type; - // If --dbus-stub was requested, pass STUB to specific components; - // Many components like login are not useful with a stub implementation. - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kDbusStub)) { - client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION; - } - + explicit DBusThreadManagerImpl() { // Create the D-Bus thread. base::Thread::Options thread_options; thread_options.message_loop_type = base::MessageLoop::TYPE_IO; @@ -78,55 +72,7 @@ class DBusThreadManagerImpl : public DBusThreadManager { system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); system_bus_ = new dbus::Bus(system_bus_options); - CreateDefaultClients(client_type, client_type_override); - } - - // InitializeClients gets called after g_dbus_thread_manager is set. - // NOTE: Clients that access other clients in their Init() must be - // initialized in the correct order. This is the only place where Clients' - // Init() should be called if DBusThreadManager is being used. - void InitializeClients() { - InitClient(bluetooth_adapter_client_.get()); - InitClient(bluetooth_agent_manager_client_.get()); - InitClient(bluetooth_device_client_.get()); - InitClient(bluetooth_input_client_.get()); - InitClient(bluetooth_profile_manager_client_.get()); - InitClient(cras_audio_client_.get()); - InitClient(cros_disks_client_.get()); - InitClient(cryptohome_client_.get()); - InitClient(debug_daemon_client_.get()); - 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()); - InitClient(image_burner_client_.get()); - InitClient(introspectable_client_.get()); - InitClient(modem_messaging_client_.get()); - // Initialize the NFC clients in the correct order. - InitClient(nfc_manager_client_.get()); - InitClient(nfc_adapter_client_.get()); - InitClient(nfc_device_client_.get()); - InitClient(nfc_tag_client_.get()); - InitClient(nfc_record_client_.get()); - InitClient(permission_broker_client_.get()); - InitClient(power_manager_client_.get()); - InitClient(session_manager_client_.get()); - InitClient(sms_client_.get()); - InitClient(system_clock_client_.get()); - InitClient(update_engine_client_.get()); - - // PowerPolicyController is dependent on PowerManagerClient, so - // initialize it after the main list of clients. - 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(); + CreateDefaultClients(); } virtual ~DBusThreadManagerImpl() { @@ -141,26 +87,23 @@ class DBusThreadManagerImpl : public DBusThreadManager { dbus_thread_->Stop(); } - // DBusThreadManager override. + // DBusThreadManager overrides: virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { DCHECK(observer); observers_.AddObserver(observer); } - // DBusThreadManager override. virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { DCHECK(observer); observers_.RemoveObserver(observer); } - // DBusThreadManager override. virtual void InitIBusBus( const std::string &ibus_address, const base::Closure& on_disconnected_callback) OVERRIDE { ibus_client_.reset(IBusClient::Create()); } - // DBusThreadManager overrides: virtual dbus::Bus* GetSystemBus() OVERRIDE { return system_bus_.get(); } @@ -292,16 +235,20 @@ class DBusThreadManagerImpl : public DBusThreadManager { } private: - // Initializes |client| with the |system_bus_|. - void InitClient(DBusClient* client) { - client->Init(system_bus_.get()); - } - // Constructs all clients -- stub or real implementation according to // |client_type| and |client_type_override| -- and stores them in the // respective *_client_ member variable. - void CreateDefaultClients(DBusClientImplementationType client_type, - DBusClientImplementationType client_type_override) { + void CreateDefaultClients() { + DBusClientImplementationType client_type = REAL_DBUS_CLIENT_IMPLEMENTATION; + DBusClientImplementationType client_type_override = + REAL_DBUS_CLIENT_IMPLEMENTATION; + // If --dbus-stub was requested, pass STUB to specific components; + // Many components like login are not useful with a stub implementation. + if (CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kDbusStub)) { + client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION; + } + bluetooth_adapter_client_.reset( BluetoothAdapterClient::Create(client_type)); bluetooth_agent_manager_client_.reset( @@ -347,6 +294,8 @@ class DBusThreadManagerImpl : public DBusThreadManager { sms_client_.reset(SMSClient::Create(client_type)); system_clock_client_.reset(SystemClockClient::Create(client_type)); update_engine_client_.reset(UpdateEngineClient::Create(client_type)); + + power_policy_controller_.reset(new PowerPolicyController); } // Note: Keep this before other members so they can call AddObserver() in @@ -387,8 +336,8 @@ class DBusThreadManagerImpl : public DBusThreadManager { scoped_ptr<SMSClient> sms_client_; scoped_ptr<UpdateEngineClient> update_engine_client_; scoped_ptr<IBusClient> ibus_client_; - scoped_ptr<PowerPolicyController> power_policy_controller_; + scoped_ptr<PowerPolicyController> power_policy_controller_; }; // static @@ -399,19 +348,16 @@ void DBusThreadManager::Initialize() { // If we initialize DBusThreadManager twice we may also be shutting it down // early; do not allow that. CHECK(g_dbus_thread_manager == NULL); + // Determine whether we use stub or real client implementations. - DBusThreadManagerImpl* dbus_thread_manager_impl; if (base::SysInfo::IsRunningOnChromeOS()) { - dbus_thread_manager_impl = - new DBusThreadManagerImpl(REAL_DBUS_CLIENT_IMPLEMENTATION); + g_dbus_thread_manager = new DBusThreadManagerImpl; + InitializeClients(); VLOG(1) << "DBusThreadManager initialized for ChromeOS"; } else { - dbus_thread_manager_impl = - new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); - VLOG(1) << "DBusThreadManager initialized with Stub"; + InitializeWithStub(); + return; } - g_dbus_thread_manager = dbus_thread_manager_impl; - dbus_thread_manager_impl->InitializeClients(); } // static @@ -423,6 +369,7 @@ void DBusThreadManager::InitializeForTesting( CHECK(dbus_thread_manager); g_dbus_thread_manager = dbus_thread_manager; g_dbus_thread_manager_set_for_testing = true; + InitializeClients(); VLOG(1) << "DBusThreadManager initialized with test implementation"; } @@ -431,10 +378,11 @@ void DBusThreadManager::InitializeWithStub() { // If we initialize DBusThreadManager twice we may also be shutting it down // early; do not allow that. CHECK(g_dbus_thread_manager == NULL); - DBusThreadManagerImpl* dbus_thread_manager_impl = - new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); - g_dbus_thread_manager = dbus_thread_manager_impl; - dbus_thread_manager_impl->InitializeClients(); + FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; + fake_dbus_thread_manager->SetFakeClients(); + g_dbus_thread_manager = fake_dbus_thread_manager; + InitializeClients(); + shill_stub_helper::SetupDefaultEnvironment(); VLOG(1) << "DBusThreadManager initialized with stub implementation"; } @@ -480,4 +428,55 @@ DBusThreadManager* DBusThreadManager::Get() { return g_dbus_thread_manager; } +// static +void DBusThreadManager::InitializeClients() { + InitClient(g_dbus_thread_manager->GetBluetoothAdapterClient()); + InitClient(g_dbus_thread_manager->GetBluetoothAgentManagerClient()); + InitClient(g_dbus_thread_manager->GetBluetoothDeviceClient()); + InitClient(g_dbus_thread_manager->GetBluetoothInputClient()); + InitClient(g_dbus_thread_manager->GetBluetoothProfileManagerClient()); + InitClient(g_dbus_thread_manager->GetCrasAudioClient()); + InitClient(g_dbus_thread_manager->GetCrosDisksClient()); + InitClient(g_dbus_thread_manager->GetCryptohomeClient()); + InitClient(g_dbus_thread_manager->GetDebugDaemonClient()); + InitClient(g_dbus_thread_manager->GetGsmSMSClient()); + InitClient(g_dbus_thread_manager->GetImageBurnerClient()); + InitClient(g_dbus_thread_manager->GetIntrospectableClient()); + InitClient(g_dbus_thread_manager->GetModemMessagingClient()); + // Initialize the NFC clients in the correct order. + InitClient(g_dbus_thread_manager->GetNfcAdapterClient()); + InitClient(g_dbus_thread_manager->GetNfcManagerClient()); + InitClient(g_dbus_thread_manager->GetNfcDeviceClient()); + InitClient(g_dbus_thread_manager->GetNfcTagClient()); + InitClient(g_dbus_thread_manager->GetPermissionBrokerClient()); + InitClient(g_dbus_thread_manager->GetPowerManagerClient()); + InitClient(g_dbus_thread_manager->GetSessionManagerClient()); + InitClient(g_dbus_thread_manager->GetShillDeviceClient()); + InitClient(g_dbus_thread_manager->GetShillIPConfigClient()); + InitClient(g_dbus_thread_manager->GetShillManagerClient()); + InitClient(g_dbus_thread_manager->GetShillServiceClient()); + InitClient(g_dbus_thread_manager->GetShillProfileClient()); + InitClient(g_dbus_thread_manager->GetSMSClient()); + InitClient(g_dbus_thread_manager->GetSystemClockClient()); + InitClient(g_dbus_thread_manager->GetUpdateEngineClient()); + + // PowerPolicyController is dependent on PowerManagerClient, so + // initialize it after the main list of clients. + if (g_dbus_thread_manager->GetPowerPolicyController()) { + g_dbus_thread_manager->GetPowerPolicyController()->Init( + g_dbus_thread_manager); + } + + // This must be called after the list of clients so they've each had a + // chance to register with their object g_dbus_thread_managers. + if (g_dbus_thread_manager->GetSystemBus()) + g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); +} + +// static +void DBusThreadManager::InitClient(DBusClient* client) { + if (client) + client->Init(g_dbus_thread_manager->GetSystemBus()); +} + } // namespace chromeos diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h index 795b8d0..1eb53d1 100644 --- a/chromeos/dbus/dbus_thread_manager.h +++ b/chromeos/dbus/dbus_thread_manager.h @@ -34,6 +34,7 @@ class BluetoothProfileManagerClient; class CrasAudioClient; class CrosDisksClient; class CryptohomeClient; +class DBusClient; class DebugDaemonClient; class GsmSMSClient; class IBusClient; @@ -50,13 +51,13 @@ class NfcTagClient; class PermissionBrokerClient; class PowerManagerClient; class PowerPolicyController; -class SMSClient; class SessionManagerClient; class ShillDeviceClient; class ShillIPConfigClient; class ShillManagerClient; class ShillProfileClient; class ShillServiceClient; +class SMSClient; class SystemClockClient; class UpdateEngineClient; @@ -131,7 +132,6 @@ class CHROMEOS_EXPORT DBusThreadManager { virtual CryptohomeClient* GetCryptohomeClient() = 0; virtual DebugDaemonClient* GetDebugDaemonClient() = 0; virtual GsmSMSClient* GetGsmSMSClient() = 0; - virtual IBusClient* GetIBusClient() = 0; virtual ImageBurnerClient* GetImageBurnerClient() = 0; virtual IntrospectableClient* GetIntrospectableClient() = 0; virtual ModemMessagingClient* GetModemMessagingClient() = 0; @@ -153,11 +153,22 @@ class CHROMEOS_EXPORT DBusThreadManager { virtual SystemClockClient* GetSystemClockClient() = 0; virtual UpdateEngineClient* GetUpdateEngineClient() = 0; + virtual IBusClient* GetIBusClient() = 0; + virtual ~DBusThreadManager(); protected: DBusThreadManager(); + private: + // InitializeClients is called after g_dbus_thread_manager is set. + // NOTE: Clients that access other clients in their Init() must be + // initialized in the correct order. + static void InitializeClients(); + + // Initializes |client| with the |system_bus_|. + static void InitClient(DBusClient* client); + DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); }; diff --git a/chromeos/dbus/fake_dbus_thread_manager.cc b/chromeos/dbus/fake_dbus_thread_manager.cc index 9657c27..6eba472 100644 --- a/chromeos/dbus/fake_dbus_thread_manager.cc +++ b/chromeos/dbus/fake_dbus_thread_manager.cc @@ -4,57 +4,44 @@ #include "chromeos/dbus/fake_dbus_thread_manager.h" +#include "chromeos/dbus/bluetooth_adapter_client.h" +#include "chromeos/dbus/bluetooth_agent_manager_client.h" +#include "chromeos/dbus/bluetooth_device_client.h" +#include "chromeos/dbus/bluetooth_input_client.h" +#include "chromeos/dbus/bluetooth_profile_manager_client.h" +#include "chromeos/dbus/cras_audio_client.h" +#include "chromeos/dbus/cros_disks_client.h" +#include "chromeos/dbus/cryptohome_client.h" +#include "chromeos/dbus/dbus_client.h" +#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager_observer.h" -#include "chromeos/dbus/fake_bluetooth_adapter_client.h" -#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" -#include "chromeos/dbus/fake_bluetooth_device_client.h" -#include "chromeos/dbus/fake_bluetooth_input_client.h" -#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" -#include "chromeos/dbus/fake_cros_disks_client.h" -#include "chromeos/dbus/fake_cryptohome_client.h" -#include "chromeos/dbus/fake_gsm_sms_client.h" -#include "chromeos/dbus/fake_image_burner_client.h" +#include "chromeos/dbus/debug_daemon_client.h" #include "chromeos/dbus/fake_nfc_adapter_client.h" #include "chromeos/dbus/fake_nfc_device_client.h" #include "chromeos/dbus/fake_nfc_manager_client.h" #include "chromeos/dbus/fake_nfc_record_client.h" #include "chromeos/dbus/fake_nfc_tag_client.h" -#include "chromeos/dbus/fake_power_manager_client.h" -#include "chromeos/dbus/fake_session_manager_client.h" -#include "chromeos/dbus/fake_shill_device_client.h" -#include "chromeos/dbus/fake_shill_manager_client.h" -#include "chromeos/dbus/fake_system_clock_client.h" -#include "chromeos/dbus/fake_update_engine_client.h" -#include "chromeos/dbus/ibus/mock_ibus_client.h" +#include "chromeos/dbus/gsm_sms_client.h" +#include "chromeos/dbus/ibus/ibus_client.h" +#include "chromeos/dbus/image_burner_client.h" +#include "chromeos/dbus/introspectable_client.h" +#include "chromeos/dbus/modem_messaging_client.h" +#include "chromeos/dbus/permission_broker_client.h" +#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/sms_client.h" +#include "chromeos/dbus/system_clock_client.h" +#include "chromeos/dbus/update_engine_client.h" namespace chromeos { -FakeDBusThreadManager::FakeDBusThreadManager() - : fake_bluetooth_adapter_client_(new FakeBluetoothAdapterClient()), - fake_bluetooth_agent_manager_client_(new FakeBluetoothAgentManagerClient()), - fake_bluetooth_device_client_(new FakeBluetoothDeviceClient()), - fake_bluetooth_input_client_(new FakeBluetoothInputClient()), - fake_bluetooth_profile_manager_client_( - new FakeBluetoothProfileManagerClient()), - fake_cros_disks_client_(new FakeCrosDisksClient), - fake_cryptohome_client_(new FakeCryptohomeClient), - fake_gsm_sms_client_(new FakeGsmSMSClient), - fake_image_burner_client_(new FakeImageBurnerClient), - fake_nfc_adapter_client_(new FakeNfcAdapterClient()), - fake_nfc_device_client_(new FakeNfcDeviceClient()), - fake_nfc_manager_client_(new FakeNfcManagerClient()), - fake_nfc_record_client_(new FakeNfcRecordClient()), - fake_nfc_tag_client_(new FakeNfcTagClient()), - fake_session_manager_client_(new FakeSessionManagerClient), - fake_shill_device_client_(new FakeShillDeviceClient), - fake_shill_manager_client_(new FakeShillManagerClient), - fake_system_clock_client_(new FakeSystemClockClient), - fake_power_manager_client_(new FakePowerManagerClient), - fake_update_engine_client_(new FakeUpdateEngineClient), - ibus_bus_(NULL) { - power_policy_controller_.reset( - new PowerPolicyController(this, fake_power_manager_client_.get())); +FakeDBusThreadManager::FakeDBusThreadManager() { } FakeDBusThreadManager::~FakeDBusThreadManager() { @@ -62,6 +49,218 @@ FakeDBusThreadManager::~FakeDBusThreadManager() { OnDBusThreadManagerDestroying(this)); } +void FakeDBusThreadManager::SetFakeClients() { + const DBusClientImplementationType client_type = + STUB_DBUS_CLIENT_IMPLEMENTATION; + SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient>( + BluetoothAdapterClient::Create(client_type))); + SetBluetoothAgentManagerClient(scoped_ptr<BluetoothAgentManagerClient>( + BluetoothAgentManagerClient::Create(client_type))); + SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient>( + BluetoothDeviceClient::Create(client_type))); + SetBluetoothInputClient(scoped_ptr<BluetoothInputClient>( + BluetoothInputClient::Create(client_type))); + SetBluetoothProfileManagerClient(scoped_ptr<BluetoothProfileManagerClient>( + BluetoothProfileManagerClient::Create(client_type))); + SetCrasAudioClient( + scoped_ptr<CrasAudioClient>(CrasAudioClient::Create(client_type))); + SetCrosDisksClient( + scoped_ptr<CrosDisksClient>(CrosDisksClient::Create(client_type))); + SetCryptohomeClient( + scoped_ptr<CryptohomeClient>(CryptohomeClient::Create(client_type))); + SetDebugDaemonClient( + scoped_ptr<DebugDaemonClient>(DebugDaemonClient::Create(client_type))); + SetIBusClient(make_scoped_ptr(IBusClient::Create())); + SetShillManagerClient( + scoped_ptr<ShillManagerClient>(ShillManagerClient::Create(client_type))); + SetShillDeviceClient( + scoped_ptr<ShillDeviceClient>(ShillDeviceClient::Create(client_type))); + SetShillIPConfigClient(scoped_ptr<ShillIPConfigClient>( + ShillIPConfigClient::Create(client_type))); + SetShillServiceClient( + scoped_ptr<ShillServiceClient>(ShillServiceClient::Create(client_type))); + SetShillProfileClient( + scoped_ptr<ShillProfileClient>(ShillProfileClient::Create(client_type))); + SetGsmSMSClient(scoped_ptr<GsmSMSClient>(GsmSMSClient::Create(client_type))); + SetImageBurnerClient( + scoped_ptr<ImageBurnerClient>(ImageBurnerClient::Create(client_type))); + SetIntrospectableClient(scoped_ptr<IntrospectableClient>( + IntrospectableClient::Create(client_type))); + SetModemMessagingClient(scoped_ptr<ModemMessagingClient>( + ModemMessagingClient::Create(client_type))); + SetNfcAdapterClient(scoped_ptr<NfcAdapterClient>(new FakeNfcAdapterClient)); + SetNfcDeviceClient(scoped_ptr<NfcDeviceClient>(new FakeNfcDeviceClient)); + SetNfcManagerClient(scoped_ptr<NfcManagerClient>(new FakeNfcManagerClient)); + SetNfcRecordClient(scoped_ptr<NfcRecordClient>(new FakeNfcRecordClient)); + SetNfcTagClient(scoped_ptr<NfcTagClient>(new FakeNfcTagClient)); + SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient>( + PermissionBrokerClient::Create(client_type))); + SetPowerManagerClient( + scoped_ptr<PowerManagerClient>(PowerManagerClient::Create(client_type))); + SetSessionManagerClient(scoped_ptr<SessionManagerClient>( + SessionManagerClient::Create(client_type))); + SetSMSClient(scoped_ptr<SMSClient>(SMSClient::Create(client_type))); + SetSystemClockClient( + scoped_ptr<SystemClockClient>(SystemClockClient::Create(client_type))); + SetUpdateEngineClient( + scoped_ptr<UpdateEngineClient>(UpdateEngineClient::Create(client_type))); + + SetPowerPolicyController(make_scoped_ptr(new PowerPolicyController)); +} + +void FakeDBusThreadManager::SetBluetoothAdapterClient( + scoped_ptr<BluetoothAdapterClient> client) { + bluetooth_adapter_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetBluetoothAgentManagerClient( + scoped_ptr<BluetoothAgentManagerClient> client) { + bluetooth_agent_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetBluetoothDeviceClient( + scoped_ptr<BluetoothDeviceClient> client) { + bluetooth_device_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetBluetoothInputClient( + scoped_ptr<BluetoothInputClient> client) { + bluetooth_input_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetBluetoothProfileManagerClient( + scoped_ptr<BluetoothProfileManagerClient> client) { + bluetooth_profile_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetCrasAudioClient( + scoped_ptr<CrasAudioClient> client) { + cras_audio_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetCrosDisksClient( + scoped_ptr<CrosDisksClient> client) { + cros_disks_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetCryptohomeClient( + scoped_ptr<CryptohomeClient> client) { + cryptohome_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetDebugDaemonClient( + scoped_ptr<DebugDaemonClient> client) { + debug_daemon_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetShillDeviceClient( + scoped_ptr<ShillDeviceClient> client) { + shill_device_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetShillIPConfigClient( + scoped_ptr<ShillIPConfigClient> client) { + shill_ipconfig_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetShillManagerClient( + scoped_ptr<ShillManagerClient> client) { + shill_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetShillServiceClient( + scoped_ptr<ShillServiceClient> client) { + shill_service_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetShillProfileClient( + scoped_ptr<ShillProfileClient> client) { + shill_profile_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetGsmSMSClient( + scoped_ptr<GsmSMSClient> client) { + gsm_sms_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetImageBurnerClient( + scoped_ptr<ImageBurnerClient> client) { + image_burner_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetIntrospectableClient( + scoped_ptr<IntrospectableClient> client) { + introspectable_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetModemMessagingClient( + scoped_ptr<ModemMessagingClient> client) { + modem_messaging_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetNfcAdapterClient( + scoped_ptr<NfcAdapterClient> client) { + nfc_adapter_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetNfcDeviceClient( + scoped_ptr<NfcDeviceClient> client) { + nfc_device_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetNfcManagerClient( + scoped_ptr<NfcManagerClient> client) { + nfc_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetNfcRecordClient( + scoped_ptr<NfcRecordClient> client) { + nfc_record_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetNfcTagClient( + scoped_ptr<NfcTagClient> client) { + nfc_tag_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetPermissionBrokerClient( + scoped_ptr<PermissionBrokerClient> client) { + permission_broker_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetPowerManagerClient( + scoped_ptr<PowerManagerClient> client) { + power_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetPowerPolicyController( + scoped_ptr<PowerPolicyController> client) { + power_policy_controller_ = client.Pass(); +} + +void FakeDBusThreadManager::SetSessionManagerClient( + scoped_ptr<SessionManagerClient> client) { + session_manager_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetSMSClient(scoped_ptr<SMSClient> client) { + sms_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetSystemClockClient( + scoped_ptr<SystemClockClient> client) { + system_clock_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetUpdateEngineClient( + scoped_ptr<UpdateEngineClient> client) { + update_engine_client_ = client.Pass(); +} + +void FakeDBusThreadManager::SetIBusClient(scoped_ptr<IBusClient> client) { + ibus_client_ = client.Pass(); +} + void FakeDBusThreadManager::AddObserver( DBusThreadManagerObserver* observer) { DCHECK(observer); @@ -77,9 +276,6 @@ void FakeDBusThreadManager::RemoveObserver( void FakeDBusThreadManager::InitIBusBus( const std::string& ibus_address, const base::Closure& closure) { - // Non-null bus address is used to ensure the connection to ibus-daemon. - ibus_bus_ = reinterpret_cast<dbus::Bus*>(0xdeadbeef); - mock_ibus_client_.reset(new MockIBusClient); } dbus::Bus* FakeDBusThreadManager::GetSystemBus() { @@ -88,122 +284,115 @@ dbus::Bus* FakeDBusThreadManager::GetSystemBus() { BluetoothAdapterClient* FakeDBusThreadManager::GetBluetoothAdapterClient() { - return fake_bluetooth_adapter_client_.get(); + return bluetooth_adapter_client_.get(); } BluetoothAgentManagerClient* FakeDBusThreadManager::GetBluetoothAgentManagerClient() { - return fake_bluetooth_agent_manager_client_.get(); + return bluetooth_agent_manager_client_.get(); } BluetoothDeviceClient* FakeDBusThreadManager::GetBluetoothDeviceClient() { - return fake_bluetooth_device_client_.get(); + return bluetooth_device_client_.get(); } BluetoothInputClient* FakeDBusThreadManager::GetBluetoothInputClient() { - return fake_bluetooth_input_client_.get(); + return bluetooth_input_client_.get(); } BluetoothProfileManagerClient* FakeDBusThreadManager::GetBluetoothProfileManagerClient() { - return fake_bluetooth_profile_manager_client_.get(); + return bluetooth_profile_manager_client_.get(); } CrasAudioClient* FakeDBusThreadManager::GetCrasAudioClient() { - return NULL; + return cras_audio_client_.get(); } CrosDisksClient* FakeDBusThreadManager::GetCrosDisksClient() { - return fake_cros_disks_client_.get(); + return cros_disks_client_.get(); } CryptohomeClient* FakeDBusThreadManager::GetCryptohomeClient() { - return fake_cryptohome_client_.get(); + return cryptohome_client_.get(); } DebugDaemonClient* FakeDBusThreadManager::GetDebugDaemonClient() { - NOTIMPLEMENTED(); - return NULL; + return debug_daemon_client_.get(); } ShillDeviceClient* FakeDBusThreadManager::GetShillDeviceClient() { - return fake_shill_device_client_.get(); + return shill_device_client_.get(); } ShillIPConfigClient* FakeDBusThreadManager::GetShillIPConfigClient() { - NOTIMPLEMENTED(); - return NULL; + return shill_ipconfig_client_.get(); } ShillManagerClient* FakeDBusThreadManager::GetShillManagerClient() { - return fake_shill_manager_client_.get(); + return shill_manager_client_.get(); } ShillProfileClient* FakeDBusThreadManager::GetShillProfileClient() { - NOTIMPLEMENTED(); - return NULL; + return shill_profile_client_.get(); } ShillServiceClient* FakeDBusThreadManager::GetShillServiceClient() { - NOTIMPLEMENTED(); - return NULL; + return shill_service_client_.get(); } GsmSMSClient* FakeDBusThreadManager::GetGsmSMSClient() { - return fake_gsm_sms_client_.get(); + return gsm_sms_client_.get(); } ImageBurnerClient* FakeDBusThreadManager::GetImageBurnerClient() { - return fake_image_burner_client_.get(); + return image_burner_client_.get(); } IntrospectableClient* FakeDBusThreadManager::GetIntrospectableClient() { - NOTIMPLEMENTED(); - return NULL; + return introspectable_client_.get(); } ModemMessagingClient* FakeDBusThreadManager::GetModemMessagingClient() { - NOTIMPLEMENTED(); - return NULL; + return modem_messaging_client_.get(); } NfcAdapterClient* FakeDBusThreadManager::GetNfcAdapterClient() { - return fake_nfc_adapter_client_.get(); + return nfc_adapter_client_.get(); } NfcDeviceClient* FakeDBusThreadManager::GetNfcDeviceClient() { - return fake_nfc_device_client_.get(); + return nfc_device_client_.get(); } NfcManagerClient* FakeDBusThreadManager::GetNfcManagerClient() { - return fake_nfc_manager_client_.get(); + return nfc_manager_client_.get(); } -NfcRecordClient* FakeDBusThreadManager::GetNfcRecordClient() { - return fake_nfc_record_client_.get(); +NfcTagClient* FakeDBusThreadManager::GetNfcTagClient() { + return nfc_tag_client_.get(); } -NfcTagClient* FakeDBusThreadManager::GetNfcTagClient() { - return fake_nfc_tag_client_.get(); +NfcRecordClient* FakeDBusThreadManager::GetNfcRecordClient() { + return nfc_record_client_.get(); } PermissionBrokerClient* FakeDBusThreadManager::GetPermissionBrokerClient() { - NOTIMPLEMENTED(); - return NULL; + return permission_broker_client_.get(); } PowerManagerClient* FakeDBusThreadManager::GetPowerManagerClient() { - return fake_power_manager_client_.get(); + return power_manager_client_.get(); } PowerPolicyController* @@ -213,24 +402,23 @@ FakeDBusThreadManager::GetPowerPolicyController() { SessionManagerClient* FakeDBusThreadManager::GetSessionManagerClient() { - return fake_session_manager_client_.get(); + return session_manager_client_.get(); } SMSClient* FakeDBusThreadManager::GetSMSClient() { - NOTIMPLEMENTED(); - return NULL; + return sms_client_.get(); } SystemClockClient* FakeDBusThreadManager::GetSystemClockClient() { - return fake_system_clock_client_.get(); + return system_clock_client_.get(); } UpdateEngineClient* FakeDBusThreadManager::GetUpdateEngineClient() { - return fake_update_engine_client_.get(); + return update_engine_client_.get(); } IBusClient* FakeDBusThreadManager::GetIBusClient() { - return mock_ibus_client_.get(); + return ibus_client_.get(); } } // namespace chromeos diff --git a/chromeos/dbus/fake_dbus_thread_manager.h b/chromeos/dbus/fake_dbus_thread_manager.h index c23f6bd..be7324b 100644 --- a/chromeos/dbus/fake_dbus_thread_manager.h +++ b/chromeos/dbus/fake_dbus_thread_manager.h @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/observer_list.h" +#include "chromeos/chromeos_export.h" #include "chromeos/dbus/dbus_thread_manager.h" namespace dbus { @@ -19,35 +20,51 @@ class ObjectPath; namespace chromeos { class DBusThreadManagerObserver; -class FakeBluetoothAdapterClient; -class FakeBluetoothAgentManagerClient; -class FakeBluetoothDeviceClient; -class FakeBluetoothInputClient; -class FakeBluetoothProfileManagerClient; -class FakeCrosDisksClient; -class FakeCryptohomeClient; -class FakeGsmSMSClient; -class FakeNfcAdapterClient; -class FakeNfcDeviceClient; -class FakeNfcManagerClient; -class FakeNfcRecordClient; -class FakeNfcTagClient; -class FakePowerManagerClient; -class FakeImageBurnerClient; -class FakeSessionManagerClient; -class FakeShillDeviceClient; -class FakeShillManagerClient; -class FakeSystemClockClient; -class FakeUpdateEngineClient; -class MockIBusClient; // This class provides a fake implementation of DBusThreadManager, which // hosts fake D-Bus clients. -class FakeDBusThreadManager : public DBusThreadManager { +class CHROMEOS_EXPORT FakeDBusThreadManager : public DBusThreadManager { public: FakeDBusThreadManager(); virtual ~FakeDBusThreadManager(); + // Creates and sets all fake DBusClients and the PowerPolicyController. + void SetFakeClients(); + + void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client); + void SetBluetoothAgentManagerClient( + scoped_ptr<BluetoothAgentManagerClient> client); + void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client); + void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client); + void SetBluetoothProfileManagerClient( + scoped_ptr<BluetoothProfileManagerClient> client); + void SetCrasAudioClient(scoped_ptr<CrasAudioClient> client); + void SetCrosDisksClient(scoped_ptr<CrosDisksClient> client); + void SetCryptohomeClient(scoped_ptr<CryptohomeClient> client); + void SetDebugDaemonClient(scoped_ptr<DebugDaemonClient> client); + void SetShillDeviceClient(scoped_ptr<ShillDeviceClient> client); + void SetShillIPConfigClient(scoped_ptr<ShillIPConfigClient> client); + void SetShillManagerClient(scoped_ptr<ShillManagerClient> client); + void SetShillServiceClient(scoped_ptr<ShillServiceClient> client); + void SetShillProfileClient(scoped_ptr<ShillProfileClient> client); + void SetGsmSMSClient(scoped_ptr<GsmSMSClient> client); + void SetImageBurnerClient(scoped_ptr<ImageBurnerClient> client); + void SetIntrospectableClient(scoped_ptr<IntrospectableClient> client); + void SetModemMessagingClient(scoped_ptr<ModemMessagingClient> client); + void SetNfcAdapterClient(scoped_ptr<NfcAdapterClient> client); + void SetNfcDeviceClient(scoped_ptr<NfcDeviceClient> client); + void SetNfcManagerClient(scoped_ptr<NfcManagerClient> client); + void SetNfcRecordClient(scoped_ptr<NfcRecordClient> client); + void SetNfcTagClient(scoped_ptr<NfcTagClient> client); + void SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient> client); + void SetPowerManagerClient(scoped_ptr<PowerManagerClient> client); + void SetPowerPolicyController(scoped_ptr<PowerPolicyController> client); + void SetSessionManagerClient(scoped_ptr<SessionManagerClient> client); + void SetSMSClient(scoped_ptr<SMSClient> client); + void SetSystemClockClient(scoped_ptr<SystemClockClient> client); + void SetUpdateEngineClient(scoped_ptr<UpdateEngineClient> client); + void SetIBusClient(scoped_ptr<IBusClient> client); + virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE; virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE; virtual void InitIBusBus(const std::string& ibus_address, @@ -88,127 +105,43 @@ class FakeDBusThreadManager : public DBusThreadManager { virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE; virtual IBusClient* GetIBusClient() OVERRIDE; - FakeBluetoothAdapterClient* fake_bluetooth_adapter_client() { - return fake_bluetooth_adapter_client_.get(); - } - - FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client() { - return fake_bluetooth_agent_manager_client_.get(); - } - - FakeBluetoothDeviceClient* fake_bluetooth_device_client() { - return fake_bluetooth_device_client_.get(); - } - - FakeBluetoothInputClient* fake_bluetooth_input_client() { - return fake_bluetooth_input_client_.get(); - } - - FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client() { - return fake_bluetooth_profile_manager_client_.get(); - } - - FakeCrosDisksClient* fake_cros_disks_client() { - return fake_cros_disks_client_.get(); - } - - FakeCryptohomeClient* fake_cryptohome_client() { - return fake_cryptohome_client_.get(); - } - - FakeGsmSMSClient* fake_gsm_sms_client() { - return fake_gsm_sms_client_.get(); - } - - FakeImageBurnerClient* fake_image_burner_client() { - return fake_image_burner_client_.get(); - } - - FakeNfcAdapterClient* fake_nfc_adapter_client() { - return fake_nfc_adapter_client_.get(); - } - - FakeNfcDeviceClient* fake_nfc_device_client() { - return fake_nfc_device_client_.get(); - } - - FakeNfcManagerClient* fake_nfc_manager_client() { - return fake_nfc_manager_client_.get(); - } - - FakeNfcRecordClient* fake_nfc_record_client() { - return fake_nfc_record_client_.get(); - } - - FakeNfcTagClient* fake_nfc_tag_client() { - return fake_nfc_tag_client_.get(); - } - - FakeSessionManagerClient* fake_session_manager_client() { - return fake_session_manager_client_.get(); - } - - FakeShillDeviceClient* fake_shill_device_client() { - return fake_shill_device_client_.get(); - } - - FakeShillManagerClient* fake_shill_manager_client() { - return fake_shill_manager_client_.get(); - } - - FakeSystemClockClient* fake_system_clock_client() { - return fake_system_clock_client_.get(); - } - - FakePowerManagerClient* fake_power_manager_client() { - return fake_power_manager_client_.get(); - } - - FakeUpdateEngineClient* fake_update_engine_client() { - return fake_update_engine_client_.get(); - } - - // TODO(komatsu): Remove IBus related code. crbug.com/275262 - MockIBusClient* mock_ibus_client() { - return mock_ibus_client_.get(); - } - - void set_ibus_bus(dbus::Bus* ibus_bus) { - ibus_bus_ = ibus_bus; - } - private: // Note: Keep this before other members so they can call AddObserver() in // their c'tors. ObserverList<DBusThreadManagerObserver> observers_; - scoped_ptr<FakeBluetoothAdapterClient> fake_bluetooth_adapter_client_; - scoped_ptr<FakeBluetoothAgentManagerClient> - fake_bluetooth_agent_manager_client_; - scoped_ptr<FakeBluetoothDeviceClient> fake_bluetooth_device_client_; - scoped_ptr<FakeBluetoothInputClient> fake_bluetooth_input_client_; - scoped_ptr<FakeBluetoothProfileManagerClient> - fake_bluetooth_profile_manager_client_; - scoped_ptr<FakeCrosDisksClient> fake_cros_disks_client_; - scoped_ptr<FakeCryptohomeClient> fake_cryptohome_client_; - scoped_ptr<FakeGsmSMSClient> fake_gsm_sms_client_; - scoped_ptr<FakeImageBurnerClient> fake_image_burner_client_; - scoped_ptr<FakeNfcAdapterClient> fake_nfc_adapter_client_; - scoped_ptr<FakeNfcDeviceClient> fake_nfc_device_client_; - scoped_ptr<FakeNfcManagerClient> fake_nfc_manager_client_; - scoped_ptr<FakeNfcRecordClient> fake_nfc_record_client_; - scoped_ptr<FakeNfcTagClient> fake_nfc_tag_client_; - scoped_ptr<FakeSessionManagerClient> fake_session_manager_client_; - scoped_ptr<FakeShillDeviceClient> fake_shill_device_client_; - scoped_ptr<FakeShillManagerClient> fake_shill_manager_client_; - scoped_ptr<FakeSystemClockClient> fake_system_clock_client_; - scoped_ptr<FakePowerManagerClient> fake_power_manager_client_; - scoped_ptr<FakeUpdateEngineClient> fake_update_engine_client_; - - scoped_ptr<MockIBusClient> mock_ibus_client_; + scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; + scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; + scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; + scoped_ptr<BluetoothInputClient> bluetooth_input_client_; + scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_; + scoped_ptr<CrasAudioClient> cras_audio_client_; + scoped_ptr<CrosDisksClient> cros_disks_client_; + scoped_ptr<CryptohomeClient> cryptohome_client_; + scoped_ptr<DebugDaemonClient> debug_daemon_client_; + scoped_ptr<ShillDeviceClient> shill_device_client_; + scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_; + scoped_ptr<ShillManagerClient> shill_manager_client_; + scoped_ptr<ShillServiceClient> shill_service_client_; + scoped_ptr<ShillProfileClient> shill_profile_client_; + scoped_ptr<GsmSMSClient> gsm_sms_client_; + scoped_ptr<ImageBurnerClient> image_burner_client_; + scoped_ptr<IntrospectableClient> introspectable_client_; + scoped_ptr<ModemMessagingClient> modem_messaging_client_; + scoped_ptr<NfcAdapterClient> nfc_adapter_client_; + scoped_ptr<NfcDeviceClient> nfc_device_client_; + scoped_ptr<NfcManagerClient> nfc_manager_client_; + scoped_ptr<NfcRecordClient> nfc_record_client_; + scoped_ptr<NfcTagClient> nfc_tag_client_; + scoped_ptr<PermissionBrokerClient> permission_broker_client_; + scoped_ptr<SystemClockClient> system_clock_client_; + scoped_ptr<PowerManagerClient> power_manager_client_; + scoped_ptr<SessionManagerClient> session_manager_client_; + scoped_ptr<SMSClient> sms_client_; + scoped_ptr<UpdateEngineClient> update_engine_client_; + scoped_ptr<IBusClient> ibus_client_; scoped_ptr<PowerPolicyController> power_policy_controller_; - dbus::Bus* ibus_bus_; DISALLOW_COPY_AND_ASSIGN(FakeDBusThreadManager); }; diff --git a/chromeos/dbus/ibus/mock_ibus_client.h b/chromeos/dbus/ibus/mock_ibus_client.h index 9011be7..ef5439e 100644 --- a/chromeos/dbus/ibus/mock_ibus_client.h +++ b/chromeos/dbus/ibus/mock_ibus_client.h @@ -7,11 +7,12 @@ #include <string> #include "base/callback.h" +#include "chromeos/chromeos_export.h" #include "chromeos/dbus/ibus/ibus_client.h" namespace chromeos { -class MockIBusClient : public IBusClient { +class CHROMEOS_EXPORT MockIBusClient : public IBusClient { public: MockIBusClient(); virtual ~MockIBusClient(); diff --git a/chromeos/dbus/mock_dbus_thread_manager.cc b/chromeos/dbus/mock_dbus_thread_manager.cc deleted file mode 100644 index 1998dfc..0000000 --- a/chromeos/dbus/mock_dbus_thread_manager.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2012 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/mock_dbus_thread_manager.h" - -#include "base/message_loop/message_loop.h" -#include "chromeos/dbus/dbus_thread_manager_observer.h" -#include "chromeos/dbus/fake_bluetooth_adapter_client.h" -#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" -#include "chromeos/dbus/fake_bluetooth_device_client.h" -#include "chromeos/dbus/fake_bluetooth_input_client.h" -#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" -#include "chromeos/dbus/fake_gsm_sms_client.h" -#include "chromeos/dbus/fake_nfc_adapter_client.h" -#include "chromeos/dbus/fake_nfc_device_client.h" -#include "chromeos/dbus/fake_nfc_manager_client.h" -#include "chromeos/dbus/fake_nfc_record_client.h" -#include "chromeos/dbus/fake_nfc_tag_client.h" -#include "chromeos/dbus/fake_shill_device_client.h" -#include "chromeos/dbus/fake_shill_ipconfig_client.h" -#include "chromeos/dbus/ibus/mock_ibus_client.h" -#include "chromeos/dbus/ibus/mock_ibus_engine_factory_service.h" -#include "chromeos/dbus/ibus/mock_ibus_engine_service.h" -#include "chromeos/dbus/mock_cryptohome_client.h" -#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/mock_session_manager_client.h" -#include "chromeos/dbus/power_policy_controller.h" - -using ::testing::AnyNumber; -using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnNull; -using ::testing::_; - -namespace chromeos { - -namespace { - -void GetMockSystemSalt( - const CryptohomeClient::GetSystemSaltCallback& callback) { - const char kStubSystemSalt[] = "stub_system_salt"; - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(callback, - DBUS_METHOD_CALL_SUCCESS, - std::vector<uint8>( - kStubSystemSalt, - kStubSystemSalt + arraysize(kStubSystemSalt) - 1))); -} - -} // namespace - -MockDBusThreadManager::MockDBusThreadManager() - : fake_bluetooth_adapter_client_(new FakeBluetoothAdapterClient), - fake_bluetooth_agent_manager_client_( - new FakeBluetoothAgentManagerClient), - fake_bluetooth_device_client_(new FakeBluetoothDeviceClient), - fake_bluetooth_input_client_(new FakeBluetoothInputClient), - fake_bluetooth_profile_manager_client_( - new FakeBluetoothProfileManagerClient), - fake_gsm_sms_client_(new FakeGsmSMSClient), - fake_nfc_adapter_client_(new FakeNfcAdapterClient()), - fake_nfc_device_client_(new FakeNfcDeviceClient()), - fake_nfc_manager_client_(new FakeNfcManagerClient()), - fake_nfc_record_client_(new FakeNfcRecordClient()), - fake_nfc_tag_client_(new FakeNfcTagClient()), - fake_shill_device_client_(new FakeShillDeviceClient), - fake_shill_ipconfig_client_(new FakeShillIPConfigClient), - mock_cryptohome_client_(new MockCryptohomeClient), - mock_shill_manager_client_(new MockShillManagerClient), - mock_shill_profile_client_(new MockShillProfileClient), - mock_shill_service_client_(new MockShillServiceClient), - mock_session_manager_client_(new MockSessionManagerClient) { - EXPECT_CALL(*this, GetCryptohomeClient()) - .WillRepeatedly(Return(mock_cryptohome_client())); - EXPECT_CALL(*this, GetBluetoothAdapterClient()) - .WillRepeatedly(Return(fake_bluetooth_adapter_client_.get())); - EXPECT_CALL(*this, GetBluetoothAgentManagerClient()) - .WillRepeatedly(Return(fake_bluetooth_agent_manager_client())); - EXPECT_CALL(*this, GetBluetoothDeviceClient()) - .WillRepeatedly(Return(fake_bluetooth_device_client_.get())); - EXPECT_CALL(*this, GetBluetoothInputClient()) - .WillRepeatedly(Return(fake_bluetooth_input_client_.get())); - EXPECT_CALL(*this, GetBluetoothProfileManagerClient()) - .WillRepeatedly(Return(fake_bluetooth_profile_manager_client())); - EXPECT_CALL(*this, GetNfcAdapterClient()) - .WillRepeatedly(Return(fake_nfc_adapter_client())); - EXPECT_CALL(*this, GetNfcDeviceClient()) - .WillRepeatedly(Return(fake_nfc_device_client())); - EXPECT_CALL(*this, GetNfcManagerClient()) - .WillRepeatedly(Return(fake_nfc_manager_client())); - EXPECT_CALL(*this, GetNfcRecordClient()) - .WillRepeatedly(Return(fake_nfc_record_client())); - EXPECT_CALL(*this, GetNfcTagClient()) - .WillRepeatedly(Return(fake_nfc_tag_client())); - EXPECT_CALL(*this, GetShillDeviceClient()) - .WillRepeatedly(Return(fake_shill_device_client())); - EXPECT_CALL(*this, GetShillIPConfigClient()) - .WillRepeatedly(Return(fake_shill_ipconfig_client())); - EXPECT_CALL(*this, GetShillManagerClient()) - .WillRepeatedly(Return(mock_shill_manager_client())); - EXPECT_CALL(*this, GetShillProfileClient()) - .WillRepeatedly(Return(mock_shill_profile_client())); - EXPECT_CALL(*this, GetShillServiceClient()) - .WillRepeatedly(Return(mock_shill_service_client())); - EXPECT_CALL(*this, GetGsmSMSClient()) - .WillRepeatedly(Return(fake_gsm_sms_client())); - EXPECT_CALL(*this, GetSessionManagerClient()) - .WillRepeatedly(Return(mock_session_manager_client_.get())); - - EXPECT_CALL(*this, GetSystemBus()) - .WillRepeatedly(ReturnNull()); - - // These observers calls are used in ChromeBrowserMainPartsChromeos. - EXPECT_CALL(*mock_session_manager_client_.get(), AddObserver(_)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_session_manager_client_.get(), RemoveObserver(_)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_session_manager_client_.get(), HasObserver(_)) - .Times(AnyNumber()); - - // Called from AsyncMethodCaller ctor and dtor. - EXPECT_CALL(*mock_cryptohome_client_.get(), SetAsyncCallStatusHandlers(_, _)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_cryptohome_client_.get(), ResetAsyncCallStatusHandlers()) - .Times(AnyNumber()); - // Called from various locations. - EXPECT_CALL(*mock_cryptohome_client_.get(), GetSystemSalt(_)) - .WillRepeatedly(Invoke(&GetMockSystemSalt)); - EXPECT_CALL(*mock_cryptohome_client_.get(), TpmIsEnabled(_)) - .Times(AnyNumber()); - - // Called from GeolocationHandler::Init(). - EXPECT_CALL(*mock_shill_manager_client_.get(), GetProperties(_)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_shill_manager_client_.get(), AddPropertyChangedObserver(_)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_shill_manager_client_.get(), - RemovePropertyChangedObserver(_)) - .Times(AnyNumber()); -} - -MockDBusThreadManager::~MockDBusThreadManager() { - FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, - OnDBusThreadManagerDestroying(this)); -} - -void MockDBusThreadManager::AddObserver(DBusThreadManagerObserver* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void MockDBusThreadManager::RemoveObserver( - DBusThreadManagerObserver* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - -} // namespace chromeos diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h deleted file mode 100644 index 850ccc4..0000000 --- a/chromeos/dbus/mock_dbus_thread_manager.h +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 2012 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_MOCK_DBUS_THREAD_MANAGER_H_ -#define CHROMEOS_DBUS_MOCK_DBUS_THREAD_MANAGER_H_ - -#include <string> - -#include "base/observer_list.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace dbus { - -class Bus; - -} // namespace dbus - -namespace chromeos { - -class DBusThreadManagerObserver; -class FakeBluetoothAdapterClient; -class FakeBluetoothAgentManagerClient; -class FakeBluetoothDeviceClient; -class FakeBluetoothInputClient; -class FakeBluetoothProfileManagerClient; -class FakeGsmSMSClient; -class FakeNfcAdapterClient; -class FakeNfcDeviceClient; -class FakeNfcManagerClient; -class FakeNfcRecordClient; -class FakeNfcTagClient; -class FakeShillDeviceClient; -class FakeShillIPConfigClient; -class MockCryptohomeClient; -class MockPowerManagerClient; -class MockSessionManagerClient; -class MockShillManagerClient; -class MockShillProfileClient; -class MockShillServiceClient; - -// This class provides a mock DBusThreadManager with mock clients -// installed. You can customize the behaviors of mock clients with -// mock_foo_client() functions. -// Please avoid adding more GMock in this class. We have an ongoing effort to -// remove GMock dependency. TODO(haruki): crbug.com/223061. -class MockDBusThreadManager : public DBusThreadManager { - public: - MockDBusThreadManager(); - virtual ~MockDBusThreadManager(); - - void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE; - void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE; - MOCK_METHOD2(InitIBusBus, void(const std::string& ibus_address, - const base::Closure& closure)); - MOCK_METHOD0(GetSystemBus, dbus::Bus*(void)); - MOCK_METHOD0(GetBluetoothAdapterClient, BluetoothAdapterClient*(void)); - MOCK_METHOD0(GetBluetoothAgentManagerClient, - BluetoothAgentManagerClient*(void)); - MOCK_METHOD0(GetBluetoothDeviceClient, BluetoothDeviceClient*(void)); - MOCK_METHOD0(GetBluetoothInputClient, BluetoothInputClient*(void)); - MOCK_METHOD0(GetBluetoothProfileManagerClient, - BluetoothProfileManagerClient*(void)); - MOCK_METHOD0(GetCrasAudioClient, CrasAudioClient*(void)); - MOCK_METHOD0(GetCrosDisksClient, CrosDisksClient*(void)); - MOCK_METHOD0(GetCryptohomeClient, CryptohomeClient*(void)); - MOCK_METHOD0(GetDebugDaemonClient, DebugDaemonClient*(void)); - MOCK_METHOD0(GetShillDeviceClient, ShillDeviceClient*(void)); - MOCK_METHOD0(GetShillIPConfigClient, ShillIPConfigClient*(void)); - MOCK_METHOD0(GetShillManagerClient, ShillManagerClient*(void)); - MOCK_METHOD0(GetShillProfileClient, ShillProfileClient*(void)); - MOCK_METHOD0(GetShillServiceClient, ShillServiceClient*(void)); - MOCK_METHOD0(GetGsmSMSClient, GsmSMSClient*(void)); - MOCK_METHOD0(GetImageBurnerClient, ImageBurnerClient*(void)); - MOCK_METHOD0(GetIntrospectableClient, IntrospectableClient*(void)); - MOCK_METHOD0(GetModemMessagingClient, ModemMessagingClient*(void)); - MOCK_METHOD0(GetNfcAdapterClient, NfcAdapterClient*(void)); - MOCK_METHOD0(GetNfcDeviceClient, NfcDeviceClient*(void)); - MOCK_METHOD0(GetNfcManagerClient, NfcManagerClient*(void)); - MOCK_METHOD0(GetNfcRecordClient, NfcRecordClient*(void)); - MOCK_METHOD0(GetNfcTagClient, NfcTagClient*(void)); - MOCK_METHOD0(GetPermissionBrokerClient, PermissionBrokerClient*(void)); - MOCK_METHOD0(GetPowerManagerClient, PowerManagerClient*(void)); - MOCK_METHOD0(GetPowerPolicyController, PowerPolicyController*(void)); - MOCK_METHOD0(GetSessionManagerClient, SessionManagerClient*(void)); - MOCK_METHOD0(GetSMSClient, SMSClient*(void)); - MOCK_METHOD0(GetSystemClockClient, SystemClockClient*(void)); - MOCK_METHOD0(GetUpdateEngineClient, UpdateEngineClient*(void)); - MOCK_METHOD0(GetIBusClient, IBusClient*(void)); - - FakeBluetoothAdapterClient* fake_bluetooth_adapter_client() { - return fake_bluetooth_adapter_client_.get(); - } - FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client() { - return fake_bluetooth_agent_manager_client_.get(); - } - FakeBluetoothDeviceClient* fake_bluetooth_device_client() { - return fake_bluetooth_device_client_.get(); - } - FakeBluetoothInputClient* fake_bluetooth_input_client() { - return fake_bluetooth_input_client_.get(); - } - FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client() { - return fake_bluetooth_profile_manager_client_.get(); - } - FakeGsmSMSClient* fake_gsm_sms_client() { - return fake_gsm_sms_client_.get(); - } - FakeNfcAdapterClient* fake_nfc_adapter_client() { - return fake_nfc_adapter_client_.get(); - } - FakeNfcDeviceClient* fake_nfc_device_client() { - return fake_nfc_device_client_.get(); - } - FakeNfcManagerClient* fake_nfc_manager_client() { - return fake_nfc_manager_client_.get(); - } - FakeNfcRecordClient* fake_nfc_record_client() { - return fake_nfc_record_client_.get(); - } - FakeNfcTagClient* fake_nfc_tag_client() { - return fake_nfc_tag_client_.get(); - } - FakeShillDeviceClient* fake_shill_device_client() { - return fake_shill_device_client_.get(); - } - FakeShillIPConfigClient* fake_shill_ipconfig_client() { - return fake_shill_ipconfig_client_.get(); - } - MockCryptohomeClient* mock_cryptohome_client() { - return mock_cryptohome_client_.get(); - } - MockShillManagerClient* mock_shill_manager_client() { - return mock_shill_manager_client_.get(); - } - MockShillProfileClient* mock_shill_profile_client() { - return mock_shill_profile_client_.get(); - } - MockShillServiceClient* mock_shill_service_client() { - return mock_shill_service_client_.get(); - } - MockSessionManagerClient* mock_session_manager_client() { - return mock_session_manager_client_.get(); - } - - private: - // Note: Keep this before other members so they can call AddObserver() in - // their c'tors. - ObserverList<DBusThreadManagerObserver> observers_; - - scoped_ptr<FakeBluetoothAdapterClient> fake_bluetooth_adapter_client_; - scoped_ptr<FakeBluetoothAgentManagerClient> - fake_bluetooth_agent_manager_client_; - scoped_ptr<FakeBluetoothDeviceClient> fake_bluetooth_device_client_; - scoped_ptr<FakeBluetoothInputClient> fake_bluetooth_input_client_; - scoped_ptr<FakeBluetoothProfileManagerClient> - fake_bluetooth_profile_manager_client_; - scoped_ptr<FakeGsmSMSClient> fake_gsm_sms_client_; - scoped_ptr<FakeNfcAdapterClient> fake_nfc_adapter_client_; - scoped_ptr<FakeNfcDeviceClient> fake_nfc_device_client_; - scoped_ptr<FakeNfcManagerClient> fake_nfc_manager_client_; - scoped_ptr<FakeNfcRecordClient> fake_nfc_record_client_; - scoped_ptr<FakeNfcTagClient> fake_nfc_tag_client_; - scoped_ptr<FakeShillDeviceClient> fake_shill_device_client_; - scoped_ptr<FakeShillIPConfigClient> fake_shill_ipconfig_client_; - scoped_ptr<MockCryptohomeClient> mock_cryptohome_client_; - scoped_ptr<MockShillManagerClient> mock_shill_manager_client_; - scoped_ptr<MockShillProfileClient> mock_shill_profile_client_; - scoped_ptr<MockShillServiceClient> mock_shill_service_client_; - scoped_ptr<MockSessionManagerClient> mock_session_manager_client_; - - DISALLOW_COPY_AND_ASSIGN(MockDBusThreadManager); -}; - -} // namespace chromeos - -#endif // CHROMEOS_DBUS_MOCK_DBUS_THREAD_MANAGER_H_ diff --git a/chromeos/dbus/mock_shill_manager_client.cc b/chromeos/dbus/mock_shill_manager_client.cc index 309b48e..bee9fa1 100644 --- a/chromeos/dbus/mock_shill_manager_client.cc +++ b/chromeos/dbus/mock_shill_manager_client.cc @@ -6,9 +6,14 @@ #include "dbus/object_path.h" +using ::testing::_; +using ::testing::AnyNumber; + namespace chromeos { -MockShillManagerClient::MockShillManagerClient() {} +MockShillManagerClient::MockShillManagerClient() { + EXPECT_CALL(*this, Init(_)).Times(AnyNumber()); +} MockShillManagerClient::~MockShillManagerClient() {} diff --git a/chromeos/dbus/mock_shill_profile_client.cc b/chromeos/dbus/mock_shill_profile_client.cc index 3f47ae8..c158905 100644 --- a/chromeos/dbus/mock_shill_profile_client.cc +++ b/chromeos/dbus/mock_shill_profile_client.cc @@ -4,9 +4,14 @@ #include "chromeos/dbus/mock_shill_profile_client.h" +using ::testing::_; +using ::testing::AnyNumber; + namespace chromeos { -MockShillProfileClient::MockShillProfileClient() {} +MockShillProfileClient::MockShillProfileClient() { + EXPECT_CALL(*this, Init(_)).Times(AnyNumber()); +} MockShillProfileClient::~MockShillProfileClient() {} diff --git a/chromeos/dbus/power_policy_controller.cc b/chromeos/dbus/power_policy_controller.cc index 6eed965..64cc665 100644 --- a/chromeos/dbus/power_policy_controller.cc +++ b/chromeos/dbus/power_policy_controller.cc @@ -123,19 +123,16 @@ std::string PowerPolicyController::GetPolicyDebugString( return str; } -PowerPolicyController::PowerPolicyController(DBusThreadManager* manager, - PowerManagerClient* client) - : manager_(manager), - client_(client), +PowerPolicyController::PowerPolicyController() + : manager_(NULL), + client_(NULL), prefs_were_set_(false), honor_screen_wake_locks_(true), next_wake_lock_id_(1) { - manager_->AddObserver(this); - client_->AddObserver(this); - SendCurrentPolicy(); } PowerPolicyController::~PowerPolicyController() { + DCHECK(manager_); // The power manager's policy is reset before this point, in // OnDBusThreadManagerDestroying(). At the time that // PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy @@ -146,6 +143,14 @@ PowerPolicyController::~PowerPolicyController() { manager_ = NULL; } +void PowerPolicyController::Init(DBusThreadManager* manager) { + manager_ = manager; + manager_->AddObserver(this); + client_ = manager_->GetPowerManagerClient(); + client_->AddObserver(this); + SendCurrentPolicy(); +} + void PowerPolicyController::ApplyPrefs(const PrefValues& values) { prefs_policy_.Clear(); diff --git a/chromeos/dbus/power_policy_controller.h b/chromeos/dbus/power_policy_controller.h index 9e133aa..0f44b0d 100644 --- a/chromeos/dbus/power_policy_controller.h +++ b/chromeos/dbus/power_policy_controller.h @@ -69,9 +69,11 @@ class CHROMEOS_EXPORT PowerPolicyController // this constant would imply. static const int kScreenLockAfterOffDelayMs; - PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client); + PowerPolicyController(); virtual ~PowerPolicyController(); + void Init(DBusThreadManager* manager); + // Updates |prefs_policy_| with |values| and sends an updated policy. void ApplyPrefs(const PrefValues& values); diff --git a/chromeos/dbus/power_policy_controller_unittest.cc b/chromeos/dbus/power_policy_controller_unittest.cc index ea7630c..ec108d6 100644 --- a/chromeos/dbus/power_policy_controller_unittest.cc +++ b/chromeos/dbus/power_policy_controller_unittest.cc @@ -23,10 +23,13 @@ class PowerPolicyControllerTest : public testing::Test { virtual void SetUp() OVERRIDE { dbus_manager_ = new FakeDBusThreadManager; + fake_power_client_ = new FakePowerManagerClient; + dbus_manager_->SetPowerManagerClient( + scoped_ptr<PowerManagerClient>(fake_power_client_)); DBusThreadManager::InitializeForTesting(dbus_manager_); // Takes ownership. - policy_controller_.reset( - new PowerPolicyController(dbus_manager_, &fake_power_client_)); + policy_controller_.reset(new PowerPolicyController); + policy_controller_->Init(dbus_manager_); } virtual void TearDown() OVERRIDE { @@ -36,7 +39,7 @@ class PowerPolicyControllerTest : public testing::Test { protected: FakeDBusThreadManager* dbus_manager_; // Not owned. - FakePowerManagerClient fake_power_client_; + FakePowerManagerClient* fake_power_client_; scoped_ptr<PowerPolicyController> policy_controller_; }; @@ -84,7 +87,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { expected_policy.set_reason("Prefs"); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); // Change some prefs and check that an updated policy is sent. prefs.ac_idle_warning_delay_ms = 700000; @@ -97,7 +100,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { power_manager::PowerManagementPolicy_Action_SUSPEND); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); // The enable-screen-lock pref should force the screen-lock delays to // match the screen-off delays plus a constant value. @@ -109,7 +112,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { 360000 + PowerPolicyController::kScreenLockAfterOffDelayMs); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); // If the screen-lock-delay prefs are set to lower values than the // screen-off delays plus the constant, the lock prefs should take @@ -121,7 +124,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); // If the artificial screen-lock delays would exceed the idle delay, they // shouldn't be set -- the power manager would ignore them since the @@ -139,7 +142,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); // Set the "allow screen wake locks" pref to false. The system should be // prevented from suspending due to user inactivity on AC power but the @@ -152,7 +155,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { expected_policy.set_reason("Prefs, Screen"); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); } TEST_F(PowerPolicyControllerTest, WakeLocks) { @@ -167,7 +170,7 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) { expected_policy.set_reason(kSystemWakeLockReason); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); const char kScreenWakeLockReason[] = "screen"; const int screen_id = policy_controller_->AddScreenWakeLock( @@ -182,19 +185,19 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) { std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); policy_controller_->RemoveWakeLock(system_id); expected_policy.set_reason(kScreenWakeLockReason); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); policy_controller_->RemoveWakeLock(screen_id); expected_policy.Clear(); EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString( - fake_power_client_.get_policy())); + fake_power_client_->get_policy())); } } // namespace chromeos diff --git a/chromeos/disks/disk_mount_manager_unittest.cc b/chromeos/disks/disk_mount_manager_unittest.cc index 83def45..36e67ad 100644 --- a/chromeos/disks/disk_mount_manager_unittest.cc +++ b/chromeos/disks/disk_mount_manager_unittest.cc @@ -122,9 +122,11 @@ class DiskMountManagerTest : public testing::Test { // Adds a test observer to the disk mount manager. virtual void SetUp() { FakeDBusThreadManager* fake_thread_manager = new FakeDBusThreadManager(); - DBusThreadManager::InitializeForTesting(fake_thread_manager); + fake_cros_disks_client_ = new FakeCrosDisksClient; + fake_thread_manager->SetCrosDisksClient( + scoped_ptr<CrosDisksClient>(fake_cros_disks_client_)); - fake_cros_disks_client_ = fake_thread_manager->fake_cros_disks_client(); + DBusThreadManager::InitializeForTesting(fake_thread_manager); DiskMountManager::Initialize(); diff --git a/chromeos/network/managed_network_configuration_handler_unittest.cc b/chromeos/network/managed_network_configuration_handler_unittest.cc index 0f87729..2fe454d 100644 --- a/chromeos/network/managed_network_configuration_handler_unittest.cc +++ b/chromeos/network/managed_network_configuration_handler_unittest.cc @@ -9,10 +9,9 @@ #include "base/message_loop/message_loop.h" #include "base/stl_util.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/mock_dbus_thread_manager.h" +#include "chromeos/dbus/fake_dbus_thread_manager.h" #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/network/managed_network_configuration_handler_impl.h" #include "chromeos/network/network_configuration_handler.h" #include "chromeos/network/network_profile_handler.h" @@ -148,32 +147,32 @@ class TestNetworkProfileHandler : public NetworkProfileHandler { class ManagedNetworkConfigurationHandlerTest : public testing::Test { public: - ManagedNetworkConfigurationHandlerTest() { + ManagedNetworkConfigurationHandlerTest() + : mock_manager_client_(NULL), + mock_profile_client_(NULL) { } virtual ~ManagedNetworkConfigurationHandlerTest() { } virtual void SetUp() OVERRIDE { - MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; - EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) - .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); + FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager; + mock_manager_client_ = new StrictMock<MockShillManagerClient>(); + mock_profile_client_ = new StrictMock<MockShillProfileClient>(); + dbus_thread_manager->SetShillManagerClient( + scoped_ptr<ShillManagerClient>(mock_manager_client_).Pass()); + dbus_thread_manager->SetShillProfileClient( + scoped_ptr<ShillProfileClient>(mock_profile_client_).Pass()); + DBusThreadManager::InitializeForTesting(dbus_thread_manager); SetNetworkConfigurationHandlerExpectations(); - EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) - .WillRepeatedly(Return(&mock_manager_client_)); - EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) - .WillRepeatedly(Return(&mock_service_client_)); - EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) - .WillRepeatedly(Return(&mock_profile_client_)); - - ON_CALL(mock_profile_client_, GetProperties(_,_,_)) + ON_CALL(*mock_profile_client_, GetProperties(_,_,_)) .WillByDefault(Invoke(&profiles_stub_, &ShillProfileTestClient::GetProperties)); - ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) + ON_CALL(*mock_profile_client_, GetEntry(_,_,_,_)) .WillByDefault(Invoke(&profiles_stub_, &ShillProfileTestClient::GetEntry)); @@ -199,9 +198,8 @@ class ManagedNetworkConfigurationHandlerTest : public testing::Test { } void VerifyAndClearExpectations() { - Mock::VerifyAndClearExpectations(&mock_manager_client_); - Mock::VerifyAndClearExpectations(&mock_service_client_); - Mock::VerifyAndClearExpectations(&mock_profile_client_); + Mock::VerifyAndClearExpectations(mock_manager_client_); + Mock::VerifyAndClearExpectations(mock_profile_client_); SetNetworkConfigurationHandlerExpectations(); } @@ -247,10 +245,10 @@ class ManagedNetworkConfigurationHandlerTest : public testing::Test { void SetNetworkConfigurationHandlerExpectations() { // These calls occur in NetworkConfigurationHandler. - EXPECT_CALL(mock_manager_client_, GetProperties(_)).Times(AnyNumber()); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, GetProperties(_)).Times(AnyNumber()); + EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_)).Times(AnyNumber()); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, RemovePropertyChangedObserver(_)).Times(AnyNumber()); } @@ -259,9 +257,8 @@ class ManagedNetworkConfigurationHandlerTest : public testing::Test { } protected: - StrictMock<MockShillManagerClient> mock_manager_client_; - StrictMock<MockShillServiceClient> mock_service_client_; - StrictMock<MockShillProfileClient> mock_profile_client_; + MockShillManagerClient* mock_manager_client_; + MockShillProfileClient* mock_profile_client_; ShillProfileTestClient profiles_stub_; scoped_ptr<TestNetworkProfileHandler> network_profile_handler_; scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; @@ -284,10 +281,10 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, RemoveIrrelevantFields) { test_utils::ReadTestDictionary( "policy/shill_policy_on_unconfigured_wifi1.json"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -305,10 +302,10 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { test_utils::ReadTestDictionary( "policy/shill_policy_on_unconfigured_wifi1.json"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -338,18 +335,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, kUser1ProfilePath, "wifi_entry"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), _, _, _)).Times(2); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "eth_entry", _, _)); EXPECT_CALL( - mock_manager_client_, + *mock_manager_client_, ConfigureServiceForProfile(dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), _, _)); @@ -361,9 +358,9 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { InitializeStandardProfiles(); - EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); + EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _)); - EXPECT_CALL(mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); message_loop_.RunUntilIdle(); @@ -373,10 +370,10 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { kUser1ProfilePath, "some_entry_path"); - EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); + EXPECT_CALL(*mock_profile_client_, GetProperties(_, _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "some_entry_path", _, _)); SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); @@ -393,18 +390,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { test_utils::ReadTestDictionary( "policy/shill_policy_on_unmanaged_wifi1.json"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -426,18 +423,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, test_utils::ReadTestDictionary( "policy/shill_policy_on_unmanaged_wifi1.json"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -462,18 +459,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { expected_shill_properties->RemoveWithoutPathExpansion( shill::kPassphraseProperty, NULL); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -498,14 +495,14 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { expected_shill_properties->RemoveWithoutPathExpansion( shill::kPassphraseProperty, NULL); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -517,11 +514,11 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { // If we apply the policy again, without change, then the Shill profile will // not be modified. - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); @@ -534,15 +531,15 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { kUser1ProfilePath, "old_entry_path"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); @@ -557,10 +554,10 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetEmptyPolicyIgnoreUnmanaged) { kUser1ProfilePath, "old_entry_path"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "old_entry_path", _, _)); @@ -575,18 +572,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { kUser1ProfilePath, "wifi2_entry_path"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); scoped_ptr<base::DictionaryValue> expected_shill_properties = test_utils::ReadTestDictionary( "policy/shill_policy_on_unconfigured_wifi1.json"); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -602,18 +599,18 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, AutoConnectDisallowed) { kUser1ProfilePath, "wifi2_entry_path"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); EXPECT_CALL( - mock_profile_client_, + *mock_profile_client_, GetEntry(dbus::ObjectPath(kUser1ProfilePath), "wifi2_entry_path", _, _)); scoped_ptr<base::DictionaryValue> expected_shill_properties = test_utils::ReadTestDictionary( "policy/shill_disallow_autoconnect_on_unmanaged_wifi2.json"); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), @@ -635,10 +632,10 @@ TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) { test_utils::ReadTestDictionary( "policy/shill_policy_on_unconfigured_wifi1.json"); - EXPECT_CALL(mock_profile_client_, + EXPECT_CALL(*mock_profile_client_, GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); - EXPECT_CALL(mock_manager_client_, + EXPECT_CALL(*mock_manager_client_, ConfigureServiceForProfile( dbus::ObjectPath(kUser1ProfilePath), IsEqualTo(expected_shill_properties.get()), diff --git a/chromeos/network/network_configuration_handler_unittest.cc b/chromeos/network/network_configuration_handler_unittest.cc index af8d593..851914a 100644 --- a/chromeos/network/network_configuration_handler_unittest.cc +++ b/chromeos/network/network_configuration_handler_unittest.cc @@ -8,7 +8,7 @@ #include "base/strings/string_piece.h" #include "base/values.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/mock_dbus_thread_manager.h" +#include "chromeos/dbus/fake_dbus_thread_manager.h" #include "chromeos/dbus/mock_shill_manager_client.h" #include "chromeos/dbus/mock_shill_profile_client.h" #include "chromeos/dbus/mock_shill_service_client.h" @@ -23,6 +23,7 @@ #include "third_party/cros_system_api/dbus/service_constants.h" using ::testing::_; +using ::testing::AnyNumber; using ::testing::Invoke; using ::testing::Pointee; using ::testing::Return; @@ -98,16 +99,27 @@ class NetworkConfigurationHandlerTest : public testing::Test { virtual ~NetworkConfigurationHandlerTest() {} virtual void SetUp() OVERRIDE { - MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; - EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) - .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); - DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); - mock_manager_client_ = - mock_dbus_thread_manager->mock_shill_manager_client(); - mock_profile_client_ = - mock_dbus_thread_manager->mock_shill_profile_client(); - mock_service_client_ = - mock_dbus_thread_manager->mock_shill_service_client(); + FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager; + mock_manager_client_ = new MockShillManagerClient(); + mock_profile_client_ = new MockShillProfileClient(); + mock_service_client_ = new MockShillServiceClient(); + dbus_thread_manager->SetShillManagerClient( + scoped_ptr<ShillManagerClient>(mock_manager_client_).Pass()); + dbus_thread_manager->SetShillProfileClient( + scoped_ptr<ShillProfileClient>(mock_profile_client_).Pass()); + dbus_thread_manager->SetShillServiceClient( + scoped_ptr<ShillServiceClient>(mock_service_client_).Pass()); + + EXPECT_CALL(*mock_service_client_, GetProperties(_, _)) + .Times(AnyNumber()); + EXPECT_CALL(*mock_manager_client_, GetProperties(_)) + .Times(AnyNumber()); + EXPECT_CALL(*mock_manager_client_, AddPropertyChangedObserver(_)) + .Times(AnyNumber()); + EXPECT_CALL(*mock_manager_client_, RemovePropertyChangedObserver(_)) + .Times(AnyNumber()); + + DBusThreadManager::InitializeForTesting(dbus_thread_manager); network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); network_configuration_handler_.reset(new NetworkConfigurationHandler()); @@ -213,10 +225,11 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties) { EXPECT_CALL(*mock_service_client_, SetProperty(dbus::ObjectPath(service_path), key, IsEqualTo(networkNameValue.get()), _, _)).Times(1); - DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( - dbus::ObjectPath(service_path), key, *networkNameValue, - base::Bind(&base::DoNothing), - base::Bind(&DBusErrorCallback)); + mock_service_client_->SetProperty(dbus::ObjectPath(service_path), + key, + *networkNameValue, + base::Bind(&base::DoNothing), + base::Bind(&DBusErrorCallback)); message_loop_.RunUntilIdle(); ShillServiceClient::DictionaryValueCallback get_properties_callback; |