Enabled 2 device tests to run on OS X (> 10.10) and adjusted android
and mac device default values to agree.
BUG=511008
Review URL: https://codereview.chromium.org/1260533003
Cr-Commit-Position: refs/heads/master@{#341567}
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index 3e8d264..4cea1b6 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -12,6 +12,8 @@
#if defined(OS_ANDROID)
#include "device/bluetooth/test/bluetooth_test_android.h"
+#elif defined(OS_MACOSX)
+#include "device/bluetooth/test/bluetooth_test_mac.h"
#endif
namespace device {
@@ -63,9 +65,13 @@
}
}
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Verifies basic device properties, e.g. GetAddress, GetName, ...
-TEST_F(BluetoothTest, DeviceProperties) {
+TEST_F(BluetoothTest, LowEnergyDeviceProperties) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
InitWithFakeAdapter();
TestBluetoothAdapterObserver observer(adapter_);
@@ -82,17 +88,21 @@
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());
+ EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetName());
+ EXPECT_FALSE(device->IsPaired());
BluetoothDevice::UUIDList uuids = device->GetUUIDs();
- EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1800")));
- EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1801")));
+ EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAccess)));
+ EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAttribute)));
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Device with no advertised Service UUIDs.
-TEST_F(BluetoothTest, DeviceNoUUIDs) {
+TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
InitWithFakeAdapter();
TestBluetoothAdapterObserver observer(adapter_);
@@ -106,7 +116,7 @@
BluetoothDevice::UUIDList uuids = device->GetUUIDs();
EXPECT_EQ(0u, uuids.size());
}
-#endif // defined(OS_ANDROID)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
// TODO(scheib): Test with a device with no name. http://crbug.com/506415
// BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index 875ab19..41a4fb9 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -74,7 +74,7 @@
}
uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
- return 0;
+ return 0x1F00; // Unspecified Device Class
}
std::string BluetoothLowEnergyDeviceMac::GetAddress() const {
diff --git a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
index 18a4683e..3a35167d 100644
--- a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
+++ b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
@@ -198,7 +198,7 @@
@Override
public int getBondState() {
- return BluetoothDevice.BOND_BONDED;
+ return BluetoothDevice.BOND_NONE;
}
@Override
diff --git a/device/bluetooth/test/bluetooth_test_mac.mm b/device/bluetooth/test/bluetooth_test_mac.mm
index 749f744..8f99087 100644
--- a/device/bluetooth/test/bluetooth_test_mac.mm
+++ b/device/bluetooth/test/bluetooth_test_mac.mm
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "device/bluetooth/test/bluetooth_test_mac.h"
+
#include "base/strings/string_number_conversions.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
-#include "device/bluetooth/test/bluetooth_test_mac.h"
#include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
#include "third_party/ocmock/OCMock/OCMock.h"
@@ -18,19 +19,20 @@
namespace {
-CBPeripheral* CreateMockPeripheral(NSString* identifier) {
+CBPeripheral* CreateMockPeripheral(NSString* peripheral_identifier) {
Class peripheral_class = NSClassFromString(@"CBPeripheral");
id mock_peripheral = [OCMockObject mockForClass:[peripheral_class class]];
- [static_cast<CBPeripheral*>(
- [[mock_peripheral stub] andReturnValue:@(CBPeripheralStateDisconnected)])
+ [[[mock_peripheral stub] andReturnValue:@(CBPeripheralStateDisconnected)]
performSelector:@selector(state)];
- [[[mock_peripheral stub] andReturn:[NSString string]] name];
Class uuid_class = NSClassFromString(@"NSUUID");
[[[mock_peripheral stub]
andReturn:[[uuid_class performSelector:@selector(UUID)]
performSelector:@selector(initWithUUIDString:)
- withObject:identifier]] identifier];
-
+ withObject:peripheral_identifier]]
+ performSelector:@selector(identifier)];
+ [[[mock_peripheral stub]
+ andReturn:[NSString stringWithUTF8String:BluetoothTest::kTestDeviceName
+ .c_str()]] name];
return mock_peripheral;
}