| 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); |
| 96 | 108 |
| 97 // Callback for the bluetooth central manager mock. | 109 // Callback for the bluetooth central manager mock. |
| 98 void OnFakeBluetoothDeviceConnectGattCalled(); | 110 void OnFakeBluetoothDeviceConnectGattCalled(); |
| 99 void OnFakeBluetoothGattDisconnect(); | 111 void OnFakeBluetoothGattDisconnect(); |
| 100 | 112 |
| 101 // Callback for the bluetooth peripheral mock. | 113 // Callback for the bluetooth peripheral mock. |
| 102 void OnFakeBluetoothServiceDiscovery(); | 114 void OnFakeBluetoothServiceDiscovery(); |
| 103 void OnFakeBluetoothCharacteristicDiscovery(); | 115 void OnFakeBluetoothCharacteristicDiscovery(); |
| 104 void OnFakeBluetoothCharacteristicReadValue(); | 116 void OnFakeBluetoothCharacteristicReadValue(); |
| 105 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); | 117 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); |
| 106 void OnFakeBluetoothGattSetCharacteristicNotification(bool notify_value); | 118 void OnFakeBluetoothGattSetCharacteristicNotification(bool notify_value); |
| 119 void OnFakeBluetoothDescriptorReadValue(); |
| 120 void OnFakeBluetoothDescriptorWriteValue(std::vector<uint8_t> value); |
| 107 | 121 |
| 108 // Returns the service UUIDs used to retrieve connected peripherals. | 122 // Returns the service UUIDs used to retrieve connected peripherals. |
| 109 BluetoothDevice::UUIDSet RetrieveConnectedPeripheralServiceUUIDs(); | 123 BluetoothDevice::UUIDSet RetrieveConnectedPeripheralServiceUUIDs(); |
| 110 // Reset RetrieveConnectedPeripheralServiceUUIDs set. | 124 // Reset RetrieveConnectedPeripheralServiceUUIDs set. |
| 111 void ResetRetrieveConnectedPeripheralServiceUUIDs(); | 125 void ResetRetrieveConnectedPeripheralServiceUUIDs(); |
| 112 | 126 |
| 113 protected: | 127 protected: |
| 114 class ScopedMockCentralManager; | 128 class ScopedMockCentralManager; |
| 115 | 129 |
| 116 // Returns MockCBPeripheral from BluetoothDevice. | 130 // Returns MockCBPeripheral from BluetoothDevice. |
| 117 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; | 131 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; |
| 118 // Returns MockCBPeripheral from BluetoothRemoteGattService. | 132 // Returns MockCBPeripheral from BluetoothRemoteGattService. |
| 119 MockCBPeripheral* GetMockCBPeripheral( | 133 MockCBPeripheral* GetMockCBPeripheral( |
| 120 BluetoothRemoteGattService* service) const; | 134 BluetoothRemoteGattService* service) const; |
| 121 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. | 135 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. |
| 122 MockCBPeripheral* GetMockCBPeripheral( | 136 MockCBPeripheral* GetMockCBPeripheral( |
| 123 BluetoothRemoteGattCharacteristic* characteristic) const; | 137 BluetoothRemoteGattCharacteristic* characteristic) const; |
| 138 // Returns MockCBPeripheral from BluetoothRemoteGattDescriptor. |
| 139 MockCBPeripheral* GetMockCBPeripheral( |
| 140 BluetoothRemoteGattDescriptor* descriptor) const; |
| 124 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. | 141 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. |
| 125 MockCBCharacteristic* GetCBMockCharacteristic( | 142 MockCBCharacteristic* GetCBMockCharacteristic( |
| 126 BluetoothRemoteGattCharacteristic* characteristic) const; | 143 BluetoothRemoteGattCharacteristic* characteristic) const; |
| 144 // Returns MockCBDescriptor from BluetoothRemoteGattDescriptor. |
| 145 MockCBDescriptor* GetCBMockDescriptor( |
| 146 BluetoothRemoteGattDescriptor* descriptor) const; |
| 127 // Adds services in MockCBPeripheral. | 147 // Adds services in MockCBPeripheral. |
| 128 void AddServicesToDevice(BluetoothDevice* device, | 148 void AddServicesToDevice(BluetoothDevice* device, |
| 129 const std::vector<std::string>& uuids); | 149 const std::vector<std::string>& uuids); |
| 130 | 150 |
| 131 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. | 151 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. |
| 132 std::string FindCBUUIDForHashTarget(); | 152 std::string FindCBUUIDForHashTarget(); |
| 133 | 153 |
| 134 BluetoothAdapterMac* adapter_mac_ = nullptr; | 154 BluetoothAdapterMac* adapter_mac_ = nullptr; |
| 135 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; | 155 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; |
| 136 | 156 |
| 137 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. | 157 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. |
| 138 bool last_notify_value_ = false; | 158 bool last_notify_value_ = false; |
| 139 int gatt_characteristic_discovery_attempts_ = 0; | 159 int gatt_characteristic_discovery_attempts_ = 0; |
| 140 }; | 160 }; |
| 141 | 161 |
| 142 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). | 162 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). |
| 143 typedef BluetoothTestMac BluetoothTest; | 163 typedef BluetoothTestMac BluetoothTest; |
| 144 | 164 |
| 145 } // namespace device | 165 } // namespace device |
| 146 | 166 |
| 147 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 167 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
| OLD | NEW |