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 f931660cc0ea069f7b036baaf381713e9678d154..917328a8fa567ce7d1cc6bf2b116e7a8bfeeb791 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 ::std::tr1::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,15 @@ ACTION_TEMPLATE(RunCallbackWithResult, |
| AND_1_VALUE_PARAMS(func)) { |
| return ::testing::get<k>(args).Run(func()); |
| } |
| + |
| +ACTION_P(GetMockDevice, adapter) { |
|
scheib
2015/05/20 20:14:08
Comment
ortuno
2015/05/20 20:54:47
Done.
|
| + std::string address = arg0; |
| + for (auto& device : adapter->GetMockDevices()) { |
| + if (device->GetAddress() == address) |
| + return device; |
| + } |
| + return NULL; |
| +} |
| } |
| namespace content { |
| @@ -57,6 +77,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 +105,8 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| .WillByDefault( |
| Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); |
| + ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); |
| + |
| return adapter.Pass(); |
| } |
| @@ -95,6 +121,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 +176,36 @@ 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(); |
|
scheib
2015/05/20 20:14:08
This is OK, but it may be simpler to read the bloc
ortuno
2015/05/20 20:54:47
Hmm this way we avoid creating a copy of the addre
Jeffrey Yasskin
2015/05/20 21:14:07
To elaborate, we have to capture the address by va
scheib
2015/05/20 21:32:13
I'm fine either way. I thought capturing the addre
Jeffrey Yasskin
2015/05/20 22:29:25
make_scoped_ptr() would also make this shorter:
ht
ortuno
2015/05/20 23:35:19
Done.
Jeffrey Yasskin
2015/05/21 00:12:00
Good point. I don't think it's worth diverging fro
|
| - return discovery_session.Pass(); |
| + ON_CALL(*device, CreateGattConnection(_, _)) |
| + .WillByDefault( |
| + RunCallbackWithResult<0 /* success_callback */>([device_ptr]() { |
| + scoped_ptr<NiceMock<MockBluetoothGattConnection>> connection( |
| + new NiceMock<MockBluetoothGattConnection>( |
| + device_ptr->GetAddress())); |
| + return connection.Pass(); |
| + })); |
| + |
| + 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 |