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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ProximityAuthBluetoothLowEnergyConnectionTest() | 127 ProximityAuthBluetoothLowEnergyConnectionTest() |
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>( | |
138 adapter_, | |
139 kBluetoothAddress)), | |
140 gatt_connection_alias_(gatt_connection_.get()), | |
141 notify_session_alias_(NULL), | 137 notify_session_alias_(NULL), |
142 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), | 138 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), |
143 task_runner_(new base::TestSimpleTaskRunner) {} | 139 task_runner_(new base::TestSimpleTaskRunner) {} |
144 | 140 |
145 void SetUp() override { | 141 void SetUp() override { |
146 device_ = make_scoped_ptr(new NiceMock<device::MockBluetoothDevice>( | 142 device_ = make_scoped_ptr(new NiceMock<device::MockBluetoothDevice>( |
147 adapter_.get(), 0, kDeviceName, kBluetoothAddress, false, false)); | 143 adapter_.get(), 0, kDeviceName, kBluetoothAddress, false, false)); |
148 | 144 |
149 service_ = make_scoped_ptr(new NiceMock<device::MockBluetoothGattService>( | 145 service_ = make_scoped_ptr(new NiceMock<device::MockBluetoothGattService>( |
150 device_.get(), kServiceID, service_uuid_, true, false)); | 146 device_.get(), kServiceID, service_uuid_, true, false)); |
151 to_peripheral_char_ = | 147 to_peripheral_char_ = |
152 make_scoped_ptr(new NiceMock<device::MockBluetoothGattCharacteristic>( | 148 make_scoped_ptr(new NiceMock<device::MockBluetoothGattCharacteristic>( |
153 service_.get(), kToPeripheralCharID, to_peripheral_char_uuid_, | 149 service_.get(), kToPeripheralCharID, to_peripheral_char_uuid_, |
154 false, kCharacteristicProperties, | 150 false, kCharacteristicProperties, |
155 device::BluetoothGattCharacteristic::PERMISSION_NONE)); | 151 device::BluetoothGattCharacteristic::PERMISSION_NONE)); |
156 | 152 |
157 from_peripheral_char_ = | 153 from_peripheral_char_ = |
158 make_scoped_ptr(new NiceMock<device::MockBluetoothGattCharacteristic>( | 154 make_scoped_ptr(new NiceMock<device::MockBluetoothGattCharacteristic>( |
159 service_.get(), kFromPeripheralCharID, from_peripheral_char_uuid_, | 155 service_.get(), kFromPeripheralCharID, from_peripheral_char_uuid_, |
160 false, kCharacteristicProperties, | 156 false, kCharacteristicProperties, |
161 device::BluetoothGattCharacteristic::PERMISSION_NONE)); | 157 device::BluetoothGattCharacteristic::PERMISSION_NONE)); |
162 | 158 |
163 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); | 159 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); |
164 | 160 |
165 std::vector<const device::BluetoothDevice*> devices; | 161 std::vector<const device::BluetoothDevice*> devices; |
166 devices.push_back(device_.get()); | 162 devices.push_back(device_.get()); |
167 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); | 163 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); |
| 164 ON_CALL(*adapter_, GetDevice(kBluetoothAddress)) |
| 165 .WillByDefault(Return(device_.get())); |
168 ON_CALL(*device_, GetGattService(kServiceID)) | 166 ON_CALL(*device_, GetGattService(kServiceID)) |
169 .WillByDefault(Return(service_.get())); | 167 .WillByDefault(Return(service_.get())); |
170 ON_CALL(*service_, GetCharacteristic(kFromPeripheralCharID)) | 168 ON_CALL(*service_, GetCharacteristic(kFromPeripheralCharID)) |
171 .WillByDefault(Return(from_peripheral_char_.get())); | 169 .WillByDefault(Return(from_peripheral_char_.get())); |
172 ON_CALL(*service_, GetCharacteristic(kToPeripheralCharID)) | 170 ON_CALL(*service_, GetCharacteristic(kToPeripheralCharID)) |
173 .WillByDefault(Return(to_peripheral_char_.get())); | 171 .WillByDefault(Return(to_peripheral_char_.get())); |
174 } | 172 } |
175 | 173 |
176 // Creates a BluetoothLowEnergyConnection and verifies it's in DISCONNECTED | 174 // Creates a BluetoothLowEnergyConnection and verifies it's in DISCONNECTED |
177 // state. | 175 // state. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 bytes[3] = static_cast<uint8>(value >> 24); | 348 bytes[3] = static_cast<uint8>(value >> 24); |
351 return bytes; | 349 return bytes; |
352 } | 350 } |
353 | 351 |
354 protected: | 352 protected: |
355 scoped_refptr<device::MockBluetoothAdapter> adapter_; | 353 scoped_refptr<device::MockBluetoothAdapter> adapter_; |
356 RemoteDevice remote_device_; | 354 RemoteDevice remote_device_; |
357 device::BluetoothUUID service_uuid_; | 355 device::BluetoothUUID service_uuid_; |
358 device::BluetoothUUID to_peripheral_char_uuid_; | 356 device::BluetoothUUID to_peripheral_char_uuid_; |
359 device::BluetoothUUID from_peripheral_char_uuid_; | 357 device::BluetoothUUID from_peripheral_char_uuid_; |
360 scoped_ptr<device::MockBluetoothGattConnection> gatt_connection_; | |
361 device::MockBluetoothGattConnection* gatt_connection_alias_; | |
362 scoped_ptr<device::MockBluetoothDevice> device_; | 358 scoped_ptr<device::MockBluetoothDevice> device_; |
363 scoped_ptr<device::MockBluetoothGattService> service_; | 359 scoped_ptr<device::MockBluetoothGattService> service_; |
364 scoped_ptr<device::MockBluetoothGattCharacteristic> to_peripheral_char_; | 360 scoped_ptr<device::MockBluetoothGattCharacteristic> to_peripheral_char_; |
365 scoped_ptr<device::MockBluetoothGattCharacteristic> from_peripheral_char_; | 361 scoped_ptr<device::MockBluetoothGattCharacteristic> from_peripheral_char_; |
366 std::vector<uint8> last_value_written_on_to_peripheral_char_; | 362 std::vector<uint8> last_value_written_on_to_peripheral_char_; |
367 device::MockBluetoothGattNotifySession* notify_session_alias_; | 363 device::MockBluetoothGattNotifySession* notify_session_alias_; |
368 scoped_ptr<MockBluetoothThrottler> bluetooth_throttler_; | 364 scoped_ptr<MockBluetoothThrottler> bluetooth_throttler_; |
369 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 365 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
370 base::MessageLoop message_loop_; | 366 base::MessageLoop message_loop_; |
371 | 367 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 create_gatt_connection_success_callback_.Run( | 676 create_gatt_connection_success_callback_.Run( |
681 make_scoped_ptr(new NiceMock<device::MockBluetoothGattConnection>( | 677 make_scoped_ptr(new NiceMock<device::MockBluetoothGattConnection>( |
682 adapter_, kBluetoothAddress))); | 678 adapter_, kBluetoothAddress))); |
683 | 679 |
684 CharacteristicsFound(connection.get()); | 680 CharacteristicsFound(connection.get()); |
685 NotifySessionStarted(connection.get()); | 681 NotifySessionStarted(connection.get()); |
686 ResponseSignalReceived(connection.get()); | 682 ResponseSignalReceived(connection.get()); |
687 } | 683 } |
688 | 684 |
689 } // namespace proximity_auth | 685 } // namespace proximity_auth |
OLD | NEW |