diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-18 03:19:06 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-18 03:19:06 +0000 |
commit | fa0e3ff90295784879f70ffa066e5f3b9bc9fa23 (patch) | |
tree | 5975c5a1a5ea6bdaff1b89fc936d68fbc191ca40 /chrome | |
parent | fb246af3f30a1775ffbcf4bdcf6bb347cd5382d1 (diff) | |
download | chromium_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
Diffstat (limited to 'chrome')
4 files changed, 21 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()); |