| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_weave_client_connec
tion.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_client_connec
tion.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 new MockBluetoothLowEnergyWeavePacketGeneratorFactory()), | 355 new MockBluetoothLowEnergyWeavePacketGeneratorFactory()), |
| 356 receiver_factory_( | 356 receiver_factory_( |
| 357 new MockBluetoothLowEnergyWeavePacketReceiverFactory()) { | 357 new MockBluetoothLowEnergyWeavePacketReceiverFactory()) { |
| 358 BluetoothLowEnergyWeavePacketGenerator::Factory::SetInstanceForTesting( | 358 BluetoothLowEnergyWeavePacketGenerator::Factory::SetInstanceForTesting( |
| 359 generator_factory_); | 359 generator_factory_); |
| 360 BluetoothLowEnergyWeavePacketReceiver::Factory::SetInstanceForTesting( | 360 BluetoothLowEnergyWeavePacketReceiver::Factory::SetInstanceForTesting( |
| 361 receiver_factory_); | 361 receiver_factory_); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void SetUp() override { | 364 void SetUp() override { |
| 365 device_ = base::WrapUnique(new NiceMock<device::MockBluetoothDevice>( | 365 device_ = base::MakeUnique<NiceMock<device::MockBluetoothDevice>>( |
| 366 adapter_.get(), 0, kTestRemoteDeviceName, | 366 adapter_.get(), 0, kTestRemoteDeviceName, |
| 367 kTestRemoteDeviceBluetoothAddress, false, false)); | 367 kTestRemoteDeviceBluetoothAddress, false, false); |
| 368 | 368 |
| 369 service_ = base::WrapUnique(new NiceMock<device::MockBluetoothGattService>( | 369 service_ = base::MakeUnique<NiceMock<device::MockBluetoothGattService>>( |
| 370 device_.get(), kServiceID, service_uuid_, true, false)); | 370 device_.get(), kServiceID, service_uuid_, true, false); |
| 371 tx_characteristic_ = | 371 tx_characteristic_ = |
| 372 base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( | 372 base::MakeUnique<NiceMock<device::MockBluetoothGattCharacteristic>>( |
| 373 service_.get(), kTXCharacteristicID, tx_characteristic_uuid_, false, | 373 service_.get(), kTXCharacteristicID, tx_characteristic_uuid_, false, |
| 374 kCharacteristicProperties, | 374 kCharacteristicProperties, |
| 375 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); | 375 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE); |
| 376 | 376 |
| 377 rx_characteristic_ = | 377 rx_characteristic_ = |
| 378 base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( | 378 base::MakeUnique<NiceMock<device::MockBluetoothGattCharacteristic>>( |
| 379 service_.get(), kRXCharacteristicID, rx_characteristic_uuid_, false, | 379 service_.get(), kRXCharacteristicID, rx_characteristic_uuid_, false, |
| 380 kCharacteristicProperties, | 380 kCharacteristicProperties, |
| 381 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); | 381 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE); |
| 382 | 382 |
| 383 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); | 383 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); |
| 384 | 384 |
| 385 std::vector<const device::BluetoothDevice*> devices; | 385 std::vector<const device::BluetoothDevice*> devices; |
| 386 devices.push_back(device_.get()); | 386 devices.push_back(device_.get()); |
| 387 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); | 387 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); |
| 388 ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress)) | 388 ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress)) |
| 389 .WillByDefault(Return(device_.get())); | 389 .WillByDefault(Return(device_.get())); |
| 390 ON_CALL(*device_, GetGattService(kServiceID)) | 390 ON_CALL(*device_, GetGattService(kServiceID)) |
| 391 .WillByDefault(Return(service_.get())); | 391 .WillByDefault(Return(service_.get())); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // Preparing |connection| to run |create_gatt_connection_success_callback_|. | 438 // Preparing |connection| to run |create_gatt_connection_success_callback_|. |
| 439 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); | 439 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); |
| 440 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); | 440 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); |
| 441 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) | 441 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) |
| 442 .WillOnce(DoAll( | 442 .WillOnce(DoAll( |
| 443 SaveArg<0>(&characteristics_finder_success_callback_), | 443 SaveArg<0>(&characteristics_finder_success_callback_), |
| 444 SaveArg<1>(&characteristics_finder_error_callback_), | 444 SaveArg<1>(&characteristics_finder_error_callback_), |
| 445 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); | 445 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); |
| 446 | 446 |
| 447 create_gatt_connection_success_callback_.Run( | 447 create_gatt_connection_success_callback_.Run( |
| 448 base::WrapUnique(new NiceMock<device::MockBluetoothGattConnection>( | 448 base::MakeUnique<NiceMock<device::MockBluetoothGattConnection>>( |
| 449 adapter_, kTestRemoteDeviceBluetoothAddress))); | 449 adapter_, kTestRemoteDeviceBluetoothAddress)); |
| 450 | 450 |
| 451 EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS); | 451 EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS); |
| 452 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); | 452 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Transitions |connection| from WAITING_CHARACTERISTICS to | 455 // Transitions |connection| from WAITING_CHARACTERISTICS to |
| 456 // WAITING_NOTIFY_SESSION state. | 456 // WAITING_NOTIFY_SESSION state. |
| 457 void CharacteristicsFound( | 457 void CharacteristicsFound( |
| 458 TestBluetoothLowEnergyWeaveClientConnection* connection) { | 458 TestBluetoothLowEnergyWeaveClientConnection* connection) { |
| 459 EXPECT_CALL(*rx_characteristic_, StartNotifySession(_, _)) | 459 EXPECT_CALL(*rx_characteristic_, StartNotifySession(_, _)) |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 InitializeConnection(connection.get(), kDefaultMaxPacketSize); | 792 InitializeConnection(connection.get(), kDefaultMaxPacketSize); |
| 793 | 793 |
| 794 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is | 794 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is |
| 795 // called. | 795 // called. |
| 796 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 796 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 797 .WillOnce( | 797 .WillOnce( |
| 798 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 798 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 799 SaveArg<1>(&write_remote_characteristic_success_callback_), | 799 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| 800 SaveArg<2>(&write_remote_characteristic_error_callback_))); | 800 SaveArg<2>(&write_remote_characteristic_error_callback_))); |
| 801 | 801 |
| 802 connection->SendMessage(base::WrapUnique(new FakeWireMessage(kSmallMessage))); | 802 connection->SendMessage(base::MakeUnique<FakeWireMessage>(kSmallMessage)); |
| 803 | 803 |
| 804 EXPECT_EQ(last_value_written_on_tx_characteristic_, kSmallPackets0); | 804 EXPECT_EQ(last_value_written_on_tx_characteristic_, kSmallPackets0); |
| 805 | 805 |
| 806 RunWriteCharacteristicSuccessCallback(); | 806 RunWriteCharacteristicSuccessCallback(); |
| 807 | 807 |
| 808 EXPECT_EQ(1, connection_observer_.GetNumSendCompleted()); | 808 EXPECT_EQ(1, connection_observer_.GetNumSendCompleted()); |
| 809 EXPECT_EQ(kSmallMessage, connection_observer_.GetLastDeserializedMessage()); | 809 EXPECT_EQ(kSmallMessage, connection_observer_.GetLastDeserializedMessage()); |
| 810 EXPECT_TRUE(connection_observer_.GetLastSendSuccess()); | 810 EXPECT_TRUE(connection_observer_.GetLastSendSuccess()); |
| 811 } | 811 } |
| 812 | 812 |
| 813 TEST_F(ProximityAuthBluetoothLowEnergyWeaveClientConnectionTest, | 813 TEST_F(ProximityAuthBluetoothLowEnergyWeaveClientConnectionTest, |
| 814 SendMessageLargerThanCharacteristicSize) { | 814 SendMessageLargerThanCharacteristicSize) { |
| 815 std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( | 815 std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( |
| 816 CreateConnection()); | 816 CreateConnection()); |
| 817 | 817 |
| 818 InitializeConnection(connection.get(), kLargeMaxPacketSize); | 818 InitializeConnection(connection.get(), kLargeMaxPacketSize); |
| 819 | 819 |
| 820 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is | 820 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is |
| 821 // called. | 821 // called. |
| 822 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 822 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 823 .WillOnce( | 823 .WillOnce( |
| 824 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 824 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 825 SaveArg<1>(&write_remote_characteristic_success_callback_), | 825 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| 826 SaveArg<2>(&write_remote_characteristic_error_callback_))); | 826 SaveArg<2>(&write_remote_characteristic_error_callback_))); |
| 827 | 827 |
| 828 connection->SendMessage(base::WrapUnique(new FakeWireMessage(kLargeMessage))); | 828 connection->SendMessage(base::MakeUnique<FakeWireMessage>(kLargeMessage)); |
| 829 | 829 |
| 830 EXPECT_EQ(last_value_written_on_tx_characteristic_, kLargePackets0); | 830 EXPECT_EQ(last_value_written_on_tx_characteristic_, kLargePackets0); |
| 831 std::vector<uint8_t> bytes_received( | 831 std::vector<uint8_t> bytes_received( |
| 832 last_value_written_on_tx_characteristic_.begin() + 1, | 832 last_value_written_on_tx_characteristic_.begin() + 1, |
| 833 last_value_written_on_tx_characteristic_.end()); | 833 last_value_written_on_tx_characteristic_.end()); |
| 834 | 834 |
| 835 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 835 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 836 .WillOnce( | 836 .WillOnce( |
| 837 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 837 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 838 SaveArg<1>(&write_remote_characteristic_success_callback_), | 838 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 859 CreateConnection()); | 859 CreateConnection()); |
| 860 InitializeConnection(connection.get(), kDefaultMaxPacketSize); | 860 InitializeConnection(connection.get(), kDefaultMaxPacketSize); |
| 861 | 861 |
| 862 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 862 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 863 .Times(kMaxNumberOfTries) | 863 .Times(kMaxNumberOfTries) |
| 864 .WillRepeatedly( | 864 .WillRepeatedly( |
| 865 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 865 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 866 SaveArg<1>(&write_remote_characteristic_success_callback_), | 866 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| 867 SaveArg<2>(&write_remote_characteristic_error_callback_))); | 867 SaveArg<2>(&write_remote_characteristic_error_callback_))); |
| 868 | 868 |
| 869 connection->SendMessage(base::WrapUnique(new FakeWireMessage(kSmallMessage))); | 869 connection->SendMessage(base::MakeUnique<FakeWireMessage>(kSmallMessage)); |
| 870 | 870 |
| 871 for (int i = 0; i < kMaxNumberOfTries; i++) { | 871 for (int i = 0; i < kMaxNumberOfTries; i++) { |
| 872 EXPECT_EQ(last_value_written_on_tx_characteristic_, kSmallPackets0); | 872 EXPECT_EQ(last_value_written_on_tx_characteristic_, kSmallPackets0); |
| 873 ASSERT_FALSE(write_remote_characteristic_error_callback_.is_null()); | 873 ASSERT_FALSE(write_remote_characteristic_error_callback_.is_null()); |
| 874 EXPECT_FALSE(write_remote_characteristic_success_callback_.is_null()); | 874 EXPECT_FALSE(write_remote_characteristic_success_callback_.is_null()); |
| 875 write_remote_characteristic_error_callback_.Run( | 875 write_remote_characteristic_error_callback_.Run( |
| 876 device::BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); | 876 device::BluetoothRemoteGattService::GATT_ERROR_UNKNOWN); |
| 877 if (i == kMaxNumberOfTries - 1) { | 877 if (i == kMaxNumberOfTries - 1) { |
| 878 EXPECT_EQ(1, connection_observer_.GetNumSendCompleted()); | 878 EXPECT_EQ(1, connection_observer_.GetNumSendCompleted()); |
| 879 EXPECT_EQ(kSmallMessage, | 879 EXPECT_EQ(kSmallMessage, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 CreateConnection()); | 935 CreateConnection()); |
| 936 | 936 |
| 937 InitializeConnection(connection.get(), kLargeMaxPacketSize); | 937 InitializeConnection(connection.get(), kLargeMaxPacketSize); |
| 938 | 938 |
| 939 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 939 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 940 .WillOnce( | 940 .WillOnce( |
| 941 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 941 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 942 SaveArg<1>(&write_remote_characteristic_success_callback_), | 942 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| 943 SaveArg<2>(&write_remote_characteristic_error_callback_))); | 943 SaveArg<2>(&write_remote_characteristic_error_callback_))); |
| 944 | 944 |
| 945 connection->SendMessage(base::WrapUnique(new FakeWireMessage(kLargeMessage))); | 945 connection->SendMessage(base::MakeUnique<FakeWireMessage>(kLargeMessage)); |
| 946 | 946 |
| 947 connection->GattCharacteristicValueChanged( | 947 connection->GattCharacteristicValueChanged( |
| 948 adapter_.get(), rx_characteristic_.get(), kErroneousPacket); | 948 adapter_.get(), rx_characteristic_.get(), kErroneousPacket); |
| 949 | 949 |
| 950 EXPECT_EQ(last_value_written_on_tx_characteristic_, kLargePackets0); | 950 EXPECT_EQ(last_value_written_on_tx_characteristic_, kLargePackets0); |
| 951 | 951 |
| 952 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) | 952 EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) |
| 953 .WillOnce( | 953 .WillOnce( |
| 954 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), | 954 DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_), |
| 955 SaveArg<1>(&write_remote_characteristic_success_callback_), | 955 SaveArg<1>(&write_remote_characteristic_success_callback_), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); | 1029 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); |
| 1030 | 1030 |
| 1031 // Preparing |connection| to run |create_gatt_connection_success_callback_|. | 1031 // Preparing |connection| to run |create_gatt_connection_success_callback_|. |
| 1032 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) | 1032 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) |
| 1033 .WillOnce(DoAll( | 1033 .WillOnce(DoAll( |
| 1034 SaveArg<0>(&characteristics_finder_success_callback_), | 1034 SaveArg<0>(&characteristics_finder_success_callback_), |
| 1035 SaveArg<1>(&characteristics_finder_error_callback_), | 1035 SaveArg<1>(&characteristics_finder_error_callback_), |
| 1036 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); | 1036 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); |
| 1037 | 1037 |
| 1038 create_gatt_connection_success_callback_.Run( | 1038 create_gatt_connection_success_callback_.Run( |
| 1039 base::WrapUnique(new NiceMock<device::MockBluetoothGattConnection>( | 1039 base::MakeUnique<NiceMock<device::MockBluetoothGattConnection>>( |
| 1040 adapter_, kTestRemoteDeviceBluetoothAddress))); | 1040 adapter_, kTestRemoteDeviceBluetoothAddress)); |
| 1041 | 1041 |
| 1042 CharacteristicsFound(connection.get()); | 1042 CharacteristicsFound(connection.get()); |
| 1043 NotifySessionStarted(connection.get()); | 1043 NotifySessionStarted(connection.get()); |
| 1044 ConnectionResponseReceived(connection.get(), kDefaultMaxPacketSize); | 1044 ConnectionResponseReceived(connection.get(), kDefaultMaxPacketSize); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 } // namespace weave | 1047 } // namespace weave |
| 1048 | 1048 |
| 1049 } // namespace proximity_auth | 1049 } // namespace proximity_auth |
| OLD | NEW |