| 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_finder.h
" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using testing::_; | 33 using testing::_; |
| 34 using testing::AtLeast; | 34 using testing::AtLeast; |
| 35 using testing::NiceMock; | 35 using testing::NiceMock; |
| 36 using testing::Return; | 36 using testing::Return; |
| 37 using testing::StrictMock; | 37 using testing::StrictMock; |
| 38 using testing::SaveArg; | 38 using testing::SaveArg; |
| 39 | 39 |
| 40 using device::BluetoothDevice; |
| 41 |
| 40 namespace proximity_auth { | 42 namespace proximity_auth { |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF"; | 45 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF"; |
| 44 const char kOtherUUID[] = "AAAAAAAA-AAAA-AAAA-AAAA-D15EA5EBEEEF"; | 46 const char kOtherUUID[] = "AAAAAAAA-AAAA-AAAA-AAAA-D15EA5EBEEEF"; |
| 45 | 47 |
| 46 const int kMaxNumberOfAttempts = 2; | 48 const int kMaxNumberOfAttempts = 2; |
| 47 | 49 |
| 48 class MockBluetoothLowEnergyDeviceWhitelist | 50 class MockBluetoothLowEnergyDeviceWhitelist |
| 49 : public BluetoothLowEnergyDeviceWhitelist { | 51 : public BluetoothLowEnergyDeviceWhitelist { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 159 } |
| 158 | 160 |
| 159 void ExpectRemoveObserver() { | 161 void ExpectRemoveObserver() { |
| 160 EXPECT_CALL(*adapter_, RemoveObserver(_)).Times(AtLeast(1)); | 162 EXPECT_CALL(*adapter_, RemoveObserver(_)).Times(AtLeast(1)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 // Prepare |device_| with |uuid|. | 165 // Prepare |device_| with |uuid|. |
| 164 void PrepareDevice(const std::string& uuid, | 166 void PrepareDevice(const std::string& uuid, |
| 165 const std::string& address, | 167 const std::string& address, |
| 166 bool paired) { | 168 bool paired) { |
| 167 std::vector<device::BluetoothUUID> uuids; | 169 BluetoothDevice::UUIDSet uuids = {device::BluetoothUUID(uuid)}; |
| 168 uuids.push_back(device::BluetoothUUID(uuid)); | |
| 169 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); | 170 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); |
| 170 ON_CALL(*device_, GetAddress()).WillByDefault(Return(address)); | 171 ON_CALL(*device_, GetAddress()).WillByDefault(Return(address)); |
| 171 ON_CALL(*device_, IsPaired()).WillByDefault(Return(paired)); | 172 ON_CALL(*device_, IsPaired()).WillByDefault(Return(paired)); |
| 172 } | 173 } |
| 173 | 174 |
| 174 scoped_refptr<device::MockBluetoothAdapter> adapter_; | 175 scoped_refptr<device::MockBluetoothAdapter> adapter_; |
| 175 ConnectionFinder::ConnectionCallback connection_callback_; | 176 ConnectionFinder::ConnectionCallback connection_callback_; |
| 176 std::unique_ptr<device::MockBluetoothDevice> device_; | 177 std::unique_ptr<device::MockBluetoothDevice> device_; |
| 177 std::unique_ptr<Connection> last_found_connection_; | 178 std::unique_ptr<Connection> last_found_connection_; |
| 178 std::unique_ptr<MockBluetoothLowEnergyDeviceWhitelist> device_whitelist_; | 179 std::unique_ptr<MockBluetoothLowEnergyDeviceWhitelist> device_whitelist_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 232 |
| 232 // TODO(sacomoto): Remove it when ProximityAuthBleSystem is not needed anymore. | 233 // TODO(sacomoto): Remove it when ProximityAuthBleSystem is not needed anymore. |
| 233 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, | 234 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, |
| 234 Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) { | 235 Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) { |
| 235 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( | 236 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( |
| 236 device_whitelist_.get(), | 237 device_whitelist_.get(), |
| 237 BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE); | 238 BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE); |
| 238 FindAndExpectStartDiscovery(connection_finder); | 239 FindAndExpectStartDiscovery(connection_finder); |
| 239 ExpectRemoveObserver(); | 240 ExpectRemoveObserver(); |
| 240 | 241 |
| 241 std::vector<device::BluetoothUUID> uuids; | 242 BluetoothDevice::UUIDSet uuids; |
| 242 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); | 243 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); |
| 243 ON_CALL(*device_, IsPaired()).WillByDefault(Return(true)); | 244 ON_CALL(*device_, IsPaired()).WillByDefault(Return(true)); |
| 244 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_)) | 245 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_)) |
| 245 .WillByDefault(Return(true)); | 246 .WillByDefault(Return(true)); |
| 246 | 247 |
| 247 connection_finder.ExpectCreateConnection(); | 248 connection_finder.ExpectCreateConnection(); |
| 248 connection_finder.DeviceAdded(adapter_.get(), device_.get()); | 249 connection_finder.DeviceAdded(adapter_.get(), device_.get()); |
| 249 } | 250 } |
| 250 | 251 |
| 251 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, | 252 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 FindAndExpectStartDiscovery(connection_finder); | 338 FindAndExpectStartDiscovery(connection_finder); |
| 338 ExpectRemoveObserver(); | 339 ExpectRemoveObserver(); |
| 339 | 340 |
| 340 // Prepare to add |device_|. | 341 // Prepare to add |device_|. |
| 341 PrepareDevice(kServiceUUID, kTestRemoteDeviceBluetoothAddress, true); | 342 PrepareDevice(kServiceUUID, kTestRemoteDeviceBluetoothAddress, true); |
| 342 | 343 |
| 343 // Prepare to add |other_device|. | 344 // Prepare to add |other_device|. |
| 344 NiceMock<device::MockBluetoothDevice> other_device( | 345 NiceMock<device::MockBluetoothDevice> other_device( |
| 345 adapter_.get(), 0, kTestRemoteDeviceName, | 346 adapter_.get(), 0, kTestRemoteDeviceName, |
| 346 kTestRemoteDeviceBluetoothAddress, false, false); | 347 kTestRemoteDeviceBluetoothAddress, false, false); |
| 347 std::vector<device::BluetoothUUID> uuids; | 348 BluetoothDevice::UUIDSet uuids = {device::BluetoothUUID(kServiceUUID)}; |
| 348 uuids.push_back(device::BluetoothUUID(kServiceUUID)); | |
| 349 ON_CALL(other_device, GetAddress()) | 349 ON_CALL(other_device, GetAddress()) |
| 350 .WillByDefault(Return(kTestRemoteDeviceBluetoothAddress)); | 350 .WillByDefault(Return(kTestRemoteDeviceBluetoothAddress)); |
| 351 ON_CALL(other_device, IsPaired()).WillByDefault(Return(true)); | 351 ON_CALL(other_device, IsPaired()).WillByDefault(Return(true)); |
| 352 ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids))); | 352 ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids))); |
| 353 | 353 |
| 354 // Only one connection should be created. | 354 // Only one connection should be created. |
| 355 connection_finder.ExpectCreateConnection(); | 355 connection_finder.ExpectCreateConnection(); |
| 356 | 356 |
| 357 // Add the devices. | 357 // Add the devices. |
| 358 connection_finder.DeviceAdded(adapter_.get(), device_.get()); | 358 connection_finder.DeviceAdded(adapter_.get(), device_.get()); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // Completing the connection. | 485 // Completing the connection. |
| 486 base::RunLoop run_loop; | 486 base::RunLoop run_loop; |
| 487 ASSERT_FALSE(last_found_connection_); | 487 ASSERT_FALSE(last_found_connection_); |
| 488 connection->SetStatus(Connection::IN_PROGRESS); | 488 connection->SetStatus(Connection::IN_PROGRESS); |
| 489 connection->SetStatus(Connection::CONNECTED); | 489 connection->SetStatus(Connection::CONNECTED); |
| 490 run_loop.RunUntilIdle(); | 490 run_loop.RunUntilIdle(); |
| 491 EXPECT_TRUE(last_found_connection_); | 491 EXPECT_TRUE(last_found_connection_); |
| 492 } | 492 } |
| 493 | 493 |
| 494 } // namespace proximity_auth | 494 } // namespace proximity_auth |
| OLD | NEW |