Index: device/bluetooth/test/bluetooth_test_win.cc |
diff --git a/device/bluetooth/test/bluetooth_test_win.cc b/device/bluetooth/test/bluetooth_test_win.cc |
index 68af54768acbb3ddcf5686aa5223a65548b01260..86e172c6933952a2ed653f535d0a2834ba19645b 100644 |
--- a/device/bluetooth/test/bluetooth_test_win.cc |
+++ b/device/bluetooth/test/bluetooth_test_win.cc |
@@ -99,6 +99,7 @@ void BluetoothTestWin::InitWithoutDefaultAdapter() { |
void BluetoothTestWin::InitWithFakeAdapter() { |
fake_bt_classic_wrapper_ = new win::BluetoothClassicWrapperFake(); |
fake_bt_le_wrapper_ = new win::BluetoothLowEnergyWrapperFake(); |
+ fake_bt_le_wrapper_->AddObserver(this); |
win::BluetoothClassicWrapper::SetInstanceForTest(fake_bt_classic_wrapper_); |
win::BluetoothLowEnergyWrapper::SetInstanceForTest(fake_bt_le_wrapper_); |
fake_bt_classic_wrapper_->SimulateARadio( |
@@ -109,6 +110,7 @@ void BluetoothTestWin::InitWithFakeAdapter() { |
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); |
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); |
adapter_win_->InitForTest(nullptr, bluetooth_task_runner_); |
+ adapter_win_->GetWinBluetoothTaskManager()->AddObserver(this); |
FinishPendingTasks(); |
} |
@@ -282,6 +284,70 @@ void BluetoothTestWin::SimulateGattCharacteristicRemoved( |
ForceRefreshDevice(); |
} |
+void BluetoothTestWin::RememberCharacteristicForSubsequentAction( |
+ BluetoothGattCharacteristic* characteristic) { |
+ remembered_characteristic_ = |
+ static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic); |
+} |
+ |
+void BluetoothTestWin::SimulateGattCharacteristicRead( |
+ BluetoothGattCharacteristic* characteristic, |
+ const std::vector<uint8_t>& value) { |
+ BluetoothGattCharacteristic* target_characteristic = characteristic; |
+ if (target_characteristic == nullptr) |
+ target_characteristic = remembered_characteristic_; |
+ CHECK(target_characteristic); |
+ |
+ win::GattCharacteristic* target_simulated_characteristic = |
+ GetSimulatedCharacteristic(target_characteristic); |
+ if (target_simulated_characteristic != nullptr) { |
+ fake_bt_le_wrapper_->SimulateGattCharacteristicValue( |
+ target_simulated_characteristic, value); |
+ } |
+ |
+ FinishPendingTasks(); |
+} |
+ |
+void BluetoothTestWin::SimulateGattCharacteristicReadError( |
+ BluetoothGattCharacteristic* characteristic, |
+ BluetoothGattService::GattErrorCode error_code) { |
+ win::GattCharacteristic* target_characteristic = |
+ GetSimulatedCharacteristic(characteristic); |
+ CHECK(target_characteristic); |
+ HRESULT hr = ERROR_SEM_TIMEOUT; |
+ if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH) |
+ hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH; |
+ fake_bt_le_wrapper_->SimulateGattCharacteristicReadError( |
+ target_characteristic, hr); |
+ |
+ FinishPendingTasks(); |
+} |
+ |
+void BluetoothTestWin::SimulateGattCharacteristicWrite( |
+ BluetoothGattCharacteristic* characteristic) { |
+ FinishPendingTasks(); |
+} |
+ |
+void BluetoothTestWin::SimulateGattCharacteristicWriteError( |
+ BluetoothGattCharacteristic* characteristic, |
+ BluetoothGattService::GattErrorCode error_code) { |
+ win::GattCharacteristic* target_characteristic = |
+ GetSimulatedCharacteristic(characteristic); |
+ CHECK(target_characteristic); |
+ HRESULT hr = ERROR_SEM_TIMEOUT; |
+ if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH) |
+ hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH; |
+ fake_bt_le_wrapper_->SimulateGattCharacteristicWriteError( |
+ target_characteristic, hr); |
+ |
+ FinishPendingTasks(); |
+} |
+ |
+void BluetoothTestWin::DeleteDevice(BluetoothDevice* device) { |
+ CHECK(device); |
+ fake_bt_le_wrapper_->RemoveSimulatedBLEDevice(device->GetAddress()); |
+} |
+ |
void BluetoothTestWin::SimulateGattDescriptor( |
BluetoothGattCharacteristic* characteristic, |
const std::string& uuid) { |
@@ -294,6 +360,21 @@ void BluetoothTestWin::SimulateGattDescriptor( |
ForceRefreshDevice(); |
} |
+void BluetoothTestWin::OnAttemptReadGattCharacteristic() { |
+ gatt_read_characteristic_attempts_++; |
+} |
+ |
+void BluetoothTestWin::OnAttemptWriteGattCharacteristic() { |
+ gatt_write_characteristic_attempts_++; |
+} |
+ |
+void BluetoothTestWin::onWriteGattCharacteristicValue( |
+ const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) { |
+ last_write_value_.clear(); |
+ for (ULONG i = 0; i < value->DataSize; i++) |
+ last_write_value_.push_back(value->Data[i]); |
+} |
+ |
win::GattService* BluetoothTestWin::GetSimulatedService( |
win::BLEDevice* device, |
BluetoothGattService* service) { |