Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3627)

Unified Diff: device/bluetooth/test/bluetooth_test_win.cc

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e7440afd9642ad9d91bc779a9c66b88db9ada7ab..bd912e3ef7a45afdbdf0834b973a0fa5a6b6243c 100644
--- a/device/bluetooth/test/bluetooth_test_win.cc
+++ b/device/bluetooth/test/bluetooth_test_win.cc
@@ -104,12 +104,13 @@ void BluetoothTestWin::InitWithFakeAdapter() {
fake_bt_classic_wrapper_->SimulateARadio(
base::SysUTF8ToWide(kTestAdapterName),
CanonicalStringToBLUETOOTH_ADDRESS(kTestAdapterAddress));
+ fake_bt_le_wrapper_->AddObserver(this);
adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
- adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
adapter_win_->InitForTest(nullptr, bluetooth_task_runner_);
+ adapter_win_->GetWinBluetoothTaskManager()->AddObserver(this);
FinishPendingTasks();
}
@@ -283,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) {
@@ -295,6 +360,21 @@ void BluetoothTestWin::SimulateGattDescriptor(
ForceRefreshDevice();
}
+void BluetoothTestWin::OnBluetoothAttemptReadGattCharacteristic() {
+ gatt_read_characteristic_attempts_++;
+}
+
+void BluetoothTestWin::OnBluetoothAttemptWriteGattCharacteristic() {
+ gatt_write_characteristic_attempts_++;
+}
+
+void BluetoothTestWin::onWriteGattCharacteristicValue(
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698