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

Unified Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 2654403002: Implement WebBluetooth descriptor.writeValue() (Closed)
Patch Set: #4 Created 3 years, 11 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: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
diff --git a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
index 9dd447ef1fcd710ffbf8d06c2ded1b310e7f529d..1b96ef96a2aeafce30295017bdd4010da9075b8d 100644
--- a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
+++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
@@ -759,21 +759,31 @@ LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer(
callback.Run(value);
}));
+ ON_CALL(*user_description, WriteRemoteDescriptor(_, _, _))
+ .WillByDefault(RunCallback<1 /* success_callback */>());
+
auto client_config = base::MakeUnique<NiceMockBluetoothGattDescriptor>(
measurement_interval.get(), "gatt.client_characteristic_configuration",
BluetoothUUID(kClientConfigUUID), false /* is_local */,
device::BluetoothRemoteGattCharacteristic::PROPERTY_READ |
device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE);
+ // Crash if WriteRemoteDescriptor called. Not using GoogleMock's Expect
+ // because this is used in layout tests that may not report a mock
+ // expectation.
+ ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _))
+ .WillByDefault(
+ Invoke([](const std::vector<uint8_t>&, const base::Closure&,
+ const BluetoothRemoteGattDescriptor::ErrorCallback&) {
+ NOTREACHED();
+ }));
+
auto no_read_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>(
measurement_interval.get(), kBlocklistedReadDescriptorUUID,
BluetoothUUID(kBlocklistedReadDescriptorUUID), false,
device::BluetoothRemoteGattCharacteristic::PROPERTY_READ |
device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE);
- std::vector<uint8_t> value(1);
- value[0] = false;
-
// Crash if ReadRemoteDescriptor called. Not using GoogleMock's Expect
// because this is used in layout tests that may not report a mock
// expectation
@@ -1132,6 +1142,28 @@ scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
}
}));
+ ON_CALL(*user_descriptor, WriteRemoteDescriptor(_, _, _))
+ .WillByDefault(Invoke([adapter_ptr, device_ptr, user_descriptor_ptr,
+ disconnect, succeeds](
+ const std::vector<uint8_t>& value, const base::Closure& callback,
+ const BluetoothRemoteGattDescriptor::ErrorCallback& error_callback) {
+ base::Closure pending;
+ if (succeeds) {
+ pending = callback;
+ } else {
+ pending = base::Bind(error_callback,
+ BluetoothRemoteGattService::GATT_ERROR_FAILED);
+ }
+ device_ptr->PushPendingCallback(pending);
+ if (disconnect) {
+ device_ptr->SetConnected(false);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
+ device_ptr));
+ }
+ }));
+
measurement_interval->AddMockDescriptor(std::move(user_descriptor));
health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
@@ -1731,6 +1763,9 @@ LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
ON_CALL(*error_descriptor, ReadRemoteDescriptor(_, _))
.WillByDefault(RunCallback<1 /* error_callback */>(error_code));
+ ON_CALL(*error_descriptor, WriteRemoteDescriptor(_, _, _))
+ .WillByDefault(RunCallback<2 /* error_callback */>(error_code));
+
characteristic->AddMockDescriptor(std::move(error_descriptor));
return characteristic;

Powered by Google App Engine
This is Rietveld 408576698