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

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

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Ensure that we throw a kGattServerNotConnected error if getDescriptor[s] is called while not connec… Created 4 years, 1 month 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 c89ddf84172aa341324a12105392da2cf34f8239..eaf77da61e68edac53788cc6f854752c61585c9c 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
@@ -23,13 +23,16 @@
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
+#include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
#include "testing/gmock/include/gmock/gmock.h"
using base::StringPiece;
using device::BluetoothAdapter;
using device::BluetoothDevice;
+using device::BluetoothGattCharacteristic;
using device::BluetoothRemoteGattCharacteristic;
+using device::BluetoothRemoteGattDescriptor;
using device::BluetoothRemoteGattService;
using device::BluetoothUUID;
using device::MockBluetoothAdapter;
@@ -37,6 +40,7 @@ using device::MockBluetoothDevice;
using device::MockBluetoothDiscoverySession;
using device::MockBluetoothGattCharacteristic;
using device::MockBluetoothGattConnection;
+using device::MockBluetoothGattDescriptor;
using device::MockBluetoothGattNotifySession;
using device::MockBluetoothGattService;
using testing::ElementsAre;
@@ -50,6 +54,8 @@ typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter;
typedef testing::NiceMock<MockBluetoothDevice> NiceMockBluetoothDevice;
typedef testing::NiceMock<MockBluetoothDiscoverySession>
NiceMockBluetoothDiscoverySession;
+typedef testing::NiceMock<MockBluetoothGattDescriptor>
+ NiceMockBluetoothGattDescriptor;
typedef testing::NiceMock<MockBluetoothGattCharacteristic>
NiceMockBluetoothGattCharacteristic;
typedef testing::NiceMock<MockBluetoothGattConnection>
@@ -84,6 +90,10 @@ const char kMeasurementIntervalUUID[] = "2a21";
const char kHeartRateMeasurementUUID[] = "2a37";
const char kSerialNumberStringUUID[] = "2a25";
const char kPeripheralPrivacyFlagUUID[] = "2a02";
+// Descriptors:
+const char kUserDescriptionUUID[] = "2901";
+// client config is in our blacklist. it must not be writable
ortuno 2016/11/21 03:34:08 s/client/Client/ and s/it/It/
dougt 2016/11/22 01:47:16 Acknowledged.
+const char kClientConfigUUID[] = "00002902-0000-1000-8000-00805f9b34fb";
ortuno 2016/11/21 03:34:08 Since it's a standard service you don't need the s
dougt 2016/11/22 01:47:16 Acknowledged.
// Invokes Run() on the k-th argument of the function with no arguments.
ACTION_TEMPLATE(RunCallback,
@@ -650,9 +660,7 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
device->AddMockService(GetGenericAccessService(device.get()));
device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
-
adapter->AddMockDevice(std::move(device));
-
return adapter;
}
@@ -1452,6 +1460,17 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateService(
return notify_session;
}));
+ // Enable descriptors on the heart_rate_measurement
+ ON_CALL(*heart_rate_measurement, GetDescriptors())
+ .WillByDefault(
+ Invoke(measurement_ptr,
+ &MockBluetoothGattCharacteristic::GetMockDescriptors));
+
+ ON_CALL(*heart_rate_measurement, GetDescriptor(_))
+ .WillByDefault(
+ Invoke(measurement_ptr,
+ &MockBluetoothGattCharacteristic::GetMockDescriptor));
+
// Body Sensor Location Characteristic (Chest)
std::unique_ptr<NiceMockBluetoothGattCharacteristic>
body_sensor_location_chest(GetBaseGATTCharacteristic(
@@ -1496,6 +1515,37 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateService(
return location;
}));
+ // Add two descriptors on the heart rate. One for user description, and one
ortuno 2016/11/21 03:34:08 I would add these to DisconnectingHealthThermomete
dougt 2016/11/29 22:50:48 Done.
+ // for client configuration. Client configuration is blacklisted for writes.
+ std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description(
+ new NiceMockBluetoothGattDescriptor(
+ heart_rate_measurement.get(), "user_description",
+ BluetoothUUID(kUserDescriptionUUID), false,
+ device::BluetoothGattCharacteristic::Permission::PERMISSION_READ));
+
+ // this descriptor is not allowed to be written.
+ std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config(
+ new NiceMockBluetoothGattDescriptor(
+ heart_rate_measurement.get(), "client_characteristic_configuration",
+ BluetoothUUID(kClientConfigUUID), false,
+ device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE));
+
+ ON_CALL(*client_config, ReadRemoteDescriptor(_, _))
+ .WillByDefault(Invoke(
+ [](const BluetoothRemoteGattDescriptor::ValueCallback& callback,
+ const BluetoothRemoteGattDescriptor::ErrorCallback&) {
+ std::vector<uint8_t> value({1});
+ callback.Run(value);
+ }));
+
+ // Default write that returns success. This is used to test blacklist
+ // handling of writes.
+ ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _))
+ .WillByDefault(RunCallback<1 /* success callback */>());
+
+ heart_rate_measurement->AddMockDescriptor(std::move(user_description));
+ heart_rate_measurement->AddMockDescriptor(std::move(client_config));
+
heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement));
heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest));
heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist));

Powered by Google App Engine
This is Rietveld 408576698