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

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: 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..8f87f8ad1210abcf75f58afc58c75866b66299aa 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,81 @@ 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")));
+}
+#endif // defined(OS_ANDROID)
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698