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 110e9f992832b5c145b29f2809c64e64f3f5b622..c0a497833dbcb03bda83e50b372ffb643feeaea2 100644 |
--- a/device/bluetooth/test/bluetooth_test_mac.mm |
+++ b/device/bluetooth/test/bluetooth_test_mac.mm |
@@ -9,15 +9,12 @@ |
#include "base/strings/string_number_conversions.h" |
#include "build/build_config.h" |
#include "device/bluetooth/bluetooth_adapter_mac.h" |
+#include "device/bluetooth/test/mock_bluetooth_cbperipheral_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" |
-#if defined(OS_IOS) |
#import <CoreBluetooth/CoreBluetooth.h> |
-#else // !defined(OS_IOS) |
-#import <IOBluetooth/IOBluetooth.h> |
-#endif // defined(OS_IOS) |
namespace device { |
@@ -63,7 +60,9 @@ const std::string BluetoothTestMac::kTestPeripheralUUID2 = |
BluetoothTestMac::BluetoothTestMac() {} |
-BluetoothTestMac::~BluetoothTestMac() {} |
+BluetoothTestMac::~BluetoothTestMac() { |
+ [(MockCentralManager*)mock_central_manager_ release]; |
scheib
2016/02/10 18:59:46
Use static_cast instead of C-Style casts. https://
jlebel
2016/02/10 21:20:08
Done.
|
+} |
void BluetoothTestMac::SetUp() {} |
@@ -83,9 +82,12 @@ void BluetoothTestMac::InitWithoutDefaultAdapter() { |
adapter_ = adapter_mac_; |
if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
- id low_energy_central_manager = [[MockCentralManager alloc] init]; |
- [low_energy_central_manager setState:CBCentralManagerStateUnsupported]; |
- adapter_mac_->SetCentralManagerForTesting(low_energy_central_manager); |
+ mock_central_manager_ = [[MockCentralManager alloc] init]; |
+ MockCentralManager* mock_central_manager = |
+ (MockCentralManager*)mock_central_manager_; |
+ [mock_central_manager setBluetoothTestMac:this]; |
+ [mock_central_manager setState:CBCentralManagerStateUnsupported]; |
+ adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager); |
} |
} |
@@ -97,9 +99,12 @@ void BluetoothTestMac::InitWithFakeAdapter() { |
adapter_ = adapter_mac_; |
if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
- id low_energy_central_manager = [[MockCentralManager alloc] init]; |
- [low_energy_central_manager setState:CBCentralManagerStatePoweredOn]; |
- adapter_mac_->SetCentralManagerForTesting(low_energy_central_manager); |
+ mock_central_manager_ = [[MockCentralManager alloc] init]; |
+ MockCentralManager* mock_central_manager = |
+ (MockCentralManager*)mock_central_manager_; |
+ mock_central_manager.bluetoothTestMac = this; |
+ [mock_central_manager setState:CBCentralManagerStatePoweredOn]; |
+ adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager); |
} |
} |
@@ -151,8 +156,11 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
break; |
} |
case 3: { |
- CBPeripheral* peripheral = CreateMockPeripheral( |
- [NSString stringWithUTF8String:kTestPeripheralUUID1.c_str()]); |
+ NSString* uuid_string = |
+ [NSString stringWithUTF8String:kTestPeripheralUUID1.c_str()]; |
+ NSUUID* identifier = [[NSUUID alloc] initWithUUIDString:uuid_string]; |
+ CBPeripheral* peripheral = (CBPeripheral*)[[MockCBPeripheral alloc] |
scheib
2016/02/10 18:59:46
scoped object?
jlebel
2016/02/10 21:20:08
Done.
|
+ initWithIdentifier:identifier]; |
NSString* name = |
[NSString stringWithUTF8String:kTestDeviceNameEmpty.c_str()]; |
NSArray* uuids = nil; |
@@ -161,6 +169,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
didDiscoverPeripheral:peripheral |
advertisementData:advertisement_data |
RSSI:[NSNumber numberWithInt:0]]; |
+ [peripheral release]; |
break; |
} |
case 4: { |
@@ -180,6 +189,55 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
return observer.last_device(); |
} |
+void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { |
+ BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
+ (BluetoothLowEnergyDeviceMac*)device; |
+ CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
+ MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
+ [mockPeripheral setStateForTesting:CBPeripheralStateConnected]; |
+ CBCentralManager* centralManager = (CBCentralManager*)mock_central_manager_; |
+ [centralManager.delegate centralManager:centralManager |
+ didConnectPeripheral:peripheral]; |
+} |
+ |
+void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { |
+ BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
+ (BluetoothLowEnergyDeviceMac*)device; |
+ CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
+ MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
+ [mockPeripheral setStateForTesting:CBPeripheralStateDisconnected]; |
+ CBCentralManager* centralManager = (CBCentralManager*)mock_central_manager_; |
+ [centralManager.delegate centralManager:centralManager |
+ didDisconnectPeripheral:peripheral |
+ error:nil]; |
+} |
+ |
+void BluetoothTestMac::SimulateGattConnectionError( |
+ BluetoothDevice* device, |
+ BluetoothDevice::ConnectErrorCode errorCode) { |
+ BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
+ (BluetoothLowEnergyDeviceMac*)device; |
+ CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
+ MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; |
+ [mockPeripheral setStateForTesting:CBPeripheralStateDisconnected]; |
+ CBCentralManager* centralManager = (CBCentralManager*)mock_central_manager_; |
+ // TODO(jlebel): Need to convert the connect error code into NSError |
scheib
2016/02/10 18:59:46
ditto: crbug.com
jlebel
2016/02/10 21:20:08
Done.
|
+ NSError* error = [NSError errorWithDomain:@"BluetoothDevice::ConnectErrorCode" |
+ code:-1 |
+ userInfo:nil]; |
+ [centralManager.delegate centralManager:centralManager |
+ didFailToConnectPeripheral:peripheral |
+ error:error]; |
+} |
+ |
+void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
+ gatt_connection_attempts_++; |
+} |
+ |
+void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
+ gatt_disconnection_attempts_++; |
+} |
+ |
// Utility function for generating new (CBUUID, address) pairs where CBUUID |
// hashes to address. For use when adding a new device address to the testing |
// suite because CoreBluetooth peripherals have CBUUIDs in place of addresses, |