Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1138913006: bluetooth: Refactor LayoutTestBluetoothAdapterProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testing-remove-mocking
Patch Set: Use lambdas for creating a discovery session. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..dc118b4787e8d1790e81e104c4d2f50ad843ff59 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,24 @@ 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();
scheib 2015/05/20 04:17:06 First time I've seen "::std::tr1". Is that better
ortuno 2015/05/20 16:44:04 Done.
+}
+
+// Invokes Run() on the k-th argument of the function with the result
+// of |func| as an argument. This is done to get around the lack of support
Jeffrey Yasskin 2015/05/20 00:27:28 I think you can remove the "This is done" explanat
ortuno 2015/05/20 16:44:04 Done.
+// for scoped_ptr in gmock.
+ACTION_TEMPLATE(RunCallbackWithResult,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(func)) {
+ return ::std::tr1::get<k>(args).Run(func());
+}
+}
+
namespace content {
// static
@@ -53,12 +71,19 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
new NiceMock<MockBluetoothAdapter>());
+ scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
scheib 2015/05/20 04:17:05 Is 'discovery_session' used? The anon function bel
ortuno 2015/05/20 16:44:04 Done.
+ GetDiscoverySession());
+
ON_CALL(*adapter, StartDiscoverySession(_, _))
- .WillByDefault(Invoke(
- &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
+ .WillByDefault(RunCallbackWithResult<0 /* success_callback */>([]() {
+ scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
+ GetDiscoverySession());
+ return discovery_session.Pass();
Jeffrey Yasskin 2015/05/20 00:27:28 In this particular function, you don't even need t
ortuno 2015/05/20 16:44:04 Done.
+ }));
ON_CALL(*adapter, GetDevices())
- .WillByDefault(Return(adapter->GetMockDevices()));
+ .WillByDefault(
scheib 2015/05/20 04:17:05 Explain in comment here why. E.g. // Using Invoke
ortuno 2015/05/20 16:44:04 Done.
scheib 2015/05/20 16:57:49 Not as done as I think you think I thought you wou
+ Invoke(adapter.get(), &MockBluetoothAdapter::GetMockDevices));
return adapter.Pass();
}
@@ -66,18 +91,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 +122,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

Powered by Google App Engine
This is Rietveld 408576698