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

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

Issue 1156573005: bluetooth: Browser-side implementation of getCharacteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-get-primary-service-initial
Patch Set: Add return to BadMessage 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 3c3dda085ed562654e58879c000ca5d54eca2361..850de98f5844f4866240342b42f12b809ee56989 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
@@ -23,6 +23,7 @@ using device::BluetoothUUID;
using device::MockBluetoothAdapter;
using device::MockBluetoothDevice;
using device::MockBluetoothDiscoverySession;
+using device::MockBluetoothGattCharacteristic;
using device::MockBluetoothGattConnection;
using device::MockBluetoothGattService;
using testing::Between;
@@ -64,8 +65,20 @@ ACTION_P(GetMockDevice, adapter) {
}
return NULL;
}
+
+// Function to iterate over the device's services and return the one
+// that matches the identifier.
+ACTION_P(GetMockService, device) {
+ std::string identifier = arg0;
+ for (BluetoothGattService* service : device->GetMockServices()) {
+ if (service->GetIdentifier() == identifier)
+ return service;
+ }
+ return NULL;
}
+} // namespace
+
namespace content {
// static
@@ -174,10 +187,18 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
list.push_back(BluetoothUUID("1801"));
ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
- empty_device->AddMockService(
- GetMockService(empty_device.get(), "1800" /* Generic Access */));
- empty_device->AddMockService(
- GetMockService(empty_device.get(), "1801" /* Generic Attribute */));
+ scoped_ptr<NiceMock<MockBluetoothGattService>> generic_access(
+ GetService(empty_device.get(), "1800" /* Generic Access */));
+ generic_access->AddMockCharacteristic(
+ GetCharacteristic(generic_access.get(), "2A00" /* Device Name */));
+
+ scoped_ptr<NiceMock<MockBluetoothGattService>> generic_attribute(
+ GetService(empty_device.get(), "1801" /* Generic Attribute */));
+ generic_attribute->AddMockCharacteristic(
+ GetCharacteristic(generic_attribute.get(), "2A05" /* Service Changed */));
+
+ empty_device->AddMockService(generic_access.Pass());
+ empty_device->AddMockService(generic_attribute.Pass());
// Using Invoke allows the device returned from this method to be futher
// modified and have more services added to it. The call to ::GetGattServices
@@ -187,6 +208,12 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
.WillByDefault(
Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices));
+ // The call to BluetoothDevice::GetService will invoke ::GetMockService
+ // which returns a service matching the identifier provided if the service
+ // was added to the mock.
+ ON_CALL(*empty_device, GetGattService(_))
+ .WillByDefault(GetMockService(empty_device.get()));
+
return empty_device.Pass();
}
@@ -223,11 +250,27 @@ LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice(
// static
scoped_ptr<NiceMock<MockBluetoothGattService>>
-LayoutTestBluetoothAdapterProvider::GetMockService(MockBluetoothDevice* device,
- const std::string& uuid) {
- return make_scoped_ptr(new NiceMock<MockBluetoothGattService>(
- device, uuid /* identifier */, BluetoothUUID(uuid), true /* is_primary */,
- false /* is_local */));
+LayoutTestBluetoothAdapterProvider::GetService(MockBluetoothDevice* device,
+ const std::string& uuid) {
+ scoped_ptr<NiceMock<MockBluetoothGattService>> service(
+ new NiceMock<MockBluetoothGattService>(
+ device, uuid /* identifier */, BluetoothUUID(uuid),
+ true /* is_primary */, false /* is_local */));
+
+ ON_CALL(*service, GetCharacteristics())
+ .WillByDefault(Invoke(service.get(),
+ &MockBluetoothGattService::GetMockCharacteristics));
+ return service.Pass();
+}
+
+// static
+scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>>
+LayoutTestBluetoothAdapterProvider::GetCharacteristic(
+ MockBluetoothGattService* service,
+ const std::string& uuid) {
+ return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>(
+ service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */,
+ NULL /* properties */, NULL /* permissions */));
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698