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

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: 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..130d41957c45125508cd5871c18c1cf468d20c32 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
@@ -53,12 +53,17 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
new NiceMock<MockBluetoothAdapter>());
+ scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
+ GetDiscoverySession());
+
ON_CALL(*adapter, StartDiscoverySession(_, _))
- .WillByDefault(Invoke(
- &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
+ .WillByDefault(RunCallbackScoped<0 /* success_callback */,
+ BluetoothDiscoverySession>(
+ discovery_session.release()));
Jeffrey Yasskin 2015/05/19 01:09:01 This will crash if StartDiscoverySession is called
ortuno 2015/05/19 01:51:53 Ah but then you can't construct the session before
Jeffrey Yasskin 2015/05/19 17:13:59 Hm, why do you need to construct the session befor
ortuno 2015/05/19 19:51:18 For BluetoothDiscoverySession we don't. But we wil
Jeffrey Yasskin 2015/05/19 20:47:49 Mhmm. Note that you can use lambdas to embed other
ortuno 2015/05/19 23:03:34 Completely forgot about lambdas. Done. Please let
ON_CALL(*adapter, GetDevices())
- .WillByDefault(Return(adapter->GetMockDevices()));
+ .WillByDefault(
+ Invoke(adapter.get(), &MockBluetoothAdapter::GetMockDevices));
return adapter.Pass();
}
@@ -66,18 +71,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 +102,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));
+ .WillByDefault(RunCallback<0 /* success_callback */>());
- callback.Run(discovery_session.Pass());
-}
-
-// 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