| 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 20 matching lines...) Expand all Loading... |
| 31 namespace device { | 31 namespace device { |
| 32 | 32 |
| 33 // This class hides Objective-C from bluetooth_test_mac.h. | 33 // This class hides Objective-C from bluetooth_test_mac.h. |
| 34 class BluetoothTestMac::ScopedMockCentralManager { | 34 class BluetoothTestMac::ScopedMockCentralManager { |
| 35 public: | 35 public: |
| 36 explicit ScopedMockCentralManager(MockCentralManager* mock_central_manager) { | 36 explicit ScopedMockCentralManager(MockCentralManager* mock_central_manager) { |
| 37 mock_central_manager_.reset(mock_central_manager); | 37 mock_central_manager_.reset(mock_central_manager); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Returns MockCentralManager instance. | 40 // Returns MockCentralManager instance. |
| 41 MockCentralManager* get() { return mock_central_manager_.get(); }; | 41 MockCentralManager* get() { return mock_central_manager_; }; |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 scoped_nsobject<MockCentralManager> mock_central_manager_; | 44 scoped_nsobject<MockCentralManager> mock_central_manager_; |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); | 46 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 scoped_nsobject<NSDictionary> CreateAdvertisementData( | 51 scoped_nsobject<NSDictionary> CreateAdvertisementData( |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 identifier = nil; | 228 identifier = nil; |
| 229 name = nil; | 229 name = nil; |
| 230 rssi = nil; | 230 rssi = nil; |
| 231 uuids = nil; | 231 uuids = nil; |
| 232 service_data = nil; | 232 service_data = nil; |
| 233 tx_power = nil; | 233 tx_power = nil; |
| 234 } | 234 } |
| 235 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] | 235 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] |
| 236 initWithUTF8StringIdentifier:identifier | 236 initWithUTF8StringIdentifier:identifier |
| 237 name:name]); | 237 name:name]); |
| 238 mock_peripheral.get().bluetoothTestMac = this; | 238 [mock_peripheral setBluetoothTestMac:this]; |
| 239 [central_manager_delegate | 239 [central_manager_delegate |
| 240 centralManager:central_manager | 240 centralManager:central_manager |
| 241 didDiscoverPeripheral:mock_peripheral.get().peripheral | 241 didDiscoverPeripheral:[mock_peripheral peripheral] |
| 242 advertisementData:CreateAdvertisementData(name, uuids, service_data, | 242 advertisementData:CreateAdvertisementData(name, uuids, service_data, |
| 243 tx_power) | 243 tx_power) |
| 244 RSSI:rssi]; | 244 RSSI:rssi]; |
| 245 return observer.last_device(); | 245 return observer.last_device(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { | 248 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { |
| 249 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); | 249 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); |
| 250 [peripheral_mock setState:CBPeripheralStateConnected]; | 250 [peripheral_mock setState:CBPeripheralStateConnected]; |
| 251 CBCentralManager* centralManager = | 251 CBCentralManager* centralManager = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 269 case ConnectedDeviceType::HEART_RATE_DEVICE: | 269 case ConnectedDeviceType::HEART_RATE_DEVICE: |
| 270 name = @(kTestDeviceName.c_str()); | 270 name = @(kTestDeviceName.c_str()); |
| 271 identifier = kTestPeripheralUUID2.c_str(); | 271 identifier = kTestPeripheralUUID2.c_str(); |
| 272 [cbUUIDs | 272 [cbUUIDs |
| 273 addObject:[CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())]]; | 273 addObject:[CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())]]; |
| 274 [cbUUIDs addObject:[CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())]]; | 274 [cbUUIDs addObject:[CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())]]; |
| 275 break; | 275 break; |
| 276 } | 276 } |
| 277 DCHECK(name); | 277 DCHECK(name); |
| 278 DCHECK(identifier); | 278 DCHECK(identifier); |
| 279 DCHECK([cbUUIDs.get() count] > 0); | 279 DCHECK([cbUUIDs count] > 0); |
| 280 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] | 280 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] |
| 281 initWithUTF8StringIdentifier:identifier | 281 initWithUTF8StringIdentifier:identifier |
| 282 name:name]); | 282 name:name]); |
| 283 mock_peripheral.get().bluetoothTestMac = this; | 283 [mock_peripheral setBluetoothTestMac:this]; |
| 284 [mock_central_manager_->get() | 284 [mock_central_manager_->get() |
| 285 setConnectedMockPeripheral:mock_peripheral.get().peripheral | 285 setConnectedMockPeripheral:[mock_peripheral peripheral] |
| 286 withServiceUUIDs:cbUUIDs.get()]; | 286 withServiceUUIDs:cbUUIDs]; |
| 287 } | 287 } |
| 288 | 288 |
| 289 void BluetoothTestMac::SimulateGattConnectionError( | 289 void BluetoothTestMac::SimulateGattConnectionError( |
| 290 BluetoothDevice* device, | 290 BluetoothDevice* device, |
| 291 BluetoothDevice::ConnectErrorCode errorCode) { | 291 BluetoothDevice::ConnectErrorCode errorCode) { |
| 292 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); | 292 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); |
| 293 [peripheral_mock setState:CBPeripheralStateDisconnected]; | 293 [peripheral_mock setState:CBPeripheralStateDisconnected]; |
| 294 CBCentralManager* centralManager = | 294 CBCentralManager* centralManager = |
| 295 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 295 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
| 296 NSError* error = | 296 NSError* error = |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 716 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
| 717 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 717 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
| 718 // return input_str; | 718 // return input_str; |
| 719 // } | 719 // } |
| 720 // ++input[0]; | 720 // ++input[0]; |
| 721 // } | 721 // } |
| 722 // return ""; | 722 // return ""; |
| 723 // } | 723 // } |
| 724 | 724 |
| 725 } // namespace device | 725 } // namespace device |
| OLD | NEW |