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

Unified Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 1215303006: bluetooth: android: Initial BluetoothDeviceAndroid implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-discovery-
Patch Set: jyasskin comments addressed. Pass UUIDs by array. Added more tests. Created 5 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
Index: device/bluetooth/bluetooth_adapter_unittest.cc
diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc
index 771876d368286e9de306ea630631f46088fb49a3..14d6f0fb809541503c3866db642219bbbb16bc72 100644
--- a/device/bluetooth/bluetooth_adapter_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_unittest.cc
@@ -9,6 +9,7 @@
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_discovery_session.h"
#include "device/bluetooth/test/bluetooth_test.h"
+#include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_ANDROID)
@@ -446,6 +447,7 @@ TEST_F(BluetoothTest, ConstructFakeAdapter) {
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID)
+// Starts and Stops a discovery session.
TEST_F(BluetoothTest, DiscoverySession) {
InitWithFakeAdapter();
EXPECT_FALSE(adapter_->IsDiscovering());
@@ -468,4 +470,111 @@ TEST_F(BluetoothTest, DiscoverySession) {
}
#endif // defined(OS_ANDROID)
+#if defined(OS_ANDROID)
+// Discovers a device.
+TEST_F(BluetoothTest, DiscoverDevice) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Start discovery and find a device.
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(1);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, observer.device_added_count());
+ BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
+ EXPECT_TRUE(device);
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Discovers the same device multiple times.
+TEST_F(BluetoothTest, DiscoverDeviceTwice) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Start discovery and find a device.
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(1);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, observer.device_added_count());
+ BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
+ EXPECT_TRUE(device);
+
+ // Find the same device again. This should not create a new device object.
+ observer.Reset();
+ DiscoverLowEnergyDevice(1);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0, observer.device_added_count());
+ EXPECT_EQ(0, observer.device_changed_count());
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Discovers a device, and then again with new Service UUIDs.
+TEST_F(BluetoothTest, DiscoverDeviceWithUpdatedUUIDs) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Start discovery and find a device.
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(1);
+ base::RunLoop().RunUntilIdle();
+ BluetoothDevice* device = observer.last_device();
+
+ // Check the initial UUIDs:
+ EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800")));
+ EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802")));
+
+ // Discover same device again with updated UUIDs:
+ observer.Reset();
+ DiscoverLowEnergyDevice(2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0, observer.device_added_count());
+ EXPECT_EQ(1, observer.device_changed_count());
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ EXPECT_EQ(device, observer.last_device());
+
+ // Expect new UUIDs:
+ EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800")));
+ EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802")));
+
+ // Discover same device again with empty UUIDs:
+ observer.Reset();
+ DiscoverLowEnergyDevice(3);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0, observer.device_added_count());
+ EXPECT_EQ(1, observer.device_changed_count());
+ EXPECT_EQ(1u, adapter_->GetDevices().size());
+ EXPECT_EQ(device, observer.last_device());
+
+ // Expect empty UUIDs:
scheib 2015/07/08 00:54:09 armansito, confirm this is what you believe should
armansito 2015/07/08 03:12:09 On Chrome OS this will be populated with the compl
scheib 2015/07/08 05:09:10 On Android, device.getUuids() will be empty unless
armansito 2015/07/08 06:00:13 SDP is a Bluetooth classic protocol, so it wouldn'
scheib 2015/07/08 16:42:51 OK, to be clear, upon a DiscoverySession we only e
Jeffrey Yasskin 2015/07/08 17:19:39 You're not really testing that situation here. You
scheib 2015/07/08 23:02:35 I don't know what Android does for sure. Our test
Jeffrey Yasskin 2015/07/08 23:18:24 I think that's right, until someone files a bug wi
+ EXPECT_EQ(0u, device->GetUUIDs().size());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Discovers multiple devices when addresses vary.
+TEST_F(BluetoothTest, DiscoverMultipleDevices) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Start discovery and find a device.
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(1);
+ DiscoverLowEnergyDevice(4);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(2, observer.device_added_count());
+ EXPECT_EQ(2u, adapter_->GetDevices().size());
+}
+#endif // defined(OS_ANDROID)
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698