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

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: s/advertisementData/advertisement_data 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 56eb27d781878f18b801c423e890475793544583..be0184893fb82da61e416cf1bb7d55f8a3d55050 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* advertisement_data,
+ int rssi) {
+ adapter_mac_->LowEnergyDeviceUpdated(peripheral, advertisement_data, 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;
}
Class peripheral_class = NSClassFromString(@"CBPeripheral");
@@ -241,6 +250,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)
@@ -248,8 +301,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());
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698