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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // Starting discovery. | 359 // Starting discovery. |
360 FindAndExpectStartDiscovery(connection_finder); | 360 FindAndExpectStartDiscovery(connection_finder); |
361 ExpectStopDiscoveryAndRemoveObserver(); | 361 ExpectStopDiscoveryAndRemoveObserver(); |
362 | 362 |
363 // Finding and creating a connection to the right device. | 363 // Finding and creating a connection to the right device. |
364 MockConnection* connection = connection_finder.ExpectCreateConnection(); | 364 MockConnection* connection = connection_finder.ExpectCreateConnection(); |
365 PrepareForNewRightDevice(kServiceUUID); | 365 PrepareForNewRightDevice(kServiceUUID); |
366 connection_finder.DeviceAdded(adapter_.get(), device_.get()); | 366 connection_finder.DeviceAdded(adapter_.get(), device_.get()); |
367 | 367 |
368 // Creating a connection. | 368 // Creating a connection. |
| 369 base::RunLoop run_loop; |
369 EXPECT_FALSE(last_found_connection_); | 370 EXPECT_FALSE(last_found_connection_); |
370 connection->SetStatus(Connection::IN_PROGRESS); | 371 connection->SetStatus(Connection::IN_PROGRESS); |
371 connection->SetStatus(Connection::CONNECTED); | 372 connection->SetStatus(Connection::CONNECTED); |
| 373 run_loop.RunUntilIdle(); |
372 EXPECT_TRUE(last_found_connection_); | 374 EXPECT_TRUE(last_found_connection_); |
373 } | 375 } |
374 | 376 |
375 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, | 377 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, |
376 Find_ConnectionFails_RestartDiscoveryAndConnectionSucceeds) { | 378 Find_ConnectionFails_RestartDiscoveryAndConnectionSucceeds) { |
377 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( | 379 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( |
378 device_whitelist_.get()); | 380 device_whitelist_.get()); |
379 | 381 |
380 // Starting discovery. | 382 // Starting discovery. |
381 FindAndExpectStartDiscovery(connection_finder); | 383 FindAndExpectStartDiscovery(connection_finder); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 419 |
418 // Preparing to create a GATT connection to the right device. | 420 // Preparing to create a GATT connection to the right device. |
419 PrepareForNewRightDevice(kServiceUUID); | 421 PrepareForNewRightDevice(kServiceUUID); |
420 connection = connection_finder.ExpectCreateConnection(); | 422 connection = connection_finder.ExpectCreateConnection(); |
421 | 423 |
422 // Trying to create a connection. | 424 // Trying to create a connection. |
423 connection_finder.DeviceAdded(adapter_.get(), device_.get()); | 425 connection_finder.DeviceAdded(adapter_.get(), device_.get()); |
424 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); | 426 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); |
425 | 427 |
426 // Completing the connection. | 428 // Completing the connection. |
| 429 base::RunLoop run_loop; |
427 EXPECT_FALSE(last_found_connection_); | 430 EXPECT_FALSE(last_found_connection_); |
428 connection->SetStatus(Connection::IN_PROGRESS); | 431 connection->SetStatus(Connection::IN_PROGRESS); |
429 connection->SetStatus(Connection::CONNECTED); | 432 connection->SetStatus(Connection::CONNECTED); |
| 433 run_loop.RunUntilIdle(); |
430 EXPECT_TRUE(last_found_connection_); | 434 EXPECT_TRUE(last_found_connection_); |
431 } | 435 } |
432 | 436 |
433 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, | 437 TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, |
434 Find_AdapterRemoved_RestartDiscoveryAndConnectionSucceeds) { | 438 Find_AdapterRemoved_RestartDiscoveryAndConnectionSucceeds) { |
435 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( | 439 StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( |
436 device_whitelist_.get()); | 440 device_whitelist_.get()); |
437 | 441 |
438 // Starting discovery. | 442 // Starting discovery. |
439 FindAndExpectStartDiscovery(connection_finder); | 443 FindAndExpectStartDiscovery(connection_finder); |
(...skipping 28 matching lines...) Expand all Loading... |
468 | 472 |
469 // Preparing to create a GATT connection to the right device. | 473 // Preparing to create a GATT connection to the right device. |
470 PrepareForNewRightDevice(kServiceUUID); | 474 PrepareForNewRightDevice(kServiceUUID); |
471 MockConnection* connection = connection_finder.ExpectCreateConnection(); | 475 MockConnection* connection = connection_finder.ExpectCreateConnection(); |
472 | 476 |
473 // Trying to create a connection. | 477 // Trying to create a connection. |
474 connection_finder.DeviceAdded(adapter_.get(), device_.get()); | 478 connection_finder.DeviceAdded(adapter_.get(), device_.get()); |
475 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); | 479 EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); |
476 | 480 |
477 // Completing the connection. | 481 // Completing the connection. |
| 482 base::RunLoop run_loop; |
478 ASSERT_FALSE(last_found_connection_); | 483 ASSERT_FALSE(last_found_connection_); |
479 connection->SetStatus(Connection::IN_PROGRESS); | 484 connection->SetStatus(Connection::IN_PROGRESS); |
480 connection->SetStatus(Connection::CONNECTED); | 485 connection->SetStatus(Connection::CONNECTED); |
| 486 run_loop.RunUntilIdle(); |
481 EXPECT_TRUE(last_found_connection_); | 487 EXPECT_TRUE(last_found_connection_); |
482 } | 488 } |
483 | 489 |
484 } // namespace proximity_auth | 490 } // namespace proximity_auth |
OLD | NEW |