Index: components/proximity_auth/ble/bluetooth_low_energy_weave_connection_unittest.cc |
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_weave_connection_unittest.cc |
similarity index 61% |
copy from components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc |
copy to components/proximity_auth/ble/bluetooth_low_energy_weave_connection_unittest.cc |
index 241595fc76cde487463bd4d4f159fc7ce4ea472f..7a41decac01b1c6791cc7089de04962a5a6a1e6c 100644 |
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc |
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_connection_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
+#include "components/proximity_auth/ble/bluetooth_low_energy_weave_connection.h" |
#include <stdint.h> |
@@ -10,21 +10,16 @@ |
#include <utility> |
#include "base/bind.h" |
-#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
-#include "base/memory/ref_counted.h" |
#include "base/message_loop/message_loop.h" |
#include "base/run_loop.h" |
#include "base/test/test_simple_task_runner.h" |
-#include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h" |
#include "components/proximity_auth/bluetooth_throttler.h" |
#include "components/proximity_auth/connection_finder.h" |
#include "components/proximity_auth/proximity_auth_test_util.h" |
#include "components/proximity_auth/remote_device.h" |
#include "components/proximity_auth/wire_message.h" |
#include "device/bluetooth/bluetooth_adapter_factory.h" |
-#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
-#include "device/bluetooth/bluetooth_uuid.h" |
#include "device/bluetooth/test/mock_bluetooth_adapter.h" |
#include "device/bluetooth/test/mock_bluetooth_device.h" |
#include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
@@ -45,8 +40,8 @@ namespace proximity_auth { |
namespace { |
const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF"; |
-const char kToPeripheralCharUUID[] = "977c6674-1239-4e72-993b-502369b8bb5a"; |
-const char kFromPeripheralCharUUID[] = "f4b904a2-a030-43b3-98a8-221c536c03cb"; |
+const char kTXCharacteristicUUID[] = "977c6674-1239-4e72-993b-502369b8bb5a"; |
+const char kRXCharacteristicUUID[] = "f4b904a2-a030-43b3-98a8-221c536c03cb"; |
const char kServiceID[] = "service id"; |
const char kToPeripheralCharID[] = "to peripheral char id"; |
@@ -61,6 +56,7 @@ const device::BluetoothRemoteGattCharacteristic::Properties |
device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE; |
const int kMaxNumberOfTries = 3; |
+const uint32_t kDefaultPacketSize = 20; |
class MockBluetoothThrottler : public BluetoothThrottler { |
public: |
@@ -84,21 +80,22 @@ class MockBluetoothLowEnergyCharacteristicsFinder |
DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyCharacteristicsFinder); |
}; |
-class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection { |
+class MockBluetoothLowEnergyWeaveConnection |
+ : public BluetoothLowEnergyWeaveConnection { |
public: |
- MockBluetoothLowEnergyConnection( |
+ MockBluetoothLowEnergyWeaveConnection( |
const RemoteDevice& remote_device, |
scoped_refptr<device::BluetoothAdapter> adapter, |
const device::BluetoothUUID remote_service_uuid, |
BluetoothThrottler* bluetooth_throttler, |
int max_number_of_write_attempts) |
- : BluetoothLowEnergyConnection(remote_device, |
- adapter, |
- remote_service_uuid, |
- bluetooth_throttler, |
- max_number_of_write_attempts) {} |
+ : BluetoothLowEnergyWeaveConnection(remote_device, |
+ adapter, |
+ remote_service_uuid, |
+ bluetooth_throttler, |
+ max_number_of_write_attempts) {} |
- ~MockBluetoothLowEnergyConnection() override {} |
+ ~MockBluetoothLowEnergyWeaveConnection() override {} |
MOCK_METHOD2( |
CreateCharacteristicsFinder, |
@@ -112,28 +109,28 @@ class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection { |
MOCK_METHOD1(OnBytesReceived, void(const std::string& bytes)); |
// Exposing inherited protected methods for testing. |
- using BluetoothLowEnergyConnection::GattCharacteristicValueChanged; |
- using BluetoothLowEnergyConnection::SetTaskRunnerForTesting; |
+ using BluetoothLowEnergyWeaveConnection::GattCharacteristicValueChanged; |
+ using BluetoothLowEnergyWeaveConnection::SetTaskRunnerForTesting; |
// Exposing inherited protected fields for testing. |
- using BluetoothLowEnergyConnection::status; |
- using BluetoothLowEnergyConnection::sub_status; |
+ using BluetoothLowEnergyWeaveConnection::status; |
+ using BluetoothLowEnergyWeaveConnection::sub_status; |
private: |
- DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnection); |
+ DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyWeaveConnection); |
}; |
} // namespace |
-class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
+class ProximityAuthBluetoothLowEnergyWeaveConnectionTest |
+ : public testing::Test { |
public: |
- ProximityAuthBluetoothLowEnergyConnectionTest() |
+ ProximityAuthBluetoothLowEnergyWeaveConnectionTest() |
: adapter_(new NiceMock<device::MockBluetoothAdapter>), |
remote_device_(CreateLERemoteDeviceForTest()), |
service_uuid_(device::BluetoothUUID(kServiceUUID)), |
- to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)), |
- from_peripheral_char_uuid_( |
- device::BluetoothUUID(kFromPeripheralCharUUID)), |
+ tx_characteristic_uuid_(device::BluetoothUUID(kTXCharacteristicUUID)), |
+ rx_characteristic_uuid_(device::BluetoothUUID(kRXCharacteristicUUID)), |
notify_session_alias_(NULL), |
bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), |
task_runner_(new base::TestSimpleTaskRunner) {} |
@@ -145,18 +142,21 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
service_ = base::WrapUnique(new NiceMock<device::MockBluetoothGattService>( |
device_.get(), kServiceID, service_uuid_, true, false)); |
- to_peripheral_char_ = |
+ tx_characteristic_ = |
base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( |
- service_.get(), kToPeripheralCharID, to_peripheral_char_uuid_, |
- false, kCharacteristicProperties, |
+ service_.get(), kToPeripheralCharID, tx_characteristic_uuid_, false, |
+ kCharacteristicProperties, |
device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); |
- from_peripheral_char_ = |
+ rx_characteristic_ = |
base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( |
- service_.get(), kFromPeripheralCharID, from_peripheral_char_uuid_, |
+ service_.get(), kFromPeripheralCharID, rx_characteristic_uuid_, |
false, kCharacteristicProperties, |
device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); |
+ packet_generator_ = |
+ BluetoothLowEnergyWeavePacketGenerator::Factory::NewInstance(); |
+ |
device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); |
std::vector<const device::BluetoothDevice*> devices; |
@@ -167,24 +167,24 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
ON_CALL(*device_, GetGattService(kServiceID)) |
.WillByDefault(Return(service_.get())); |
ON_CALL(*service_, GetCharacteristic(kFromPeripheralCharID)) |
- .WillByDefault(Return(from_peripheral_char_.get())); |
+ .WillByDefault(Return(rx_characteristic_.get())); |
ON_CALL(*service_, GetCharacteristic(kToPeripheralCharID)) |
- .WillByDefault(Return(to_peripheral_char_.get())); |
+ .WillByDefault(Return(tx_characteristic_.get())); |
} |
- // Creates a BluetoothLowEnergyConnection and verifies it's in DISCONNECTED |
- // state. |
- std::unique_ptr<MockBluetoothLowEnergyConnection> CreateConnection() { |
+ // Creates a BluetoothLowEnergyWeaveConnection and verifies it's in |
+ // DISCONNECTED state. |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> CreateConnection() { |
EXPECT_CALL(*adapter_, AddObserver(_)); |
EXPECT_CALL(*adapter_, RemoveObserver(_)); |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
- new MockBluetoothLowEnergyConnection( |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
+ new MockBluetoothLowEnergyWeaveConnection( |
remote_device_, adapter_, service_uuid_, bluetooth_throttler_.get(), |
kMaxNumberOfTries)); |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::DISCONNECTED); |
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); |
connection->SetTaskRunnerForTesting(task_runner_); |
@@ -194,7 +194,7 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
// Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS |
// state, without an existing GATT connection. |
- void ConnectGatt(MockBluetoothLowEnergyConnection* connection) { |
+ void ConnectGatt(MockBluetoothLowEnergyWeaveConnection* connection) { |
// Preparing |connection| for a CreateGattConnection call. |
EXPECT_CALL(*device_, CreateGattConnection(_, _)) |
.WillOnce(DoAll(SaveArg<0>(&create_gatt_connection_success_callback_), |
@@ -206,8 +206,9 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
connection->Connect(); |
- EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::WAITING_GATT_CONNECTION); |
+ EXPECT_EQ( |
+ connection->sub_status(), |
+ BluetoothLowEnergyWeaveConnection::SubStatus::WAITING_GATT_CONNECTION); |
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
// Preparing |connection| to run |create_gatt_connection_success_callback_|. |
@@ -223,15 +224,16 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
base::WrapUnique(new NiceMock<device::MockBluetoothGattConnection>( |
adapter_, kTestRemoteDeviceBluetoothAddress))); |
- EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS); |
+ EXPECT_EQ( |
+ connection->sub_status(), |
+ BluetoothLowEnergyWeaveConnection::SubStatus::WAITING_CHARACTERISTICS); |
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
} |
// Transitions |connection| from WAITING_CHARACTERISTICS to |
// WAITING_NOTIFY_SESSION state. |
- void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) { |
- EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)) |
+ void CharacteristicsFound(MockBluetoothLowEnergyWeaveConnection* connection) { |
+ EXPECT_CALL(*rx_characteristic_, StartNotifySession(_, _)) |
.WillOnce(DoAll(SaveArg<0>(¬ify_session_success_callback_), |
SaveArg<1>(¬ify_session_error_callback_))); |
EXPECT_FALSE(characteristics_finder_error_callback_.is_null()); |
@@ -239,20 +241,21 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
characteristics_finder_success_callback_.Run( |
{service_uuid_, kServiceID}, |
- {to_peripheral_char_uuid_, kToPeripheralCharID}, |
- {from_peripheral_char_uuid_, kFromPeripheralCharID}); |
+ {tx_characteristic_uuid_, kToPeripheralCharID}, |
+ {rx_characteristic_uuid_, kFromPeripheralCharID}); |
- EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::WAITING_NOTIFY_SESSION); |
+ EXPECT_EQ( |
+ connection->sub_status(), |
+ BluetoothLowEnergyWeaveConnection::SubStatus::WAITING_NOTIFY_SESSION); |
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
} |
// Transitions |connection| from WAITING_NOTIFY_SESSION to |
// WAITING_RESPONSE_SIGNAL state. |
- void NotifySessionStarted(MockBluetoothLowEnergyConnection* connection) { |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
+ void NotifySessionStarted(MockBluetoothLowEnergyWeaveConnection* connection) { |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
.WillOnce( |
- DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), |
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
SaveArg<1>(&write_remote_characteristic_success_callback_), |
SaveArg<2>(&write_remote_characteristic_error_callback_))); |
EXPECT_FALSE(notify_session_error_callback_.is_null()); |
@@ -267,40 +270,39 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
notify_session_success_callback_.Run(std::move(notify_session)); |
task_runner_->RunUntilIdle(); |
- EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::WAITING_RESPONSE_SIGNAL); |
+ EXPECT_EQ( |
+ connection->sub_status(), |
+ BluetoothLowEnergyWeaveConnection::SubStatus::WAITING_RESPONSE_SIGNAL); |
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
} |
// Transitions |connection| from WAITING_RESPONSE_SIGNAL to CONNECTED state. |
- void ResponseSignalReceived(MockBluetoothLowEnergyConnection* connection) { |
- // Written value contains only the |
- // BluetoothLowEneryConnection::ControlSignal::kInviteToConnectSignal. |
- const std::vector<uint8_t> kInviteToConnectSignal = ToByteVector( |
- static_cast<uint32_t>(BluetoothLowEnergyConnection::ControlSignal:: |
- kInviteToConnectSignal)); |
- EXPECT_EQ(last_value_written_on_to_peripheral_char_, |
- kInviteToConnectSignal); |
+ void ResponseSignalReceived(MockBluetoothLowEnergyWeaveConnection* connection, |
+ uint32_t selected_packet_size) { |
+ // Written value contains only the Connection Request. |
+ packet_generator_->SetMaxPacketSize(selected_packet_size); |
+ const std::vector<uint8_t> request = |
+ packet_generator_->CreateConnectionRequest(); |
+ EXPECT_EQ(last_value_written_on_tx_characteristic_, request); |
EXPECT_CALL(*connection, OnDidSendMessage(_, _)).Times(0); |
RunWriteCharacteristicSuccessCallback(); |
- // Received the |
- // BluetoothLowEneryConnection::ControlSignal::kInvitationResponseSignal. |
- const std::vector<uint8_t> kInvitationResponseSignal = ToByteVector( |
- static_cast<uint32_t>(BluetoothLowEnergyConnection::ControlSignal:: |
- kInvitationResponseSignal)); |
+ // Received Connection Response. |
+ packet_generator_->SetMaxPacketSize(selected_packet_size); |
+ const std::vector<uint8_t> response = |
+ packet_generator_->CreateConnectionResponse(); |
connection->GattCharacteristicValueChanged( |
- adapter_.get(), from_peripheral_char_.get(), kInvitationResponseSignal); |
+ adapter_.get(), rx_characteristic_.get(), response); |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::CONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::CONNECTED); |
EXPECT_EQ(connection->status(), Connection::CONNECTED); |
} |
// Transitions |connection| to a DISCONNECTED state regardless of its initial |
// state. |
- void Disconnect(MockBluetoothLowEnergyConnection* connection) { |
+ void Disconnect(MockBluetoothLowEnergyWeaveConnection* connection) { |
// A notify session was previously set. |
if (notify_session_alias_) |
EXPECT_CALL(*notify_session_alias_, Stop(_)); |
@@ -308,15 +310,16 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
connection->Disconnect(); |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::DISCONNECTED); |
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); |
} |
- void InitializeConnection(MockBluetoothLowEnergyConnection* connection) { |
+ void InitializeConnection(MockBluetoothLowEnergyWeaveConnection* connection, |
+ uint32_t selected_packet_size) { |
ConnectGatt(connection); |
CharacteristicsFound(connection); |
NotifySessionStarted(connection); |
- ResponseSignalReceived(connection); |
+ ResponseSignalReceived(connection, selected_packet_size); |
} |
void RunWriteCharacteristicSuccessCallback() { |
@@ -327,7 +330,7 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
std::vector<uint8_t> CreateSendSignalWithSize(int message_size) { |
std::vector<uint8_t> value = ToByteVector(static_cast<uint32_t>( |
- BluetoothLowEnergyConnection::ControlSignal::kSendSignal)); |
+ BluetoothLowEnergyWeaveConnection::ControlSignal::kSendSignal)); |
std::vector<uint8_t> size = |
ToByteVector(static_cast<uint32_t>(message_size)); |
value.insert(value.end(), size.begin(), size.end()); |
@@ -356,14 +359,13 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
scoped_refptr<device::MockBluetoothAdapter> adapter_; |
RemoteDevice remote_device_; |
device::BluetoothUUID service_uuid_; |
- device::BluetoothUUID to_peripheral_char_uuid_; |
- device::BluetoothUUID from_peripheral_char_uuid_; |
+ device::BluetoothUUID tx_characteristic_uuid_; |
+ device::BluetoothUUID rx_characteristic_uuid_; |
std::unique_ptr<device::MockBluetoothDevice> device_; |
std::unique_ptr<device::MockBluetoothGattService> service_; |
- std::unique_ptr<device::MockBluetoothGattCharacteristic> to_peripheral_char_; |
- std::unique_ptr<device::MockBluetoothGattCharacteristic> |
- from_peripheral_char_; |
- std::vector<uint8_t> last_value_written_on_to_peripheral_char_; |
+ std::unique_ptr<device::MockBluetoothGattCharacteristic> tx_characteristic_; |
+ std::unique_ptr<device::MockBluetoothGattCharacteristic> rx_characteristic_; |
+ std::vector<uint8_t> last_value_written_on_tx_characteristic_; |
device::MockBluetoothGattNotifySession* notify_session_alias_; |
std::unique_ptr<MockBluetoothThrottler> bluetooth_throttler_; |
scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
@@ -388,59 +390,61 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test { |
base::Closure write_remote_characteristic_success_callback_; |
device::BluetoothRemoteGattCharacteristic::ErrorCallback |
write_remote_characteristic_error_callback_; |
+ |
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_; |
}; |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- CreateAndDestroyWithouthConnectCallDoesntCrash) { |
- BluetoothLowEnergyConnection connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ CreateAndDestroyWithoutConnectCallDoesntCrash) { |
+ BluetoothLowEnergyWeaveConnection connection( |
remote_device_, adapter_, service_uuid_, bluetooth_throttler_.get(), |
kMaxNumberOfTries); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Disconect_WithoutConnectDoesntCrash) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ DisconectWithoutConnectDoesntCrash) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
Disconnect(connection.get()); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, Connect_Success) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, ConnectSuccess) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
CharacteristicsFound(connection.get()); |
NotifySessionStarted(connection.get()); |
- ResponseSignalReceived(connection.get()); |
+ ResponseSignalReceived(connection.get(), kDefaultPacketSize); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Success_Disconnect) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectSuccessDisconnect) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
- InitializeConnection(connection.get()); |
+ InitializeConnection(connection.get(), kDefaultPacketSize); |
Disconnect(connection.get()); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Incomplete_Disconnect_FromWaitingCharacteristicsState) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectIncompleteDisconnectFromWaitingCharacteristicsState) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
Disconnect(connection.get()); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Incomplete_Disconnect_FromWaitingNotifySessionState) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectIncompleteDisconnectFromWaitingNotifySessionState) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
CharacteristicsFound(connection.get()); |
Disconnect(connection.get()); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Incomplete_Disconnect_FromWaitingResponseSignalState) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectIncompleteDisconnectFromWaitingResponseSignalState) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
CharacteristicsFound(connection.get()); |
@@ -448,34 +452,33 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
Disconnect(connection.get()); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Fails_CharacteristicsNotFound) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectFailsCharacteristicsNotFound) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
- EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)).Times(0); |
+ EXPECT_CALL(*rx_characteristic_, 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}); |
+ {tx_characteristic_uuid_, kToPeripheralCharID}, |
+ {rx_characteristic_uuid_, kFromPeripheralCharID}); |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::DISCONNECTED); |
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Fails_NotifySessionError) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectFailsNotifySessionError) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
CharacteristicsFound(connection.get()); |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
- .Times(0); |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)).Times(0); |
EXPECT_FALSE(notify_session_success_callback_.is_null()); |
ASSERT_FALSE(notify_session_error_callback_.is_null()); |
@@ -483,13 +486,13 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
device::BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::DISCONNECTED); |
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_Fails_ErrorSendingInviteToConnectSignal) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectFailsErrorSendingConnectionRequest) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
ConnectGatt(connection.get()); |
CharacteristicsFound(connection.get()); |
@@ -500,19 +503,17 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
// WriteRemoteCharacteristic(_,_,_) in NotifySessionStated, that's why we use |
// |kMaxNumberOfTries-1| in the EXPECT_CALL statement. |
EXPECT_CALL(*connection, OnDidSendMessage(_, _)).Times(0); |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
.Times(kMaxNumberOfTries - 1) |
.WillRepeatedly( |
- DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), |
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
SaveArg<1>(&write_remote_characteristic_success_callback_), |
SaveArg<2>(&write_remote_characteristic_error_callback_))); |
for (int i = 0; i < kMaxNumberOfTries; i++) { |
- const std::vector<uint8_t> kInviteToConnectSignal = ToByteVector( |
- static_cast<uint32_t>(BluetoothLowEnergyConnection::ControlSignal:: |
- kInviteToConnectSignal)); |
- EXPECT_EQ(last_value_written_on_to_peripheral_char_, |
- kInviteToConnectSignal); |
+ const std::vector<uint8_t> request = |
+ packet_generator_->CreateConnectionRequest(); |
+ EXPECT_EQ(last_value_written_on_tx_characteristic_, request); |
ASSERT_FALSE(write_remote_characteristic_error_callback_.is_null()); |
EXPECT_FALSE(write_remote_characteristic_success_callback_.is_null()); |
write_remote_characteristic_error_callback_.Run( |
@@ -520,136 +521,123 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
} |
EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::DISCONNECTED); |
+ BluetoothLowEnergyWeaveConnection::SubStatus::DISCONNECTED); |
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Receive_MessageSmallerThanCharacteristicSize) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ReceiveMessageSmallerThanCharacteristicSize) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
- InitializeConnection(connection.get()); |
+ InitializeConnection(connection.get(), kDefaultPacketSize); |
std::string received_bytes; |
EXPECT_CALL(*connection, OnBytesReceived(_)) |
.WillOnce(SaveArg<0>(&received_bytes)); |
// Message (bytes) that is going to be received. |
- std::string message(100, 'A'); |
+ std::string message(kDefaultPacketSize - 1, 'A'); |
+ |
+ std::vector<std::vector<uint8_t>> packets = |
+ packet_generator_->EncodeDataMessage(message); |
- // Sending the |kSendSignal| + |message_size| + |message|. |
connection->GattCharacteristicValueChanged( |
- adapter_.get(), from_peripheral_char_.get(), |
- CreateFirstCharacteristicValue(message, message.size())); |
+ adapter_.get(), rx_characteristic_.get(), packets[0]); |
EXPECT_EQ(received_bytes, message); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Receive_MessageLargerThanCharacteristicSize) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ReceiveMessageLargerThanCharacteristicSize) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
- InitializeConnection(connection.get()); |
+ |
+ const uint32_t selected_packet_size = 500; |
+ InitializeConnection(connection.get(), selected_packet_size); |
std::string received_bytes; |
- int chunk_size = 500; |
EXPECT_CALL(*connection, OnBytesReceived(_)) |
.WillOnce(SaveArg<0>(&received_bytes)); |
// Message (bytes) that is going to be received. |
- int message_size = 600; |
- std::string message(message_size, 'A'); |
+ std::string message(600, 'A'); |
- // Sending the |kSendSignal| + |message_size| + |message| (truncated at |
- // |chunk_size|). |
- int first_write_payload_size = |
- chunk_size - CreateSendSignalWithSize(message_size).size(); |
- connection->GattCharacteristicValueChanged( |
- adapter_.get(), from_peripheral_char_.get(), |
- CreateFirstCharacteristicValue( |
- message.substr(0, first_write_payload_size), message.size())); |
- |
- // Sending the remaining bytes. |
- std::vector<uint8_t> value; |
- value.push_back(0); |
- value.insert(value.end(), message.begin() + first_write_payload_size, |
- message.end()); |
- connection->GattCharacteristicValueChanged( |
- adapter_.get(), from_peripheral_char_.get(), value); |
+ std::vector<std::vector<uint8_t>> packets = |
+ packet_generator_->EncodeDataMessage(message); |
+ for (auto packet : packets) { |
+ connection->GattCharacteristicValueChanged( |
+ adapter_.get(), rx_characteristic_.get(), packet); |
+ } |
EXPECT_EQ(received_bytes, message); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- SendMessage_SmallerThanCharacteristicSize) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ SendMessageSmallerThanCharacteristicSize) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
- InitializeConnection(connection.get()); |
+ InitializeConnection(connection.get(), kDefaultPacketSize); |
// Expecting a first call of WriteRemoteCharacteristic, after SendMessage is |
// called. |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
.WillOnce( |
- DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), |
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
SaveArg<1>(&write_remote_characteristic_success_callback_), |
SaveArg<2>(&write_remote_characteristic_error_callback_))); |
// Message (bytes) that is going to be sent. |
- int message_size = 100; |
- std::string message(message_size, 'A'); |
+ std::string message(kDefaultPacketSize - 1, 'A'); |
message[0] = 'B'; |
connection->SendMessage(base::WrapUnique(new FakeWireMessage(message))); |
+ std::vector<std::vector<uint8_t>> packets = |
+ packet_generator_->EncodeDataMessage(message); |
// Expecting that |kSendSignal| + |message_size| + |message| was written. |
- EXPECT_EQ(last_value_written_on_to_peripheral_char_, |
- CreateFirstCharacteristicValue(message, message.size())); |
+ EXPECT_EQ(last_value_written_on_tx_characteristic_, packets[0]); |
EXPECT_CALL(*connection, OnDidSendMessage(_, _)); |
RunWriteCharacteristicSuccessCallback(); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- SendMessage_LagerThanCharacteristicSize) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ SendMessageLargerThanCharacteristicSize) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
- InitializeConnection(connection.get()); |
+ |
+ const uint32_t selected_packet_size = 500; |
+ InitializeConnection(connection.get(), selected_packet_size); |
// Expecting a first call of WriteRemoteCharacteristic, after SendMessage is |
// called. |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
.WillOnce( |
- DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), |
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
SaveArg<1>(&write_remote_characteristic_success_callback_), |
SaveArg<2>(&write_remote_characteristic_error_callback_))); |
// Message (bytes) that is going to be sent. |
- int message_size = 600; |
- std::string message(message_size, 'A'); |
+ std::string message(600, 'A'); |
message[0] = 'B'; |
connection->SendMessage(base::WrapUnique(new FakeWireMessage(message))); |
- // Expecting that |kSendSignal| + |message_size| was written in the first 8 |
- // bytes. |
- std::vector<uint8_t> prefix( |
- last_value_written_on_to_peripheral_char_.begin(), |
- last_value_written_on_to_peripheral_char_.begin() + 8); |
- EXPECT_EQ(prefix, CreateSendSignalWithSize(message_size)); |
+ std::vector<std::vector<uint8_t>> packets = |
+ packet_generator_->EncodeDataMessage(message); |
+ EXPECT_EQ(last_value_written_on_tx_characteristic_, packets[0]); |
std::vector<uint8_t> bytes_received( |
- last_value_written_on_to_peripheral_char_.begin() + 8, |
- last_value_written_on_to_peripheral_char_.end()); |
+ last_value_written_on_tx_characteristic_.begin() + 1, |
+ last_value_written_on_tx_characteristic_.end()); |
- // Expecting a second call of WriteRemoteCharacteristic, after success |
- // callback is called. |
- EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) |
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
.WillOnce( |
- DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), |
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
SaveArg<1>(&write_remote_characteristic_success_callback_), |
SaveArg<2>(&write_remote_characteristic_error_callback_))); |
RunWriteCharacteristicSuccessCallback(); |
bytes_received.insert(bytes_received.end(), |
- last_value_written_on_to_peripheral_char_.begin() + 1, |
- last_value_written_on_to_peripheral_char_.end()); |
+ last_value_written_on_tx_characteristic_.begin() + 1, |
+ last_value_written_on_tx_characteristic_.end()); |
// Expecting that the message was written. |
std::vector<uint8_t> expected_value(message.begin(), message.end()); |
@@ -660,9 +648,9 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
RunWriteCharacteristicSuccessCallback(); |
} |
-TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
- Connect_AfterADelayWhenThrottled) { |
- std::unique_ptr<MockBluetoothLowEnergyConnection> connection( |
+TEST_F(ProximityAuthBluetoothLowEnergyWeaveConnectionTest, |
+ ConnectAfterDelayWhenThrottled) { |
+ std::unique_ptr<MockBluetoothLowEnergyWeaveConnection> connection( |
CreateConnection()); |
EXPECT_CALL(*bluetooth_throttler_, GetDelay()) |
@@ -673,8 +661,9 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
// No GATT connection should be created before the delay. |
connection->Connect(); |
- EXPECT_EQ(connection->sub_status(), |
- BluetoothLowEnergyConnection::SubStatus::WAITING_GATT_CONNECTION); |
+ EXPECT_EQ( |
+ connection->sub_status(), |
+ BluetoothLowEnergyWeaveConnection::SubStatus::WAITING_GATT_CONNECTION); |
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
EXPECT_TRUE(create_gatt_connection_error_callback_.is_null()); |
EXPECT_TRUE(create_gatt_connection_success_callback_.is_null()); |
@@ -697,7 +686,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, |
CharacteristicsFound(connection.get()); |
NotifySessionStarted(connection.get()); |
- ResponseSignalReceived(connection.get()); |
+ ResponseSignalReceived(connection.get(), kDefaultPacketSize); |
} |
} // namespace proximity_auth |