Index: device/bluetooth/bluetooth_device_unittest.cc |
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc |
index 9433fda99ef8071763ef0334f2aa22e896eafcfb..85b80e89f8f77e6735cf09b5e4f4185256b916a4 100644 |
--- a/device/bluetooth/bluetooth_device_unittest.cc |
+++ b/device/bluetooth/bluetooth_device_unittest.cc |
@@ -109,7 +109,14 @@ TEST_F(BluetoothTest, LowEnergyDeviceProperties) { |
EXPECT_EQ(0, device->GetVendorID()); |
EXPECT_EQ(0, device->GetProductID()); |
EXPECT_EQ(0, device->GetDeviceID()); |
- EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay()); |
+// There is no advertised name in Windows. |
+// TODO(crbug.com/629456): Enable on macOS. |
+#if defined(OS_ANDROID) |
+ EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceAdvertisedName), |
+ device->GetNameForDisplay()); |
+#else |
+ EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceGapName), device->GetNameForDisplay()); |
+#endif // defined(OS_ANDROID) |
EXPECT_FALSE(device->IsPaired()); |
UUIDSet uuids = device->GetUUIDs(); |
EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAccess))); |
@@ -695,6 +702,82 @@ TEST_F(BluetoothTest, GetName_NullName) { |
} |
#endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) |
+#if defined(OS_ANDROID) |
+TEST_F(BluetoothTest, GetName_NonConnectedNonAdvertising) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ InitWithFakeAdapter(); |
+ StartLowEnergyDiscoverySession(); |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
+ |
+ discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
+ GetErrorCallback(Call::NOT_EXPECTED)); |
+ ASSERT_FALSE(adapter_->IsDiscovering()); |
+ ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
+ |
+ EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
+} |
+#endif // defined(OS_ANDROID) |
+ |
+#if defined(OS_ANDROID) |
+TEST_F(BluetoothTest, GetName_ConnectedNonAdvertising) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ InitWithFakeAdapter(); |
+ StartLowEnergyDiscoverySession(); |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
+ |
+ discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
+ GetErrorCallback(Call::NOT_EXPECTED)); |
+ ASSERT_FALSE(adapter_->IsDiscovering()); |
+ ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
+ |
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
+ GetConnectErrorCallback(Call::NOT_EXPECTED)); |
+ SimulateGattConnection(device); |
+ ASSERT_TRUE(device->IsGattConnected()); |
+ |
+ EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
+} |
+#endif // defined(OS_ANDROID) |
+ |
+#if defined(OS_ANDROID) |
+TEST_F(BluetoothTest, GetName_NonConnectedAdvertising) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ InitWithFakeAdapter(); |
+ StartLowEnergyDiscoverySession(); |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
+ |
+ EXPECT_EQ(kTestDeviceAdvertisedName, device->GetName().value()); |
+} |
+#endif // defined(OS_ANDROID) |
+ |
+#if defined(OS_ANDROID) |
+TEST_F(BluetoothTest, GetName_ConnectedAdvertising) { |
+ if (!PlatformSupportsLowEnergy()) { |
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
+ return; |
+ } |
+ InitWithFakeAdapter(); |
+ StartLowEnergyDiscoverySession(); |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
+ |
+ device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
+ GetConnectErrorCallback(Call::NOT_EXPECTED)); |
+ SimulateGattConnection(device); |
+ ASSERT_TRUE(device->IsGattConnected()); |
+ |
+ EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
+} |
+#endif // defined(OS_ANDROID) |
+ |
// TODO(506415): Test GetNameForDisplay with a device with no name. |
// BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which |
// requires string resources to be loaded. For that, something like |