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

Side by Side Diff: device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm

Issue 2638653002: Bluetooth: macOS: DidModifyServices can happens while scanning (Closed)
Patch Set: More unit tests Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 5 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "device/bluetooth/test/bluetooth_test_mac.h" 9 #include "device/bluetooth/test/bluetooth_test_mac.h"
10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" 10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 - (void)discoverCharacteristics:(NSArray*)characteristics 88 - (void)discoverCharacteristics:(NSArray*)characteristics
89 forService:(CBService*)service { 89 forService:(CBService*)service {
90 if (_bluetoothTestMac) { 90 if (_bluetoothTestMac) {
91 _bluetoothTestMac->OnFakeBluetoothCharacteristicDiscovery(); 91 _bluetoothTestMac->OnFakeBluetoothCharacteristicDiscovery();
92 } 92 }
93 } 93 }
94 94
95 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic { 95 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic {
96 MockCBCharacteristic* mock_characteristic =
97 ObjCCast<MockCBCharacteristic>(characteristic);
98 [mock_characteristic discoverDescriptors];
99 } 96 }
100 97
101 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { 98 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic {
102 DCHECK(_bluetoothTestMac); 99 DCHECK(_bluetoothTestMac);
103 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue(); 100 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue();
104 } 101 }
105 102
106 - (void)writeValue:(NSData*)data 103 - (void)writeValue:(NSData*)data
107 forCharacteristic:(CBCharacteristic*)characteristic 104 forCharacteristic:(CBCharacteristic*)characteristic
108 type:(CBCharacteristicWriteType)type { 105 type:(CBCharacteristicWriteType)type {
(...skipping 29 matching lines...) Expand all
138 base::scoped_policy::RETAIN); 135 base::scoped_policy::RETAIN);
139 DCHECK(serviceToRemove); 136 DCHECK(serviceToRemove);
140 [_services.get() removeObject:serviceToRemove]; 137 [_services.get() removeObject:serviceToRemove];
141 [self didModifyServices:@[ serviceToRemove ]]; 138 [self didModifyServices:@[ serviceToRemove ]];
142 } 139 }
143 140
144 - (void)mockDidDiscoverServices { 141 - (void)mockDidDiscoverServices {
145 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; 142 [_delegate peripheral:self.peripheral didDiscoverServices:nil];
146 } 143 }
147 144
145 - (void)mockDidDiscoverCharacteristicsForService:(CBService*)service {
146 [_delegate peripheral:self.peripheral
147 didDiscoverCharacteristicsForService:service
148 error:nil];
149 }
150
151 - (void)mockDidDiscoverDescriptorsForCharacteristic:
152 (CBCharacteristic*)characteristic {
153 [_delegate peripheral:self.peripheral
154 didDiscoverDescriptorsForCharacteristic:characteristic
155 error:nil];
156 }
157
148 - (void)mockDidDiscoverEvents { 158 - (void)mockDidDiscoverEvents {
149 [self mockDidDiscoverServices]; 159 [self mockDidDiscoverServices];
150 // BluetoothLowEnergyDeviceMac is expected to call 160 // BluetoothLowEnergyDeviceMac is expected to call
151 // -[CBPeripheral discoverCharacteristics:forService:] for each services, 161 // -[CBPeripheral discoverCharacteristics:forService:] for each services,
152 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: 162 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService:
153 // error:] needs to be called for all services. 163 // error:] needs to be called for all services.
154 for (CBService* service in _services.get()) { 164 for (CBService* service in _services.get()) {
155 [_delegate peripheral:self.peripheral 165 [self mockDidDiscoverCharacteristicsForService:service];
156 didDiscoverCharacteristicsForService:service
157 error:nil];
158 for (CBCharacteristic* characteristic in service.characteristics) { 166 for (CBCharacteristic* characteristic in service.characteristics) {
159 // After discovering services, BluetoothLowEnergyDeviceMac is expected to 167 // After discovering services, BluetoothLowEnergyDeviceMac is expected to
160 // discover characteristics for all services. 168 // discover characteristics for all services.
161 [_delegate peripheral:self.peripheral 169 [_delegate peripheral:self.peripheral
162 didDiscoverDescriptorsForCharacteristic:characteristic 170 didDiscoverDescriptorsForCharacteristic:characteristic
163 error:nil]; 171 error:nil];
164 } 172 }
165 } 173 }
166 } 174 }
167 175
(...skipping 26 matching lines...) Expand all
194 return ObjCCast<CBPeripheral>(self); 202 return ObjCCast<CBPeripheral>(self);
195 } 203 }
196 204
197 - (void)setNotifyValue:(BOOL)notification 205 - (void)setNotifyValue:(BOOL)notification
198 forCharacteristic:(CBCharacteristic*)characteristic { 206 forCharacteristic:(CBCharacteristic*)characteristic {
199 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( 207 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification(
200 notification == YES); 208 notification == YES);
201 } 209 }
202 210
203 @end 211 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698