| 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 73527a2bbafe639696dab33a984c6f43d2ece5e2..7f59b54f8dfde7560dc25e7eaa5d05a1ff23e6ac 100644
|
| --- a/device/bluetooth/test/bluetooth_test_mac.mm
|
| +++ b/device/bluetooth/test/bluetooth_test_mac.mm
|
| @@ -12,6 +12,7 @@
|
| #include "device/bluetooth/bluetooth_adapter_mac.h"
|
| #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
|
| #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
|
| +#include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
|
| #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
|
| #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
|
| #include "third_party/ocmock/OCMock/OCMock.h"
|
| @@ -21,6 +22,18 @@
|
| using base::mac::ObjCCast;
|
| using base::scoped_nsobject;
|
|
|
| +namespace {
|
| +
|
| +static void DidDiscoverServices(MockCBPeripheral* peripheral_mock) {
|
| + [peripheral_mock didDiscoverServicesWithError:nil];
|
| + // BluetoothLowEnergyDeviceMac is expected to call
|
| + // -[CBPeripheral discoverCharacteristics:forService:] for each services,
|
| + // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService:
|
| + // error:] needs to be called
|
| + [peripheral_mock didDiscoverCharactericsForAllServices];
|
| +}
|
| +} // namespace
|
| +
|
| namespace device {
|
|
|
| // This class hides Objective-C from bluetooth_test_mac.h.
|
| @@ -235,7 +248,7 @@ void BluetoothTestMac::SimulateGattServicesDiscovered(
|
| [services addObject:cb_service_uuid];
|
| }
|
| [peripheral_mock addServices:services];
|
| - [peripheral_mock didDiscoverServicesWithError:nil];
|
| + DidDiscoverServices(peripheral_mock);
|
| }
|
|
|
| void BluetoothTestMac::SimulateGattServiceRemoved(
|
| @@ -250,7 +263,30 @@ void BluetoothTestMac::SimulateGattServiceRemoved(
|
| CBPeripheral* peripheral = device_mac->GetPeripheral();
|
| MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral);
|
| [peripheral_mock removeService:mac_gatt_service->GetService()];
|
| - [peripheral_mock didDiscoverServicesWithError:nil];
|
| + // After -[MockCBPeripheral removeService:], BluetoothLowEnergyDeviceMac is
|
| + // expected to call -[CBPeripheral discoverServices:]
|
| + DidDiscoverServices(peripheral_mock);
|
| +}
|
| +
|
| +void BluetoothTestMac::SimulateGattCharacteristic(
|
| + BluetoothRemoteGattService* service,
|
| + const std::string& uuid,
|
| + int properties) {
|
| + BluetoothRemoteGattServiceMac* mac_gatt_service =
|
| + static_cast<BluetoothRemoteGattServiceMac*>(service);
|
| + CBService* cb_service = mac_gatt_service->GetService();
|
| + MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
|
| + CBUUID* cb_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
|
| + [service_mock addCharacteristicWithUUID:cb_uuid properties:properties];
|
| + BluetoothDevice* device = service->GetDevice();
|
| + BluetoothLowEnergyDeviceMac* device_mac =
|
| + static_cast<BluetoothLowEnergyDeviceMac*>(device);
|
| + CBPeripheral* cb_peripheral = device_mac->GetPeripheral();
|
| + MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(cb_peripheral);
|
| + [peripheral_mock didModifyServices:@[]];
|
| + // After -[MockCBPeripheral didModifyServices:], BluetoothLowEnergyDeviceMac
|
| + // is expected to call -[CBPeripheral discoverServices:]
|
| + DidDiscoverServices(peripheral_mock);
|
| }
|
|
|
| void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() {
|
|
|