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

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

Issue 1120373004: bluetooth: Browser-side implementation of connectGATT. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-request-device-implementation
Patch Set: Address jyasskin's comments 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
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698