| 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 "device/bluetooth/bluetooth_adapter_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 14 #include "device/bluetooth/bluetooth_common.h" | 15 #include "device/bluetooth/bluetooth_common.h" |
| 15 #include "device/bluetooth/bluetooth_discovery_session.h" | 16 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 16 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 17 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 17 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 18 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" | 19 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| 19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" | 20 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 CBAdvertisementDataIsConnectable : @(YES), | 77 CBAdvertisementDataIsConnectable : @(YES), |
| 77 CBAdvertisementDataServiceDataKey : [NSDictionary dictionary], | 78 CBAdvertisementDataServiceDataKey : [NSDictionary dictionary], |
| 78 }; | 79 }; |
| 79 return [advertisement_data retain]; | 80 return [advertisement_data retain]; |
| 80 } | 81 } |
| 81 | 82 |
| 82 std::string GetHashAddress(CBPeripheral* peripheral) { | 83 std::string GetHashAddress(CBPeripheral* peripheral) { |
| 83 return BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 84 return BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void AddLowEnergyDevice(BluetoothLowEnergyDeviceMac* device) { | |
| 87 adapter_mac_->devices_.set(device->GetAddress(), | |
| 88 std::unique_ptr<BluetoothDevice>(device)); | |
| 89 } | |
| 90 | |
| 91 int NumDevices() { return adapter_mac_->devices_.size(); } | 87 int NumDevices() { return adapter_mac_->devices_.size(); } |
| 92 | 88 |
| 93 bool DevicePresent(CBPeripheral* peripheral) { | 89 bool DevicePresent(CBPeripheral* peripheral) { |
| 94 BluetoothDevice* device = adapter_mac_->GetDevice( | 90 BluetoothDevice* device = adapter_mac_->GetDevice( |
| 95 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral)); | 91 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral)); |
| 96 return (device != NULL); | 92 return (device != NULL); |
| 97 } | 93 } |
| 98 | 94 |
| 99 bool SetMockCentralManager(CBCentralManagerState desired_state) { | 95 bool SetMockCentralManager(CBCentralManagerState desired_state) { |
| 100 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { | 96 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData()); | 249 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData()); |
| 254 | 250 |
| 255 EXPECT_EQ(0, NumDevices()); | 251 EXPECT_EQ(0, NumDevices()); |
| 256 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 252 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
| 257 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); | 253 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); |
| 258 EXPECT_EQ(1, NumDevices()); | 254 EXPECT_EQ(1, NumDevices()); |
| 259 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 255 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
| 260 } | 256 } |
| 261 | 257 |
| 262 } // namespace device | 258 } // namespace device |
| OLD | NEW |