Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: device/bluetooth/bluetooth_gatt_chromeos_unittest.cc

Issue 418483003: device/bluetooth: Move GATT observer methods to BluetoothAdapter::Observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device_win.cc ('k') | device/bluetooth/bluetooth_gatt_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
diff --git a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
index a585f819799a78255a5b281678bc843a616dc696..d3f78cbf180b1d5f5bad49a259b7a88ebb768ef2 100644
--- a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc
@@ -57,28 +57,33 @@ bool ValuesEqual(const std::vector<uint8>& value0,
return true;
}
-class TestDeviceObserver : public BluetoothDevice::Observer {
+class TestObserver : public BluetoothAdapter::Observer {
public:
- TestDeviceObserver(scoped_refptr<BluetoothAdapter> adapter,
- BluetoothDevice* device)
+ TestObserver(scoped_refptr<BluetoothAdapter> adapter)
: gatt_service_added_count_(0),
gatt_service_removed_count_(0),
- device_address_(device->GetAddress()),
+ gatt_service_changed_count_(0),
+ gatt_discovery_complete_count_(0),
+ gatt_characteristic_added_count_(0),
+ gatt_characteristic_removed_count_(0),
+ gatt_characteristic_value_changed_count_(0),
+ gatt_descriptor_added_count_(0),
+ gatt_descriptor_removed_count_(0),
+ gatt_descriptor_value_changed_count_(0),
adapter_(adapter) {
- device->AddObserver(this);
+ adapter_->AddObserver(this);
}
- virtual ~TestDeviceObserver() {
- BluetoothDevice* device = adapter_->GetDevice(device_address_);
- if (device)
- device->RemoveObserver(this);
+ virtual ~TestObserver() {
+ adapter_->RemoveObserver(this);
}
- // BluetoothDevice::Observer overrides.
- virtual void GattServiceAdded(
- BluetoothDevice* device,
- BluetoothGattService* service) OVERRIDE {
- ASSERT_EQ(device_address_, device->GetAddress());
+ // BluetoothAdapter::Observer overrides.
+ virtual void GattServiceAdded(BluetoothAdapter* adapter,
+ BluetoothDevice* device,
+ BluetoothGattService* service) OVERRIDE {
+ ASSERT_EQ(adapter_.get(), adapter);
+ ASSERT_EQ(service->GetDevice(), device);
++gatt_service_added_count_;
last_gatt_service_id_ = service->GetIdentifier();
@@ -92,10 +97,11 @@ class TestDeviceObserver : public BluetoothDevice::Observer {
QuitMessageLoop();
}
- virtual void GattServiceRemoved(
- BluetoothDevice* device,
- BluetoothGattService* service) OVERRIDE {
- ASSERT_EQ(device_address_, device->GetAddress());
+ virtual void GattServiceRemoved(BluetoothAdapter* adapter,
+ BluetoothDevice* device,
+ BluetoothGattService* service) OVERRIDE {
+ ASSERT_EQ(adapter_.get(), adapter);
+ ASSERT_EQ(service->GetDevice(), device);
++gatt_service_removed_count_;
last_gatt_service_id_ = service->GetIdentifier();
@@ -110,172 +116,131 @@ class TestDeviceObserver : public BluetoothDevice::Observer {
QuitMessageLoop();
}
- int gatt_service_added_count_;
- int gatt_service_removed_count_;
- std::string last_gatt_service_id_;
- BluetoothUUID last_gatt_service_uuid_;
-
- private:
- // Some tests use a message loop since background processing is simulated;
- // break out of those loops.
- void QuitMessageLoop() {
- if (base::MessageLoop::current() &&
- base::MessageLoop::current()->is_running())
- base::MessageLoop::current()->Quit();
- }
-
- std::string device_address_;
- scoped_refptr<BluetoothAdapter> adapter_;
-};
-
-class TestGattServiceObserver : public BluetoothGattService::Observer {
- public:
- TestGattServiceObserver(scoped_refptr<BluetoothAdapter> adapter,
- BluetoothDevice* device,
- BluetoothGattService* service)
- : gatt_service_changed_count_(0),
- gatt_discovery_complete_count_(0),
- gatt_characteristic_added_count_(0),
- gatt_characteristic_removed_count_(0),
- gatt_characteristic_value_changed_count_(0),
- gatt_descriptor_added_count_(0),
- gatt_descriptor_removed_count_(0),
- gatt_descriptor_value_changed_count_(0),
- device_address_(device->GetAddress()),
- gatt_service_id_(service->GetIdentifier()),
- adapter_(adapter) {
- service->AddObserver(this);
- }
-
- virtual ~TestGattServiceObserver() {
- // See if either the device or the service even exist.
- BluetoothDevice* device = adapter_->GetDevice(device_address_);
- if (!device)
- return;
-
- BluetoothGattService* service = device->GetGattService(gatt_service_id_);
- if (!service)
- return;
-
- service->RemoveObserver(this);
- }
-
- // BluetoothGattService::Observer overrides.
virtual void GattDiscoveryCompleteForService(
+ BluetoothAdapter* adapter,
BluetoothGattService* service) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, service->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_discovery_complete_count_;
QuitMessageLoop();
}
- virtual void GattServiceChanged(BluetoothGattService* service) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, service->GetIdentifier());
+ virtual void GattServiceChanged(BluetoothAdapter* adapter,
+ BluetoothGattService* service) OVERRIDE {
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_service_changed_count_;
QuitMessageLoop();
}
virtual void GattCharacteristicAdded(
- BluetoothGattService* service,
+ BluetoothAdapter* adapter,
BluetoothGattCharacteristic* characteristic) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, service->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_characteristic_added_count_;
last_gatt_characteristic_id_ = characteristic->GetIdentifier();
last_gatt_characteristic_uuid_ = characteristic->GetUUID();
- EXPECT_EQ(service->GetCharacteristic(last_gatt_characteristic_id_),
+ ASSERT_TRUE(characteristic->GetService());
+ EXPECT_EQ(characteristic->GetService()->GetCharacteristic(
+ last_gatt_characteristic_id_),
characteristic);
- EXPECT_EQ(service, characteristic->GetService());
QuitMessageLoop();
}
virtual void GattCharacteristicRemoved(
- BluetoothGattService* service,
+ BluetoothAdapter* adapter,
BluetoothGattCharacteristic* characteristic) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, service->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_characteristic_removed_count_;
last_gatt_characteristic_id_ = characteristic->GetIdentifier();
last_gatt_characteristic_uuid_ = characteristic->GetUUID();
// The service should return NULL for this characteristic.
- EXPECT_FALSE(service->GetCharacteristic(last_gatt_characteristic_id_));
- EXPECT_EQ(service, characteristic->GetService());
+ ASSERT_TRUE(characteristic->GetService());
+ EXPECT_FALSE(characteristic->GetService()->GetCharacteristic(
+ last_gatt_characteristic_id_));
QuitMessageLoop();
}
virtual void GattCharacteristicValueChanged(
- BluetoothGattService* service,
+ BluetoothAdapter* adapter,
BluetoothGattCharacteristic* characteristic,
const std::vector<uint8>& value) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, service->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_characteristic_value_changed_count_;
last_gatt_characteristic_id_ = characteristic->GetIdentifier();
last_gatt_characteristic_uuid_ = characteristic->GetUUID();
last_changed_characteristic_value_ = value;
- EXPECT_EQ(service->GetCharacteristic(last_gatt_characteristic_id_),
+ ASSERT_TRUE(characteristic->GetService());
+ EXPECT_EQ(characteristic->GetService()->GetCharacteristic(
+ last_gatt_characteristic_id_),
characteristic);
- EXPECT_EQ(service, characteristic->GetService());
QuitMessageLoop();
}
virtual void GattDescriptorAdded(
- BluetoothGattCharacteristic* characteristic,
+ BluetoothAdapter* adapter,
BluetoothGattDescriptor* descriptor) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_descriptor_added_count_;
last_gatt_descriptor_id_ = descriptor->GetIdentifier();
last_gatt_descriptor_uuid_ = descriptor->GetUUID();
- EXPECT_EQ(characteristic->GetDescriptor(last_gatt_descriptor_id_),
+ ASSERT_TRUE(descriptor->GetCharacteristic());
+ EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor(
+ last_gatt_descriptor_id_),
descriptor);
- EXPECT_EQ(characteristic, descriptor->GetCharacteristic());
QuitMessageLoop();
}
virtual void GattDescriptorRemoved(
- BluetoothGattCharacteristic* characteristic,
+ BluetoothAdapter* adapter,
BluetoothGattDescriptor* descriptor) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_descriptor_removed_count_;
last_gatt_descriptor_id_ = descriptor->GetIdentifier();
last_gatt_descriptor_uuid_ = descriptor->GetUUID();
// The characteristic should return NULL for this descriptor..
- EXPECT_FALSE(characteristic->GetDescriptor(last_gatt_descriptor_id_));
- EXPECT_EQ(characteristic, descriptor->GetCharacteristic());
+ ASSERT_TRUE(descriptor->GetCharacteristic());
+ EXPECT_FALSE(descriptor->GetCharacteristic()->GetDescriptor(
+ last_gatt_descriptor_id_));
QuitMessageLoop();
}
virtual void GattDescriptorValueChanged(
- BluetoothGattCharacteristic* characteristic,
+ BluetoothAdapter* adapter,
BluetoothGattDescriptor* descriptor,
const std::vector<uint8>& value) OVERRIDE {
- ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier());
+ ASSERT_EQ(adapter_.get(), adapter);
++gatt_descriptor_value_changed_count_;
last_gatt_descriptor_id_ = descriptor->GetIdentifier();
last_gatt_descriptor_uuid_ = descriptor->GetUUID();
last_changed_descriptor_value_ = value;
- EXPECT_EQ(characteristic->GetDescriptor(last_gatt_descriptor_id_),
+ ASSERT_TRUE(descriptor->GetCharacteristic());
+ EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor(
+ last_gatt_descriptor_id_),
descriptor);
- EXPECT_EQ(characteristic, descriptor->GetCharacteristic());
QuitMessageLoop();
}
+ int gatt_service_added_count_;
+ int gatt_service_removed_count_;
int gatt_service_changed_count_;
int gatt_discovery_complete_count_;
int gatt_characteristic_added_count_;
@@ -284,6 +249,8 @@ class TestGattServiceObserver : public BluetoothGattService::Observer {
int gatt_descriptor_added_count_;
int gatt_descriptor_removed_count_;
int gatt_descriptor_value_changed_count_;
+ std::string last_gatt_service_id_;
+ BluetoothUUID last_gatt_service_uuid_;
std::string last_gatt_characteristic_id_;
BluetoothUUID last_gatt_characteristic_uuid_;
std::vector<uint8> last_changed_characteristic_value_;
@@ -300,8 +267,6 @@ class TestGattServiceObserver : public BluetoothGattService::Observer {
base::MessageLoop::current()->Quit();
}
- std::string device_address_;
- std::string gatt_service_id_;
scoped_refptr<BluetoothAdapter> adapter_;
};
@@ -515,7 +480,8 @@ TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
+
EXPECT_EQ(0, observer.gatt_service_added_count_);
EXPECT_EQ(0, observer.gatt_service_removed_count_);
EXPECT_TRUE(observer.last_gatt_service_id_.empty());
@@ -605,7 +571,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -616,12 +582,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(0, service_observer.gatt_discovery_complete_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_added_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(0, observer.gatt_discovery_complete_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_added_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_removed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(service->GetCharacteristics().empty());
// Run the message loop so that the characteristics appear.
@@ -630,19 +595,19 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) {
// 3 characteristics should appear. Only 1 of the characteristics sends
// value changed signals. Service changed should be fired once for
// descriptor added.
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_);
- EXPECT_EQ(3, service_observer.gatt_characteristic_added_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count_);
+ EXPECT_EQ(3, observer.gatt_characteristic_added_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_removed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
EXPECT_EQ(3U, service->GetCharacteristics().size());
// Hide the characteristics. 3 removed signals should be received.
fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics();
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(3, service_observer.gatt_characteristic_added_count_);
- EXPECT_EQ(3, service_observer.gatt_characteristic_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(3, observer.gatt_characteristic_added_count_);
+ EXPECT_EQ(3, observer.gatt_characteristic_removed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(service->GetCharacteristics().empty());
// Re-expose the heart rate characteristics. We shouldn't get another
@@ -651,19 +616,19 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) {
// only if the service will also be subsequently removed.
fake_bluetooth_gatt_characteristic_client_->ExposeHeartRateCharacteristics(
fake_bluetooth_gatt_service_client_->GetHeartRateServicePath());
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_);
- EXPECT_EQ(6, service_observer.gatt_characteristic_added_count_);
- EXPECT_EQ(3, service_observer.gatt_characteristic_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count_);
+ EXPECT_EQ(6, observer.gatt_characteristic_added_count_);
+ EXPECT_EQ(3, observer.gatt_characteristic_removed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
EXPECT_EQ(3U, service->GetCharacteristics().size());
// Hide the service. All characteristics should disappear.
fake_bluetooth_gatt_service_client_->HideHeartRateService();
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(6, service_observer.gatt_characteristic_added_count_);
- EXPECT_EQ(6, service_observer.gatt_characteristic_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(6, observer.gatt_characteristic_added_count_);
+ EXPECT_EQ(6, observer.gatt_characteristic_removed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
}
TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) {
@@ -674,7 +639,7 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -685,22 +650,21 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_added_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_added_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_removed_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_);
EXPECT_TRUE(service->GetCharacteristics().empty());
// Run the message loop so that the characteristics appear.
base::MessageLoop::current()->Run();
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
// Only the Heart Rate Measurement characteristic has a descriptor.
- EXPECT_EQ(1, service_observer.gatt_descriptor_added_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_added_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_removed_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_);
BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
fake_bluetooth_gatt_characteristic_client_->
@@ -724,40 +688,37 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) {
EXPECT_FALSE(descriptor->IsLocal());
EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
descriptor->GetUUID());
- EXPECT_EQ(descriptor->GetUUID(),
- service_observer.last_gatt_descriptor_uuid_);
- EXPECT_EQ(descriptor->GetIdentifier(),
- service_observer.last_gatt_descriptor_id_);
+ EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid_);
+ EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id_);
// Hide the descriptor.
fake_bluetooth_gatt_descriptor_client_->HideDescriptor(
dbus::ObjectPath(descriptor->GetIdentifier()));
EXPECT_TRUE(characteristic->GetDescriptors().empty());
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_descriptor_added_count_);
- EXPECT_EQ(1, service_observer.gatt_descriptor_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_added_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_removed_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_);
// Expose the descriptor again.
- service_observer.last_gatt_descriptor_id_.clear();
- service_observer.last_gatt_descriptor_uuid_ = BluetoothUUID();
+ observer.last_gatt_descriptor_id_.clear();
+ observer.last_gatt_descriptor_uuid_ = BluetoothUUID();
fake_bluetooth_gatt_descriptor_client_->ExposeDescriptor(
dbus::ObjectPath(characteristic->GetIdentifier()),
FakeBluetoothGattDescriptorClient::
kClientCharacteristicConfigurationUUID);
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
EXPECT_EQ(1U, characteristic->GetDescriptors().size());
- EXPECT_EQ(2, service_observer.gatt_descriptor_added_count_);
- EXPECT_EQ(1, service_observer.gatt_descriptor_removed_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(2, observer.gatt_descriptor_added_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_removed_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_);
descriptor = characteristic->GetDescriptors()[0];
EXPECT_FALSE(descriptor->IsLocal());
EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(),
descriptor->GetUUID());
- EXPECT_EQ(descriptor->GetUUID(), service_observer.last_gatt_descriptor_uuid_);
- EXPECT_EQ(descriptor->GetIdentifier(),
- service_observer.last_gatt_descriptor_id_);
+ EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid_);
+ EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id_);
}
TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) {
@@ -844,7 +805,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -855,15 +816,14 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
// Run the message loop so that the characteristics appear.
base::MessageLoop::current()->Run();
// Issue write request to non-writeable characteristics.
- service_observer.last_gatt_characteristic_id_.clear();
- service_observer.last_gatt_characteristic_uuid_ = BluetoothUUID();
+ observer.last_gatt_characteristic_id_.clear();
+ observer.last_gatt_characteristic_uuid_ = BluetoothUUID();
std::vector<uint8> write_value;
write_value.push_back(0x01);
@@ -882,11 +842,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
base::Unretained(this)),
base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
base::Unretained(this)));
- EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty());
- EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid());
+ EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty());
+ EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid());
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(1, error_callback_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
characteristic = service->GetCharacteristic(
fake_bluetooth_gatt_characteristic_client_->
@@ -902,11 +862,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
base::Unretained(this)),
base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
base::Unretained(this)));
- EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty());
- EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid());
+ EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty());
+ EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid());
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(2, error_callback_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
// Issue write request to writeable characteristic. The "Body Sensor Location"
// characteristic does not send notifications and WriteValue does not result
@@ -926,11 +886,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
base::Unretained(this)),
base::Bind(&BluetoothGattChromeOSTest::ErrorCallback,
base::Unretained(this)));
- EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty());
- EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid());
+ EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty());
+ EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid());
EXPECT_EQ(1, success_callback_count_);
EXPECT_EQ(2, error_callback_count_);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
// Issue a read request. A successful read results in a
// CharacteristicValueChanged notification.
@@ -949,7 +909,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) {
base::Unretained(this)));
EXPECT_EQ(2, success_callback_count_);
EXPECT_EQ(2, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_));
}
@@ -961,7 +921,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -971,7 +931,6 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
EXPECT_TRUE(service->GetCharacteristics().empty());
// Run the message loop so that the characteristics appear.
@@ -1004,7 +963,7 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) {
FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -1015,16 +974,15 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(0, service_observer.gatt_discovery_complete_count_);
- EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(0, observer.gatt_discovery_complete_count_);
+ EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_);
EXPECT_TRUE(service->GetCharacteristics().empty());
// Run the message loop so that the characteristics appear.
base::MessageLoop::current()->Run();
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_discovery_complete_count_);
// Only the Heart Rate Measurement characteristic has a descriptor.
BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
@@ -1061,8 +1019,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) {
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue()));
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_);
// Write value. Writes to this descriptor will fail.
desc_value[0] = 0x03;
@@ -1076,8 +1034,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) {
EXPECT_EQ(1, error_callback_count_);
EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_);
// Read new value.
descriptor->ReadRemoteDescriptor(
@@ -1089,8 +1047,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) {
EXPECT_EQ(1, error_callback_count_);
EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue()));
EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue()));
- EXPECT_EQ(0, service_observer.gatt_service_changed_count_);
- EXPECT_EQ(2, service_observer.gatt_descriptor_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_service_changed_count_);
+ EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_);
}
TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
@@ -1101,7 +1059,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -1112,8 +1070,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
// Run the message loop so that the characteristics appear.
base::MessageLoop::current()->Run();
@@ -1136,7 +1093,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
// notification.
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(update_sessions_.empty());
// Send a two more requests, which should get queued.
@@ -1152,7 +1109,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
base::Unretained(this)));
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(update_sessions_.empty());
EXPECT_TRUE(characteristic->IsNotifying());
@@ -1162,12 +1119,12 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
EXPECT_EQ(3, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_EQ(3U, update_sessions_.size());
// Notifications should be getting sent regularly now.
base::MessageLoop::current()->Run();
- EXPECT_GT(service_observer.gatt_characteristic_value_changed_count_, 1);
+ EXPECT_GT(observer.gatt_characteristic_value_changed_count_, 1);
// Stop one of the sessions. The session should become inactive but the
// characteristic should still be notifying.
@@ -1195,7 +1152,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
EXPECT_FALSE(characteristic->IsNotifying());
success_callback_count_ = 0;
- service_observer.gatt_characteristic_value_changed_count_ = 0;
+ observer.gatt_characteristic_value_changed_count_ = 0;
// Enable notifications again.
characteristic->StartNotifySession(
@@ -1205,7 +1162,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
base::Unretained(this)));
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(update_sessions_.empty());
EXPECT_TRUE(characteristic->IsNotifying());
@@ -1214,14 +1171,14 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) {
EXPECT_EQ(1, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_EQ(1U, update_sessions_.size());
EXPECT_TRUE(update_sessions_[0]->IsActive());
EXPECT_TRUE(characteristic->IsNotifying());
// Check that notifications are happening.
base::MessageLoop::current()->Run();
- EXPECT_GT(service_observer.gatt_characteristic_value_changed_count_, 1);
+ EXPECT_GT(observer.gatt_characteristic_value_changed_count_, 1);
// Request another session. This should return immediately.
characteristic->StartNotifySession(
@@ -1251,7 +1208,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
- TestDeviceObserver observer(adapter_, device);
+ TestObserver observer(adapter_);
// Expose the fake Heart Rate service. This will asynchronously expose
// characteristics.
@@ -1262,8 +1219,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
BluetoothGattService* service =
device->GetGattService(observer.last_gatt_service_id_);
- TestGattServiceObserver service_observer(adapter_, device, service);
- EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_);
// Run the message loop so that the characteristics appear.
base::MessageLoop::current()->Run();
@@ -1301,7 +1257,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
// notification.
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(characteristic->IsNotifying());
EXPECT_TRUE(update_sessions_.empty());
@@ -1311,7 +1267,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
EXPECT_EQ(4, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(characteristic->IsNotifying());
EXPECT_EQ(4U, update_sessions_.size());
@@ -1338,7 +1294,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
// the session count and make a request through the client.
update_sessions_.clear();
success_callback_count_ = 0;
- service_observer.gatt_characteristic_value_changed_count_ = 0;
+ observer.gatt_characteristic_value_changed_count_ = 0;
characteristic->StartNotifySession(
base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback,
base::Unretained(this)),
@@ -1347,7 +1303,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
EXPECT_EQ(0, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(characteristic->IsNotifying());
EXPECT_TRUE(update_sessions_.empty());
@@ -1355,7 +1311,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) {
EXPECT_EQ(1, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
- EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_);
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_);
EXPECT_TRUE(characteristic->IsNotifying());
EXPECT_EQ(1U, update_sessions_.size());
EXPECT_TRUE(update_sessions_[0]->IsActive());
« no previous file with comments | « device/bluetooth/bluetooth_device_win.cc ('k') | device/bluetooth/bluetooth_gatt_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698