| 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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
| 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| 11 #include "device/bluetooth/test/bluetooth_test.h" | 11 #include "device/bluetooth/test/bluetooth_test.h" |
| 12 | 12 |
| 13 #if __OBJC__ | 13 #if __OBJC__ |
| 14 @class MockCBDescriptor; |
| 14 @class MockCBCharacteristic; | 15 @class MockCBCharacteristic; |
| 15 @class MockCBPeripheral; | 16 @class MockCBPeripheral; |
| 16 #else // __OBJC__ | 17 #else // __OBJC__ |
| 18 class MockCBDescriptor; |
| 17 class MockCBCharacteristic; | 19 class MockCBCharacteristic; |
| 18 class MockCBPeripheral; | 20 class MockCBPeripheral; |
| 19 #endif // __OBJC__ | 21 #endif // __OBJC__ |
| 20 | 22 |
| 21 namespace device { | 23 namespace device { |
| 22 | 24 |
| 23 class BluetoothAdapterMac; | 25 class BluetoothAdapterMac; |
| 24 | 26 |
| 25 // Mac implementation of BluetoothTestBase. | 27 // Mac implementation of BluetoothTestBase. |
| 26 class BluetoothTestMac : public BluetoothTestBase { | 28 class BluetoothTestMac : public BluetoothTestBase { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 BluetoothRemoteGattCharacteristic* characteristic) override; | 80 BluetoothRemoteGattCharacteristic* characteristic) override; |
| 79 void SimulateGattNotifySessionStopError( | 81 void SimulateGattNotifySessionStopError( |
| 80 BluetoothRemoteGattCharacteristic* characteristic, | 82 BluetoothRemoteGattCharacteristic* characteristic, |
| 81 BluetoothRemoteGattService::GattErrorCode error_code) override; | 83 BluetoothRemoteGattService::GattErrorCode error_code) override; |
| 82 void SimulateGattCharacteristicChanged( | 84 void SimulateGattCharacteristicChanged( |
| 83 BluetoothRemoteGattCharacteristic* characteristic, | 85 BluetoothRemoteGattCharacteristic* characteristic, |
| 84 const std::vector<uint8_t>& value) override; | 86 const std::vector<uint8_t>& value) override; |
| 85 void SimulateGattCharacteristicRemoved( | 87 void SimulateGattCharacteristicRemoved( |
| 86 BluetoothRemoteGattService* service, | 88 BluetoothRemoteGattService* service, |
| 87 BluetoothRemoteGattCharacteristic* characteristic) override; | 89 BluetoothRemoteGattCharacteristic* characteristic) override; |
| 90 void SimulateGattDescriptorRead(BluetoothRemoteGattDescriptor* descriptor, |
| 91 const std::vector<uint8_t>& value) override; |
| 92 void SimulateGattDescriptorReadError( |
| 93 BluetoothRemoteGattDescriptor* descriptor, |
| 94 BluetoothRemoteGattService::GattErrorCode error_code) override; |
| 95 void SimulateGattDescriptorWrite( |
| 96 BluetoothRemoteGattDescriptor* descriptor) override; |
| 97 void SimulateGattDescriptorWriteError( |
| 98 BluetoothRemoteGattDescriptor* descriptor, |
| 99 BluetoothRemoteGattService::GattErrorCode error_code) override; |
| 88 void ExpectedChangeNotifyValueAttempts(int attempts) override; | 100 void ExpectedChangeNotifyValueAttempts(int attempts) override; |
| 89 void ExpectedNotifyValue(NotifyValueState expected_value_state) override; | 101 void ExpectedNotifyValue(NotifyValueState expected_value_state) override; |
| 90 | 102 |
| 91 // macOS is the only platform for which we need to discover each set of | 103 // macOS is the only platform for which we need to discover each set of |
| 92 // attributes individually so we need a method to simulate discovering each | 104 // attributes individually so we need a method to simulate discovering each |
| 93 // set of attributes. | 105 // set of attributes. |
| 94 void SimulateDidDiscoverServices(BluetoothDevice* device, | 106 void SimulateDidDiscoverServices(BluetoothDevice* device, |
| 95 const std::vector<std::string>& uuids); | 107 const std::vector<std::string>& uuids); |
| 108 // CoreBluetooth can return NSData when reading remote gatt descriptors. |
| 109 // This methods simulate receiving NSData from CoreBluetooth. |
| 110 void SimulateGattDescriptorReadNSData( |
| 111 BluetoothRemoteGattDescriptor* descriptor, |
| 112 const std::vector<uint8_t>& value); |
| 113 // CoreBluetooth can return NSString when reading remote gatt descriptors. |
| 114 // This methods simulate receiving NSString from CoreBluetooth. |
| 115 void SimulateGattDescriptorReadNSString( |
| 116 BluetoothRemoteGattDescriptor* descriptor, |
| 117 const std::string& value); |
| 118 // CoreBluetooth can return NSString when reading remote gatt descriptors. |
| 119 // This methods simulate receiving NSString from CoreBluetooth. |
| 120 void SimulateGattDescriptorReadNSNumber( |
| 121 BluetoothRemoteGattDescriptor* descriptor, |
| 122 short value); |
| 96 | 123 |
| 97 // Callback for the bluetooth central manager mock. | 124 // Callback for the bluetooth central manager mock. |
| 98 void OnFakeBluetoothDeviceConnectGattCalled(); | 125 void OnFakeBluetoothDeviceConnectGattCalled(); |
| 99 void OnFakeBluetoothGattDisconnect(); | 126 void OnFakeBluetoothGattDisconnect(); |
| 100 | 127 |
| 101 // Callback for the bluetooth peripheral mock. | 128 // Callback for the bluetooth peripheral mock. |
| 102 void OnFakeBluetoothServiceDiscovery(); | 129 void OnFakeBluetoothServiceDiscovery(); |
| 103 void OnFakeBluetoothCharacteristicDiscovery(); | 130 void OnFakeBluetoothCharacteristicDiscovery(); |
| 104 void OnFakeBluetoothCharacteristicReadValue(); | 131 void OnFakeBluetoothCharacteristicReadValue(); |
| 105 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); | 132 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); |
| 106 void OnFakeBluetoothGattSetCharacteristicNotification(bool notify_value); | 133 void OnFakeBluetoothGattSetCharacteristicNotification(bool notify_value); |
| 134 void OnFakeBluetoothDescriptorReadValue(); |
| 135 void OnFakeBluetoothDescriptorWriteValue(std::vector<uint8_t> value); |
| 107 | 136 |
| 108 // Returns the service UUIDs used to retrieve connected peripherals. | 137 // Returns the service UUIDs used to retrieve connected peripherals. |
| 109 BluetoothDevice::UUIDSet RetrieveConnectedPeripheralServiceUUIDs(); | 138 BluetoothDevice::UUIDSet RetrieveConnectedPeripheralServiceUUIDs(); |
| 110 // Reset RetrieveConnectedPeripheralServiceUUIDs set. | 139 // Reset RetrieveConnectedPeripheralServiceUUIDs set. |
| 111 void ResetRetrieveConnectedPeripheralServiceUUIDs(); | 140 void ResetRetrieveConnectedPeripheralServiceUUIDs(); |
| 112 | 141 |
| 113 protected: | 142 protected: |
| 114 class ScopedMockCentralManager; | 143 class ScopedMockCentralManager; |
| 115 | 144 |
| 116 // Returns MockCBPeripheral from BluetoothDevice. | 145 // Returns MockCBPeripheral from BluetoothDevice. |
| 117 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; | 146 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; |
| 118 // Returns MockCBPeripheral from BluetoothRemoteGattService. | 147 // Returns MockCBPeripheral from BluetoothRemoteGattService. |
| 119 MockCBPeripheral* GetMockCBPeripheral( | 148 MockCBPeripheral* GetMockCBPeripheral( |
| 120 BluetoothRemoteGattService* service) const; | 149 BluetoothRemoteGattService* service) const; |
| 121 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. | 150 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. |
| 122 MockCBPeripheral* GetMockCBPeripheral( | 151 MockCBPeripheral* GetMockCBPeripheral( |
| 123 BluetoothRemoteGattCharacteristic* characteristic) const; | 152 BluetoothRemoteGattCharacteristic* characteristic) const; |
| 153 // Returns MockCBPeripheral from BluetoothRemoteGattDescriptor. |
| 154 MockCBPeripheral* GetMockCBPeripheral( |
| 155 BluetoothRemoteGattDescriptor* descriptor) const; |
| 124 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. | 156 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. |
| 125 MockCBCharacteristic* GetCBMockCharacteristic( | 157 MockCBCharacteristic* GetCBMockCharacteristic( |
| 126 BluetoothRemoteGattCharacteristic* characteristic) const; | 158 BluetoothRemoteGattCharacteristic* characteristic) const; |
| 159 // Returns MockCBDescriptor from BluetoothRemoteGattDescriptor. |
| 160 MockCBDescriptor* GetCBMockDescriptor( |
| 161 BluetoothRemoteGattDescriptor* descriptor) const; |
| 127 // Adds services in MockCBPeripheral. | 162 // Adds services in MockCBPeripheral. |
| 128 void AddServicesToDevice(BluetoothDevice* device, | 163 void AddServicesToDevice(BluetoothDevice* device, |
| 129 const std::vector<std::string>& uuids); | 164 const std::vector<std::string>& uuids); |
| 130 | 165 |
| 131 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. | 166 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. |
| 132 std::string FindCBUUIDForHashTarget(); | 167 std::string FindCBUUIDForHashTarget(); |
| 133 | 168 |
| 134 BluetoothAdapterMac* adapter_mac_ = nullptr; | 169 BluetoothAdapterMac* adapter_mac_ = nullptr; |
| 135 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; | 170 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; |
| 136 | 171 |
| 137 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. | 172 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. |
| 138 bool last_notify_value_ = false; | 173 bool last_notify_value_ = false; |
| 139 int gatt_characteristic_discovery_attempts_ = 0; | 174 int gatt_characteristic_discovery_attempts_ = 0; |
| 140 }; | 175 }; |
| 141 | 176 |
| 142 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). | 177 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). |
| 143 typedef BluetoothTestMac BluetoothTest; | 178 typedef BluetoothTestMac BluetoothTest; |
| 144 | 179 |
| 145 } // namespace device | 180 } // namespace device |
| 146 | 181 |
| 147 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 182 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
| OLD | NEW |