diff options
author | sacomoto <sacomoto@chromium.org> | 2015-07-30 07:04:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-30 14:05:12 +0000 |
commit | 7f538d6ea1c991f14d1a53fcbc7448f123c3edf7 (patch) | |
tree | 4ffd9524703d8fc218f6a98c387b1fce260ed5dd /components/proximity_auth | |
parent | 7cdc93ca18e82e9f3849edccbc2ac11856b5a3b5 (diff) | |
download | chromium_src-7f538d6ea1c991f14d1a53fcbc7448f123c3edf7.zip chromium_src-7f538d6ea1c991f14d1a53fcbc7448f123c3edf7.tar.gz chromium_src-7f538d6ea1c991f14d1a53fcbc7448f123c3edf7.tar.bz2 |
Refactoring BLE connection finder.
- Removes all code related to the creation of a GATT connection from
BLE connection finder.
- Removes |pending_connections_| from BLE connection finder, as no
GATT connection is created.
- Removes from BLE connection the code path that starts when it
receives a GATT connection.
- Moves the workaround for crbug.com/498850 from BLE connection
finder to BLE connection.
BUG=514626
Review URL: https://codereview.chromium.org/1261493004
Cr-Commit-Position: refs/heads/master@{#341111}
Diffstat (limited to 'components/proximity_auth')
6 files changed, 138 insertions, 348 deletions
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc index a788fa2..e0eba83 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc @@ -5,8 +5,10 @@ #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" #include "base/bind.h" +#include "base/location.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" +#include "base/thread_task_runner_handle.h" #include "base/time/time.h" #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h" #include "components/proximity_auth/ble/fake_wire_message.h" @@ -38,6 +40,11 @@ const int kFirstByteZero = 0; // request. const int kMaxChunkSize = 100; +// This delay is necessary as a workaroud for crbug.com/507325. Reading/writing +// characteristics immediatelly after the connection is complete fails with +// GATT_ERROR_FAILED. +const int kDelayAfterGattConnectionMilliseconds = 1000; + } // namespace BluetoothLowEnergyConnection::BluetoothLowEnergyConnection( @@ -46,24 +53,23 @@ BluetoothLowEnergyConnection::BluetoothLowEnergyConnection( const BluetoothUUID remote_service_uuid, const BluetoothUUID to_peripheral_char_uuid, const BluetoothUUID from_peripheral_char_uuid, - scoped_ptr<BluetoothGattConnection> gatt_connection, int max_number_of_write_attempts) : Connection(device), adapter_(adapter), remote_service_({remote_service_uuid, ""}), to_peripheral_char_({to_peripheral_char_uuid, ""}), from_peripheral_char_({from_peripheral_char_uuid, ""}), - gatt_connection_(gatt_connection.Pass()), sub_status_(SubStatus::DISCONNECTED), receiving_bytes_(false), write_remote_characteristic_pending_(false), max_number_of_write_attempts_(max_number_of_write_attempts), max_chunk_size_(kMaxChunkSize), + delay_after_gatt_connection_(base::TimeDelta::FromMilliseconds( + kDelayAfterGattConnectionMilliseconds)), weak_ptr_factory_(this) { DCHECK(adapter_); DCHECK(adapter_->IsInitialized()); - start_time_ = base::TimeTicks::Now(); adapter_->AddObserver(this); } @@ -76,13 +82,13 @@ BluetoothLowEnergyConnection::~BluetoothLowEnergyConnection() { } void BluetoothLowEnergyConnection::Connect() { - if (gatt_connection_ && gatt_connection_->IsConnected()) { - OnGattConnectionCreated(gatt_connection_.Pass()); - return; - } + DCHECK(sub_status() == SubStatus::DISCONNECTED); + start_time_ = base::TimeTicks::Now(); BluetoothDevice* remote_device = GetRemoteDevice(); if (remote_device) { + PA_LOG(INFO) << "Creating GATT connection with " + << remote_device->GetAddress(); SetSubStatus(SubStatus::WAITING_GATT_CONNECTION); remote_device->CreateGattConnection( base::Bind(&BluetoothLowEnergyConnection::OnGattConnectionCreated, @@ -93,7 +99,7 @@ void BluetoothLowEnergyConnection::Connect() { } void BluetoothLowEnergyConnection::Disconnect() { - if (sub_status_ != SubStatus::DISCONNECTED) { + if (sub_status() != SubStatus::DISCONNECTED) { ClearWriteRequestsQueue(); StopNotifySession(); characteristic_finder_.reset(); @@ -125,6 +131,10 @@ void BluetoothLowEnergyConnection::SetSubStatus(SubStatus new_sub_status) { } } +void BluetoothLowEnergyConnection::SetDelayForTesting(base::TimeDelta delay) { + delay_after_gatt_connection_ = delay; +} + void BluetoothLowEnergyConnection::SendMessageImpl( scoped_ptr<WireMessage> message) { PA_LOG(INFO) << "Sending message " << message->Serialize(); @@ -161,13 +171,15 @@ void BluetoothLowEnergyConnection::SendMessageImpl( // Changes in the GATT connection with the remote device should be observed // here. If the GATT connection is dropped, we should call Disconnect() anyway, -// so the object can notify its observers put itself in the right state. +// so the object can notify its observers. void BluetoothLowEnergyConnection::DeviceChanged(BluetoothAdapter* adapter, BluetoothDevice* device) { - if (sub_status_ == SubStatus::DISCONNECTED) + DCHECK(device); + if (sub_status() == SubStatus::DISCONNECTED || + device->GetAddress() != GetRemoteDeviceAddress()) return; - if (device && device->GetAddress() == GetRemoteDeviceAddress() && + if (sub_status() != SubStatus::WAITING_GATT_CONNECTION && !device->IsConnected()) { PA_LOG(INFO) << "GATT connection dropped " << GetRemoteDeviceAddress() << "\ndevice connected: " << device->IsConnected() @@ -180,23 +192,23 @@ void BluetoothLowEnergyConnection::DeviceChanged(BluetoothAdapter* adapter, void BluetoothLowEnergyConnection::DeviceRemoved(BluetoothAdapter* adapter, BluetoothDevice* device) { - if (sub_status_ == SubStatus::DISCONNECTED) + DCHECK(device); + if (sub_status_ == SubStatus::DISCONNECTED || + device->GetAddress() != GetRemoteDeviceAddress()) return; - if (device && device->GetAddress() == GetRemoteDeviceAddress()) { - PA_LOG(INFO) << "Device removed " << GetRemoteDeviceAddress(); - Disconnect(); - } + PA_LOG(INFO) << "Device removed " << GetRemoteDeviceAddress(); + Disconnect(); } void BluetoothLowEnergyConnection::GattCharacteristicValueChanged( BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic, const std::vector<uint8>& value) { - if (sub_status_ == SubStatus::DISCONNECTED) - return; - DCHECK_EQ(adapter, adapter_.get()); + if (sub_status() != SubStatus::WAITING_RESPONSE_SIGNAL && + sub_status() != SubStatus::CONNECTED) + return; PA_LOG(INFO) << "Characteristic value changed: " << characteristic->GetUUID().canonical_value(); @@ -270,6 +282,7 @@ void BluetoothLowEnergyConnection::CompleteConnection() { void BluetoothLowEnergyConnection::OnCreateGattConnectionError( device::BluetoothDevice::ConnectErrorCode error_code) { + DCHECK(sub_status_ == SubStatus::WAITING_GATT_CONNECTION); PA_LOG(WARNING) << "Error creating GATT connection to " << remote_device().bluetooth_address << "error code: " << error_code; @@ -278,6 +291,10 @@ void BluetoothLowEnergyConnection::OnCreateGattConnectionError( void BluetoothLowEnergyConnection::OnGattConnectionCreated( scoped_ptr<device::BluetoothGattConnection> gatt_connection) { + DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION); + PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() + << " created."; + gatt_connection_ = gatt_connection.Pass(); SetSubStatus(SubStatus::WAITING_CHARACTERISTICS); characteristic_finder_.reset(CreateCharacteristicsFinder( @@ -302,6 +319,7 @@ void BluetoothLowEnergyConnection::OnCharacteristicsFound( const RemoteAttribute& service, const RemoteAttribute& to_peripheral_char, const RemoteAttribute& from_peripheral_char) { + DCHECK(sub_status() == SubStatus::WAITING_CHARACTERISTICS); remote_service_ = service; to_peripheral_char_ = to_peripheral_char; from_peripheral_char_ = from_peripheral_char; @@ -313,6 +331,7 @@ void BluetoothLowEnergyConnection::OnCharacteristicsFound( void BluetoothLowEnergyConnection::OnCharacteristicsFinderError( const RemoteAttribute& to_peripheral_char, const RemoteAttribute& from_peripheral_char) { + DCHECK(sub_status() == SubStatus::WAITING_CHARACTERISTICS); PA_LOG(WARNING) << "Connection error, missing characteristics for SmartLock " "service.\n" << (to_peripheral_char.id.empty() @@ -353,19 +372,20 @@ void BluetoothLowEnergyConnection::StartNotifySession() { void BluetoothLowEnergyConnection::OnNotifySessionError( BluetoothGattService::GattErrorCode error) { + DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); PA_LOG(WARNING) << "Error starting notification session: " << error; Disconnect(); } void BluetoothLowEnergyConnection::OnNotifySessionStarted( scoped_ptr<BluetoothGattNotifySession> notify_session) { + DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); PA_LOG(INFO) << "Notification session started " << notify_session->GetCharacteristicIdentifier(); SetSubStatus(SubStatus::NOTIFY_SESSION_READY); notify_session_ = notify_session.Pass(); - // Sends an invite to connect signal if ready. SendInviteToConnectSignal(); } @@ -386,7 +406,14 @@ void BluetoothLowEnergyConnection::SendInviteToConnectSignal() { static_cast<uint32>(ControlSignal::kInviteToConnectSignal)), std::vector<uint8>(), false); - WriteRemoteCharacteristic(write_request); + // This is a workaround for crbug.com/498850. Currently, trying to + // write/read characteristics immediatelly after the GATT connection was + // established fails with GATT_ERROR_FAILED. + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, + base::Bind(&BluetoothLowEnergyConnection::WriteRemoteCharacteristic, + weak_ptr_factory_.GetWeakPtr(), write_request), + delay_after_gatt_connection_); } } diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_connection.h index a03ad65..827ea32 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection.h +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.h @@ -65,7 +65,6 @@ class BluetoothLowEnergyConnection : public Connection, enum class SubStatus { DISCONNECTED, WAITING_GATT_CONNECTION, - GATT_CONNECTION_ESTABLISHED, WAITING_CHARACTERISTICS, CHARACTERISTICS_FOUND, WAITING_NOTIFY_SESSION, @@ -85,7 +84,6 @@ class BluetoothLowEnergyConnection : public Connection, const device::BluetoothUUID remote_service_uuid, const device::BluetoothUUID to_peripheral_char_uuid, const device::BluetoothUUID from_peripheral_char_uuid, - scoped_ptr<device::BluetoothGattConnection> gatt_connection, int max_number_of_write_attempts); ~BluetoothLowEnergyConnection() override; @@ -99,6 +97,9 @@ class BluetoothLowEnergyConnection : public Connection, void SetSubStatus(SubStatus status); SubStatus sub_status() { return sub_status_; } + // Sets |delay_after_gatt_connection_| for testing. + void SetDelayForTesting(base::TimeDelta delay); + // Virtual for testing. virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& @@ -288,6 +289,12 @@ class BluetoothLowEnergyConnection : public Connection, // Stores when the instace was created. base::TimeTicks start_time_; + // Delay imposed after a GATT connection is created and before any read/write + // request is sent to the characteristics. This delay is necessary as a + // workaroud for crbug.com/507325. Reading/writing characteristics + // immediatelly after the connection is complete fails with GATT_ERROR_FAILED. + base::TimeDelta delay_after_gatt_connection_; + base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc index 5f9a59e..85d0474 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc @@ -14,7 +14,6 @@ #include "base/thread_task_runner_handle.h" #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h" -#include "components/proximity_auth/connection.h" #include "components/proximity_auth/logging/logging.h" #include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_device.h" @@ -29,7 +28,6 @@ using device::BluetoothDiscoveryFilter; namespace proximity_auth { namespace { const int kMinDiscoveryRSSI = -90; -const int kDelayAfterGattConnectionMilliseconds = 1000; } // namespace BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( @@ -43,10 +41,7 @@ BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( from_peripheral_char_uuid_( device::BluetoothUUID(from_peripheral_char_uuid)), device_whitelist_(device_whitelist), - connected_(false), max_number_of_tries_(max_number_of_tries), - delay_after_gatt_connection_(base::TimeDelta::FromMilliseconds( - kDelayAfterGattConnectionMilliseconds)), weak_ptr_factory_(this) { } @@ -129,36 +124,26 @@ void BluetoothLowEnergyConnectionFinder::DeviceChanged( void BluetoothLowEnergyConnectionFinder::HandleDeviceUpdated( BluetoothDevice* device) { - if (connected_) + // Ensuring only one call to |CreateConnection()| is made. A new |connection_| + // can be created only when the previous one disconnects, triggering a call to + // |OnConnectionStatusChanged|. + if (connection_ || !device->IsPaired()) return; - const auto& i = pending_connections_.find(device); - if (i != pending_connections_.end()) { - PA_LOG(INFO) << "Pending connection to device " << device->GetAddress(); - return; - } - if (device->IsPaired() && - (HasService(device) || - device_whitelist_->HasDeviceWithAddress(device->GetAddress()))) { + + if (HasService(device) || + device_whitelist_->HasDeviceWithAddress(device->GetAddress())) { PA_LOG(INFO) << "Connecting to paired device " << device->GetAddress() << " with service (" << HasService(device) << ") or is whitelisted (" << device_whitelist_->HasDeviceWithAddress( device->GetAddress()) << ")"; - pending_connections_.insert(device); - CreateGattConnection(device); - } -} -void BluetoothLowEnergyConnectionFinder::DeviceRemoved( - BluetoothAdapter* adapter, - BluetoothDevice* device) { - if (connected_) - return; + connection_ = CreateConnection(device->GetAddress()); + connection_->AddObserver(this); + connection_->Connect(); - const auto& i = pending_connections_.find(device); - if (i != pending_connections_.end()) { - PA_LOG(INFO) << "Remove pending connection to " << device->GetAddress(); - pending_connections_.erase(i); + adapter_->RemoveObserver(this); + StopDiscoverySession(); } } @@ -257,82 +242,14 @@ bool BluetoothLowEnergyConnectionFinder::HasService( return false; } -void BluetoothLowEnergyConnectionFinder::OnCreateGattConnectionError( - std::string device_address, - BluetoothDevice::ConnectErrorCode error_code) { - PA_LOG(WARNING) << "Error creating connection to device " << device_address - << " : error code = " << error_code; - - BluetoothDevice* device = GetDevice(device_address); - const auto& i = pending_connections_.find(device); - if (i != pending_connections_.end()) { - PA_LOG(INFO) << "Remove pending connection to " << device->GetAddress(); - pending_connections_.erase(i); - } -} - -void BluetoothLowEnergyConnectionFinder::OnGattConnectionCreated( - scoped_ptr<BluetoothGattConnection> gatt_connection) { - if (connected_) { - CloseGattConnection(gatt_connection.Pass()); - return; - } - - PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() - << " created."; - connected_ = true; - pending_connections_.clear(); - - gatt_connection_ = gatt_connection.Pass(); - - // This is a workaround for crbug.com/498850. Currently, trying to write/read - // characteristics immediatelly after the GATT connection was established - // fails with the very informative GATT_ERROR_FAILED. - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, - base::Bind(&BluetoothLowEnergyConnectionFinder::CompleteConnection, - weak_ptr_factory_.GetWeakPtr()), - delay_after_gatt_connection_); - - StopDiscoverySession(); -} - -void BluetoothLowEnergyConnectionFinder::CompleteConnection() { - connection_ = CreateConnection(gatt_connection_.Pass()); - connection_->AddObserver(this); - connection_->Connect(); -} - -void BluetoothLowEnergyConnectionFinder::CreateGattConnection( - device::BluetoothDevice* remote_device) { - PA_LOG(INFO) << "Creating GATT connection with " - << remote_device->GetAddress(); - remote_device->CreateGattConnection( - base::Bind(&BluetoothLowEnergyConnectionFinder::OnGattConnectionCreated, - weak_ptr_factory_.GetWeakPtr()), - base::Bind( - &BluetoothLowEnergyConnectionFinder::OnCreateGattConnectionError, - weak_ptr_factory_.GetWeakPtr(), remote_device->GetAddress())); -} - -void BluetoothLowEnergyConnectionFinder::CloseGattConnection( - scoped_ptr<device::BluetoothGattConnection> gatt_connection) { - DCHECK(gatt_connection); - PA_LOG(INFO) << "Closing GATT connection with " - << gatt_connection->GetDeviceAddress(); - - // Destroying the BluetoothGattConnection also disconnects it. - gatt_connection.reset(); -} - scoped_ptr<Connection> BluetoothLowEnergyConnectionFinder::CreateConnection( - scoped_ptr<BluetoothGattConnection> gatt_connection) { - remote_device_.bluetooth_address = gatt_connection->GetDeviceAddress(); + const std::string& device_address) { + RemoteDevice remote_device(std::string(), std::string(), device_address, + std::string()); return make_scoped_ptr(new BluetoothLowEnergyConnection( - remote_device_, adapter_, remote_service_uuid_, to_peripheral_char_uuid_, - from_peripheral_char_uuid_, gatt_connection.Pass(), - max_number_of_tries_)); + remote_device, adapter_, remote_service_uuid_, to_peripheral_char_uuid_, + from_peripheral_char_uuid_, max_number_of_tries_)); } void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged( @@ -367,11 +284,9 @@ void BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionWhenReady() { // |device::BluetoothDiscoverySession::Stop()|. // The second condition is satisfied when |OnDiscoveryStopped| is called and // |discovery_session_| is reset. - if ((!gatt_connection_ || !gatt_connection_->IsConnected()) && - !discovery_session_) { + if (!discovery_session_) { PA_LOG(INFO) << "Ready to start discovery."; connection_.reset(); - connected_ = false; StartDiscoverySession(); } else { base::ThreadTaskRunnerHandle::Get()->PostTask( @@ -381,11 +296,6 @@ void BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionWhenReady() { } } -void BluetoothLowEnergyConnectionFinder::SetDelayForTesting( - base::TimeDelta delay) { - delay_after_gatt_connection_ = delay; -} - BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( std::string device_address) { // It's not possible to simply use diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h index 0b22598..bc07b3c 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h @@ -41,7 +41,7 @@ class BluetoothLowEnergyConnectionFinder int max_number_of_tries); ~BluetoothLowEnergyConnectionFinder() override; - // Finds a connection to the remote device. Only the first one is functional. + // Finds a connection to the remote device. void Find(const ConnectionCallback& connection_callback) override; // proximity_auth::ConnectionObserver: @@ -56,21 +56,12 @@ class BluetoothLowEnergyConnectionFinder device::BluetoothDevice* device) override; void DeviceChanged(device::BluetoothAdapter* adapter, device::BluetoothDevice* device) override; - void DeviceRemoved(device::BluetoothAdapter* adapter, - device::BluetoothDevice* device) override; protected: - // Closes the GATT connection. Virtual for testing. - virtual void CloseGattConnection( - scoped_ptr<device::BluetoothGattConnection> gatt_connection); - - // Creates a proximity_auth::Connection based on |gatt_connection|. Exposed - // for testing. + // Creates a proximity_auth::Connection with the device given by + // |device_address|. Exposed for testing. virtual scoped_ptr<Connection> CreateConnection( - scoped_ptr<device::BluetoothGattConnection> gatt_connection); - - // Sets |delay_after_gatt_connection_| for testing. - void SetDelayForTesting(base::TimeDelta delay); + const std::string& device_address); private: // Callback to be called when the Bluetooth adapter is initialized. @@ -102,23 +93,6 @@ class BluetoothLowEnergyConnectionFinder // Checks if a service with |service_uuid| is offered by |remote_device|. bool HasService(device::BluetoothDevice* remote_device); - // Callback called when there is an error creating the connection. - void OnCreateGattConnectionError( - std::string device_address, - device::BluetoothDevice::ConnectErrorCode error_code); - - // Callback called when a GATT connection is created. - void OnGattConnectionCreated( - scoped_ptr<device::BluetoothGattConnection> gatt_connection); - - // Creates a GATT connection with |remote_device|, |connection_callback_| will - // be called once the connection is established. - void CreateGattConnection(device::BluetoothDevice* remote_device); - - // Creates a BluetoothLowEnergyconnection object and adds the necessary - // observers. - void CompleteConnection(); - // Restarts the discovery session after creating |connection_| fails. void RestartDiscoverySessionWhenReady(); @@ -144,16 +118,6 @@ class BluetoothLowEnergyConnectionFinder // The discovery session associated to this object. scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; - // True if a connection was established with a paired remote device that has - // the service |remote_service_uuid_|. - bool connected_; - - // The remote device |gatt_connection_| was created with. - RemoteDevice remote_device_; - - // The GATT connection with |remote_device|. - scoped_ptr<device::BluetoothGattConnection> gatt_connection_; - // The connection with |remote_device|. scoped_ptr<Connection> connection_; @@ -161,16 +125,9 @@ class BluetoothLowEnergyConnectionFinder // device::BluetoothDevice::GattConnectionCallback connection_callback_; ConnectionCallback connection_callback_; - // The set of devices this connection finder has tried to connect to. - std::set<device::BluetoothDevice*> pending_connections_; - // BluetoothLowEnergyConnection parameter. int max_number_of_tries_; - // Necessary delay after a GATT connection is created and before any - // read/write request is sent to the characteristics. - base::TimeDelta delay_after_gatt_connection_; - base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc index d685e6f..39ee9bc 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc @@ -90,7 +90,6 @@ class MockBluetoothLowEnergyConnectionFinder kFromPeripheralCharUUID, device_whitelist, kMaxNumberOfAttempts) { - SetDelayForTesting(base::TimeDelta()); } ~MockBluetoothLowEnergyConnectionFinder() override {} @@ -117,17 +116,10 @@ class MockBluetoothLowEnergyConnectionFinder protected: scoped_ptr<Connection> CreateConnection( - scoped_ptr<device::BluetoothGattConnection> gatt_connection) override { + const std::string& device_address) override { return make_scoped_ptr(CreateConnectionProxy()); } - void CloseGattConnection( - scoped_ptr<device::BluetoothGattConnection> gatt_connection) override { - BluetoothLowEnergyConnectionFinder::CloseGattConnection( - gatt_connection.Pass()); - CloseGattConnectionProxy(); - } - private: DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnectionFinder); }; @@ -199,20 +191,15 @@ class ProximityAuthBluetoothLowEnergyConnectionFinderTest } // Prepare expectations to add/change a right device. - void PrepareForNewRightDevice( - const std::string& uuid, - device::BluetoothDevice::GattConnectionCallback& callback) { + void PrepareForNewRightDevice(const std::string& uuid) { PrepareDevice(uuid); ON_CALL(*device_, IsPaired()).WillByDefault(Return(true)); - EXPECT_CALL(*device_, CreateGattConnection(_, _)) - .WillOnce(SaveArg<0>(&callback)); } // Prepare expectations to add/change a wrong device. void PrepareForNewWrongDevice(const std::string& uuid) { PrepareDevice(uuid); ON_CALL(*device_, IsPaired()).WillByDefault(Return(true)); - EXPECT_CALL(*device_, CreateGattConnection(_, _)).Times(0); } scoped_refptr<device::MockBluetoothAdapter> adapter_; @@ -272,11 +259,9 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_CreatesGattConnectionWhenWhitelistedDeviceIsAdded) { - BluetoothLowEnergyConnectionFinder connection_finder( - kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID, - device_whitelist_.get(), kMaxNumberOfAttempts); - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; + Find_CreatesConnectionWhenWhitelistedDeviceIsAdded) { + StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( + device_whitelist_.get()); FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); @@ -286,129 +271,101 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ON_CALL(*device_whitelist_, HasDeviceWithAddress(_)) .WillByDefault(Return(true)); - EXPECT_CALL(*device_, CreateGattConnection(_, _)) - .WillOnce(SaveArg<0>(&gatt_connection_callback)); - EXPECT_TRUE(gatt_connection_callback.is_null()); + connection_finder.ExpectCreateConnection(); connection_finder.DeviceAdded(adapter_.get(), device_.get()); - EXPECT_FALSE(gatt_connection_callback.is_null()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_CreatesGattConnectionWhenRightDeviceIsAdded) { - BluetoothLowEnergyConnectionFinder connection_finder( - kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID, - device_whitelist_.get(), kMaxNumberOfAttempts); - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; + Find_CreatesConnectionWhenRightDeviceIsAdded) { + StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( + device_whitelist_.get()); + FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); + connection_finder.ExpectCreateConnection(); connection_finder.DeviceAdded(adapter_.get(), device_.get()); - ASSERT_FALSE(gatt_connection_callback.is_null()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_DoesntCreateGattConnectionWhenWrongDeviceIsAdded) { - BluetoothLowEnergyConnectionFinder connection_finder( - kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID, - device_whitelist_.get(), kMaxNumberOfAttempts); + Find_DoesntCreateConnectionWhenWrongDeviceIsAdded) { + StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( + device_whitelist_.get()); FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); PrepareForNewWrongDevice(kOtherUUID); + EXPECT_CALL(connection_finder, CreateConnectionProxy()).Times(0); connection_finder.DeviceAdded(adapter_.get(), device_.get()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_CreatesGattConnectionWhenRightDeviceIsChanged) { - BluetoothLowEnergyConnectionFinder connection_finder( - kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID, - device_whitelist_.get(), kMaxNumberOfAttempts); - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; + Find_CreatesConnectionWhenRightDeviceIsChanged) { + StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( + device_whitelist_.get()); + FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); + connection_finder.ExpectCreateConnection(); connection_finder.DeviceChanged(adapter_.get(), device_.get()); - ASSERT_FALSE(gatt_connection_callback.is_null()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_DoesntCreateGattConnectionWhenWrongDeviceIsChanged) { - BluetoothLowEnergyConnectionFinder connection_finder( - kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID, - device_whitelist_.get(), kMaxNumberOfAttempts); + Find_DoesntCreateConnectionWhenWrongDeviceIsChanged) { + StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( + device_whitelist_.get()); + FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); PrepareForNewWrongDevice(kOtherUUID); + EXPECT_CALL(connection_finder, CreateConnectionProxy()).Times(0); connection_finder.DeviceChanged(adapter_.get(), device_.get()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, - Find_CreatesTwoGattConnections) { + Find_CreatesOnlyOneConnection) { StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( device_whitelist_.get()); FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); - connection_finder.ExpectCreateConnection(); // Prepare to add |device_|. - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); // Prepare to add |other_device|. - device::BluetoothDevice::GattConnectionCallback - other_gatt_connection_callback; NiceMock<device::MockBluetoothDevice> other_device( adapter_.get(), 0, kDeviceName, kOtherBluetoothAddress, false, false); std::vector<device::BluetoothUUID> uuids; uuids.push_back(device::BluetoothUUID(kServiceUUID)); ON_CALL(other_device, IsPaired()).WillByDefault(Return(true)); ON_CALL(other_device, GetUUIDs()).WillByDefault((Return(uuids))); - EXPECT_CALL(other_device, CreateGattConnection(_, _)) - .WillOnce(SaveArg<0>(&other_gatt_connection_callback)); + + // Only one connection should be created. + connection_finder.ExpectCreateConnection(); // Add the devices. connection_finder.DeviceAdded(adapter_.get(), device_.get()); connection_finder.DeviceAdded(adapter_.get(), &other_device); - - ASSERT_FALSE(gatt_connection_callback.is_null()); - ASSERT_FALSE(other_gatt_connection_callback.is_null()); - - base::RunLoop run_loop; - gatt_connection_callback.Run(make_scoped_ptr( - new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); - run_loop.RunUntilIdle(); - - // The second device should be forgetten. - EXPECT_CALL(connection_finder, CloseGattConnectionProxy()); - other_gatt_connection_callback.Run( - make_scoped_ptr(new NiceMock<device::MockBluetoothGattConnection>( - kOtherBluetoothAddress))); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, Find_ConnectionSucceeds) { StrictMock<MockBluetoothLowEnergyConnectionFinder> connection_finder( device_whitelist_.get()); - // Starting discovery. FindAndExpectStartDiscovery(connection_finder); ExpectStopDiscoveryAndRemoveObserver(); - // Finding and creating a GATT connection to the right device. - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + // Finding and creating a connection to the right device. + MockConnection* connection = connection_finder.ExpectCreateConnection(); + PrepareForNewRightDevice(kServiceUUID); connection_finder.DeviceAdded(adapter_.get(), device_.get()); // Creating a connection. - MockConnection* connection = connection_finder.ExpectCreateConnection(); - ASSERT_FALSE(gatt_connection_callback.is_null()); - base::RunLoop run_loop; - gatt_connection_callback.Run(make_scoped_ptr( - new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); - run_loop.RunUntilIdle(); EXPECT_FALSE(last_found_connection_); connection->SetStatus(Connection::IN_PROGRESS); connection->SetStatus(Connection::CONNECTED); @@ -427,17 +384,11 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, .WillOnce(SaveArg<0>(&stop_discovery_session_callback)); // Preparing to create a GATT connection to the right device. - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); MockConnection* connection = connection_finder.ExpectCreateConnection(); // Trying to create a connection. connection_finder.DeviceAdded(adapter_.get(), device_.get()); - ASSERT_FALSE(gatt_connection_callback.is_null()); - base::RunLoop run_loop; - gatt_connection_callback.Run(make_scoped_ptr( - new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); - run_loop.RunUntilIdle(); ASSERT_FALSE(last_found_connection_); connection->SetStatus(Connection::IN_PROGRESS); @@ -465,17 +416,12 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, discovery_callback.Run(discovery_session.Pass()); // Preparing to create a GATT connection to the right device. - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); connection = connection_finder.ExpectCreateConnection(); // Trying to create a connection. connection_finder.DeviceAdded(adapter_.get(), device_.get()); EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); - ASSERT_FALSE(gatt_connection_callback.is_null()); - base::RunLoop other_run_loop; - gatt_connection_callback.Run(make_scoped_ptr( - new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); - other_run_loop.RunUntilIdle(); // Completing the connection. EXPECT_FALSE(last_found_connection_); @@ -521,18 +467,12 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, discovery_callback.Run(discovery_session.Pass()); // Preparing to create a GATT connection to the right device. - device::BluetoothDevice::GattConnectionCallback gatt_connection_callback; - PrepareForNewRightDevice(kServiceUUID, gatt_connection_callback); + PrepareForNewRightDevice(kServiceUUID); MockConnection* connection = connection_finder.ExpectCreateConnection(); // Trying to create a connection. connection_finder.DeviceAdded(adapter_.get(), device_.get()); EXPECT_CALL(*last_discovery_session_alias_, Stop(_, _)).Times(AtLeast(1)); - ASSERT_FALSE(gatt_connection_callback.is_null()); - base::RunLoop run_loop; - gatt_connection_callback.Run(make_scoped_ptr( - new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress))); - run_loop.RunUntilIdle(); // Completing the connection. ASSERT_FALSE(last_found_connection_); diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc index 2e550c9..971f24a 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc @@ -7,6 +7,8 @@ #include "base/bind.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" +#include "base/run_loop.h" #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h" #include "components/proximity_auth/connection_finder.h" #include "components/proximity_auth/remote_device.h" @@ -70,15 +72,15 @@ class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection { const device::BluetoothUUID remote_service_uuid, const device::BluetoothUUID to_peripheral_char_uuid, const device::BluetoothUUID from_peripheral_char_uuid, - scoped_ptr<device::BluetoothGattConnection> gatt_connection, int max_number_of_write_attempts) : BluetoothLowEnergyConnection(remote_device, adapter, remote_service_uuid, to_peripheral_char_uuid, from_peripheral_char_uuid, - gatt_connection.Pass(), - max_number_of_write_attempts) {} + max_number_of_write_attempts) { + SetDelayForTesting(base::TimeDelta()); + } ~MockBluetoothLowEnergyConnection() override {} @@ -160,8 +162,7 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { scoped_ptr<MockBluetoothLowEnergyConnection> connection( new MockBluetoothLowEnergyConnection( remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_, - from_peripheral_char_uuid_, gatt_connection_.Pass(), - kMaxNumberOfTries)); + from_peripheral_char_uuid_, kMaxNumberOfTries)); EXPECT_EQ(connection->sub_status(), BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); @@ -171,29 +172,9 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { } // Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS - // state, using an existing GATT connection. - void ConnectWithExistingGattConnection( - MockBluetoothLowEnergyConnection* connection) { - EXPECT_CALL(*gatt_connection_alias_, IsConnected()).WillOnce(Return(true)); - EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) - .WillOnce( - DoAll(SaveArg<0>(&characteristics_finder_success_callback_), - SaveArg<1>(&characteristics_finder_error_callback_), - Return(new MockBluetoothLowEnergyCharacteristicsFinder))); - - connection->Connect(); - - EXPECT_EQ(connection->sub_status(), - BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS); - EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); - } - - // Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS // state, without an existing GATT connection. - void ConnectWithoutExistingGattConnection( - MockBluetoothLowEnergyConnection* connection) { + void ConnectGatt(MockBluetoothLowEnergyConnection* connection) { // Preparing |connection| for a CreateGattConnection call. - EXPECT_CALL(*gatt_connection_alias_, IsConnected()).WillOnce(Return(false)); EXPECT_CALL(*device_, CreateGattConnection(_, _)) .WillOnce(DoAll(SaveArg<0>(&create_gatt_connection_success_callback_), SaveArg<1>(&create_gatt_connection_error_callback_))); @@ -256,7 +237,10 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { new NiceMock<device::MockBluetoothGattNotifySession>( kToPeripheralCharID)); notify_session_alias_ = notify_session.get(); + + base::RunLoop run_loop; notify_session_success_callback_.Run(notify_session.Pass()); + run_loop.RunUntilIdle(); EXPECT_EQ(connection->sub_status(), BluetoothLowEnergyConnection::SubStatus::WAITING_RESPONSE_SIGNAL); @@ -304,7 +288,7 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { } void InitializeConnection(MockBluetoothLowEnergyConnection* connection) { - ConnectWithExistingGattConnection(connection); + ConnectGatt(connection); CharacteristicsFound(connection); NotifySessionStarted(connection); ResponseSignalReceived(connection); @@ -347,6 +331,7 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { scoped_ptr<device::MockBluetoothGattCharacteristic> from_peripheral_char_; std::vector<uint8> last_value_written_on_to_peripheral_char_; device::MockBluetoothGattNotifySession* notify_session_alias_; + base::MessageLoop message_loop_; // Callbacks device::BluetoothDevice::GattConnectionCallback @@ -373,7 +358,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, CreateAndDestroyWithouthConnectCallDoesntCrash) { BluetoothLowEnergyConnection connection( remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_, - from_peripheral_char_uuid_, gatt_connection_.Pass(), kMaxNumberOfTries); + from_peripheral_char_uuid_, kMaxNumberOfTries); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, @@ -382,19 +367,9 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Disconnect(connection.get()); } -TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, - Connect_Success_WithGattConnection) { - scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); - CharacteristicsFound(connection.get()); - NotifySessionStarted(connection.get()); - ResponseSignalReceived(connection.get()); -} - -TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, - Connect_Success_WithoutGattConnection) { +TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Success) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithoutExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); ResponseSignalReceived(connection.get()); @@ -407,25 +382,17 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Disconnect(connection.get()); } -TEST_F( - ProximityAuthBluetoothLowEnergyConnectionTest, - Connect_Incomplete_Disconnect_FromWaitingCharacteristicsStateWithoutExistingGattConnection) { - scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithoutExistingGattConnection(connection.get()); - Disconnect(connection.get()); -} - TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Incomplete_Disconnect_FromWaitingCharacteristicsState) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); Disconnect(connection.get()); } TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Incomplete_Disconnect_FromWaitingNotifySessionState) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); Disconnect(connection.get()); } @@ -433,7 +400,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Incomplete_Disconnect_FromWaitingResponseSignalState) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); Disconnect(connection.get()); @@ -442,7 +409,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Fails_CharacteristicsNotFound) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)).Times(0); EXPECT_FALSE(characteristics_finder_success_callback_.is_null()); @@ -460,7 +427,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Fails_NotifySessionError) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) @@ -479,7 +446,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Fails_ErrorSendingInviteToConnectSignal) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithExistingGattConnection(connection.get()); + ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); @@ -513,24 +480,6 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, } TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, - Connect_Fails_CharacteristicsNotFound_WithoutExistingGattConnection) { - scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); - ConnectWithoutExistingGattConnection(connection.get()); - - EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)).Times(0); - EXPECT_FALSE(characteristics_finder_success_callback_.is_null()); - ASSERT_FALSE(characteristics_finder_error_callback_.is_null()); - - characteristics_finder_error_callback_.Run( - {to_peripheral_char_uuid_, kToPeripheralCharID}, - {from_peripheral_char_uuid_, kFromPeripheralCharID}); - - EXPECT_EQ(connection->sub_status(), - BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); - EXPECT_EQ(connection->status(), Connection::DISCONNECTED); -} - -TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Receive_MessageSmallerThanCharacteristicSize) { scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection()); InitializeConnection(connection.get()); |