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

Unified Diff: device/bluetooth/bluetooth_adapter_mac_unittest.mm

Issue 1229473005: BluetoothAdapterMac::LowEnergyDeviceUpdated() Implemented (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hash
Patch Set: Scheib's comments 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_mac_unittest.mm
diff --git a/device/bluetooth/bluetooth_adapter_mac_unittest.mm b/device/bluetooth/bluetooth_adapter_mac_unittest.mm
index cc1d2ff89f841762d7450b9d5bbbcfbb420ffaeb..c682650483492c76089011b03378342a9d2ffff2 100644
--- a/device/bluetooth/bluetooth_adapter_mac_unittest.mm
+++ b/device/bluetooth/bluetooth_adapter_mac_unittest.mm
@@ -24,6 +24,7 @@ namespace {
// |kTestHashAddress| is the hash corresponding to identifier |kTestNSUUID|.
NSString* const kTestNSUUID = @"00000000-1111-2222-3333-444444444444";
const std::string kTestHashAddress = "D1:6F:E3:22:FD:5B";
+const int kTestRssi = 0;
} // namespace
namespace device {
@@ -42,11 +43,19 @@ class BluetoothAdapterMacTest : public testing::Test {
// Helper methods for setup and access to BluetoothAdapterMacTest's members.
void PollAdapter() { adapter_mac_->PollAdapter(); }
+ void LowEnergyDeviceUpdated(CBPeripheral* peripheral,
+ NSDictionary* advertisementData,
+ int rssi) {
+ adapter_mac_->LowEnergyDeviceUpdated(peripheral, advertisementData, rssi);
+ }
+
+ BluetoothDevice* GetDevice(const std::string& address) {
+ return adapter_->GetDevice(address);
+ }
+
CBPeripheral* CreateMockPeripheral(NSString* identifier) {
if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
- // For stability we only use CoreBluetooth on OS X >= 10.10. Thus on
- // previous OS X versions the code cannot be tested.
- LOG(WARNING) << "OS X version < 10.10, skipping unit test.";
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return nil;
}
id mock_peripheral =
@@ -239,6 +248,50 @@ TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) {
EXPECT_EQ(kTestHashAddress, GetHashAddress(mock_peripheral));
}
+TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) {
+ base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID));
+ if (mock_peripheral.get() == nil)
+ return;
+ base::scoped_nsobject<NSDictionary> advertisement_data(
+ CreateAdvertisementData());
+
+ EXPECT_EQ(0, NumDevices());
+ EXPECT_FALSE(DevicePresent(mock_peripheral));
+ LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi);
+ EXPECT_EQ(1, NumDevices());
+ EXPECT_TRUE(DevicePresent(mock_peripheral));
+}
+
+TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedOldDevice) {
+ base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID));
+ if (mock_peripheral.get() == nil)
+ return;
+ base::scoped_nsobject<NSDictionary> advertisement_data(
+ CreateAdvertisementData());
+
+ // Update the device for the first time and check it was correctly added to
+ // |devices_|.
+ EXPECT_EQ(0, NumDevices());
+ EXPECT_FALSE(DevicePresent(mock_peripheral));
+ LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi);
+ EXPECT_EQ(1, NumDevices());
+ EXPECT_TRUE(DevicePresent(mock_peripheral));
+ // Search for the device by the address corresponding to |kTestNSUUID|.
+ BluetoothDeviceMac* device =
+ static_cast<BluetoothDeviceMac*>(GetDevice(kTestHashAddress));
+ base::scoped_nsobject<NSDate> first_update_time(
+ [device->GetLastUpdateTime() retain]);
+
+ // Update the device a second time. The device should be updated in
+ // |devices_| so check the time returned by GetLastUpdateTime() has increased.
+ LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi);
+ EXPECT_EQ(1, NumDevices());
+ EXPECT_TRUE(DevicePresent(mock_peripheral));
+ device = static_cast<BluetoothDeviceMac*>(GetDevice(kTestHashAddress));
+ EXPECT_TRUE([device->GetLastUpdateTime() compare:first_update_time] ==
+ NSOrderedDescending);
+}
+
TEST_F(BluetoothAdapterMacTest, UpdateDevicesRemovesLowEnergyDevice) {
base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID));
if (mock_peripheral.get() == nil)
@@ -246,8 +299,8 @@ TEST_F(BluetoothAdapterMacTest, UpdateDevicesRemovesLowEnergyDevice) {
base::scoped_nsobject<NSDictionary> advertisement_data(
CreateAdvertisementData());
- BluetoothLowEnergyDeviceMac* device =
- new BluetoothLowEnergyDeviceMac(mock_peripheral, advertisement_data, 0);
+ BluetoothLowEnergyDeviceMac* device = new BluetoothLowEnergyDeviceMac(
+ mock_peripheral, advertisement_data, kTestRssi);
SetDeviceTimeGreaterThanTimeout(device);
EXPECT_EQ(0, NumDevices());
« device/bluetooth/bluetooth_adapter_mac.mm ('K') | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698