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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2783733002: Bluetooth: Add service data unit tests for chromeos (Closed)
Patch Set: trybot Created 3 years, 9 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 ab478fc7386df4a49d9bf91a0645488354e48239..a72e07a05d6fdc3ecfc31270bd70d32f72a07d36 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -167,7 +167,7 @@ TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) {
EXPECT_EQ(0u, uuids.size());
}
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX)
// TODO(ortuno): Enable on Android once it supports Service Data.
// http://crbug.com/639408
TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
@@ -176,7 +176,12 @@ TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
return;
}
InitWithFakeAdapter();
+
+#if defined(OS_MACOSX)
ortuno 2017/04/03 02:47:24 #if !defined(OS_LINUX) && !defined(OS_CHROMEOS) S
xiaoyinh(OOO Sep 11-29) 2017/04/03 21:28:22 Done.
+ // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is
+ // implemented for bluez.
StartLowEnergyDiscoverySession();
+#endif // defined(OS_MACOSX)
// Receive Advertisement with service data.
ortuno 2017/04/03 02:47:24 optional: Could we add a test for when the service
xiaoyinh(OOO Sep 11-29) 2017/04/03 21:28:22 Thanks for the suggestion. I added another device
ortuno 2017/04/03 22:39:34 Looks great. Thanks.
BluetoothDevice* device = SimulateLowEnergyDevice(1);
@@ -191,26 +196,44 @@ TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
// Receive Advertisement with no service data.
SimulateLowEnergyDevice(3);
+// TODO(crbug.com/707039): Remove #if once the BlueZ caching behavior is
+// changed.
+#if defined(OS_MACOSX)
ortuno 2017/04/03 02:47:24 To avoid having this #if for future platforms: #i
xiaoyinh(OOO Sep 11-29) 2017/04/03 21:28:22 Done.
EXPECT_TRUE(device->GetServiceData().empty());
EXPECT_TRUE(device->GetServiceDataUUIDs().empty());
EXPECT_EQ(nullptr,
device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
+#else
+ // On ChromeOS and Linux, BlueZ persists all service data meaning if
+ // a device stops advertising service data for a UUID, BlueZ will
+ // still return the cached value for that UUID.
+ EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}),
+ device->GetServiceData());
+ EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}),
+ device->GetServiceDataUUIDs());
+ EXPECT_EQ(std::vector<uint8_t>({1}),
+ *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
+#endif
// Receive Advertisement with new service data.
SimulateLowEnergyDevice(2);
- EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}},
- {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}),
+ EXPECT_EQ(ServiceDataMap(
+ {{BluetoothUUID(kTestUUIDHeartRate), std::vector<uint8_t>({})},
+ {BluetoothUUID(kTestUUIDImmediateAlert), {0, 2}}}),
device->GetServiceData());
EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate),
BluetoothUUID(kTestUUIDImmediateAlert)}),
device->GetServiceDataUUIDs());
- EXPECT_EQ(std::vector<uint8_t>({2}),
+ EXPECT_EQ(std::vector<uint8_t>({}),
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
EXPECT_EQ(
- std::vector<uint8_t>({0}),
+ std::vector<uint8_t>({0, 2}),
*device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
+#if defined(OS_MACOSX)
ortuno 2017/04/03 02:47:24 #if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
xiaoyinh(OOO Sep 11-29) 2017/04/03 21:28:22 Done.
+ // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is
+ // implemented for bluez.
// Stop discovery.
discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
GetErrorCallback(Call::NOT_EXPECTED));
@@ -223,8 +246,9 @@ TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
EXPECT_EQ(nullptr, device->GetServiceDataForUUID(
BluetoothUUID(kTestUUIDImmediateAlert)));
-}
#endif // defined(OS_MACOSX)
+}
+#endif // defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX)
#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Tests that the Advertisement Data fields are correctly updated during
« no previous file with comments | « no previous file | device/bluetooth/bluez/bluetooth_bluez_unittest.cc » ('j') | device/bluetooth/test/bluetooth_test.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698