| 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 #import "device/bluetooth/test/bluetooth_test_mac.h" |
| 6 | 6 |
| 7 #import <CoreBluetooth/CoreBluetooth.h> |
| 7 #include <stdint.h> | 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "device/bluetooth/bluetooth_adapter_mac.h" | 14 #import "device/bluetooth/bluetooth_adapter_mac.h" |
| 14 #include "device/bluetooth/bluetooth_device_mac.h" | 15 #import "device/bluetooth/bluetooth_device_mac.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" | 16 #import "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h" | 17 #import "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h" |
| 17 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 18 #import "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
| 18 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" | 19 #import "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" |
| 19 #include "device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h" | 20 #import "device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h" |
| 20 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" | 21 #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| 21 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" | 22 #import "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" |
| 22 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" | 23 #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 24 #import "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 24 #include "third_party/ocmock/OCMock/OCMock.h" | 25 #import "third_party/ocmock/OCMock/OCMock.h" |
| 25 | |
| 26 #import <CoreBluetooth/CoreBluetooth.h> | |
| 27 | 26 |
| 28 using base::mac::ObjCCast; | 27 using base::mac::ObjCCast; |
| 29 using base::scoped_nsobject; | 28 using base::scoped_nsobject; |
| 30 | 29 |
| 31 namespace device { | 30 namespace device { |
| 32 | 31 |
| 33 // This class hides Objective-C from bluetooth_test_mac.h. | 32 // This class hides Objective-C from bluetooth_test_mac.h. |
| 34 class BluetoothTestMac::ScopedMockCentralManager { | 33 class BluetoothTestMac::ScopedMockCentralManager { |
| 35 public: | 34 public: |
| 36 explicit ScopedMockCentralManager(MockCentralManager* mock_central_manager) { | 35 explicit ScopedMockCentralManager(MockCentralManager* mock_central_manager) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void BluetoothTestMac::InitWithoutDefaultAdapter() { | 106 void BluetoothTestMac::InitWithoutDefaultAdapter() { |
| 108 adapter_mac_ = BluetoothAdapterMac::CreateAdapterForTest( | 107 adapter_mac_ = BluetoothAdapterMac::CreateAdapterForTest( |
| 109 "", "", scoped_task_environment_.GetMainThreadTaskRunner()) | 108 "", "", scoped_task_environment_.GetMainThreadTaskRunner()) |
| 110 .get(); | 109 .get(); |
| 111 adapter_ = adapter_mac_; | 110 adapter_ = adapter_mac_; |
| 112 | 111 |
| 113 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { | 112 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| 114 mock_central_manager_.reset( | 113 mock_central_manager_.reset( |
| 115 new ScopedMockCentralManager([[MockCentralManager alloc] init])); | 114 new ScopedMockCentralManager([[MockCentralManager alloc] init])); |
| 116 [mock_central_manager_->get() setBluetoothTestMac:this]; | 115 [mock_central_manager_->get() setBluetoothTestMac:this]; |
| 117 [mock_central_manager_->get() setState:CBCentralManagerStateUnsupported]; | 116 [mock_central_manager_->get() setState:CBManagerStateUnsupported]; |
| 118 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); | 117 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 | 120 |
| 122 void BluetoothTestMac::InitWithFakeAdapter() { | 121 void BluetoothTestMac::InitWithFakeAdapter() { |
| 123 adapter_mac_ = BluetoothAdapterMac::CreateAdapterForTest( | 122 adapter_mac_ = BluetoothAdapterMac::CreateAdapterForTest( |
| 124 kTestAdapterName, kTestAdapterAddress, | 123 kTestAdapterName, kTestAdapterAddress, |
| 125 scoped_task_environment_.GetMainThreadTaskRunner()) | 124 scoped_task_environment_.GetMainThreadTaskRunner()) |
| 126 .get(); | 125 .get(); |
| 127 adapter_ = adapter_mac_; | 126 adapter_ = adapter_mac_; |
| 128 | 127 |
| 129 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { | 128 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| 130 mock_central_manager_.reset( | 129 mock_central_manager_.reset( |
| 131 new ScopedMockCentralManager([[MockCentralManager alloc] init])); | 130 new ScopedMockCentralManager([[MockCentralManager alloc] init])); |
| 132 mock_central_manager_->get().bluetoothTestMac = this; | 131 mock_central_manager_->get().bluetoothTestMac = this; |
| 133 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; | 132 [mock_central_manager_->get() setState:CBManagerStatePoweredOn]; |
| 134 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); | 133 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 | 136 |
| 138 void BluetoothTestMac::ResetEventCounts() { | 137 void BluetoothTestMac::ResetEventCounts() { |
| 139 BluetoothTestBase::ResetEventCounts(); | 138 BluetoothTestBase::ResetEventCounts(); |
| 140 last_notify_value_ = false; | 139 last_notify_value_ = false; |
| 141 } | 140 } |
| 142 | 141 |
| 143 void BluetoothTestMac::SimulateAdapterPoweredOff() { | 142 void BluetoothTestMac::SimulateAdapterPoweredOff() { |
| 144 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOff]; | 143 [mock_central_manager_->get() setState:CBManagerStatePoweredOff]; |
| 145 | 144 |
| 146 for (BluetoothDevice* device : adapter_->GetDevices()) { | 145 for (BluetoothDevice* device : adapter_->GetDevices()) { |
| 147 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); | 146 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); |
| 148 [peripheral_mock setState:CBPeripheralStateDisconnected]; | 147 [peripheral_mock setState:CBPeripheralStateDisconnected]; |
| 149 } | 148 } |
| 150 | 149 |
| 151 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = | 150 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = |
| 152 adapter_mac_->low_energy_central_manager_delegate_; | 151 adapter_mac_->low_energy_central_manager_delegate_; |
| 153 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; | 152 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; |
| 154 [central_manager_delegate centralManagerDidUpdateState:central_manager]; | 153 [central_manager_delegate centralManagerDidUpdateState:central_manager]; |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 715 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
| 717 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 716 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
| 718 // return input_str; | 717 // return input_str; |
| 719 // } | 718 // } |
| 720 // ++input[0]; | 719 // ++input[0]; |
| 721 // } | 720 // } |
| 722 // return ""; | 721 // return ""; |
| 723 // } | 722 // } |
| 724 | 723 |
| 725 } // namespace device | 724 } // namespace device |
| OLD | NEW |