| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/bluetooth_test_mac.h" | 5 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/sys_string_conversions.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "device/bluetooth/bluetooth_adapter_mac.h" | 13 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 13 #include "device/bluetooth/bluetooth_device_mac.h" | 14 #include "device/bluetooth/bluetooth_device_mac.h" |
| 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" | 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
| 16 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" | 17 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" |
| 17 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" | 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| 18 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" | 19 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" |
| 19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" | 20 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| 20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 21 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 241 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 241 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 242 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
| 242 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 243 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
| 243 [mockPeripheral setState:CBPeripheralStateConnected]; | 244 [mockPeripheral setState:CBPeripheralStateConnected]; |
| 244 CBCentralManager* centralManager = | 245 CBCentralManager* centralManager = |
| 245 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 246 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| 246 [centralManager.delegate centralManager:centralManager | 247 [centralManager.delegate centralManager:centralManager |
| 247 didConnectPeripheral:peripheral]; | 248 didConnectPeripheral:peripheral]; |
| 248 } | 249 } |
| 249 | 250 |
| 251 void BluetoothTestMac::SimulateConnectedLowEnergyDevice( |
| 252 ConnectedDeviceType device_ordinal) { |
| 253 const char* identifier = nullptr; |
| 254 NSString* name = nil; |
| 255 scoped_nsobject<NSMutableSet> cbUUIDs([[NSMutableSet alloc] init]); |
| 256 switch (device_ordinal) { |
| 257 case ConnectedDeviceType::GENERIC_DEVICE: |
| 258 name = @(kTestDeviceName.c_str()); |
| 259 identifier = kTestPeripheralUUID1.c_str(); |
| 260 [cbUUIDs |
| 261 addObject:[CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())]]; |
| 262 break; |
| 263 case ConnectedDeviceType::HEART_RATE_DEVICE: |
| 264 name = @(kTestDeviceName.c_str()); |
| 265 identifier = kTestPeripheralUUID2.c_str(); |
| 266 [cbUUIDs |
| 267 addObject:[CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())]]; |
| 268 [cbUUIDs addObject:[CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())]]; |
| 269 break; |
| 270 } |
| 271 DCHECK(name); |
| 272 DCHECK(identifier); |
| 273 DCHECK([cbUUIDs.get() count] > 0); |
| 274 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] |
| 275 initWithUTF8StringIdentifier:identifier |
| 276 name:name]); |
| 277 mock_peripheral.get().bluetoothTestMac = this; |
| 278 [mock_central_manager_->get() |
| 279 setConnectedMockPeripheral:mock_peripheral.get().peripheral |
| 280 withServiceUUIDs:cbUUIDs.get()]; |
| 281 } |
| 282 |
| 250 void BluetoothTestMac::SimulateGattConnectionError( | 283 void BluetoothTestMac::SimulateGattConnectionError( |
| 251 BluetoothDevice* device, | 284 BluetoothDevice* device, |
| 252 BluetoothDevice::ConnectErrorCode errorCode) { | 285 BluetoothDevice::ConnectErrorCode errorCode) { |
| 253 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 286 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
| 254 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 287 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 255 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 288 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
| 256 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 289 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
| 257 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 290 [mockPeripheral setState:CBPeripheralStateDisconnected]; |
| 258 CBCentralManager* centralManager = | 291 CBCentralManager* centralManager = |
| 259 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 292 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( | 466 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( |
| 434 std::vector<uint8_t> value) { | 467 std::vector<uint8_t> value) { |
| 435 last_write_value_ = value; | 468 last_write_value_ = value; |
| 436 gatt_write_characteristic_attempts_++; | 469 gatt_write_characteristic_attempts_++; |
| 437 } | 470 } |
| 438 | 471 |
| 439 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() { | 472 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() { |
| 440 gatt_notify_characteristic_attempts_++; | 473 gatt_notify_characteristic_attempts_++; |
| 441 } | 474 } |
| 442 | 475 |
| 476 BluetoothDevice::UUIDSet |
| 477 BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() { |
| 478 BluetoothDevice::UUIDSet service_uuids; |
| 479 for (CBUUID* uuid in |
| 480 [mock_central_manager_->get() retrieveConnectedPeripheralServiceUUIDs]) { |
| 481 service_uuids.insert(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid)); |
| 482 } |
| 483 return service_uuids; |
| 484 } |
| 485 |
| 486 void BluetoothTestMac::ResetRetrieveConnectedPeripheralServiceUUIDs() { |
| 487 [mock_central_manager_->get() resetRetrieveConnectedPeripheralServiceUUIDs]; |
| 488 } |
| 489 |
| 443 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( | 490 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( |
| 444 BluetoothRemoteGattService* service) const { | 491 BluetoothRemoteGattService* service) const { |
| 445 BluetoothDevice* device = service->GetDevice(); | 492 BluetoothDevice* device = service->GetDevice(); |
| 446 BluetoothLowEnergyDeviceMac* device_mac = | 493 BluetoothLowEnergyDeviceMac* device_mac = |
| 447 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 494 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 448 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); | 495 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); |
| 449 return ObjCCast<MockCBPeripheral>(cb_peripheral); | 496 return ObjCCast<MockCBPeripheral>(cb_peripheral); |
| 450 } | 497 } |
| 451 | 498 |
| 452 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( | 499 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 535 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
| 489 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 536 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
| 490 // return input_str; | 537 // return input_str; |
| 491 // } | 538 // } |
| 492 // ++input[0]; | 539 // ++input[0]; |
| 493 // } | 540 // } |
| 494 // return ""; | 541 // return ""; |
| 495 // } | 542 // } |
| 496 | 543 |
| 497 } // namespace device | 544 } // namespace device |
| OLD | NEW |