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

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

Issue 1172853004: Chromium side of RequestDeviceOptions implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Switch to a layout test for the new requestDevice behavior Created 5 years, 6 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 3c3dda085ed562654e58879c000ca5d54eca2361..3cd722af77189b2dcf77acba4f0a4b527dfe1a67 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
@@ -26,12 +26,22 @@ using device::MockBluetoothDiscoverySession;
using device::MockBluetoothGattConnection;
using device::MockBluetoothGattService;
using testing::Between;
+using testing::ElementsAre;
using testing::Invoke;
-using testing::Return;
using testing::NiceMock;
+using testing::ResultOf;
+using testing::Return;
+using testing::WithArgs;
using testing::_;
namespace {
+// Bluetooth UUIDs suitable to pass to BluetoothUUID().
+const char kBatteryServiceUUID[] = "180f";
+const char kGenericAccessServiceUUID[] = "1800";
+const char kGenericAttributeServiceUUID[] = "1801";
+const char kGlucoseServiceUUID[] = "1808";
+const char kHeartRateServiceUUID[] = "180d";
+
// Invokes Run() on the k-th argument of the function with no arguments.
ACTION_TEMPLATE(RunCallback,
HAS_1_TEMPLATE_PARAMS(int, k),
@@ -80,6 +90,10 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
return GetConnectableDeviceAdapter();
else if (fake_adapter_name == "UnconnectableDeviceAdapter")
return GetUnconnectableDeviceAdapter();
+ else if (fake_adapter_name == "ScanFilterCheckingAdapter")
+ return GetScanFilterCheckingAdapter();
+ else if (fake_adapter_name == "MultiDeviceAdapter")
+ return GetMultiDeviceAdapter();
else if (fake_adapter_name == "")
return NULL;
@@ -93,8 +107,8 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
new NiceMock<MockBluetoothAdapter>());
- ON_CALL(*adapter, StartDiscoverySession(_, _))
- .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
+ ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
+ .WillByDefault(RunCallbackWithResult<1 /* success_callback */>(
[]() { return GetDiscoverySession(); }));
// Using Invoke allows the adapter returned from this method to be futher
@@ -111,6 +125,56 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
return adapter.Pass();
}
+static std::set<BluetoothUUID> GetUUIDs(
+ const device::BluetoothDiscoveryFilter* filter) {
+ std::set<BluetoothUUID> result;
+ filter->GetUUIDs(result);
+ return result;
+};
+
+static void LogFilterUUIDs(const device::BluetoothDiscoveryFilter* filter) {
+ std::string uuid_message;
+ for (const BluetoothUUID& uuid : GetUUIDs(filter)) {
+ uuid_message += uuid.canonical_value() + ", ";
+ }
+ LOG(ERROR) << "Unexpected UUIDs in filter: " << uuid_message;
+}
+
+// static
+scoped_refptr<NiceMock<MockBluetoothAdapter>>
+LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() {
+ scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
+ new NiceMock<MockBluetoothAdapter>());
+
+ EXPECT_CALL(
+ *adapter,
+ StartDiscoverySessionWithFilterRaw(
+ ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID),
+ BluetoothUUID(kHeartRateServiceUUID),
+ BluetoothUUID(kBatteryServiceUUID))),
+ _, _))
+ .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>(
+ []() { return GetDiscoverySession(); }));
+
+ // Any unexpected call results in the failure callback.
+ ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
+ .WillByDefault(DoAll(WithArgs<0>(Invoke(&LogFilterUUIDs)),
+ RunCallback<2 /* failure_callback */>()));
+
+ // Using Invoke allows the adapter returned from this method to be futher
+ // modified and have devices added to it. The call to ::GetDevices will
+ // invoke ::GetConstMockDevices, returning all devices added up to that time.
+ ON_CALL(*adapter, GetDevices())
+ .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();
+}
+
// static
scoped_refptr<NiceMock<MockBluetoothAdapter>>
LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() {
@@ -123,6 +187,29 @@ LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() {
// static
scoped_refptr<NiceMock<MockBluetoothAdapter>>
+LayoutTestBluetoothAdapterProvider::GetMultiDeviceAdapter() {
+ scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
+
+ scoped_ptr<NiceMock<MockBluetoothDevice>> heart_rate_device =
+ GetEmptyDevice(adapter.get(), "Heart Rate Device");
+ BluetoothDevice::UUIDList heart_rate_uuid_list;
+ heart_rate_uuid_list.push_back(BluetoothUUID(kHeartRateServiceUUID));
+ ON_CALL(*heart_rate_device, GetUUIDs())
+ .WillByDefault(Return(heart_rate_uuid_list));
+ adapter->AddMockDevice(heart_rate_device.Pass());
+
+ scoped_ptr<NiceMock<MockBluetoothDevice>> glucose_device =
+ GetEmptyDevice(adapter.get(), "Glucose Device");
+ BluetoothDevice::UUIDList glucose_uuid_list;
+ glucose_uuid_list.push_back(BluetoothUUID(kGlucoseServiceUUID));
+ ON_CALL(*glucose_device, GetUUIDs()).WillByDefault(Return(glucose_uuid_list));
+ adapter->AddMockDevice(glucose_device.Pass());
+
+ return adapter.Pass();
+}
+
+// static
+scoped_refptr<NiceMock<MockBluetoothAdapter>>
LayoutTestBluetoothAdapterProvider::GetConnectableDeviceAdapter() {
scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
@@ -156,11 +243,12 @@ LayoutTestBluetoothAdapterProvider::GetDiscoverySession() {
// static
scoped_ptr<NiceMock<MockBluetoothDevice>>
LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
- MockBluetoothAdapter* adapter) {
+ MockBluetoothAdapter* adapter,
+ const std::string& device_name) {
scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device(
new NiceMock<MockBluetoothDevice>(
- adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
- "Empty Mock Device instanceID", true /* Paired */,
+ adapter, 0x1F00 /* Bluetooth Class */, device_name,
+ device_name + " instanceID", true /* Paired */,
true /* Connected */));
ON_CALL(*empty_device, GetVendorIDSource())
@@ -170,14 +258,14 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
BluetoothDevice::UUIDList list;
- list.push_back(BluetoothUUID("1800"));
- list.push_back(BluetoothUUID("1801"));
+ list.push_back(BluetoothUUID(kGenericAccessServiceUUID));
+ list.push_back(BluetoothUUID(kGenericAttributeServiceUUID));
ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
empty_device->AddMockService(
- GetMockService(empty_device.get(), "1800" /* Generic Access */));
+ GetMockService(empty_device.get(), kGenericAccessServiceUUID));
empty_device->AddMockService(
- GetMockService(empty_device.get(), "1801" /* Generic Attribute */));
+ GetMockService(empty_device.get(), kGenericAttributeServiceUUID));
// Using Invoke allows the device returned from this method to be futher
// modified and have more services added to it. The call to ::GetGattServices
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | device/bluetooth/bluetooth_uuid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698