| 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" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 180 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 181 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 181 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
| 182 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 182 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
| 183 [mockPeripheral setState:CBPeripheralStateConnected]; | 183 [mockPeripheral setState:CBPeripheralStateConnected]; |
| 184 CBCentralManager* centralManager = | 184 CBCentralManager* centralManager = |
| 185 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 185 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| 186 [centralManager.delegate centralManager:centralManager | 186 [centralManager.delegate centralManager:centralManager |
| 187 didConnectPeripheral:peripheral]; | 187 didConnectPeripheral:peripheral]; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { | 190 void BluetoothTestMac::SimulateGattConnectionError( |
| 191 BluetoothDevice* device, |
| 192 BluetoothDevice::ConnectErrorCode errorCode) { |
| 191 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 193 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
| 192 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 194 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 193 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 195 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
| 194 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 196 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
| 195 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 197 [mockPeripheral setState:CBPeripheralStateDisconnected]; |
| 196 CBCentralManager* centralManager = | 198 CBCentralManager* centralManager = |
| 197 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 199 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| 200 NSError* error = |
| 201 BluetoothDeviceMac::GetNSErrorFromConnectErrorCode(errorCode); |
| 198 [centralManager.delegate centralManager:centralManager | 202 [centralManager.delegate centralManager:centralManager |
| 199 didDisconnectPeripheral:peripheral | 203 didFailToConnectPeripheral:peripheral |
| 200 error:nil]; | 204 error:error]; |
| 201 } | 205 } |
| 202 | 206 |
| 203 void BluetoothTestMac::SimulateGattConnectionError( | 207 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { |
| 204 BluetoothDevice* device, | |
| 205 BluetoothDevice::ConnectErrorCode errorCode) { | |
| 206 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 208 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
| 207 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 209 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| 208 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 210 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
| 209 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 211 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
| 210 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 212 [mockPeripheral setState:CBPeripheralStateDisconnected]; |
| 211 CBCentralManager* centralManager = | 213 CBCentralManager* centralManager = |
| 212 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 214 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| 213 // TODO(http://crbug.com/585894): Need to convert the connect error code into | |
| 214 // NSError | |
| 215 NSError* error = [NSError errorWithDomain:@"BluetoothDevice::ConnectErrorCode" | |
| 216 code:-1 | |
| 217 userInfo:nil]; | |
| 218 [centralManager.delegate centralManager:centralManager | 215 [centralManager.delegate centralManager:centralManager |
| 219 didFailToConnectPeripheral:peripheral | 216 didDisconnectPeripheral:peripheral |
| 220 error:error]; | 217 error:nil]; |
| 221 } | 218 } |
| 222 | 219 |
| 223 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { | 220 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
| 224 gatt_connection_attempts_++; | 221 gatt_connection_attempts_++; |
| 225 } | 222 } |
| 226 | 223 |
| 227 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { | 224 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
| 228 gatt_disconnection_attempts_++; | 225 gatt_disconnection_attempts_++; |
| 229 } | 226 } |
| 230 | 227 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 257 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 254 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
| 258 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 255 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
| 259 // return input_str; | 256 // return input_str; |
| 260 // } | 257 // } |
| 261 // ++input[0]; | 258 // ++input[0]; |
| 262 // } | 259 // } |
| 263 // return ""; | 260 // return ""; |
| 264 // } | 261 // } |
| 265 | 262 |
| 266 } // namespace device | 263 } // namespace device |
| OLD | NEW |