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

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

Issue 1948763003: Adding support for service scan on OS X (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Fixing comments Created 4 years, 7 months 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/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..eb6fea43dee8cf93af6b972e41a3e53429cf997a 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;
+ scoped_nsobject<NSMutableArray> _services;
}
@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.reset([[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.get() removeAllObjects];
+}
+
+- (void)addServices:(NSArray*)services {
+ for (CBUUID* uuid in services) {
+ base::scoped_nsobject<MockCBService> service(
+ [[MockCBService alloc] initWithCBUUID:uuid primary:YES]);
+ [_services.get() addObject:service.get().service];
+ }
+}
+
+- (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.get() removeObject:serviceToRemove];
+ NSAssert(serviceToRemove, @"Unknown service to remove %@", service);
+ [_services.get() removeObject:serviceToRemove];
+ // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available
+ // with 10.9. It is safe to call this method (even if chrome is running on
+ // 10.8) since WebBluetooth is enabled only with 10.10.
+ DCHECK(
+ [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]);
+ [_delegate performSelector:@selector(peripheral:didModifyServices:)
+ withObject:self.peripheral
+ withObject:@[ serviceToRemove ]];
+}
+
- (NSUUID*)identifier {
return _identifier.get();
}
@@ -80,6 +124,10 @@ using base::scoped_nsobject;
return _name.get();
}
+- (NSArray*)services {
+ return _services.get();
+}
+
- (CBPeripheral*)peripheral {
return ObjCCast<CBPeripheral>(self);
}
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbservice_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698