summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-18 03:19:06 +0000
committerkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-18 03:19:06 +0000
commitfa0e3ff90295784879f70ffa066e5f3b9bc9fa23 (patch)
tree5975c5a1a5ea6bdaff1b89fc936d68fbc191ca40
parentfb246af3f30a1775ffbcf4bdcf6bb347cd5382d1 (diff)
downloadchromium_src-fa0e3ff90295784879f70ffa066e5f3b9bc9fa23.zip
chromium_src-fa0e3ff90295784879f70ffa066e5f3b9bc9fa23.tar.gz
chromium_src-fa0e3ff90295784879f70ffa066e5f3b9bc9fa23.tar.bz2
bluetooth: Improve testability
Make a bunch of changes to the bluetooth code to improve its testability: - BluetoothAdapter and BluetoothDevice base observer and delegate classes made public, allows a test to static cast the pointer and call those methods as if it were the dbus client. - Add MockBluetoothAdapter::Observer and MockBluetoothDevice::Observer classes; these can be used by tests to check BluetoothAdapter and BluetoothDevice call observer methods at the correct time, with the correct arguments. - Add MockBluetooth*Client::Properties classes; these mock out the Get(), GetAll() and Set() methods so a test can verify whether or not they're called. Tests can also use MockBluetooth*Client::GetProperties() to return one of these mock classes constructed statically in the test, using ReplaceValue() on each property to set values. BUG=none TEST=can write a unit test Change-Id: I9eaeb6412de891f9b1b3cdaae66d32dfecbac8c9 Review URL: https://chromiumcodereview.appspot.com/10831360 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152234 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_adapter.h6
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_device.h4
-rw-r--r--chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc3
-rw-r--r--chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h13
-rw-r--r--chromeos/dbus/mock_bluetooth_adapter_client.cc6
-rw-r--r--chromeos/dbus/mock_bluetooth_adapter_client.h15
-rw-r--r--chromeos/dbus/mock_bluetooth_device_client.cc6
-rw-r--r--chromeos/dbus/mock_bluetooth_device_client.h15
-rw-r--r--chromeos/dbus/mock_bluetooth_input_client.cc6
-rw-r--r--chromeos/dbus/mock_bluetooth_input_client.h15
-rw-r--r--chromeos/dbus/mock_bluetooth_manager_client.cc6
-rw-r--r--chromeos/dbus/mock_bluetooth_manager_client.h15
-rw-r--r--chromeos/dbus/mock_bluetooth_node_client.cc6
-rw-r--r--chromeos/dbus/mock_bluetooth_node_client.h15
14 files changed, 126 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h
index eb3715d..d9d4df5 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h
@@ -33,9 +33,9 @@ class BluetoothDevice;
// The class may be instantiated for either a specific adapter, or for the
// generic "default adapter" which may change depending on availability.
class BluetoothAdapter : public base::RefCounted<BluetoothAdapter>,
- private BluetoothManagerClient::Observer,
- private BluetoothAdapterClient::Observer,
- private BluetoothDeviceClient::Observer {
+ public BluetoothManagerClient::Observer,
+ public BluetoothAdapterClient::Observer,
+ public BluetoothDeviceClient::Observer {
public:
// Interface for observing changes from bluetooth adapters.
class Observer {
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.h b/chrome/browser/chromeos/bluetooth/bluetooth_device.h
index 07d1c89..0064f48 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_device.h
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_device.h
@@ -37,8 +37,8 @@ class BluetoothSocket;
// Since the lifecycle of BluetoothDevice instances is managed by
// BluetoothAdapter, that class rather than this provides observer methods
// for devices coming and going, as well as properties being updated.
-class BluetoothDevice : private BluetoothDeviceClient::Observer,
- private BluetoothAgentServiceProvider::Delegate {
+class BluetoothDevice : public BluetoothDeviceClient::Observer,
+ public BluetoothAgentServiceProvider::Delegate {
public:
// Possible values that may be returned by GetDeviceType(), representing
// different types of bluetooth device that we support or are aware of
diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc b/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc
index b986133..f3d17cf 100644
--- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc
+++ b/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.cc
@@ -6,6 +6,9 @@
namespace chromeos {
+MockBluetoothAdapter::Observer::Observer() {}
+MockBluetoothAdapter::Observer::~Observer() {}
+
MockBluetoothAdapter::MockBluetoothAdapter() {}
MockBluetoothAdapter::~MockBluetoothAdapter() {}
diff --git a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h b/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h
index 2335a81..d770421 100644
--- a/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h
+++ b/chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h
@@ -17,6 +17,19 @@ namespace chromeos {
class MockBluetoothAdapter : public BluetoothAdapter {
public:
+ class Observer : public BluetoothAdapter::Observer {
+ public:
+ Observer();
+ virtual ~Observer();
+
+ MOCK_METHOD2(AdapterPresentChanged, void(BluetoothAdapter*, bool));
+ MOCK_METHOD2(AdapterPoweredChanged, void(BluetoothAdapter*, bool));
+ MOCK_METHOD2(AdapterDiscoveringChanged, void(BluetoothAdapter *, bool));
+ MOCK_METHOD2(DeviceAdded, void(BluetoothAdapter *, BluetoothDevice *));
+ MOCK_METHOD2(DeviceChanged, void(BluetoothAdapter *, BluetoothDevice *));
+ MOCK_METHOD2(DeviceRemoved, void(BluetoothAdapter *, BluetoothDevice *));
+ };
+
MockBluetoothAdapter();
MOCK_CONST_METHOD0(IsPresent, bool());
diff --git a/chromeos/dbus/mock_bluetooth_adapter_client.cc b/chromeos/dbus/mock_bluetooth_adapter_client.cc
index bef773c..73b3d54 100644
--- a/chromeos/dbus/mock_bluetooth_adapter_client.cc
+++ b/chromeos/dbus/mock_bluetooth_adapter_client.cc
@@ -6,6 +6,12 @@
namespace chromeos {
+MockBluetoothAdapterClient::Properties::Properties()
+ : BluetoothAdapterClient::Properties::Properties(
+ NULL, PropertyChangedCallback()) {}
+
+MockBluetoothAdapterClient::Properties::~Properties() {}
+
MockBluetoothAdapterClient::MockBluetoothAdapterClient() {}
MockBluetoothAdapterClient::~MockBluetoothAdapterClient() {}
diff --git a/chromeos/dbus/mock_bluetooth_adapter_client.h b/chromeos/dbus/mock_bluetooth_adapter_client.h
index a823945..c1d5f1e 100644
--- a/chromeos/dbus/mock_bluetooth_adapter_client.h
+++ b/chromeos/dbus/mock_bluetooth_adapter_client.h
@@ -14,6 +14,21 @@ namespace chromeos {
class MockBluetoothAdapterClient : public BluetoothAdapterClient {
public:
+ struct Properties : public BluetoothAdapterClient::Properties {
+ Properties();
+ virtual ~Properties();
+
+ MOCK_METHOD0(ConnectSignals, void());
+
+ MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
+ dbus::PropertySet::GetCallback callback));
+ MOCK_METHOD0(GetAll, void());
+ MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
+ dbus::PropertySet::SetCallback callback));
+
+ MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
+ };
+
MockBluetoothAdapterClient();
virtual ~MockBluetoothAdapterClient();
diff --git a/chromeos/dbus/mock_bluetooth_device_client.cc b/chromeos/dbus/mock_bluetooth_device_client.cc
index 75b5c44..f595daa 100644
--- a/chromeos/dbus/mock_bluetooth_device_client.cc
+++ b/chromeos/dbus/mock_bluetooth_device_client.cc
@@ -6,6 +6,12 @@
namespace chromeos {
+MockBluetoothDeviceClient::Properties::Properties()
+ : BluetoothDeviceClient::Properties::Properties(
+ NULL, PropertyChangedCallback()) {}
+
+MockBluetoothDeviceClient::Properties::~Properties() {}
+
MockBluetoothDeviceClient::MockBluetoothDeviceClient() {}
MockBluetoothDeviceClient::~MockBluetoothDeviceClient() {}
diff --git a/chromeos/dbus/mock_bluetooth_device_client.h b/chromeos/dbus/mock_bluetooth_device_client.h
index 35050e2..94cb8c4 100644
--- a/chromeos/dbus/mock_bluetooth_device_client.h
+++ b/chromeos/dbus/mock_bluetooth_device_client.h
@@ -14,6 +14,21 @@ namespace chromeos {
class MockBluetoothDeviceClient : public BluetoothDeviceClient {
public:
+ struct Properties : public BluetoothDeviceClient::Properties {
+ Properties();
+ virtual ~Properties();
+
+ MOCK_METHOD0(ConnectSignals, void());
+
+ MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
+ dbus::PropertySet::GetCallback callback));
+ MOCK_METHOD0(GetAll, void());
+ MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
+ dbus::PropertySet::SetCallback callback));
+
+ MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
+ };
+
MockBluetoothDeviceClient();
virtual ~MockBluetoothDeviceClient();
diff --git a/chromeos/dbus/mock_bluetooth_input_client.cc b/chromeos/dbus/mock_bluetooth_input_client.cc
index b73ef1e..54cc0a0 100644
--- a/chromeos/dbus/mock_bluetooth_input_client.cc
+++ b/chromeos/dbus/mock_bluetooth_input_client.cc
@@ -6,6 +6,12 @@
namespace chromeos {
+MockBluetoothInputClient::Properties::Properties()
+ : BluetoothInputClient::Properties::Properties(
+ NULL, PropertyChangedCallback()) {}
+
+MockBluetoothInputClient::Properties::~Properties() {}
+
MockBluetoothInputClient::MockBluetoothInputClient() {}
MockBluetoothInputClient::~MockBluetoothInputClient() {}
diff --git a/chromeos/dbus/mock_bluetooth_input_client.h b/chromeos/dbus/mock_bluetooth_input_client.h
index afa438c..19bfaee 100644
--- a/chromeos/dbus/mock_bluetooth_input_client.h
+++ b/chromeos/dbus/mock_bluetooth_input_client.h
@@ -14,6 +14,21 @@ namespace chromeos {
class MockBluetoothInputClient : public BluetoothInputClient {
public:
+ struct Properties : public BluetoothInputClient::Properties {
+ Properties();
+ virtual ~Properties();
+
+ MOCK_METHOD0(ConnectSignals, void());
+
+ MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
+ dbus::PropertySet::GetCallback callback));
+ MOCK_METHOD0(GetAll, void());
+ MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
+ dbus::PropertySet::SetCallback callback));
+
+ MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
+ };
+
MockBluetoothInputClient();
virtual ~MockBluetoothInputClient();
diff --git a/chromeos/dbus/mock_bluetooth_manager_client.cc b/chromeos/dbus/mock_bluetooth_manager_client.cc
index 9fd6f93..3b31d72 100644
--- a/chromeos/dbus/mock_bluetooth_manager_client.cc
+++ b/chromeos/dbus/mock_bluetooth_manager_client.cc
@@ -6,6 +6,12 @@
namespace chromeos {
+MockBluetoothManagerClient::Properties::Properties()
+ : BluetoothManagerClient::Properties::Properties(
+ NULL, PropertyChangedCallback()) {}
+
+MockBluetoothManagerClient::Properties::~Properties() {}
+
MockBluetoothManagerClient::MockBluetoothManagerClient() {}
MockBluetoothManagerClient::~MockBluetoothManagerClient() {}
diff --git a/chromeos/dbus/mock_bluetooth_manager_client.h b/chromeos/dbus/mock_bluetooth_manager_client.h
index 9485e24..b6175c2 100644
--- a/chromeos/dbus/mock_bluetooth_manager_client.h
+++ b/chromeos/dbus/mock_bluetooth_manager_client.h
@@ -14,6 +14,21 @@ namespace chromeos {
class MockBluetoothManagerClient : public BluetoothManagerClient {
public:
+ struct Properties : public BluetoothManagerClient::Properties {
+ Properties();
+ virtual ~Properties();
+
+ MOCK_METHOD0(ConnectSignals, void());
+
+ MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
+ dbus::PropertySet::GetCallback callback));
+ MOCK_METHOD0(GetAll, void());
+ MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
+ dbus::PropertySet::SetCallback callback));
+
+ MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
+ };
+
MockBluetoothManagerClient();
virtual ~MockBluetoothManagerClient();
diff --git a/chromeos/dbus/mock_bluetooth_node_client.cc b/chromeos/dbus/mock_bluetooth_node_client.cc
index fddd878..9c5efa9 100644
--- a/chromeos/dbus/mock_bluetooth_node_client.cc
+++ b/chromeos/dbus/mock_bluetooth_node_client.cc
@@ -6,6 +6,12 @@
namespace chromeos {
+MockBluetoothNodeClient::Properties::Properties()
+ : BluetoothNodeClient::Properties::Properties(
+ NULL, PropertyChangedCallback()) {}
+
+MockBluetoothNodeClient::Properties::~Properties() {}
+
MockBluetoothNodeClient::MockBluetoothNodeClient() {}
MockBluetoothNodeClient::~MockBluetoothNodeClient() {}
diff --git a/chromeos/dbus/mock_bluetooth_node_client.h b/chromeos/dbus/mock_bluetooth_node_client.h
index 78b1497..dd0b591 100644
--- a/chromeos/dbus/mock_bluetooth_node_client.h
+++ b/chromeos/dbus/mock_bluetooth_node_client.h
@@ -14,6 +14,21 @@ namespace chromeos {
class MockBluetoothNodeClient : public BluetoothNodeClient {
public:
+ struct Properties : public BluetoothNodeClient::Properties {
+ Properties();
+ virtual ~Properties();
+
+ MOCK_METHOD0(ConnectSignals, void());
+
+ MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
+ dbus::PropertySet::GetCallback callback));
+ MOCK_METHOD0(GetAll, void());
+ MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
+ dbus::PropertySet::SetCallback callback));
+
+ MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
+ };
+
MockBluetoothNodeClient();
virtual ~MockBluetoothNodeClient();