| 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 61fcc0ccdfd04a6be3b1c96a6838f2d295ba8ff2..211d1c470ac4ad8471e81a32217a7d8ba150dd35 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
|
| @@ -13,10 +13,12 @@
|
| #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_notify_session.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
|
|
| using device::BluetoothAdapter;
|
| using device::BluetoothDevice;
|
| +using device::BluetoothGattCharacteristic;
|
| using device::BluetoothGattService;
|
| using device::BluetoothUUID;
|
| using device::MockBluetoothAdapter;
|
| @@ -24,6 +26,7 @@ using device::MockBluetoothDevice;
|
| using device::MockBluetoothDiscoverySession;
|
| using device::MockBluetoothGattCharacteristic;
|
| using device::MockBluetoothGattConnection;
|
| +using device::MockBluetoothGattNotifySession;
|
| using device::MockBluetoothGattService;
|
| using testing::ElementsAre;
|
| using testing::Invoke;
|
| @@ -41,6 +44,8 @@ typedef testing::NiceMock<MockBluetoothGattConnection>
|
| NiceMockBluetoothGattConnection;
|
| typedef testing::NiceMock<MockBluetoothGattService>
|
| NiceMockBluetoothGattService;
|
| +typedef testing::NiceMock<MockBluetoothGattNotifySession>
|
| + NiceMockBluetoothGattNotifySession;
|
|
|
| namespace {
|
| // Bluetooth UUIDs suitable to pass to BluetoothUUID().
|
| @@ -48,6 +53,7 @@ const char kBatteryServiceUUID[] = "180f";
|
| const char kGenericAccessServiceUUID[] = "1800";
|
| const char kGlucoseServiceUUID[] = "1808";
|
| const char kHeartRateServiceUUID[] = "180d";
|
| +const char kHeartRateMeasurementUUID[] = "2a37";
|
| const char kDeviceNameUUID[] = "2a00";
|
|
|
| // Invokes Run() on the k-th argument of the function with no arguments.
|
| @@ -118,6 +124,8 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
|
| return GetMissingCharacteristicGenericAccessAdapter();
|
| else if (fake_adapter_name == "GenericAccessAdapter")
|
| return GetGenericAccessAdapter();
|
| + else if (fake_adapter_name == "HeartRateAdapter")
|
| + return GetHeartRateAdapter();
|
| else if (fake_adapter_name == "FailingConnectionsAdapter")
|
| return GetFailingConnectionsAdapter();
|
| else if (fake_adapter_name == "FailingGATTOperationsAdapter")
|
| @@ -313,6 +321,49 @@ LayoutTestBluetoothAdapterProvider::GetGenericAccessAdapter() {
|
|
|
| // static
|
| scoped_refptr<NiceMockBluetoothAdapter>
|
| +LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
|
| + scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
|
| +
|
| + scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get()));
|
| +
|
| + scoped_ptr<NiceMockBluetoothGattService> heart_rate(
|
| + GetBaseGATTService(device.get(), kHeartRateServiceUUID));
|
| +
|
| + // TODO(ortuno): Implement the rest of the service's characteristics
|
| + // See: http://crbug.com/529975
|
| +
|
| + scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement(
|
| + GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID));
|
| +
|
| + BluetoothGattCharacteristic* measurement_ptr = heart_rate_measurement.get();
|
| +
|
| + ON_CALL(*heart_rate_measurement, StartNotifySession(_, _))
|
| + .WillByDefault(
|
| + RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() {
|
| + return GetBaseGATTNotifySession(measurement_ptr->GetIdentifier());
|
| + }));
|
| +
|
| + heart_rate->AddMockCharacteristic(heart_rate_measurement.Pass());
|
| + device->AddMockService(heart_rate.Pass());
|
| + adapter->AddMockDevice(device.Pass());
|
| +
|
| + return adapter.Pass();
|
| +}
|
| +
|
| +// static
|
| +scoped_ptr<NiceMockBluetoothGattNotifySession>
|
| +LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession(
|
| + const std::string& characteristic_identifier) {
|
| + scoped_ptr<NiceMockBluetoothGattNotifySession> session(
|
| + new NiceMockBluetoothGattNotifySession(characteristic_identifier));
|
| +
|
| + ON_CALL(*session, Stop(_)).WillByDefault(RunCallback<0>());
|
| +
|
| + return session.Pass();
|
| +}
|
| +
|
| +// static
|
| +scoped_refptr<NiceMockBluetoothAdapter>
|
| LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() {
|
| scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
|
|
|
| @@ -435,8 +486,8 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateDevice(
|
| uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
|
| uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
|
|
|
| - return GetBaseDevice(adapter, "Heart Rate Device", uuids,
|
| - makeMACAddress(0x3));
|
| + return GetConnectableDevice(adapter, "Heart Rate Device", uuids,
|
| + makeMACAddress(0x3));
|
| }
|
|
|
| // static
|
| @@ -444,9 +495,10 @@ scoped_ptr<NiceMockBluetoothDevice>
|
| LayoutTestBluetoothAdapterProvider::GetConnectableDevice(
|
| device::MockBluetoothAdapter* adapter,
|
| const std::string& device_name,
|
| - BluetoothDevice::UUIDList uuids) {
|
| + BluetoothDevice::UUIDList uuids,
|
| + const std::string& address) {
|
| scoped_ptr<NiceMockBluetoothDevice> device(
|
| - GetBaseDevice(adapter, device_name, uuids));
|
| + GetBaseDevice(adapter, device_name, uuids, address));
|
|
|
| BluetoothDevice* device_ptr = device.get();
|
|
|
| @@ -541,6 +593,10 @@ LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
|
| ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
|
| .WillByDefault(RunCallback<2 /* error_callback */>(error_code));
|
|
|
| + // StartNotifySession response
|
| + ON_CALL(*characteristic, StartNotifySession(_, _))
|
| + .WillByDefault(RunCallback<1 /* error_callback */>(error_code));
|
| +
|
| return characteristic.Pass();
|
| }
|
|
|
|
|