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/bluetooth_test_mac.h" | 5 #include "device/bluetooth/test/bluetooth_test_mac.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); | 46 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); |
47 }; | 47 }; |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 scoped_nsobject<NSDictionary> CreateAdvertisementData( | 51 scoped_nsobject<NSDictionary> CreateAdvertisementData( |
52 NSString* name, | 52 NSString* name, |
53 NSArray* uuids, | 53 NSArray* uuids, |
54 NSDictionary* service_data, | 54 NSDictionary* service_data, |
55 NSNumber* tx_power) { | 55 NSNumber* tx_power, |
| 56 BOOL connectable) { |
56 NSMutableDictionary* advertisement_data( | 57 NSMutableDictionary* advertisement_data( |
57 [NSMutableDictionary dictionaryWithDictionary:@{ | 58 [NSMutableDictionary dictionaryWithDictionary:@{ |
58 CBAdvertisementDataIsConnectable : @(YES) | 59 CBAdvertisementDataIsConnectable : @(connectable) |
59 }]); | 60 }]); |
60 | 61 |
61 if (name) { | 62 if (name) { |
62 [advertisement_data setObject:name forKey:CBAdvertisementDataLocalNameKey]; | 63 [advertisement_data setObject:name forKey:CBAdvertisementDataLocalNameKey]; |
63 } | 64 } |
64 | 65 |
65 if (uuids) { | 66 if (uuids) { |
66 [advertisement_data setObject:uuids | 67 [advertisement_data setObject:uuids |
67 forKey:CBAdvertisementDataServiceUUIDsKey]; | 68 forKey:CBAdvertisementDataServiceUUIDsKey]; |
68 } | 69 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; | 146 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; |
146 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = | 147 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = |
147 adapter_mac_->low_energy_central_manager_delegate_; | 148 adapter_mac_->low_energy_central_manager_delegate_; |
148 | 149 |
149 const char* identifier; | 150 const char* identifier; |
150 NSString* name; | 151 NSString* name; |
151 NSArray* uuids; | 152 NSArray* uuids; |
152 NSNumber* rssi; | 153 NSNumber* rssi; |
153 NSDictionary* service_data; | 154 NSDictionary* service_data; |
154 NSNumber* tx_power; | 155 NSNumber* tx_power; |
| 156 BOOL connectable; |
155 | 157 |
156 switch (device_ordinal) { | 158 switch (device_ordinal) { |
157 case 1: | 159 case 1: |
158 identifier = kTestPeripheralUUID1.c_str(); | 160 identifier = kTestPeripheralUUID1.c_str(); |
159 name = @(kTestDeviceName.c_str()); | 161 name = @(kTestDeviceName.c_str()); |
160 rssi = @(static_cast<int8_t>(TestRSSI::LOWEST)); | 162 rssi = @(static_cast<int8_t>(TestRSSI::LOWEST)); |
161 uuids = @[ | 163 uuids = @[ |
162 [CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())], | 164 [CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())], |
163 [CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())] | 165 [CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())] |
164 ]; | 166 ]; |
165 service_data = @{ | 167 service_data = @{ |
166 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] : | 168 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] : |
167 [NSData dataWithBytes:(unsigned char[]){1} length:1] | 169 [NSData dataWithBytes:(unsigned char[]){1} length:1] |
168 }; | 170 }; |
169 tx_power = @(static_cast<int8_t>(TestTxPower::LOWEST)); | 171 tx_power = @(static_cast<int8_t>(TestTxPower::LOWEST)); |
| 172 connectable = YES; |
170 break; | 173 break; |
171 case 2: | 174 case 2: |
172 identifier = kTestPeripheralUUID1.c_str(); | 175 identifier = kTestPeripheralUUID1.c_str(); |
173 name = @(kTestDeviceName.c_str()); | 176 name = @(kTestDeviceName.c_str()); |
174 rssi = @(static_cast<int8_t>(TestRSSI::LOWER)); | 177 rssi = @(static_cast<int8_t>(TestRSSI::LOWER)); |
175 uuids = @[ | 178 uuids = @[ |
176 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())], | 179 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())], |
177 [CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())] | 180 [CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())] |
178 ]; | 181 ]; |
179 service_data = @{ | 182 service_data = @{ |
180 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] : | 183 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] : |
181 [NSData dataWithBytes:(unsigned char[]){} length:0], | 184 [NSData dataWithBytes:(unsigned char[]){} length:0], |
182 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())] : | 185 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())] : |
183 [NSData dataWithBytes:(unsigned char[]){0, 2} length:2] | 186 [NSData dataWithBytes:(unsigned char[]){0, 2} length:2] |
184 }; | 187 }; |
185 tx_power = @(static_cast<int8_t>(TestTxPower::LOWER)); | 188 tx_power = @(static_cast<int8_t>(TestTxPower::LOWER)); |
| 189 connectable = YES; |
186 break; | 190 break; |
187 case 3: | 191 case 3: |
188 identifier = kTestPeripheralUUID1.c_str(); | 192 identifier = kTestPeripheralUUID1.c_str(); |
189 name = @(kTestDeviceNameEmpty.c_str()); | 193 name = @(kTestDeviceNameEmpty.c_str()); |
190 rssi = @(static_cast<int8_t>(TestRSSI::LOW)); | 194 rssi = @(static_cast<int8_t>(TestRSSI::LOW)); |
191 uuids = nil; | 195 uuids = nil; |
192 service_data = nil; | 196 service_data = nil; |
193 tx_power = nil; | 197 tx_power = nil; |
| 198 connectable = YES; |
194 break; | 199 break; |
195 case 4: | 200 case 4: |
196 identifier = kTestPeripheralUUID2.c_str(); | 201 identifier = kTestPeripheralUUID2.c_str(); |
197 name = @(kTestDeviceNameEmpty.c_str()); | 202 name = @(kTestDeviceNameEmpty.c_str()); |
198 rssi = @(static_cast<int8_t>(TestRSSI::MEDIUM)); | 203 rssi = @(static_cast<int8_t>(TestRSSI::MEDIUM)); |
199 uuids = nil; | 204 uuids = nil; |
200 service_data = nil; | 205 service_data = nil; |
201 tx_power = nil; | 206 tx_power = nil; |
| 207 connectable = YES; |
202 break; | 208 break; |
203 case 5: | 209 case 5: |
204 identifier = kTestPeripheralUUID1.c_str(); | 210 identifier = kTestPeripheralUUID1.c_str(); |
205 name = nil; | 211 name = nil; |
206 rssi = @(static_cast<int8_t>(TestRSSI::HIGH)); | 212 rssi = @(static_cast<int8_t>(TestRSSI::HIGH)); |
207 uuids = nil; | 213 uuids = nil; |
208 service_data = nil; | 214 service_data = nil; |
209 tx_power = nil; | 215 tx_power = nil; |
| 216 connectable = YES; |
| 217 break; |
| 218 case 6: |
| 219 identifier = kTestPeripheralUUID1.c_str(); |
| 220 name = nil; |
| 221 rssi = @(static_cast<int8_t>(TestRSSI::HIGH)); |
| 222 uuids = nil; |
| 223 service_data = nil; |
| 224 tx_power = nil; |
| 225 connectable = NO; |
210 break; | 226 break; |
211 default: | 227 default: |
212 NOTREACHED() << "SimulateLowEnergyDevice not implemented for " | 228 NOTREACHED() << "SimulateLowEnergyDevice not implemented for " |
213 << device_ordinal; | 229 << device_ordinal; |
214 identifier = nil; | 230 identifier = nil; |
215 name = nil; | 231 name = nil; |
216 rssi = nil; | 232 rssi = nil; |
217 uuids = nil; | 233 uuids = nil; |
218 service_data = nil; | 234 service_data = nil; |
219 tx_power = nil; | 235 tx_power = nil; |
| 236 connectable = NO; |
220 } | 237 } |
221 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] | 238 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] |
222 initWithUTF8StringIdentifier:identifier | 239 initWithUTF8StringIdentifier:identifier |
223 name:name]); | 240 name:name]); |
224 mock_peripheral.get().bluetoothTestMac = this; | 241 mock_peripheral.get().bluetoothTestMac = this; |
225 [central_manager_delegate | 242 [central_manager_delegate |
226 centralManager:central_manager | 243 centralManager:central_manager |
227 didDiscoverPeripheral:mock_peripheral.get().peripheral | 244 didDiscoverPeripheral:mock_peripheral.get().peripheral |
228 advertisementData:CreateAdvertisementData(name, uuids, service_data, | 245 advertisementData:CreateAdvertisementData(name, uuids, service_data, |
229 tx_power) | 246 tx_power, connectable) |
230 RSSI:rssi]; | 247 RSSI:rssi]; |
231 return observer.last_device(); | 248 return observer.last_device(); |
232 } | 249 } |
233 | 250 |
234 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { | 251 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { |
235 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); | 252 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(device); |
236 [peripheral_mock setState:CBPeripheralStateConnected]; | 253 [peripheral_mock setState:CBPeripheralStateConnected]; |
237 CBCentralManager* centralManager = | 254 CBCentralManager* centralManager = |
238 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 255 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
239 [centralManager.delegate centralManager:centralManager | 256 [centralManager.delegate centralManager:centralManager |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 678 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
662 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 679 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
663 // return input_str; | 680 // return input_str; |
664 // } | 681 // } |
665 // ++input[0]; | 682 // ++input[0]; |
666 // } | 683 // } |
667 // return ""; | 684 // return ""; |
668 // } | 685 // } |
669 | 686 |
670 } // namespace device | 687 } // namespace device |
OLD | NEW |