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 738685a8bc28601c1a1878c2adab5952717a2587..f1de1db6f16ec5f5a2fbed40350dd054c4ab9c94 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/12/02 06:14:50
s/blacklist/blocklist/
dougt
2016/12/02 18:31:28
Done.
|
| +const char kClientConfigUUID[] = "2902"; |
| // Invokes Run() on the k-th argument of the function with no arguments. |
| ACTION_TEMPLATE(RunCallback, |
| @@ -650,11 +660,49 @@ 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( |
|
ortuno
2016/12/02 06:14:50
Given that this will only be used in one place (se
dougt
2016/12/02 18:31:28
Acknowledged.
I was thinking that it might be nee
ortuno
2016/12/07 08:05:12
hmm I can't see us using this but maybe I'm missin
|
| + device::MockBluetoothGattCharacteristic* characteristic) { |
| + std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description( |
| + new NiceMockBluetoothGattDescriptor( |
| + characteristic, "user_description", |
| + BluetoothUUID(kUserDescriptionUUID), false, |
| + device::BluetoothGattCharacteristic::Permission::PERMISSION_READ)); |
| + |
| + std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config( |
| + new NiceMockBluetoothGattDescriptor( |
| + characteristic, "client_characteristic_configuration", |
| + BluetoothUUID(kClientConfigUUID), false, |
| + device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE)); |
| + |
| + ON_CALL(*client_config, ReadRemoteDescriptor(_, _)) |
|
ortuno
2016/12/02 06:14:50
No need for Write/Read yet.
dougt
2016/12/02 18:31:28
Done.
|
| + .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(_, _, _)) |
|
ortuno
2016/12/02 06:14:50
Rather than succeeding this should DCHECK. See oth
dougt
2016/12/02 18:31:28
Acknowledged. Removing as we're not doing write i
|
| + .WillByDefault(RunCallback<1 /* success callback */>()); |
| + |
| + ON_CALL(*characteristic, GetDescriptors()) |
|
ortuno
2016/12/02 06:14:50
Add these to GetBaseGATTCharacteristic so that all
dougt
2016/12/02 18:31:28
Done.
|
| + .WillByDefault( |
| + Invoke(characteristic, |
| + &MockBluetoothGattCharacteristic::GetMockDescriptors)); |
| + |
| + ON_CALL(*characteristic, GetDescriptor(_)) |
| + .WillByDefault(Invoke( |
| + characteristic, &MockBluetoothGattCharacteristic::GetMockDescriptor)); |
| + |
| + characteristic->AddMockDescriptor(std::move(user_description)); |
| + characteristic->AddMockDescriptor(std::move(client_config)); |
| +} |
| // static |
| scoped_refptr<NiceMockBluetoothAdapter> |
| @@ -705,6 +753,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)); |
| @@ -999,6 +1049,8 @@ scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: |
| } |
| })); |
| + AddDescriptorsToCharacteristic(measurement_interval.get()); |
|
ortuno
2016/12/02 06:14:50
I don't think this applies here. When you read/wri
dougt
2016/12/02 18:31:28
Done.
|
| + |
| health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
| device->AddMockService(std::move(health_thermometer)); |
| adapter->AddMockDevice(std::move(device)); |