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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2248913002: bluetooth: Implement RSSI and Tx Power on macOS and Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-refactor-adv-data
Patch Set: Clean up Created 4 years, 4 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
Index: device/bluetooth/bluetooth_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index 3f1ba60a6d259df012064f0a1028eefbf3b77249..d8420c205730e415250f5549bd1781ff8847965b 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -133,15 +133,21 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
InitWithFakeAdapter();
TestBluetoothAdapterObserver observer(adapter_);
- // Start Discovery Session and receive Advertisement. No DeviceChanged event
- // because the device is new.
+ // Start Discovery Session and receive Advertisement, should
+ // not notify of device changed because the device is new.
+ // - GetInquiryRSSI: Should return the packet's rssi.
// - GetUUIDs: Should return Advertised UUIDs.
// - GetServiceData: Should return advertised Service Data.
+ // - GetInquiryTxPower: Should return the packet's advertised Tx Power.
StartLowEnergyDiscoverySession();
BluetoothDevice* device = SimulateLowEnergyDevice(1);
EXPECT_EQ(0, observer.device_changed_count());
+
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
+
EXPECT_EQ(2u, device->GetUUIDs().size());
+
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
@@ -160,14 +166,20 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
- // Receive Advertisement with no UUIDs or Service Data, should notify
- // device changed.
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
+
+ // Receive Advertisement with no UUIDs, Service Data, or Tx Power, should
+ // notify device changed.
+ // - GetInquiryRSSI: Should return packet's rssi.
// - GetUUIDs: Should return no UUIDs.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because of no Tx Power.
SimulateLowEnergyDevice(3);
EXPECT_EQ(1, observer.device_changed_count());
- EXPECT_EQ(0u, device->GetUUIDs().size());
+ EXPECT_EQ(kTestRSSI3, device->GetInquiryRSSI().value());
+
+ EXPECT_EQ(0u, device->GetUUIDs().size());
#if defined(OS_MACOSX)
// TODO(ortuno): Enable on Android once it supports Service Data.
// http://crbug.com/639408
@@ -177,13 +189,21 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
- // Receive Advertisement with different UUIDs and Service Data, should notify
- // device changed.
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
Jeffrey Yasskin 2016/08/24 04:32:02 Does just EXPECT_FALSE(device->GetInquiryTxPower()
ortuno 2016/08/24 21:29:09 Done.
+
+ // Receive Advertisement with different UUIDs, Service Data, and Tx Power,
+ // should notify device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return latest Advertised UUIDs.
// - GetServiceData: Should return last advertised Service Data.
+ // - GetInquiryTxPower: Should return last advertised Tx Power.
SimulateLowEnergyDevice(2);
EXPECT_EQ(2, observer.device_changed_count());
+
+ EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value());
+
EXPECT_EQ(2u, device->GetUUIDs().size());
+
EXPECT_FALSE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
@@ -207,15 +227,24 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value());
+
// Stop discovery session, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should not return any UUIDs.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
GetErrorCallback(Call::NOT_EXPECTED));
ASSERT_FALSE(adapter_->IsDiscovering());
ASSERT_FALSE(discovery_sessions_[0]->IsActive());
EXPECT_EQ(3, observer.device_changed_count());
+
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
+
EXPECT_EQ(0u, device->GetUUIDs().size());
#if defined(OS_MACOSX)
@@ -229,15 +258,23 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
BluetoothUUID(kTestUUIDImmediateAlert)));
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
+
// Discover the device again with different UUIDs, should notify of device
// changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return only the latest Advertised UUIDs.
// - GetServiceData: Should return last advertise Service Data.
+ // - GetInquiryTxPower: Should return last advertised Tx Power.
StartLowEnergyDiscoverySession();
device = SimulateLowEnergyDevice(1);
EXPECT_EQ(4, observer.device_changed_count());
+
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
+
EXPECT_EQ(2u, device->GetUUIDs().size());
+
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
@@ -255,6 +292,8 @@ TEST_F(BluetoothTest, AdvertisementData_Discovery) {
EXPECT_EQ(std::vector<uint8_t>({1}),
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
@@ -275,16 +314,23 @@ TEST_F(BluetoothTest, GetUUIDs_Connection) {
GetErrorCallback(Call::NOT_EXPECTED));
// Connect to the device.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return no UUIDs because Services have not been
// discovered.
// - GetServiceData: Should return empty map because we are no longer
// discovering.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device);
ASSERT_TRUE(device->IsConnected());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
+
EXPECT_EQ(0u, device->GetUUIDs().size());
+
#if defined(OS_MACOSX)
// TODO(ortuno): Enable on Android once it supports Service Data.
// http://crbug.com/639408
@@ -292,16 +338,25 @@ TEST_F(BluetoothTest, GetUUIDs_Connection) {
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
+
observer.Reset();
// Discover services, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return the device's services' UUIDs.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
std::vector<std::string> services;
services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value());
SimulateGattServicesDiscovered(device, services);
EXPECT_EQ(1, observer.device_changed_count());
+
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
+
EXPECT_EQ(1u, device->GetUUIDs().size());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
@@ -313,6 +368,8 @@ TEST_F(BluetoothTest, GetUUIDs_Connection) {
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
+
#if defined(OS_MACOSX)
// TODO(ortuno): Enable in Android and Windows.
// Android and Windows don't yet support service changed events.
@@ -322,43 +379,60 @@ TEST_F(BluetoothTest, GetUUIDs_Connection) {
observer.Reset();
// Notify of services changed, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return no UUIDs because we no longer know what services
// the device has.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
SimulateGattServicesChanged(device);
ASSERT_FALSE(device->IsGattServicesDiscoveryComplete());
EXPECT_EQ(1, observer.device_changed_count());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(0u, device->GetUUIDs().size());
-
EXPECT_EQ(ServiceDataMap(), device->GetServiceData());
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
// Services discovered again, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return Service UUIDs.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
SimulateGattServicesDiscovered(device, {} /* services */);
EXPECT_EQ(2, observer.device_changed_count());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(1u, device->GetUUIDs().size());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_EQ(ServiceDataMap(), device->GetServiceData());
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
+
#endif // defined(OS_MACOSX)
observer.Reset();
// Disconnect, should notify device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return no UUIDs since we no longer know what services
// the device holds and notify of device changed.
// - GetServiceData: Should return empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
gatt_connections_[0]->Disconnect();
SimulateGattDisconnection(device);
ASSERT_FALSE(device->IsGattConnected());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(0u, device->GetUUIDs().size());
@@ -368,6 +442,8 @@ TEST_F(BluetoothTest, GetUUIDs_Connection) {
EXPECT_EQ(ServiceDataMap(), device->GetServiceData());
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
#endif // defined(OS_MACOSX)
+
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
@@ -408,16 +484,22 @@ TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) {
// Start Discovery and receive advertisement during connection,
// should notify of device changed.
+ // - GetInquiryRSSI: Should return the packet's rssi.
// - GetUUIDs: Should return only Advertised UUIDs since services haven't
// been discovered yet.
// - GetServiceData: Should return last advertised Service Data.
+ // - GetInquiryTxPower: Should return the packet's advertised Tx Power.
StartLowEnergyDiscoverySession();
ASSERT_TRUE(adapter_->IsDiscovering());
ASSERT_TRUE(discovery_sessions_[0]->IsActive());
device = SimulateLowEnergyDevice(1);
EXPECT_EQ(1, observer.device_changed_count());
+
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
+
EXPECT_EQ(2u, device->GetUUIDs().size());
+
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
@@ -436,15 +518,20 @@ TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
+
// Discover services, should notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return both Advertised UUIDs and Service UUIDs.
// - GetServiceData: Should return same data as before since there was
// no new advertised data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
std::vector<std::string> services;
services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value());
SimulateGattServicesDiscovered(device, services);
EXPECT_EQ(2, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
EXPECT_EQ(3u, device->GetUUIDs().size());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
@@ -465,31 +552,41 @@ TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) {
EXPECT_EQ(std::vector<uint8_t>({1}),
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
// Receive advertisement again, notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return only new Advertised UUIDs and Service UUIDs.
// - GetServiceData: Should return last advertised Service Data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
device = SimulateLowEnergyDevice(2);
EXPECT_EQ(3, observer.device_changed_count());
EXPECT_EQ(3u, device->GetUUIDs().size());
+ EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value());
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDImmediateAlert)));
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate)));
+ EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value());
// Stop discovery session, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should only return Service UUIDs.
// - GetServiceData: Should return an empty map since we are no longer
// discovering.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
GetErrorCallback(Call::NOT_EXPECTED));
ASSERT_FALSE(adapter_->IsDiscovering());
ASSERT_FALSE(discovery_sessions_[0]->IsActive());
EXPECT_EQ(4, observer.device_changed_count());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(1u, device->GetUUIDs().size());
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate)));
@@ -500,15 +597,21 @@ TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) {
EXPECT_EQ(ServiceDataMap(), device->GetServiceData());
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
// Disconnect device, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return no UUIDs.
// - GetServiceData: Should still return an empty map.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
gatt_connections_[0]->Disconnect();
SimulateGattDisconnection(device);
ASSERT_FALSE(device->IsGattConnected());
EXPECT_EQ(5, observer.device_changed_count());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(0u, device->GetUUIDs().size());
#if defined(OS_MACOSX)
@@ -517,6 +620,7 @@ TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) {
EXPECT_EQ(ServiceDataMap(), device->GetServiceData());
EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs());
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
@@ -534,14 +638,17 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
// Start discovery session and receive and advertisement. No device changed
// notification because it's a new device.
+ // - GetInquiryRSSI: Should return the packet's rssi.
Jeffrey Yasskin 2016/08/24 04:32:02 A some point in these tests, you've verified that
ortuno 2016/08/24 21:29:09 I've removed checks where checking advertisement d
// - GetUUIDs: Should return Advertised UUIDs.
// - GetServiceData: Should return advertised Service Data.
+ // - GetInquiryTxPower: Should return the packet's advertised Tx Power.
StartLowEnergyDiscoverySession();
ASSERT_TRUE(adapter_->IsDiscovering());
ASSERT_TRUE(discovery_sessions_[0]->IsActive());
BluetoothDevice* device = SimulateLowEnergyDevice(1);
EXPECT_EQ(0, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
EXPECT_EQ(2u, device->GetUUIDs().size());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
@@ -561,9 +668,13 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
+
// Connect, should notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return Advertised UUIDs even before GATT Discovery.
// - GetServiceData: Should still return the same Service Data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device);
@@ -571,6 +682,7 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
observer.Reset();
EXPECT_EQ(2u, device->GetUUIDs().size());
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
@@ -589,12 +701,17 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
+
// Receive Advertisement with new UUIDs, should notify of device changed.
+ // - GetInquiryRSSI: Should return the packet's rssi.
// - GetUUIDs: Should return new Advertised UUIDs.
// - GetServiceData: Should return new advertised Service Data.
+ // - GetInquiryTxPower: Should return the packet's advertised Tx Power.
device = SimulateLowEnergyDevice(2);
EXPECT_EQ(1, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value());
EXPECT_EQ(2u, device->GetUUIDs().size());
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
@@ -618,15 +735,19 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
std::vector<uint8_t>({0}),
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value());
// Discover Service, should notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return Advertised UUIDs and Service UUIDs.
// - GetServiceData: Should return same advertised Service Data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
std::vector<std::string> services;
services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value());
SimulateGattServicesDiscovered(device, services);
EXPECT_EQ(2, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value());
EXPECT_EQ(3u, device->GetUUIDs().size());
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
@@ -653,14 +774,19 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value());
+
// Disconnect, should notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return only Advertised UUIDs.
// - GetServiceData: Should still return same advertised Service Data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
gatt_connections_[0]->Disconnect();
SimulateGattDisconnection(device);
ASSERT_FALSE(device->IsGattConnected());
EXPECT_EQ(3, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value());
EXPECT_EQ(2u, device->GetUUIDs().size());
EXPECT_TRUE(
base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
@@ -685,12 +811,17 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value());
+
// Receive Advertisement with new UUIDs, should notify of device changed.
+ // - GetInquiryRSSI: Should return last packet's rssi.
// - GetUUIDs: Should return only new Advertised UUIDs.
// - GetServiceData: Should return only new advertised Service Data.
+ // - GetInquiryTxPower: Should return the last packet's advertised Tx Power.
device = SimulateLowEnergyDevice(1);
EXPECT_EQ(4, observer.device_changed_count());
+ EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value());
EXPECT_EQ(2u, device->GetUUIDs().size());
EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(),
BluetoothUUID(kTestUUIDGenericAccess)));
@@ -710,13 +841,20 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value());
+
// Stop discovery session, should notify of device changed.
+ // - GetInquiryRSSI: Should return nullopt because we are no longer
+ // discovering.
// - GetUUIDs: Should return no UUIDs.
- // - GetServiceData: Should return no UUIDs since we are no longer
- // discovering.
+ // - GetServiceData: Should return no UUIDs since we are no longer
+ // discovering.
+ // - GetInquiryTxPower: Should return nullopt because we are no longer
+ // discovering.
discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
GetErrorCallback(Call::NOT_EXPECTED));
EXPECT_EQ(5, observer.device_changed_count());
+ EXPECT_FALSE(!!device->GetInquiryRSSI());
EXPECT_EQ(0u, device->GetUUIDs().size());
#if defined(OS_MACOSX)
@@ -727,6 +865,7 @@ TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) {
EXPECT_EQ(nullptr,
device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
#endif // defined(OS_MACOSX)
+ EXPECT_FALSE(!!device->GetInquiryTxPower());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)

Powered by Google App Engine
This is Rietveld 408576698