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 f931660cc0ea069f7b036baaf381713e9678d154..d10b87e9be4f13e0e875894a7c8724b34af88dfd 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 |
@@ -10,16 +10,20 @@ |
#include "device/bluetooth/bluetooth_uuid.h" |
#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 "testing/gmock/include/gmock/gmock.h" |
using device::BluetoothAdapter; |
using device::BluetoothAdapterFactory; |
using device::BluetoothDevice; |
using device::BluetoothDiscoverySession; |
+using device::BluetoothGattConnection; |
using device::BluetoothUUID; |
using device::MockBluetoothAdapter; |
using device::MockBluetoothDevice; |
using device::MockBluetoothDiscoverySession; |
+using device::MockBluetoothGattConnection; |
+using testing::Between; |
using testing::Invoke; |
using testing::Return; |
using testing::NiceMock; |
@@ -33,6 +37,13 @@ ACTION_TEMPLATE(RunCallback, |
return ::testing::get<k>(args).Run(); |
} |
+// Invokes Run() on the k-th argument of the function with 1 argument. |
+ACTION_TEMPLATE(RunCallback, |
+ HAS_1_TEMPLATE_PARAMS(int, k), |
+ AND_1_VALUE_PARAMS(p0)) { |
+ return ::testing::get<k>(args).Run(p0); |
+} |
+ |
// Invokes Run() on the k-th argument of the function with the result |
// of |func| as an argument. |
ACTION_TEMPLATE(RunCallbackWithResult, |
@@ -40,6 +51,17 @@ ACTION_TEMPLATE(RunCallbackWithResult, |
AND_1_VALUE_PARAMS(func)) { |
return ::testing::get<k>(args).Run(func()); |
} |
+ |
+// Function to iterate over the adapter's devices and return the one |
+// that matches the address. |
+ACTION_P(GetMockDevice, adapter) { |
+ std::string address = arg0; |
+ for (BluetoothDevice* device : adapter->GetMockDevices()) { |
+ if (device->GetAddress() == address) |
+ return device; |
+ } |
+ return NULL; |
+} |
} |
namespace content { |
@@ -57,6 +79,10 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( |
else if (fake_adapter_name == "Single Empty Device" || |
fake_adapter_name == "SingleEmptyDeviceAdapter") { |
return GetSingleEmptyDeviceAdapter(); |
+ } else if (fake_adapter_name == "ConnectableDeviceAdapter") { |
+ return GetConnectableDeviceAdapter(); |
+ } else if (fake_adapter_name == "UnconnectableDeviceAdapter") { |
+ return GetUnconnectableDeviceAdapter(); |
} else if (fake_adapter_name == "") { |
return NULL; |
} |
@@ -81,6 +107,10 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
.WillByDefault( |
Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); |
+ // The call to ::GetDevice will invoke GetMockDevice which returns a device |
+ // matching the address provided if the device was added to the mock. |
+ ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); |
+ |
return adapter.Pass(); |
} |
@@ -95,6 +125,38 @@ LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { |
} |
// static |
+scoped_refptr<NiceMock<MockBluetoothAdapter>> |
+LayoutTestBluetoothAdapterProvider::GetConnectableDeviceAdapter() { |
+ scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
+ |
+ adapter->AddMockDevice(GetConnectableDevice(adapter.get())); |
+ |
+ return adapter.Pass(); |
+} |
+ |
+// static |
+scoped_refptr<NiceMock<MockBluetoothAdapter>> |
+LayoutTestBluetoothAdapterProvider::GetUnconnectableDeviceAdapter() { |
+ scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
+ |
+ adapter->AddMockDevice(GetUnconnectableDevice(adapter.get())); |
+ |
+ return adapter.Pass(); |
+} |
+ |
+// static |
+scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> |
+LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
+ scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
+ new NiceMock<MockBluetoothDiscoverySession>()); |
+ |
+ ON_CALL(*discovery_session, Stop(_, _)) |
+ .WillByDefault(RunCallback<0 /* success_callback */>()); |
+ |
+ return discovery_session.Pass(); |
+} |
+ |
+// static |
scoped_ptr<NiceMock<MockBluetoothDevice>> |
LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
MockBluetoothAdapter* adapter) { |
@@ -118,15 +180,34 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
} |
// static |
-scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> |
-LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
- scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
- new NiceMock<MockBluetoothDiscoverySession>()); |
+scoped_ptr<NiceMock<MockBluetoothDevice>> |
+LayoutTestBluetoothAdapterProvider::GetConnectableDevice( |
+ MockBluetoothAdapter* adapter) { |
+ scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); |
- ON_CALL(*discovery_session, Stop(_, _)) |
- .WillByDefault(RunCallback<0 /* success_callback */>()); |
+ BluetoothDevice* device_ptr = device.get(); |
- return discovery_session.Pass(); |
+ ON_CALL(*device, CreateGattConnection(_, _)) |
+ .WillByDefault( |
+ RunCallbackWithResult<0 /* success_callback */>([device_ptr]() { |
+ return make_scoped_ptr(new NiceMock<MockBluetoothGattConnection>( |
+ device_ptr->GetAddress())); |
+ })); |
+ |
+ return device.Pass(); |
+} |
+ |
+// static |
+scoped_ptr<NiceMock<MockBluetoothDevice>> |
+LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( |
+ MockBluetoothAdapter* adapter) { |
+ scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); |
+ |
+ ON_CALL(*device, CreateGattConnection(_, _)) |
+ .WillByDefault( |
+ RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED)); |
+ |
+ return device.Pass(); |
} |
} // namespace content |