Chromium Code Reviews| 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 16b3c54101fe862d446299187044c16ed8f82ab3..2602d0da07cbf9880cb87935cf21ecb379743ad7 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,12 @@ 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 blocklist. It must not be writable |
| +const char kClientConfigUUID[] = "2902"; |
| +// Blocklisted descriptor |
| +const char kBlocklistedDescriptorUUID[] = "bad0"; |
| // Invokes Run() on the k-th argument of the function with no arguments. |
| ACTION_TEMPLATE(RunCallback, |
| @@ -654,11 +666,36 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
| device->AddMockService(GetGenericAccessService(device.get())); |
| device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| - |
| adapter->AddMockDevice(std::move(device)); |
| - |
| return adapter; |
| } |
| +// static |
| +void LayoutTestBluetoothAdapterProvider::AddDescriptorsToCharacteristic( |
| + device::MockBluetoothGattCharacteristic* characteristic) { |
| + std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description( |
| + new NiceMockBluetoothGattDescriptor( |
| + characteristic, "gatt.characteristic_user_description", |
| + BluetoothUUID(kUserDescriptionUUID), false, |
| + device::BluetoothGattCharacteristic::Permission::PERMISSION_READ)); |
| + |
| + std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config( |
| + new NiceMockBluetoothGattDescriptor( |
| + characteristic, "gatt.client_characteristic_configuration", |
| + BluetoothUUID(kClientConfigUUID), false, |
| + device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE)); |
| + |
| + // add it here with full permission as the blocklist should prevent us from |
|
ortuno
2016/12/07 08:05:12
nit: s/add/Add/ Also this should DCHECK to match o
dougt
2016/12/07 19:48:57
You mean reading and writing to it, correct? We h
dougt
2016/12/07 22:21:43
In any case, in this CL, we don't read or write ye
ortuno
2016/12/08 05:42:51
For future reference. The intent is to make sure w
|
| + // accessing this descriptor |
| + std::unique_ptr<NiceMockBluetoothGattDescriptor> blocklisted_descriptor( |
| + new NiceMockBluetoothGattDescriptor( |
| + characteristic, "bad0", BluetoothUUID(kBlocklistedDescriptorUUID), |
| + false, |
| + device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
| + device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
| + |
| + characteristic->AddMockDescriptor(std::move(user_description)); |
| + characteristic->AddMockDescriptor(std::move(client_config)); |
| +} |
| // static |
| scoped_refptr<NiceMockBluetoothAdapter> |
| @@ -709,6 +746,8 @@ LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { |
| return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr()); |
| })); |
| + AddDescriptorsToCharacteristic(measurement_interval.get()); |
| + |
| health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
| device->AddMockService(std::move(health_thermometer)); |
| @@ -1588,6 +1627,18 @@ LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( |
| .WillByDefault( |
| RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
| + // getDescriptors response |
|
ortuno
2016/12/07 08:05:12
nit: I don't think the comment is necessary.
dougt
2016/12/07 19:48:57
I agree. I will also remove the three other comme
|
| + ON_CALL(*characteristic, GetDescriptors()) |
| + .WillByDefault( |
| + Invoke(characteristic.get(), |
| + &MockBluetoothGattCharacteristic::GetMockDescriptors)); |
| + |
| + // getDescriptor response |
| + ON_CALL(*characteristic, GetDescriptor(_)) |
| + .WillByDefault( |
| + Invoke(characteristic.get(), |
| + &MockBluetoothGattCharacteristic::GetMockDescriptor)); |
| + |
| return characteristic; |
| } |