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

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: 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 d68e6eff115a878afdf6379f776a997087a331f7..0aefb1fbaabd3c4cb0dc584dc47317217dbf5b85 100644
--- a/device/bluetooth/bluetooth_adapter_mac_unittest.mm
+++ b/device/bluetooth/bluetooth_adapter_mac_unittest.mm
@@ -25,6 +25,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 {
@@ -43,6 +44,16 @@ 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) {
Class aClass = NSClassFromString(@"CBPeripheral");
if (aClass == nil) {
@@ -242,6 +253,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)
@@ -249,8 +304,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