| 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 "components/proximity_auth/ble/bluetooth_low_energy_connection.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 : adapter_(new NiceMock<device::MockBluetoothAdapter>), | 128 : adapter_(new NiceMock<device::MockBluetoothAdapter>), |
| 129 remote_device_(kDeviceName, | 129 remote_device_(kDeviceName, |
| 130 kPublicKey, | 130 kPublicKey, |
| 131 kBluetoothAddress, | 131 kBluetoothAddress, |
| 132 kPersistentSymmetricKey), | 132 kPersistentSymmetricKey), |
| 133 service_uuid_(device::BluetoothUUID(kServiceUUID)), | 133 service_uuid_(device::BluetoothUUID(kServiceUUID)), |
| 134 to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)), | 134 to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)), |
| 135 from_peripheral_char_uuid_( | 135 from_peripheral_char_uuid_( |
| 136 device::BluetoothUUID(kFromPeripheralCharUUID)), | 136 device::BluetoothUUID(kFromPeripheralCharUUID)), |
| 137 gatt_connection_(new NiceMock<device::MockBluetoothGattConnection>( | 137 gatt_connection_(new NiceMock<device::MockBluetoothGattConnection>( |
| 138 adapter_, |
| 138 kBluetoothAddress)), | 139 kBluetoothAddress)), |
| 139 gatt_connection_alias_(gatt_connection_.get()), | 140 gatt_connection_alias_(gatt_connection_.get()), |
| 140 notify_session_alias_(NULL), | 141 notify_session_alias_(NULL), |
| 141 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), | 142 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), |
| 142 task_runner_(new base::TestSimpleTaskRunner) {} | 143 task_runner_(new base::TestSimpleTaskRunner) {} |
| 143 | 144 |
| 144 void SetUp() override { | 145 void SetUp() override { |
| 145 device_ = make_scoped_ptr(new NiceMock<device::MockBluetoothDevice>( | 146 device_ = make_scoped_ptr(new NiceMock<device::MockBluetoothDevice>( |
| 146 adapter_.get(), 0, kDeviceName, kBluetoothAddress, false, false)); | 147 adapter_.get(), 0, kDeviceName, kBluetoothAddress, false, false)); |
| 147 | 148 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 213 |
| 213 // Preparing |connection| to run |create_gatt_connection_success_callback_|. | 214 // Preparing |connection| to run |create_gatt_connection_success_callback_|. |
| 214 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); | 215 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); |
| 215 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); | 216 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); |
| 216 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) | 217 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) |
| 217 .WillOnce(DoAll( | 218 .WillOnce(DoAll( |
| 218 SaveArg<0>(&characteristics_finder_success_callback_), | 219 SaveArg<0>(&characteristics_finder_success_callback_), |
| 219 SaveArg<1>(&characteristics_finder_error_callback_), | 220 SaveArg<1>(&characteristics_finder_error_callback_), |
| 220 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); | 221 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); |
| 221 | 222 |
| 222 create_gatt_connection_success_callback_.Run(make_scoped_ptr( | 223 create_gatt_connection_success_callback_.Run( |
| 223 new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); | 224 make_scoped_ptr(new NiceMock<device::MockBluetoothGattConnection>( |
| 225 adapter_, kBluetoothAddress))); |
| 224 | 226 |
| 225 EXPECT_EQ(connection->sub_status(), | 227 EXPECT_EQ(connection->sub_status(), |
| 226 BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS); | 228 BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS); |
| 227 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); | 229 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
| 228 } | 230 } |
| 229 | 231 |
| 230 // Transitions |connection| from WAITING_CHARACTERISTICS to | 232 // Transitions |connection| from WAITING_CHARACTERISTICS to |
| 231 // WAITING_NOTIFY_SESSION state. | 233 // WAITING_NOTIFY_SESSION state. |
| 232 void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) { | 234 void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) { |
| 233 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)) | 235 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)) |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); | 670 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); |
| 669 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); | 671 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); |
| 670 | 672 |
| 671 // Preparing |connection| to run |create_gatt_connection_success_callback_|. | 673 // Preparing |connection| to run |create_gatt_connection_success_callback_|. |
| 672 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) | 674 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) |
| 673 .WillOnce(DoAll( | 675 .WillOnce(DoAll( |
| 674 SaveArg<0>(&characteristics_finder_success_callback_), | 676 SaveArg<0>(&characteristics_finder_success_callback_), |
| 675 SaveArg<1>(&characteristics_finder_error_callback_), | 677 SaveArg<1>(&characteristics_finder_error_callback_), |
| 676 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); | 678 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); |
| 677 | 679 |
| 678 create_gatt_connection_success_callback_.Run(make_scoped_ptr( | 680 create_gatt_connection_success_callback_.Run( |
| 679 new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); | 681 make_scoped_ptr(new NiceMock<device::MockBluetoothGattConnection>( |
| 682 adapter_, kBluetoothAddress))); |
| 680 | 683 |
| 681 CharacteristicsFound(connection.get()); | 684 CharacteristicsFound(connection.get()); |
| 682 NotifySessionStarted(connection.get()); | 685 NotifySessionStarted(connection.get()); |
| 683 ResponseSignalReceived(connection.get()); | 686 ResponseSignalReceived(connection.get()); |
| 684 } | 687 } |
| 685 | 688 |
| 686 } // namespace proximity_auth | 689 } // namespace proximity_auth |
| OLD | NEW |