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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 1215303006: bluetooth: android: Initial BluetoothDeviceAndroid implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-discovery-
Patch Set: Merge TOT 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_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index 7fb505925368ef7368e882e42b5168d93a17559d..c92392d1327d80b24175c263957cc0e690ac60b5 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -5,8 +5,15 @@
#include "device/bluetooth/bluetooth_device.h"
#include "base/macros.h"
+#include "base/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_ANDROID)
+#include "device/bluetooth/test/bluetooth_test_android.h"
+#endif
+
namespace device {
TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
@@ -56,4 +63,56 @@ TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) {
}
}
+#if defined(OS_ANDROID)
+// Verifies basic device properties, e.g. GetAddress, GetName, ...
+TEST_F(BluetoothTest, DeviceProperties) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(1);
+ base::RunLoop().RunUntilIdle();
+ BluetoothDevice* device = observer.last_device();
+ ASSERT_TRUE(device);
+ EXPECT_EQ(0x1F00u, device->GetBluetoothClass());
+ EXPECT_EQ("AA:00:00:00:00:01", device->GetAddress());
+ EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
+ EXPECT_EQ(0, device->GetVendorID());
+ EXPECT_EQ(0, device->GetProductID());
+ EXPECT_EQ(0, device->GetDeviceID());
+ EXPECT_EQ(base::UTF8ToUTF16("FakeBluetoothDevice"), device->GetName());
+ EXPECT_EQ(true, device->IsPaired());
+ BluetoothDevice::UUIDList uuids = device->GetUUIDs();
+ EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1800")));
+ EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1801")));
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Device with no advertised Service UUIDs.
+TEST_F(BluetoothTest, DeviceNoUUIDs) {
+ InitWithFakeAdapter();
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
+ GetErrorCallback());
+ base::RunLoop().RunUntilIdle();
+ DiscoverLowEnergyDevice(3);
+ base::RunLoop().RunUntilIdle();
+ BluetoothDevice* device = observer.last_device();
+ ASSERT_TRUE(device);
+ BluetoothDevice::UUIDList uuids = device->GetUUIDs();
+ EXPECT_EQ(0u, uuids.size());
+}
+#endif // defined(OS_ANDROID)
+
+// TODO(scheib): Test with a device with no name. http://crbug.com/506415
+// BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which
+// requires string resources to be loaded. For that, something like
+// InitSharedInstance must be run. See unittest files that call that. It will
+// also require build configuration to generate string resources into a .pak
+// file.
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698