OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
10 #include "device/bluetooth/bluetooth_adapter_mac.h" | 10 #include "device/bluetooth/bluetooth_adapter_mac.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 RemoveDiscoverySession(discovery_filter.get()); | 244 RemoveDiscoverySession(discovery_filter.get()); |
245 EXPECT_EQ(0, callback_count_); | 245 EXPECT_EQ(0, callback_count_); |
246 EXPECT_EQ(1, error_callback_count_); | 246 EXPECT_EQ(1, error_callback_count_); |
247 EXPECT_EQ(0, NumDiscoverySessions()); | 247 EXPECT_EQ(0, NumDiscoverySessions()); |
248 | 248 |
249 // Check that stopScan was not called. | 249 // Check that stopScan was not called. |
250 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | 250 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); |
251 } | 251 } |
252 | 252 |
253 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) { | 253 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) { |
| 254 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 255 return; |
254 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); | 256 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); |
255 if (mock_peripheral.get() == nil) | 257 if (mock_peripheral.get() == nil) |
256 return; | 258 return; |
257 EXPECT_EQ(kTestHashAddress, GetHashAddress(mock_peripheral)); | 259 EXPECT_EQ(kTestHashAddress, GetHashAddress(mock_peripheral)); |
258 } | 260 } |
259 | 261 |
260 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) { | 262 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) { |
| 263 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 264 return; |
261 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); | 265 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); |
262 if (mock_peripheral.get() == nil) | 266 if (mock_peripheral.get() == nil) |
263 return; | 267 return; |
264 base::scoped_nsobject<NSDictionary> advertisement_data( | 268 base::scoped_nsobject<NSDictionary> advertisement_data( |
265 CreateAdvertisementData()); | 269 CreateAdvertisementData()); |
266 | 270 |
267 EXPECT_EQ(0, NumDevices()); | 271 EXPECT_EQ(0, NumDevices()); |
268 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 272 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
269 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); | 273 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); |
270 EXPECT_EQ(1, NumDevices()); | 274 EXPECT_EQ(1, NumDevices()); |
271 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 275 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
272 } | 276 } |
273 | 277 |
274 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedOldDevice) { | 278 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedOldDevice) { |
| 279 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 280 return; |
275 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); | 281 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); |
276 if (mock_peripheral.get() == nil) | 282 if (mock_peripheral.get() == nil) |
277 return; | 283 return; |
278 base::scoped_nsobject<NSDictionary> advertisement_data( | 284 base::scoped_nsobject<NSDictionary> advertisement_data( |
279 CreateAdvertisementData()); | 285 CreateAdvertisementData()); |
280 | 286 |
281 // Update the device for the first time and check it was correctly added to | 287 // Update the device for the first time and check it was correctly added to |
282 // |devices_|. | 288 // |devices_|. |
283 EXPECT_EQ(0, NumDevices()); | 289 EXPECT_EQ(0, NumDevices()); |
284 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 290 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
(...skipping 10 matching lines...) Expand all Loading... |
295 // |devices_| so check the time returned by GetLastUpdateTime() has increased. | 301 // |devices_| so check the time returned by GetLastUpdateTime() has increased. |
296 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); | 302 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); |
297 EXPECT_EQ(1, NumDevices()); | 303 EXPECT_EQ(1, NumDevices()); |
298 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 304 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
299 device = static_cast<BluetoothDeviceMac*>(GetDevice(kTestHashAddress)); | 305 device = static_cast<BluetoothDeviceMac*>(GetDevice(kTestHashAddress)); |
300 EXPECT_TRUE([device->GetLastUpdateTime() compare:first_update_time] == | 306 EXPECT_TRUE([device->GetLastUpdateTime() compare:first_update_time] == |
301 NSOrderedDescending); | 307 NSOrderedDescending); |
302 } | 308 } |
303 | 309 |
304 TEST_F(BluetoothAdapterMacTest, UpdateDevicesRemovesLowEnergyDevice) { | 310 TEST_F(BluetoothAdapterMacTest, UpdateDevicesRemovesLowEnergyDevice) { |
| 311 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 312 return; |
305 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); | 313 base::scoped_nsobject<id> mock_peripheral(CreateMockPeripheral(kTestNSUUID)); |
306 if (mock_peripheral.get() == nil) | 314 if (mock_peripheral.get() == nil) |
307 return; | 315 return; |
308 base::scoped_nsobject<NSDictionary> advertisement_data( | 316 base::scoped_nsobject<NSDictionary> advertisement_data( |
309 CreateAdvertisementData()); | 317 CreateAdvertisementData()); |
310 | 318 |
311 BluetoothLowEnergyDeviceMac* device = new BluetoothLowEnergyDeviceMac( | 319 BluetoothLowEnergyDeviceMac* device = new BluetoothLowEnergyDeviceMac( |
312 adapter_mac_, mock_peripheral, advertisement_data, kTestRssi); | 320 adapter_mac_, mock_peripheral, advertisement_data, kTestRssi); |
313 SetDeviceTimeGreaterThanTimeout(device); | 321 SetDeviceTimeGreaterThanTimeout(device); |
314 | 322 |
315 EXPECT_EQ(0, NumDevices()); | 323 EXPECT_EQ(0, NumDevices()); |
316 AddLowEnergyDevice(device); | 324 AddLowEnergyDevice(device); |
317 EXPECT_EQ(1, NumDevices()); | 325 EXPECT_EQ(1, NumDevices()); |
318 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 326 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
319 | 327 |
320 // Check that object pointed to by |device| is deleted by the adapter. | 328 // Check that object pointed to by |device| is deleted by the adapter. |
321 RemoveTimedOutDevices(); | 329 RemoveTimedOutDevices(); |
322 EXPECT_EQ(0, NumDevices()); | 330 EXPECT_EQ(0, NumDevices()); |
323 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 331 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
324 } | 332 } |
325 | 333 |
326 } // namespace device | 334 } // namespace device |
OLD | NEW |