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..e0148cae8493aafb0c45b0fd0a96fd749fe5e351 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; |
|
ortuno
2016/05/06 16:03:34
How does this array get destroyed?
jlebel
2016/05/07 00:16:12
Done.
|
| } |
| @end |
| @@ -21,6 +24,8 @@ using base::scoped_nsobject; |
| @implementation MockCBPeripheral |
| @synthesize state = _state; |
| +@synthesize delegate = _delegate; |
|
ortuno
2016/05/06 16:03:34
Why do you need to manually synthesize these, I th
jlebel
2016/05/07 00:16:12
Unfortunately Chrome is not using ARC yet. Therefo
ortuno
2016/05/09 19:54:01
Ah. I see.
|
| +@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]); |
| @@ -72,6 +78,44 @@ 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) { |
| + MockCBService* service = |
|
ortuno
2016/05/06 16:03:34
Who manages the lifetime of this object? Does it's
jlebel
2016/05/07 00:16:12
Done.
|
| + [[MockCBService alloc] initWithCBUUID:uuid primary:YES]; |
| + [_services addObject:service.service]; |
| + } |
| +} |
| + |
| +- (void)didDiscoverWithError:(NSError*)error { |
| + [_delegate peripheral:self.peripheral didDiscoverServices:error]; |
|
ortuno
2016/05/06 16:03:34
What is this called? I've never seen this pattern
jlebel
2016/05/07 00:16:12
What pattern are you talking about? "self.peripher
ortuno
2016/05/09 19:54:01
I guess I'm not sure what the second and third par
|
| +} |
| + |
| +- (void)removeServiceWithCBUUID:(CBUUID*)uuid { |
| + CBService* serviceToRemove = nil; |
| + for (MockCBService* service in _services) { |
| + if ([service.UUID isEqual:uuid]) { |
| + serviceToRemove = service.service; |
| + break; |
| + } |
| + } |
| + NSAssert(serviceToRemove, @"Unknown service to remove %@", uuid); |
| + [_services removeObject:serviceToRemove]; |
| +#pragma clang diagnostic push |
|
ortuno
2016/05/06 16:03:34
Can you comment why you need this?
jlebel
2016/05/07 00:16:12
Done.
|
| +#pragma clang diagnostic ignored "-Wpartial-availability" |
| + [_delegate peripheral:self.peripheral didModifyServices:@[ serviceToRemove ]]; |
| +#pragma clang diagnostic pop |
| +} |
| + |
| - (NSUUID*)identifier { |
| return _identifier.get(); |
| } |
| @@ -80,6 +124,10 @@ using base::scoped_nsobject; |
| return _name.get(); |
| } |
| +- (NSArray*)services { |
| + return _services; |
| +} |
| + |
| - (CBPeripheral*)peripheral { |
| return ObjCCast<CBPeripheral>(self); |
| } |