Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc

Issue 2250023005: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 remote_device_(CreateLERemoteDeviceForTest()), 132 remote_device_(CreateLERemoteDeviceForTest()),
133 service_uuid_(device::BluetoothUUID(kServiceUUID)), 133 service_uuid_(device::BluetoothUUID(kServiceUUID)),
134 to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)), 134 to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)),
135 from_peripheral_char_uuid_( 135 from_peripheral_char_uuid_(
136 device::BluetoothUUID(kFromPeripheralCharUUID)), 136 device::BluetoothUUID(kFromPeripheralCharUUID)),
137 notify_session_alias_(NULL), 137 notify_session_alias_(NULL),
138 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>), 138 bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>),
139 task_runner_(new base::TestSimpleTaskRunner) {} 139 task_runner_(new base::TestSimpleTaskRunner) {}
140 140
141 void SetUp() override { 141 void SetUp() override {
142 device_ = base::WrapUnique(new NiceMock<device::MockBluetoothDevice>( 142 device_ = base::MakeUnique<NiceMock<device::MockBluetoothDevice>>(
143 adapter_.get(), 0, kTestRemoteDeviceName, 143 adapter_.get(), 0, kTestRemoteDeviceName,
144 kTestRemoteDeviceBluetoothAddress, false, false)); 144 kTestRemoteDeviceBluetoothAddress, false, false);
145 145
146 service_ = base::WrapUnique(new NiceMock<device::MockBluetoothGattService>( 146 service_ = base::MakeUnique<NiceMock<device::MockBluetoothGattService>>(
147 device_.get(), kServiceID, service_uuid_, true, false)); 147 device_.get(), kServiceID, service_uuid_, true, false);
148 to_peripheral_char_ = 148 to_peripheral_char_ =
149 base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( 149 base::MakeUnique<NiceMock<device::MockBluetoothGattCharacteristic>>(
150 service_.get(), kToPeripheralCharID, to_peripheral_char_uuid_, 150 service_.get(), kToPeripheralCharID, to_peripheral_char_uuid_,
151 false, kCharacteristicProperties, 151 false, kCharacteristicProperties,
152 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); 152 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE);
153 153
154 from_peripheral_char_ = 154 from_peripheral_char_ =
155 base::WrapUnique(new NiceMock<device::MockBluetoothGattCharacteristic>( 155 base::MakeUnique<NiceMock<device::MockBluetoothGattCharacteristic>>(
156 service_.get(), kFromPeripheralCharID, from_peripheral_char_uuid_, 156 service_.get(), kFromPeripheralCharID, from_peripheral_char_uuid_,
157 false, kCharacteristicProperties, 157 false, kCharacteristicProperties,
158 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); 158 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE);
159 159
160 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); 160 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_);
161 161
162 std::vector<const device::BluetoothDevice*> devices; 162 std::vector<const device::BluetoothDevice*> devices;
163 devices.push_back(device_.get()); 163 devices.push_back(device_.get());
164 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); 164 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices));
165 ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress)) 165 ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
166 .WillByDefault(Return(device_.get())); 166 .WillByDefault(Return(device_.get()));
167 ON_CALL(*device_, GetGattService(kServiceID)) 167 ON_CALL(*device_, GetGattService(kServiceID))
168 .WillByDefault(Return(service_.get())); 168 .WillByDefault(Return(service_.get()));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Preparing |connection| to run |create_gatt_connection_success_callback_|. 213 // Preparing |connection| to run |create_gatt_connection_success_callback_|.
214 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); 214 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null());
215 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); 215 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null());
216 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) 216 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _))
217 .WillOnce(DoAll( 217 .WillOnce(DoAll(
218 SaveArg<0>(&characteristics_finder_success_callback_), 218 SaveArg<0>(&characteristics_finder_success_callback_),
219 SaveArg<1>(&characteristics_finder_error_callback_), 219 SaveArg<1>(&characteristics_finder_error_callback_),
220 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); 220 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>)));
221 221
222 create_gatt_connection_success_callback_.Run( 222 create_gatt_connection_success_callback_.Run(
223 base::WrapUnique(new NiceMock<device::MockBluetoothGattConnection>( 223 base::MakeUnique<NiceMock<device::MockBluetoothGattConnection>>(
224 adapter_, kTestRemoteDeviceBluetoothAddress))); 224 adapter_, kTestRemoteDeviceBluetoothAddress));
225 225
226 EXPECT_EQ(connection->sub_status(), 226 EXPECT_EQ(connection->sub_status(),
227 BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS); 227 BluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS);
228 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); 228 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
229 } 229 }
230 230
231 // Transitions |connection| from WAITING_CHARACTERISTICS to 231 // Transitions |connection| from WAITING_CHARACTERISTICS to
232 // WAITING_NOTIFY_SESSION state. 232 // WAITING_NOTIFY_SESSION state.
233 void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) { 233 void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) {
234 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)) 234 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _))
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) 591 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _))
592 .WillOnce( 592 .WillOnce(
593 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), 593 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_),
594 SaveArg<1>(&write_remote_characteristic_success_callback_), 594 SaveArg<1>(&write_remote_characteristic_success_callback_),
595 SaveArg<2>(&write_remote_characteristic_error_callback_))); 595 SaveArg<2>(&write_remote_characteristic_error_callback_)));
596 596
597 // Message (bytes) that is going to be sent. 597 // Message (bytes) that is going to be sent.
598 int message_size = 100; 598 int message_size = 100;
599 std::string message(message_size, 'A'); 599 std::string message(message_size, 'A');
600 message[0] = 'B'; 600 message[0] = 'B';
601 connection->SendMessage(base::WrapUnique(new FakeWireMessage(message))); 601 connection->SendMessage(base::MakeUnique<FakeWireMessage>(message));
602 602
603 // Expecting that |kSendSignal| + |message_size| + |message| was written. 603 // Expecting that |kSendSignal| + |message_size| + |message| was written.
604 EXPECT_EQ(last_value_written_on_to_peripheral_char_, 604 EXPECT_EQ(last_value_written_on_to_peripheral_char_,
605 CreateFirstCharacteristicValue(message, message.size())); 605 CreateFirstCharacteristicValue(message, message.size()));
606 EXPECT_CALL(*connection, OnDidSendMessage(_, _)); 606 EXPECT_CALL(*connection, OnDidSendMessage(_, _));
607 607
608 RunWriteCharacteristicSuccessCallback(); 608 RunWriteCharacteristicSuccessCallback();
609 } 609 }
610 610
611 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest, 611 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
612 SendMessage_LagerThanCharacteristicSize) { 612 SendMessage_LagerThanCharacteristicSize) {
613 std::unique_ptr<MockBluetoothLowEnergyConnection> connection( 613 std::unique_ptr<MockBluetoothLowEnergyConnection> connection(
614 CreateConnection()); 614 CreateConnection());
615 InitializeConnection(connection.get()); 615 InitializeConnection(connection.get());
616 616
617 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is 617 // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is
618 // called. 618 // called.
619 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _)) 619 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _))
620 .WillOnce( 620 .WillOnce(
621 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_), 621 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_),
622 SaveArg<1>(&write_remote_characteristic_success_callback_), 622 SaveArg<1>(&write_remote_characteristic_success_callback_),
623 SaveArg<2>(&write_remote_characteristic_error_callback_))); 623 SaveArg<2>(&write_remote_characteristic_error_callback_)));
624 624
625 // Message (bytes) that is going to be sent. 625 // Message (bytes) that is going to be sent.
626 int message_size = 600; 626 int message_size = 600;
627 std::string message(message_size, 'A'); 627 std::string message(message_size, 'A');
628 message[0] = 'B'; 628 message[0] = 'B';
629 connection->SendMessage(base::WrapUnique(new FakeWireMessage(message))); 629 connection->SendMessage(base::MakeUnique<FakeWireMessage>(message));
630 630
631 // Expecting that |kSendSignal| + |message_size| was written in the first 8 631 // Expecting that |kSendSignal| + |message_size| was written in the first 8
632 // bytes. 632 // bytes.
633 std::vector<uint8_t> prefix( 633 std::vector<uint8_t> prefix(
634 last_value_written_on_to_peripheral_char_.begin(), 634 last_value_written_on_to_peripheral_char_.begin(),
635 last_value_written_on_to_peripheral_char_.begin() + 8); 635 last_value_written_on_to_peripheral_char_.begin() + 8);
636 EXPECT_EQ(prefix, CreateSendSignalWithSize(message_size)); 636 EXPECT_EQ(prefix, CreateSendSignalWithSize(message_size));
637 std::vector<uint8_t> bytes_received( 637 std::vector<uint8_t> bytes_received(
638 last_value_written_on_to_peripheral_char_.begin() + 8, 638 last_value_written_on_to_peripheral_char_.begin() + 8,
639 last_value_written_on_to_peripheral_char_.end()); 639 last_value_written_on_to_peripheral_char_.end());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null()); 685 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null());
686 686
687 // Preparing |connection| to run |create_gatt_connection_success_callback_|. 687 // Preparing |connection| to run |create_gatt_connection_success_callback_|.
688 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _)) 688 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _))
689 .WillOnce(DoAll( 689 .WillOnce(DoAll(
690 SaveArg<0>(&characteristics_finder_success_callback_), 690 SaveArg<0>(&characteristics_finder_success_callback_),
691 SaveArg<1>(&characteristics_finder_error_callback_), 691 SaveArg<1>(&characteristics_finder_error_callback_),
692 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>))); 692 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>)));
693 693
694 create_gatt_connection_success_callback_.Run( 694 create_gatt_connection_success_callback_.Run(
695 base::WrapUnique(new NiceMock<device::MockBluetoothGattConnection>( 695 base::MakeUnique<NiceMock<device::MockBluetoothGattConnection>>(
696 adapter_, kTestRemoteDeviceBluetoothAddress))); 696 adapter_, kTestRemoteDeviceBluetoothAddress));
697 697
698 CharacteristicsFound(connection.get()); 698 CharacteristicsFound(connection.get());
699 NotifySessionStarted(connection.get()); 699 NotifySessionStarted(connection.get());
700 ResponseSignalReceived(connection.get()); 700 ResponseSignalReceived(connection.get());
701 } 701 }
702 702
703 } // namespace proximity_auth 703 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698