OLD | NEW |
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 _state = state; | 76 _state = state; |
77 if (_state == CBPeripheralStateDisconnected) { | 77 if (_state == CBPeripheralStateDisconnected) { |
78 _services.reset(); | 78 _services.reset(); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 - (void)discoverServices:(NSArray*)serviceUUIDs { | 82 - (void)discoverServices:(NSArray*)serviceUUIDs { |
83 if (_bluetoothTestMac) { | 83 if (_bluetoothTestMac) { |
84 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); | 84 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); |
85 } | 85 } |
86 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; | |
87 } | 86 } |
88 | 87 |
89 - (void)discoverCharacteristics:(NSArray*)characteristics | 88 - (void)discoverCharacteristics:(NSArray*)characteristics |
90 forService:(CBService*)service { | 89 forService:(CBService*)service { |
| 90 if (_bluetoothTestMac) { |
| 91 _bluetoothTestMac->OnFakeBluetoothCharacteristicDiscovery(); |
| 92 } |
91 } | 93 } |
92 | 94 |
93 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic { | 95 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic { |
94 MockCBCharacteristic* mock_characteristic = | 96 MockCBCharacteristic* mock_characteristic = |
95 ObjCCast<MockCBCharacteristic>(characteristic); | 97 ObjCCast<MockCBCharacteristic>(characteristic); |
96 [mock_characteristic discoverDescriptors]; | 98 [mock_characteristic discoverDescriptors]; |
97 } | 99 } |
98 | 100 |
99 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { | 101 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { |
100 DCHECK(_bluetoothTestMac); | 102 DCHECK(_bluetoothTestMac); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 134 } |
133 | 135 |
134 - (void)removeService:(CBService*)service { | 136 - (void)removeService:(CBService*)service { |
135 base::scoped_nsobject<CBService> serviceToRemove(service, | 137 base::scoped_nsobject<CBService> serviceToRemove(service, |
136 base::scoped_policy::RETAIN); | 138 base::scoped_policy::RETAIN); |
137 DCHECK(serviceToRemove); | 139 DCHECK(serviceToRemove); |
138 [_services.get() removeObject:serviceToRemove]; | 140 [_services.get() removeObject:serviceToRemove]; |
139 [self didModifyServices:@[ serviceToRemove ]]; | 141 [self didModifyServices:@[ serviceToRemove ]]; |
140 } | 142 } |
141 | 143 |
| 144 - (void)mockDidDiscoverServices { |
| 145 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; |
| 146 } |
| 147 |
142 - (void)mockDidDiscoverEvents { | 148 - (void)mockDidDiscoverEvents { |
143 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; | 149 [self mockDidDiscoverServices]; |
144 // BluetoothLowEnergyDeviceMac is expected to call | 150 // BluetoothLowEnergyDeviceMac is expected to call |
145 // -[CBPeripheral discoverCharacteristics:forService:] for each services, | 151 // -[CBPeripheral discoverCharacteristics:forService:] for each services, |
146 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: | 152 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: |
147 // error:] needs to be called for all services. | 153 // error:] needs to be called for all services. |
148 for (CBService* service in _services.get()) { | 154 for (CBService* service in _services.get()) { |
149 [_delegate peripheral:self.peripheral | 155 [_delegate peripheral:self.peripheral |
150 didDiscoverCharacteristicsForService:service | 156 didDiscoverCharacteristicsForService:service |
151 error:nil]; | 157 error:nil]; |
152 for (CBCharacteristic* characteristic in service.characteristics) { | 158 for (CBCharacteristic* characteristic in service.characteristics) { |
153 // After discovering services, BluetoothLowEnergyDeviceMac is expected to | 159 // After discovering services, BluetoothLowEnergyDeviceMac is expected to |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return ObjCCast<CBPeripheral>(self); | 194 return ObjCCast<CBPeripheral>(self); |
189 } | 195 } |
190 | 196 |
191 - (void)setNotifyValue:(BOOL)notification | 197 - (void)setNotifyValue:(BOOL)notification |
192 forCharacteristic:(CBCharacteristic*)characteristic { | 198 forCharacteristic:(CBCharacteristic*)characteristic { |
193 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( | 199 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( |
194 notification == YES); | 200 notification == YES); |
195 } | 201 } |
196 | 202 |
197 @end | 203 @end |
OLD | NEW |