Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / proximity_auth / ble / bluetooth_low_energy_connection_finder_unittest.cc
blob1f48015eae499f81da95d475766d7f733c16c216
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
3 // found in the LICENSE file.
5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h"
16 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
17 #include "components/proximity_auth/connection.h"
18 #include "components/proximity_auth/remote_device.h"
19 #include "components/proximity_auth/wire_message.h"
20 #include "device/bluetooth/bluetooth_adapter_factory.h"
21 #include "device/bluetooth/bluetooth_uuid.h"
22 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
23 #include "device/bluetooth/test/mock_bluetooth_device.h"
24 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
25 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h"
29 using testing::_;
30 using testing::AtLeast;
31 using testing::NiceMock;
32 using testing::Return;
33 using testing::StrictMock;
34 using testing::SaveArg;
36 namespace proximity_auth {
37 namespace {
39 const char kDeviceName[] = "Device name";
40 const char kPublicKey[] = "Public key";
41 const char kBluetoothAddress[] = "11:22:33:44:55:66";
42 const char kPersistentSymmetricKey[] = "PSK";
44 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF";
45 const char kOtherUUID[] = "AAAAAAAA-AAAA-AAAA-AAAA-D15EA5EBEEEF";
47 const int kMaxNumberOfAttempts = 2;
49 RemoteDevice CreateRemoteDevice() {
50 return RemoteDevice(kDeviceName, kPublicKey, kBluetoothAddress,
51 kPersistentSymmetricKey);
54 class MockConnection : public Connection {
55 public:
56 MockConnection() : Connection(CreateRemoteDevice()) {}
57 ~MockConnection() override {}
59 MOCK_METHOD0(Connect, void());
61 using Connection::SetStatus;
63 private:
64 void Disconnect() override {}
65 void SendMessageImpl(scoped_ptr<WireMessage> message) override {}
67 DISALLOW_COPY_AND_ASSIGN(MockConnection);
70 class MockBluetoothLowEnergyDeviceWhitelist
71 : public BluetoothLowEnergyDeviceWhitelist {
72 public:
73 MockBluetoothLowEnergyDeviceWhitelist()
74 : BluetoothLowEnergyDeviceWhitelist(nullptr) {}
75 ~MockBluetoothLowEnergyDeviceWhitelist() override {}
77 MOCK_CONST_METHOD1(HasDeviceWithAddress, bool(const std::string&));
80 class MockBluetoothLowEnergyConnectionFinder
81 : public BluetoothLowEnergyConnectionFinder {
82 public:
83 MockBluetoothLowEnergyConnectionFinder(
84 const BluetoothLowEnergyDeviceWhitelist* device_whitelist,
85 FinderStrategy finder_strategy)
86 : BluetoothLowEnergyConnectionFinder(CreateRemoteDevice(),
87 kServiceUUID,
88 finder_strategy,
89 device_whitelist,
90 nullptr,
91 kMaxNumberOfAttempts) {}
93 ~MockBluetoothLowEnergyConnectionFinder() override {}
95 // Mock methods don't support return type scoped_ptr<>. This is a possible
96 // workaround: mock a proxy method to be called by the target overrided method
97 // (CreateConnection).
98 MOCK_METHOD0(CreateConnectionProxy, Connection*());
100 // Creates a mock connection and sets an expectation that the mock connection
101 // finder's CreateConnection() method will be called and will return the
102 // created connection. Returns a reference to the created connection.
103 // NOTE: The returned connection's lifetime is managed by the connection
104 // finder.
105 MockConnection* ExpectCreateConnection() {
106 scoped_ptr<MockConnection> connection(new NiceMock<MockConnection>());
107 MockConnection* connection_alias = connection.get();
108 EXPECT_CALL(*this, CreateConnectionProxy())
109 .WillOnce(Return(connection.release()));
110 return connection_alias;
113 MOCK_METHOD0(CloseGattConnectionProxy, void(void));
115 protected:
116 scoped_ptr<Connection> CreateConnection(
117 const std::string& device_address) override {
118 return make_scoped_ptr(CreateConnectionProxy());
121 private:
122 DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnectionFinder);
125 } // namespace
127 class ProximityAuthBluetoothLowEnergyConnectionFinderTest
128 : public testing::Test {
129 protected:
130 ProximityAuthBluetoothLowEnergyConnectionFinderTest()
131 : adapter_(new NiceMock<device::MockBluetoothAdapter>),
132 connection_callback_(
133 base::Bind(&ProximityAuthBluetoothLowEnergyConnectionFinderTest::
134 OnConnectionFound,
135 base::Unretained(this))),
136 device_(new NiceMock<device::MockBluetoothDevice>(adapter_.get(),
138 kDeviceName,
139 kBluetoothAddress,
140 false,
141 false)),
142 device_whitelist_(new MockBluetoothLowEnergyDeviceWhitelist()),
143 last_discovery_session_alias_(nullptr) {
144 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_);
146 std::vector<const device::BluetoothDevice*> devices;
147 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices));
149 ON_CALL(*adapter_, IsPresent()).WillByDefault(Return(true));
150 ON_CALL(*adapter_, IsPowered()).WillByDefault(Return(true));
152 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_))
153 .WillByDefault(Return(false));
156 void OnConnectionFound(scoped_ptr<Connection> connection) {
157 last_found_connection_ = connection.Pass();
160 void FindAndExpectStartDiscovery(
161 BluetoothLowEnergyConnectionFinder& connection_finder) {
162 device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
163 scoped_ptr<device::MockBluetoothDiscoverySession> discovery_session(
164 new NiceMock<device::MockBluetoothDiscoverySession>());
165 last_discovery_session_alias_ = discovery_session.get();
167 // Starting a discovery session. StartDiscoveryWithFilterRaw is a proxy for
168 // StartDiscoveryWithFilter.
169 EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _))
170 .WillOnce(SaveArg<1>(&discovery_callback));
171 EXPECT_CALL(*adapter_, AddObserver(_));
172 ON_CALL(*last_discovery_session_alias_, IsActive())
173 .WillByDefault(Return(true));
174 connection_finder.Find(connection_callback_);
175 ASSERT_FALSE(discovery_callback.is_null());
176 discovery_callback.Run(discovery_session.Pass());
179 void ExpectStopDiscoveryAndRemoveObserver() {
180 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1));
181 EXPECT_CALL(*adapter_, RemoveObserver(_)).Times(AtLeast(1));
184 // Prepare |device_| with |uuid|.
185 void PrepareDevice(const std::string& uuid,
186 const std::string& address,
187 bool paired) {
188 std::vector<device::BluetoothUUID> uuids;
189 uuids.push_back(device::BluetoothUUID(uuid));
190 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids));
191 ON_CALL(*device_, GetAddress()).WillByDefault(Return(address));
192 ON_CALL(*device_, IsPaired()).WillByDefault(Return(paired));
195 scoped_refptr<device::MockBluetoothAdapter> adapter_;
196 ConnectionFinder::ConnectionCallback connection_callback_;
197 scoped_ptr<device::MockBluetoothDevice> device_;
198 scoped_ptr<Connection> last_found_connection_;
199 scoped_ptr<MockBluetoothLowEnergyDeviceWhitelist> device_whitelist_;
200 device::MockBluetoothDiscoverySession* last_discovery_session_alias_;
202 private:
203 base::MessageLoop message_loop_;
206 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
207 ConstructAndDestroyDoesntCrash) {
208 // Destroying a BluetoothConnectionFinder for which Find() has not been called
209 // should not crash.
210 BluetoothLowEnergyConnectionFinder connection_finder(
211 CreateRemoteDevice(), kServiceUUID,
212 BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE,
213 device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
216 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
217 Find_StartsDiscoverySession) {
218 BluetoothLowEnergyConnectionFinder connection_finder(
219 CreateRemoteDevice(), kServiceUUID,
220 BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE,
221 device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
223 EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _));
224 EXPECT_CALL(*adapter_, AddObserver(_));
225 connection_finder.Find(connection_callback_);
228 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
229 Find_StopsDiscoverySessionBeforeDestroying) {
230 BluetoothLowEnergyConnectionFinder connection_finder(
231 CreateRemoteDevice(), kServiceUUID,
232 BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE,
233 device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
235 device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
236 scoped_ptr<device::MockBluetoothDiscoverySession> discovery_session(
237 new NiceMock<device::MockBluetoothDiscoverySession>());
238 device::MockBluetoothDiscoverySession* discovery_session_alias =
239 discovery_session.get();
241 EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _))
242 .WillOnce(SaveArg<1>(&discovery_callback));
243 ON_CALL(*discovery_session_alias, IsActive()).WillByDefault(Return(true));
244 EXPECT_CALL(*adapter_, AddObserver(_));
245 connection_finder.Find(connection_callback_);
247 EXPECT_CALL(*discovery_session_alias, Stop(_, _));
248 ASSERT_FALSE(discovery_callback.is_null());
249 discovery_callback.Run(discovery_session.Pass());
251 EXPECT_CALL(*adapter_, RemoveObserver(_));
254 // TODO(sacomoto): Remove it when ProximityAuthBleSystem is not needed anymore.
255 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
256 Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) {
257 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
258 device_whitelist_.get(),
259 BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
260 FindAndExpectStartDiscovery(connection_finder);
261 ExpectStopDiscoveryAndRemoveObserver();
263 std::vector<device::BluetoothUUID> uuids;
264 ON_CALL(*device_, GetUUIDs()).WillByDefault(Return(uuids));
265 ON_CALL(*device_, IsPaired()).WillByDefault(Return(true));
266 ON_CALL(*device_whitelist_, HasDeviceWithAddress(_))
267 .WillByDefault(Return(true));
269 connection_finder.ExpectCreateConnection();
270 connection_finder.DeviceAdded(adapter_.get(), device_.get());
273 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
274 Find_CreatesConnectionWhenRightDeviceIsAdded_NoPublicAddress) {
275 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
276 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
278 FindAndExpectStartDiscovery(connection_finder);
279 ExpectStopDiscoveryAndRemoveObserver();
281 PrepareDevice(kServiceUUID, kBluetoothAddress, false);
282 ON_CALL(*device_, GetName())
283 .WillByDefault(Return(base::UTF8ToUTF16(kDeviceName)));
285 connection_finder.ExpectCreateConnection();
286 connection_finder.DeviceAdded(adapter_.get(), device_.get());
289 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
290 Find_DoesntCreatesConnectionWhenWrongDeviceIsAdded_NoPublicAddress) {
291 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
292 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
294 FindAndExpectStartDiscovery(connection_finder);
295 ExpectStopDiscoveryAndRemoveObserver();
297 PrepareDevice(kOtherUUID, kBluetoothAddress, false);
298 ON_CALL(*device_, GetName())
299 .WillByDefault(Return(base::UTF8ToUTF16("Other name")));
301 EXPECT_CALL(connection_finder, CreateConnectionProxy()).Times(0);
302 connection_finder.DeviceAdded(adapter_.get(), device_.get());
305 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
306 Find_CreatesConnectionWhenRightDeviceIsAdded_HasPublicAddress) {
307 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
308 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
310 FindAndExpectStartDiscovery(connection_finder);
311 ExpectStopDiscoveryAndRemoveObserver();
313 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
314 connection_finder.ExpectCreateConnection();
315 connection_finder.DeviceAdded(adapter_.get(), device_.get());
318 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
319 Find_DoesntCreateConnectionWhenWrongDeviceIsAdded_HasPublicAddress) {
320 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
321 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
322 FindAndExpectStartDiscovery(connection_finder);
323 ExpectStopDiscoveryAndRemoveObserver();
325 PrepareDevice(kOtherUUID, "", true);
326 EXPECT_CALL(connection_finder, CreateConnectionProxy()).Times(0);
327 connection_finder.DeviceAdded(adapter_.get(), device_.get());
330 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
331 Find_CreatesConnectionWhenRightDeviceIsChanged_HasPublicAddress) {
332 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
333 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
335 FindAndExpectStartDiscovery(connection_finder);
336 ExpectStopDiscoveryAndRemoveObserver();
338 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
339 connection_finder.ExpectCreateConnection();
340 connection_finder.DeviceChanged(adapter_.get(), device_.get());
343 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
344 Find_DoesntCreateConnectionWhenWrongDeviceIsChanged_HasPublicAddress) {
345 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
346 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
348 FindAndExpectStartDiscovery(connection_finder);
349 ExpectStopDiscoveryAndRemoveObserver();
351 PrepareDevice(kOtherUUID, "", true);
352 EXPECT_CALL(connection_finder, CreateConnectionProxy()).Times(0);
353 connection_finder.DeviceChanged(adapter_.get(), device_.get());
356 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
357 Find_CreatesOnlyOneConnection) {
358 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
359 nullptr, BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE);
360 FindAndExpectStartDiscovery(connection_finder);
361 ExpectStopDiscoveryAndRemoveObserver();
363 // Prepare to add |device_|.
364 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
366 // Prepare to add |other_device|.
367 NiceMock<device::MockBluetoothDevice> other_device(
368 adapter_.get(), 0, kDeviceName, kBluetoothAddress, false, false);
369 std::vector<device::BluetoothUUID> uuids;
370 uuids.push_back(device::BluetoothUUID(kServiceUUID));
371 ON_CALL(other_device, GetAddress()).WillByDefault(Return(kBluetoothAddress));
372 ON_CALL(other_device, IsPaired()).WillByDefault(Return(true));
373 ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids)));
375 // Only one connection should be created.
376 connection_finder.ExpectCreateConnection();
378 // Add the devices.
379 connection_finder.DeviceAdded(adapter_.get(), device_.get());
380 connection_finder.DeviceAdded(adapter_.get(), &other_device);
383 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
384 Find_ConnectionSucceeds_WithRemoteDevice) {
385 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
386 nullptr, BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE);
387 // Starting discovery.
388 FindAndExpectStartDiscovery(connection_finder);
389 ExpectStopDiscoveryAndRemoveObserver();
391 // Finding and creating a connection to the right device.
392 MockConnection* connection = connection_finder.ExpectCreateConnection();
393 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
394 connection_finder.DeviceAdded(adapter_.get(), device_.get());
396 // Creating a connection.
397 base::RunLoop run_loop;
398 EXPECT_FALSE(last_found_connection_);
399 connection->SetStatus(Connection::IN_PROGRESS);
400 connection->SetStatus(Connection::CONNECTED);
401 run_loop.RunUntilIdle();
402 EXPECT_TRUE(last_found_connection_);
405 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
406 Find_ConnectionFails_RestartDiscoveryAndConnectionSucceeds) {
407 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
408 nullptr, BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE);
410 // Starting discovery.
411 FindAndExpectStartDiscovery(connection_finder);
412 base::Closure stop_discovery_session_callback;
413 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _))
414 .WillOnce(SaveArg<0>(&stop_discovery_session_callback));
416 // Preparing to create a GATT connection to the right device.
417 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
418 MockConnection* connection = connection_finder.ExpectCreateConnection();
420 // Trying to create a connection.
421 connection_finder.DeviceAdded(adapter_.get(), device_.get());
422 ASSERT_FALSE(last_found_connection_);
423 connection->SetStatus(Connection::IN_PROGRESS);
425 // Stopping the discovery session.
426 ASSERT_FALSE(stop_discovery_session_callback.is_null());
427 stop_discovery_session_callback.Run();
429 // Preparing to restart the discovery session.
430 device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
431 std::vector<const device::BluetoothDevice*> devices;
432 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices));
433 EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _))
434 .WillOnce(SaveArg<1>(&discovery_callback));
436 // Connection fails.
437 connection->SetStatus(Connection::DISCONNECTED);
439 // Restarting the discovery session.
440 scoped_ptr<device::MockBluetoothDiscoverySession> discovery_session(
441 new NiceMock<device::MockBluetoothDiscoverySession>());
442 last_discovery_session_alias_ = discovery_session.get();
443 ON_CALL(*last_discovery_session_alias_, IsActive())
444 .WillByDefault(Return(true));
445 ASSERT_FALSE(discovery_callback.is_null());
446 discovery_callback.Run(discovery_session.Pass());
448 // Preparing to create a GATT connection to the right device.
449 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
450 connection = connection_finder.ExpectCreateConnection();
452 // Trying to create a connection.
453 connection_finder.DeviceAdded(adapter_.get(), device_.get());
454 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1));
456 // Completing the connection.
457 base::RunLoop run_loop;
458 EXPECT_FALSE(last_found_connection_);
459 connection->SetStatus(Connection::IN_PROGRESS);
460 connection->SetStatus(Connection::CONNECTED);
461 run_loop.RunUntilIdle();
462 EXPECT_TRUE(last_found_connection_);
465 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
466 Find_AdapterRemoved_RestartDiscoveryAndConnectionSucceeds) {
467 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder(
468 nullptr, BluetoothLowEnergyConnectionFinder::FIND_PAIRED_DEVICE);
470 // Starting discovery.
471 FindAndExpectStartDiscovery(connection_finder);
473 // Removing the adapter.
474 ON_CALL(*adapter_, IsPresent()).WillByDefault(Return(false));
475 ON_CALL(*adapter_, IsPowered()).WillByDefault(Return(false));
476 ON_CALL(*last_discovery_session_alias_, IsActive())
477 .WillByDefault(Return(false));
478 connection_finder.AdapterPoweredChanged(adapter_.get(), false);
479 connection_finder.AdapterPresentChanged(adapter_.get(), false);
481 // Adding the adapter.
482 ON_CALL(*adapter_, IsPresent()).WillByDefault(Return(true));
483 ON_CALL(*adapter_, IsPowered()).WillByDefault(Return(true));
485 device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
486 scoped_ptr<device::MockBluetoothDiscoverySession> discovery_session(
487 new NiceMock<device::MockBluetoothDiscoverySession>());
488 last_discovery_session_alias_ = discovery_session.get();
490 // Restarting the discovery session.
491 EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _))
492 .WillOnce(SaveArg<1>(&discovery_callback));
493 connection_finder.AdapterPresentChanged(adapter_.get(), true);
494 connection_finder.AdapterPoweredChanged(adapter_.get(), true);
495 ON_CALL(*last_discovery_session_alias_, IsActive())
496 .WillByDefault(Return(true));
498 ASSERT_FALSE(discovery_callback.is_null());
499 discovery_callback.Run(discovery_session.Pass());
501 // Preparing to create a GATT connection to the right device.
502 PrepareDevice(kServiceUUID, kBluetoothAddress, true);
503 MockConnection* connection = connection_finder.ExpectCreateConnection();
505 // Trying to create a connection.
506 connection_finder.DeviceAdded(adapter_.get(), device_.get());
507 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1));
509 // Completing the connection.
510 base::RunLoop run_loop;
511 ASSERT_FALSE(last_found_connection_);
512 connection->SetStatus(Connection::IN_PROGRESS);
513 connection->SetStatus(Connection::CONNECTED);
514 run_loop.RunUntilIdle();
515 EXPECT_TRUE(last_found_connection_);
518 } // namespace proximity_auth