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

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

Issue 2447593002: bluetooth: Require frame to be connected for startNotifications to succeed. (Closed)
Patch Set: Remove stopNotifications code Created 4 years, 2 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 86401e1a471071a0c95da1e94b6d5faa7d2b40b9..45892a05f843bc9697ffdf3d47de110df5b64cc3 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
@@ -671,7 +671,8 @@ LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() {
"Measurement Interval", health_thermometer.get(),
kMeasurementIntervalUUID,
BluetoothRemoteGattCharacteristic::PROPERTY_READ |
- BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
+ BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
+ BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
NiceMockBluetoothGattCharacteristic* measurement_ptr =
measurement_interval.get();
@@ -687,9 +688,13 @@ LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() {
}));
ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
- .WillByDefault(RunCallback<1 /* success callback */>());
+ .WillByDefault(RunCallback<1 /* success_callback */>());
- // TODO(crbug.com/608538): Mock StartNotifySession.
+ ON_CALL(*measurement_interval, StartNotifySession(_, _))
+ .WillByDefault(
+ RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() {
+ return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr());
+ }));
health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
device->AddMockService(std::move(health_thermometer));
@@ -908,7 +913,8 @@ scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
"Measurement Interval", health_thermometer.get(),
kMeasurementIntervalUUID,
BluetoothRemoteGattCharacteristic::PROPERTY_READ |
- BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
+ BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
+ BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
NiceMockBluetoothGattCharacteristic* measurement_ptr =
measurement_interval.get();
@@ -958,6 +964,32 @@ scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
device_ptr));
}
}));
+
+ ON_CALL(*measurement_interval, StartNotifySession(_, _))
+ .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr,
+ disconnect, succeeds](
+ const BluetoothRemoteGattCharacteristic::NotifySessionCallback&
+ callback,
+ const BluetoothRemoteGattCharacteristic::ErrorCallback&
+ error_callback) {
+ base::Closure pending;
+ if (succeeds) {
+ pending = base::Bind(callback, base::Passed(GetBaseGATTNotifySession(
+ measurement_ptr->GetWeakPtr())));
+ } 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));
+ }
+ }));
+
health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
device->AddMockService(std::move(health_thermometer));
adapter->AddMockDevice(std::move(device));

Powered by Google App Engine
This is Rietveld 408576698