| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { | 127 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| 128 mock_central_manager_.reset( | 128 mock_central_manager_.reset( |
| 129 new ScopedMockCentralManager([[MockCentralManager alloc] init])); | 129 new ScopedMockCentralManager([[MockCentralManager alloc] init])); |
| 130 mock_central_manager_->get().bluetoothTestMac = this; | 130 mock_central_manager_->get().bluetoothTestMac = this; |
| 131 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; | 131 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; |
| 132 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); | 132 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 void BluetoothTestMac::ResetEventCounts() { |
| 137 BluetoothTestBase::ResetEventCounts(); |
| 138 last_notify_value_ = false; |
| 139 } |
| 140 |
| 136 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { | 141 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { |
| 137 TestBluetoothAdapterObserver observer(adapter_); | 142 TestBluetoothAdapterObserver observer(adapter_); |
| 138 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; | 143 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; |
| 139 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = | 144 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = |
| 140 adapter_mac_->low_energy_central_manager_delegate_; | 145 adapter_mac_->low_energy_central_manager_delegate_; |
| 141 | 146 |
| 142 const char* identifier; | 147 const char* identifier; |
| 143 NSString* name; | 148 NSString* name; |
| 144 NSArray* uuids; | 149 NSArray* uuids; |
| 145 NSNumber* rssi; | 150 NSNumber* rssi; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 BluetoothRemoteGattCharacteristicMac* characteristic_mac = | 463 BluetoothRemoteGattCharacteristicMac* characteristic_mac = |
| 459 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); | 464 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); |
| 460 CBCharacteristic* cb_characteristic = | 465 CBCharacteristic* cb_characteristic = |
| 461 characteristic_mac->GetCBCharacteristic(); | 466 characteristic_mac->GetCBCharacteristic(); |
| 462 MockCBCharacteristic* characteristic_mock = | 467 MockCBCharacteristic* characteristic_mock = |
| 463 ObjCCast<MockCBCharacteristic>(cb_characteristic); | 468 ObjCCast<MockCBCharacteristic>(cb_characteristic); |
| 464 [service_mock removeCharacteristicMock:characteristic_mock]; | 469 [service_mock removeCharacteristicMock:characteristic_mock]; |
| 465 [peripheral_mock mockDidDiscoverEvents]; | 470 [peripheral_mock mockDidDiscoverEvents]; |
| 466 } | 471 } |
| 467 | 472 |
| 473 void BluetoothTestMac::ExpectedChangeNotifyValueAttempts(int attempts) { |
| 474 EXPECT_EQ(attempts, gatt_notify_characteristic_attempts_); |
| 475 } |
| 476 |
| 477 void BluetoothTestMac::ExpectedNotifyValue( |
| 478 NotifyValueState expected_value_state) { |
| 479 switch (expected_value_state) { |
| 480 case NotifyValueState::NONE: |
| 481 EXPECT_FALSE(last_notify_value_); |
| 482 break; |
| 483 case NotifyValueState::NOTIFY: |
| 484 case NotifyValueState::INDICATE: |
| 485 EXPECT_TRUE(last_notify_value_); |
| 486 break; |
| 487 } |
| 488 } |
| 489 |
| 468 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { | 490 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
| 469 gatt_connection_attempts_++; | 491 gatt_connection_attempts_++; |
| 470 } | 492 } |
| 471 | 493 |
| 472 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { | 494 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
| 473 gatt_disconnection_attempts_++; | 495 gatt_disconnection_attempts_++; |
| 474 } | 496 } |
| 475 | 497 |
| 476 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { | 498 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { |
| 477 gatt_discovery_attempts_++; | 499 gatt_discovery_attempts_++; |
| 478 } | 500 } |
| 479 | 501 |
| 480 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { | 502 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { |
| 481 gatt_read_characteristic_attempts_++; | 503 gatt_read_characteristic_attempts_++; |
| 482 } | 504 } |
| 483 | 505 |
| 484 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( | 506 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( |
| 485 std::vector<uint8_t> value) { | 507 std::vector<uint8_t> value) { |
| 486 last_write_value_ = value; | 508 last_write_value_ = value; |
| 487 gatt_write_characteristic_attempts_++; | 509 gatt_write_characteristic_attempts_++; |
| 488 } | 510 } |
| 489 | 511 |
| 490 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification( | 512 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification( |
| 491 bool notify_value) { | 513 bool notify_value) { |
| 492 last_notify_value = notify_value; | 514 last_notify_value_ = notify_value; |
| 493 gatt_notify_characteristic_attempts_++; | 515 gatt_notify_characteristic_attempts_++; |
| 494 } | 516 } |
| 495 | 517 |
| 496 BluetoothDevice::UUIDSet | 518 BluetoothDevice::UUIDSet |
| 497 BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() { | 519 BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() { |
| 498 BluetoothDevice::UUIDSet service_uuids; | 520 BluetoothDevice::UUIDSet service_uuids; |
| 499 for (CBUUID* uuid in | 521 for (CBUUID* uuid in |
| 500 [mock_central_manager_->get() retrieveConnectedPeripheralServiceUUIDs]) { | 522 [mock_central_manager_->get() retrieveConnectedPeripheralServiceUUIDs]) { |
| 501 service_uuids.insert(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid)); | 523 service_uuids.insert(BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid)); |
| 502 } | 524 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 582 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
| 561 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 583 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
| 562 // return input_str; | 584 // return input_str; |
| 563 // } | 585 // } |
| 564 // ++input[0]; | 586 // ++input[0]; |
| 565 // } | 587 // } |
| 566 // return ""; | 588 // return ""; |
| 567 // } | 589 // } |
| 568 | 590 |
| 569 } // namespace device | 591 } // namespace device |
| OLD | NEW |