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

Unified Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: More tests, and fixing ortuno's comments Created 4 years, 1 month 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: device/bluetooth/test/bluetooth_test_mac.mm
diff --git a/device/bluetooth/test/bluetooth_test_mac.mm b/device/bluetooth/test/bluetooth_test_mac.mm
index d7e6f4b63ad6020d8ebfeed19d13e4afb3bd52ee..b3856af9d340f5cc584e6cdc2005cd56f28c058f 100644
--- a/device/bluetooth/test/bluetooth_test_mac.mm
+++ b/device/bluetooth/test/bluetooth_test_mac.mm
@@ -8,6 +8,7 @@
#include "base/mac/foundation_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/sys_string_conversions.h"
#include "build/build_config.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
#include "device/bluetooth/bluetooth_device_mac.h"
@@ -247,6 +248,43 @@ void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) {
didConnectPeripheral:peripheral];
}
+void BluetoothTestMac::SimulateConnectedLowEnergyDevice(
+ ConnectedDeviceType device_ordinal) {
+ const char* identifier = nullptr;
+ NSString* name = nil;
+ BluetoothDevice::UUIDSet service_uuids;
+ switch (device_ordinal) {
+ case ConnectedDeviceType::GENERIC_DEVICE:
+ name = @(kTestDeviceName.c_str());
+ identifier = kTestPeripheralUUID1.c_str();
+ service_uuids.insert(device::BluetoothUUID(kTestUUIDGenericAccess));
ortuno 2016/11/07 03:12:34 q: To avoid having to loop over this set, could yo
jlebel 2016/11/07 05:56:39 Yes, of course!
+ break;
+ case ConnectedDeviceType::HEART_RATE_DEVICE:
+ name = @(kTestDeviceName.c_str());
+ identifier = kTestPeripheralUUID2.c_str();
+ service_uuids.insert(device::BluetoothUUID(kTestUUIDGenericAccess));
+ service_uuids.insert(device::BluetoothUUID(kTestUUIDHeartRate));
+ break;
+ }
+ DCHECK(name);
+ DCHECK(identifier);
+ DCHECK(service_uuids.size() > 0);
+ scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc]
+ initWithUTF8StringIdentifier:identifier
+ name:name]);
+ mock_peripheral.get().bluetoothTestMac = this;
+ scoped_nsobject<NSMutableSet> cbUUIDs([[NSMutableSet alloc] init]);
+ for (auto iterator = service_uuids.begin(); iterator != service_uuids.end();
+ ++iterator) {
+ NSString* uuidString =
+ base::SysUTF8ToNSString(iterator->canonical_value().c_str());
+ [cbUUIDs.get() addObject:[CBUUID UUIDWithString:uuidString]];
+ }
+ [mock_central_manager_->get()
+ setConnectedMockPeripheral:mock_peripheral.get().peripheral
+ withServiceUUIDs:cbUUIDs.get()];
+}
+
void BluetoothTestMac::SimulateGattConnectionError(
BluetoothDevice* device,
BluetoothDevice::ConnectErrorCode errorCode) {
@@ -440,6 +478,20 @@ void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() {
gatt_notify_characteristic_attempts_++;
}
+BluetoothDevice::UUIDSet
+BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() {
+ BluetoothDevice::UUIDSet service_uuids;
+ for (CBUUID* uuid in
+ [mock_central_manager_->get() retrieveConnectedPeripheralServiceUUIDs]) {
+ service_uuids.insert(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid));
+ }
+ return service_uuids;
+}
+
+void BluetoothTestMac::ResetRetrieveConnectedPeripheralServiceUUIDs() {
+ [mock_central_manager_->get() resetRetrieveConnectedPeripheralServiceUUIDs];
+}
+
MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
BluetoothRemoteGattService* service) const {
BluetoothDevice* device = service->GetDevice();

Powered by Google App Engine
This is Rietveld 408576698