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

Side by Side Diff: components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix arc Created 4 years, 4 months 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 "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
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
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;
Jeffrey Yasskin 2016/08/18 16:04:32 I believe you can use BluetoothDevice::UUIDSet
ortuno 2016/08/19 20:50:32 Done.
168 uuids.push_back(device::BluetoothUUID(uuid)); 170 uuids.insert(device::BluetoothUUID(uuid));
169 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); 171 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids));
170 ON_CALL(*device_, GetAddress()).WillByDefault(Return(address)); 172 ON_CALL(*device_, GetAddress()).WillByDefault(Return(address));
171 ON_CALL(*device_, IsPaired()).WillByDefault(Return(paired)); 173 ON_CALL(*device_, IsPaired()).WillByDefault(Return(paired));
172 } 174 }
173 175
174 scoped_refptr<device::MockBluetoothAdapter> adapter_; 176 scoped_refptr<device::MockBluetoothAdapter> adapter_;
175 ConnectionFinder::ConnectionCallback connection_callback_; 177 ConnectionFinder::ConnectionCallback connection_callback_;
176 std::unique_ptr<device::MockBluetoothDevice> device_; 178 std::unique_ptr<device::MockBluetoothDevice> device_;
177 std::unique_ptr<Connection> last_found_connection_; 179 std::unique_ptr<Connection> last_found_connection_;
178 std::unique_ptr<MockBluetoothLowEnergyDeviceWhitelist> device_whitelist_; 180 std::unique_ptr<MockBluetoothLowEnergyDeviceWhitelist> device_whitelist_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 233
232 // TODO(sacomoto): Remove it when ProximityAuthBleSystem is not needed anymore. 234 // TODO(sacomoto): Remove it when ProximityAuthBleSystem is not needed anymore.
233 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, 235 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
234 Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) { 236 Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) {
235 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( 237 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
236 device_whitelist_.get(), 238 device_whitelist_.get(),
237 BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE); 239 BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
238 FindAndExpectStartDiscovery(connection_finder); 240 FindAndExpectStartDiscovery(connection_finder);
239 ExpectRemoveObserver(); 241 ExpectRemoveObserver();
240 242
241 std::vector<device::BluetoothUUID> uuids; 243 BluetoothDevice::UUIDSet uuids;
242 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids)); 244 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids));
243 ON_CALL(*device_, IsPaired()).WillByDefault(Return(true)); 245 ON_CALL(*device_, IsPaired()).WillByDefault(Return(true));
244 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_)) 246 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_))
245 .WillByDefault(Return(true)); 247 .WillByDefault(Return(true));
246 248
247 connection_finder.ExpectCreateConnection(); 249 connection_finder.ExpectCreateConnection();
248 connection_finder.DeviceAdded(adapter_.get(), device_.get()); 250 connection_finder.DeviceAdded(adapter_.get(), device_.get());
249 } 251 }
250 252
251 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, 253 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 FindAndExpectStartDiscovery(connection_finder); 339 FindAndExpectStartDiscovery(connection_finder);
338 ExpectRemoveObserver(); 340 ExpectRemoveObserver();
339 341
340 // Prepare to add |device_|. 342 // Prepare to add |device_|.
341 PrepareDevice(kServiceUUID, kTestRemoteDeviceBluetoothAddress, true); 343 PrepareDevice(kServiceUUID, kTestRemoteDeviceBluetoothAddress, true);
342 344
343 // Prepare to add |other_device|. 345 // Prepare to add |other_device|.
344 NiceMock<device::MockBluetoothDevice> other_device( 346 NiceMock<device::MockBluetoothDevice> other_device(
345 adapter_.get(), 0, kTestRemoteDeviceName, 347 adapter_.get(), 0, kTestRemoteDeviceName,
346 kTestRemoteDeviceBluetoothAddress, false, false); 348 kTestRemoteDeviceBluetoothAddress, false, false);
347 std::vector<device::BluetoothUUID> uuids; 349 BluetoothDevice::UUIDSet uuids;
348 uuids.push_back(device::BluetoothUUID(kServiceUUID)); 350 uuids.insert(device::BluetoothUUID(kServiceUUID));
349 ON_CALL(other_device, GetAddress()) 351 ON_CALL(other_device, GetAddress())
350 .WillByDefault(Return(kTestRemoteDeviceBluetoothAddress)); 352 .WillByDefault(Return(kTestRemoteDeviceBluetoothAddress));
351 ON_CALL(other_device, IsPaired()).WillByDefault(Return(true)); 353 ON_CALL(other_device, IsPaired()).WillByDefault(Return(true));
352 ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids))); 354 ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids)));
353 355
354 // Only one connection should be created. 356 // Only one connection should be created.
355 connection_finder.ExpectCreateConnection(); 357 connection_finder.ExpectCreateConnection();
356 358
357 // Add the devices. 359 // Add the devices.
358 connection_finder.DeviceAdded(adapter_.get(), device_.get()); 360 connection_finder.DeviceAdded(adapter_.get(), device_.get());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Completing the connection. 487 // Completing the connection.
486 base::RunLoop run_loop; 488 base::RunLoop run_loop;
487 ASSERT_FALSE(last_found_connection_); 489 ASSERT_FALSE(last_found_connection_);
488 connection->SetStatus(Connection::IN_PROGRESS); 490 connection->SetStatus(Connection::IN_PROGRESS);
489 connection->SetStatus(Connection::CONNECTED); 491 connection->SetStatus(Connection::CONNECTED);
490 run_loop.RunUntilIdle(); 492 run_loop.RunUntilIdle();
491 EXPECT_TRUE(last_found_connection_); 493 EXPECT_TRUE(last_found_connection_);
492 } 494 }
493 495
494 } // namespace proximity_auth 496 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698