Chromium Code Reviews| Index: device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm |
| diff --git a/device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm b/device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm |
| index d549fc39a4d3ba198e086e8f30de52768347f1fe..fa915037f83ee034ecb73fd98edad07a3940c6f2 100644 |
| --- a/device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm |
| +++ b/device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm |
| @@ -6,7 +6,8 @@ |
| #include "base/mac/foundation_util.h" |
| #include "base/mac/scoped_nsobject.h" |
| -#include "device/bluetooth/test/bluetooth_test.h" |
| +#include "device/bluetooth/test/bluetooth_test_mac.h" |
| +#include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" |
| using base::mac::ObjCCast; |
| using base::scoped_nsobject; |
| @@ -14,6 +15,8 @@ using base::scoped_nsobject; |
| @interface MockCBPeripheral () { |
| scoped_nsobject<NSUUID> _identifier; |
| scoped_nsobject<NSString> _name; |
| + id<CBPeripheralDelegate> _delegate; |
| + NSMutableArray* _services; |
|
erikchen
2016/05/09 20:00:08
used a scoped_nsobject?
jlebel
2016/05/09 23:05:59
Done.
|
| } |
| @end |
| @@ -21,6 +24,8 @@ using base::scoped_nsobject; |
| @implementation MockCBPeripheral |
| @synthesize state = _state; |
| +@synthesize delegate = _delegate; |
| +@synthesize bluetoothTestMac = _bluetoothTestMac; |
| - (instancetype)init { |
| [self doesNotRecognizeSelector:_cmd]; |
| @@ -40,6 +45,7 @@ using base::scoped_nsobject; |
| - (instancetype)initWithIdentifier:(NSUUID*)identifier name:(NSString*)name { |
| self = [super init]; |
| if (self) { |
| + _services = [[NSMutableArray alloc] init]; |
| _identifier.reset([identifier retain]); |
| if (name) { |
| _name.reset([name retain]); |
| @@ -52,6 +58,11 @@ using base::scoped_nsobject; |
| return self; |
| } |
| +- (void)dealloc { |
| + [_services release]; |
| + [super dealloc]; |
| +} |
| + |
| - (BOOL)isKindOfClass:(Class)aClass { |
| if (aClass == [CBPeripheral class] || |
| [aClass isSubclassOfClass:[CBPeripheral class]]) { |
| @@ -72,6 +83,43 @@ using base::scoped_nsobject; |
| _state = state; |
| } |
| +- (void)discoverServices:(NSArray*)serviceUUIDs { |
| + if (_bluetoothTestMac) { |
| + _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); |
| + } |
| +} |
| + |
| +- (void)removeAllServices { |
| + [_services removeAllObjects]; |
| +} |
| + |
| +- (void)addServices:(NSArray*)services { |
| + for (CBUUID* uuid in services) { |
| + base::scoped_nsobject<MockCBService> service( |
| + [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); |
| + [_services addObject:service.get().service]; |
|
ortuno
2016/05/09 19:54:01
Will this make it so that the service is retained
jlebel
2016/05/09 23:05:59
yes.
|
| + } |
| +} |
| + |
| +- (void)didDiscoverWithError:(NSError*)error { |
| + [_delegate peripheral:self.peripheral didDiscoverServices:error]; |
| +} |
| + |
| +- (void)removeService:(CBService*)service { |
| + base::scoped_nsobject<CBService> serviceToRemove(service, |
| + base::scoped_policy::RETAIN); |
| + [_services removeObject:serviceToRemove]; |
| + NSAssert(serviceToRemove, @"Unknown service to remove %@", service); |
| + [_services removeObject:serviceToRemove]; |
| +// -[CBPeripheralDelegate peripheral:didModifyServices:] is only available |
|
erikchen
2016/05/09 20:00:08
Ah, you should probably just do:
if ([_delegate r
ortuno
2016/05/09 20:25:36
Can confirm that this works:
DCHECK([_delegate re
jlebel
2016/05/09 23:05:59
Done.
jlebel
2016/05/09 23:05:59
Done.
|
| +// with 10.9. It is safe to call this method (even if chrome is compiled with |
| +// 10.8) since WebBluetooth is enabled only with 10.10. |
| +#pragma clang diagnostic push |
| +#pragma clang diagnostic ignored "-Wpartial-availability" |
| + [_delegate peripheral:self.peripheral didModifyServices:@[ serviceToRemove ]]; |
| +#pragma clang diagnostic pop |
| +} |
| + |
| - (NSUUID*)identifier { |
| return _identifier.get(); |
| } |
| @@ -80,6 +128,10 @@ using base::scoped_nsobject; |
| return _name.get(); |
| } |
| +- (NSArray*)services { |
| + return _services; |
| +} |
| + |
| - (CBPeripheral*)peripheral { |
| return ObjCCast<CBPeripheral>(self); |
| } |