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

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

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: More tests, and fixing ortuno's comments Created 4 years, 1 month 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/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"
11 #include "base/strings/sys_string_conversions.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "device/bluetooth/bluetooth_adapter_mac.h" 13 #include "device/bluetooth/bluetooth_adapter_mac.h"
13 #include "device/bluetooth/bluetooth_device_mac.h" 14 #include "device/bluetooth/bluetooth_device_mac.h"
14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
15 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" 16 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
16 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" 17 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h"
17 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
18 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" 19 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 20 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 21 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 static_cast<BluetoothLowEnergyDeviceMac*>(device); 241 static_cast<BluetoothLowEnergyDeviceMac*>(device);
241 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); 242 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral();
242 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; 243 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral;
243 [mockPeripheral setState:CBPeripheralStateConnected]; 244 [mockPeripheral setState:CBPeripheralStateConnected];
244 CBCentralManager* centralManager = 245 CBCentralManager* centralManager =
245 ObjCCast<CBCentralManager>(mock_central_manager_->get()); 246 ObjCCast<CBCentralManager>(mock_central_manager_->get());
246 [centralManager.delegate centralManager:centralManager 247 [centralManager.delegate centralManager:centralManager
247 didConnectPeripheral:peripheral]; 248 didConnectPeripheral:peripheral];
248 } 249 }
249 250
251 void BluetoothTestMac::SimulateConnectedLowEnergyDevice(
252 ConnectedDeviceType device_ordinal) {
253 const char* identifier = nullptr;
254 NSString* name = nil;
255 BluetoothDevice::UUIDSet service_uuids;
256 switch (device_ordinal) {
257 case ConnectedDeviceType::GENERIC_DEVICE:
258 name = @(kTestDeviceName.c_str());
259 identifier = kTestPeripheralUUID1.c_str();
260 service_uuids.insert(device::BluetoothUUID(kTestUUIDGenericAccess));
ortuno 2016/11/07 03:12:34 q: To avoid having to loop over this set, could yo
jlebel 2016/11/07 05:56:39 Yes, of course!
261 break;
262 case ConnectedDeviceType::HEART_RATE_DEVICE:
263 name = @(kTestDeviceName.c_str());
264 identifier = kTestPeripheralUUID2.c_str();
265 service_uuids.insert(device::BluetoothUUID(kTestUUIDGenericAccess));
266 service_uuids.insert(device::BluetoothUUID(kTestUUIDHeartRate));
267 break;
268 }
269 DCHECK(name);
270 DCHECK(identifier);
271 DCHECK(service_uuids.size() > 0);
272 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc]
273 initWithUTF8StringIdentifier:identifier
274 name:name]);
275 mock_peripheral.get().bluetoothTestMac = this;
276 scoped_nsobject<NSMutableSet> cbUUIDs([[NSMutableSet alloc] init]);
277 for (auto iterator = service_uuids.begin(); iterator != service_uuids.end();
278 ++iterator) {
279 NSString* uuidString =
280 base::SysUTF8ToNSString(iterator->canonical_value().c_str());
281 [cbUUIDs.get() addObject:[CBUUID UUIDWithString:uuidString]];
282 }
283 [mock_central_manager_->get()
284 setConnectedMockPeripheral:mock_peripheral.get().peripheral
285 withServiceUUIDs:cbUUIDs.get()];
286 }
287
250 void BluetoothTestMac::SimulateGattConnectionError( 288 void BluetoothTestMac::SimulateGattConnectionError(
251 BluetoothDevice* device, 289 BluetoothDevice* device,
252 BluetoothDevice::ConnectErrorCode errorCode) { 290 BluetoothDevice::ConnectErrorCode errorCode) {
253 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = 291 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac =
254 static_cast<BluetoothLowEnergyDeviceMac*>(device); 292 static_cast<BluetoothLowEnergyDeviceMac*>(device);
255 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); 293 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral();
256 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; 294 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral;
257 [mockPeripheral setState:CBPeripheralStateDisconnected]; 295 [mockPeripheral setState:CBPeripheralStateDisconnected];
258 CBCentralManager* centralManager = 296 CBCentralManager* centralManager =
259 ObjCCast<CBCentralManager>(mock_central_manager_->get()); 297 ObjCCast<CBCentralManager>(mock_central_manager_->get());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( 471 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue(
434 std::vector<uint8_t> value) { 472 std::vector<uint8_t> value) {
435 last_write_value_ = value; 473 last_write_value_ = value;
436 gatt_write_characteristic_attempts_++; 474 gatt_write_characteristic_attempts_++;
437 } 475 }
438 476
439 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() { 477 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() {
440 gatt_notify_characteristic_attempts_++; 478 gatt_notify_characteristic_attempts_++;
441 } 479 }
442 480
481 BluetoothDevice::UUIDSet
482 BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() {
483 BluetoothDevice::UUIDSet service_uuids;
484 for (CBUUID* uuid in
485 [mock_central_manager_->get() retrieveConnectedPeripheralServiceUUIDs]) {
486 service_uuids.insert(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid));
487 }
488 return service_uuids;
489 }
490
491 void BluetoothTestMac::ResetRetrieveConnectedPeripheralServiceUUIDs() {
492 [mock_central_manager_->get() resetRetrieveConnectedPeripheralServiceUUIDs];
493 }
494
443 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( 495 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
444 BluetoothRemoteGattService* service) const { 496 BluetoothRemoteGattService* service) const {
445 BluetoothDevice* device = service->GetDevice(); 497 BluetoothDevice* device = service->GetDevice();
446 BluetoothLowEnergyDeviceMac* device_mac = 498 BluetoothLowEnergyDeviceMac* device_mac =
447 static_cast<BluetoothLowEnergyDeviceMac*>(device); 499 static_cast<BluetoothLowEnergyDeviceMac*>(device);
448 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); 500 CBPeripheral* cb_peripheral = device_mac->GetPeripheral();
449 return ObjCCast<MockCBPeripheral>(cb_peripheral); 501 return ObjCCast<MockCBPeripheral>(cb_peripheral);
450 } 502 }
451 503
452 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( 504 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 540 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
489 // if (base::HexEncode(raw, sizeof(raw)) == target) { 541 // if (base::HexEncode(raw, sizeof(raw)) == target) {
490 // return input_str; 542 // return input_str;
491 // } 543 // }
492 // ++input[0]; 544 // ++input[0];
493 // } 545 // }
494 // return ""; 546 // return "";
495 // } 547 // }
496 548
497 } // namespace device 549 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698