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 cb9c01c7a17689d3acdef2fc7528d6f65ca317d6..89f37631d02d410c3088958f84a7711d7444466b 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 |
| @@ -25,6 +25,25 @@ using testing::Return; |
| using testing::NiceMock; |
| using testing::_; |
| +namespace { |
| +// Invokes Run() on the k-th argument of the function with no arguments. |
| +ACTION_TEMPLATE(RunCallback, |
| + HAS_1_TEMPLATE_PARAMS(int, k), |
| + AND_0_VALUE_PARAMS()) { |
| + return ::std::tr1::get<k>(args).Run(); |
| +} |
| + |
| +// Function for when the value passed to the callback needs to be a scoped_ptr. |
| +// Invokes Run() on the k-th argument of the function with value wrapped in |
| +// scoped_ptr<T> |
| +ACTION_TEMPLATE(RunCallbackScoped, |
| + HAS_2_TEMPLATE_PARAMS(int, k, typename, T), |
| + AND_1_VALUE_PARAMS(value)) { |
| + return ::std::tr1::get<k>(args).Run(scoped_ptr<T>(value)); |
| +} |
| + |
| +} |
| + |
| namespace content { |
| // static |
| @@ -53,12 +72,17 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( |
| new NiceMock<MockBluetoothAdapter>()); |
| - ON_CALL(*adapter, StartDiscoverySession(_, _)) |
| - .WillByDefault(Invoke( |
| - &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
| + scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
| + GetDiscoverySession()); |
| + |
| + EXPECT_CALL(*adapter, StartDiscoverySession(_, _)) |
| + .WillOnce(RunCallbackScoped<0 /* success_callback */, |
| + BluetoothDiscoverySession>( |
|
Jeffrey Yasskin
2015/05/19 20:47:49
Run `git cl format` to fix the indentation here.
|
| + discovery_session.release())); |
| ON_CALL(*adapter, GetDevices()) |
| - .WillByDefault(Return(adapter->GetMockDevices())); |
| + .WillByDefault( |
| + Invoke(adapter.get(), &MockBluetoothAdapter::GetMockDevices)); |
| return adapter.Pass(); |
| } |
| @@ -66,18 +90,10 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| // static |
| scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { |
| - scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( |
| - new NiceMock<MockBluetoothAdapter>()); |
| - |
| - ON_CALL(*adapter, StartDiscoverySession(_, _)) |
| - .WillByDefault(Invoke( |
| - &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
| + scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
| adapter->AddMockDevice(GetEmptyDevice(adapter.get())); |
| - ON_CALL(*adapter, GetDevices()) |
| - .WillByDefault(Return(adapter->GetMockDevices())); |
| - |
| return adapter.Pass(); |
| } |
| @@ -105,24 +121,15 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
| } |
| // static |
| -void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( |
| - const BluetoothAdapter::DiscoverySessionCallback& callback, |
| - const BluetoothAdapter::ErrorCallback& error_callback) { |
| +scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> |
| +LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
| scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
| new NiceMock<MockBluetoothDiscoverySession>()); |
| ON_CALL(*discovery_session, Stop(_, _)) |
| - .WillByDefault(Invoke( |
| - &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop)); |
| - |
| - callback.Run(discovery_session.Pass()); |
| -} |
| + .WillByDefault(RunCallback<0 /* success_callback */>()); |
| -// static |
| -void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop( |
| - const base::Closure& callback, |
| - const base::Closure& error_callback) { |
| - callback.Run(); |
| + return discovery_session.Pass(); |
| } |
| } // namespace content |