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

Side by Side Diff: components/proximity_auth/bluetooth_connection_unittest.cc

Issue 1912433002: Convert //components/proximity_auth from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bluetooth_connection.h" 5 #include "components/proximity_auth/bluetooth_connection.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 callback.Run(socket_); 393 callback.Run(socket_);
394 } 394 }
395 395
396 TEST_F(ProximityAuthBluetoothConnectionTest, 396 TEST_F(ProximityAuthBluetoothConnectionTest,
397 SendMessage_SendsExpectedDataOverTheWire) { 397 SendMessage_SendsExpectedDataOverTheWire) {
398 // Create a connected connection. 398 // Create a connected connection.
399 StrictMock<MockBluetoothConnection> connection; 399 StrictMock<MockBluetoothConnection> connection;
400 Connect(&connection); 400 Connect(&connection);
401 401
402 scoped_refptr<net::IOBuffer> buffer; 402 scoped_refptr<net::IOBuffer> buffer;
403 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 403 std::unique_ptr<TestWireMessage> wire_message(new TestWireMessage);
404 EXPECT_CALL(*socket_, Send(_, kSerializedMessageLength, _, _)) 404 EXPECT_CALL(*socket_, Send(_, kSerializedMessageLength, _, _))
405 .WillOnce(SaveArg<0>(&buffer)); 405 .WillOnce(SaveArg<0>(&buffer));
406 connection.SendMessage(std::move(wire_message)); 406 connection.SendMessage(std::move(wire_message));
407 ASSERT_TRUE(buffer.get()); 407 ASSERT_TRUE(buffer.get());
408 EXPECT_EQ(kSerializedMessage, 408 EXPECT_EQ(kSerializedMessage,
409 std::string(buffer->data(), kSerializedMessageLength)); 409 std::string(buffer->data(), kSerializedMessageLength));
410 410
411 // The connection disconnects and unregisters as an observer upon destruction. 411 // The connection disconnects and unregisters as an observer upon destruction.
412 EXPECT_CALL(*socket_, Disconnect(_)); 412 EXPECT_CALL(*socket_, Disconnect(_));
413 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 413 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
414 } 414 }
415 415
416 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Success) { 416 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Success) {
417 // Create a connected connection. 417 // Create a connected connection.
418 StrictMock<MockBluetoothConnection> connection; 418 StrictMock<MockBluetoothConnection> connection;
419 Connect(&connection); 419 Connect(&connection);
420 420
421 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 421 std::unique_ptr<TestWireMessage> wire_message(new TestWireMessage);
422 // Ownership will be transfered below, so grab a reference here. 422 // Ownership will be transfered below, so grab a reference here.
423 TestWireMessage* expected_wire_message = wire_message.get(); 423 TestWireMessage* expected_wire_message = wire_message.get();
424 424
425 device::BluetoothSocket::SendCompletionCallback callback; 425 device::BluetoothSocket::SendCompletionCallback callback;
426 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<2>(&callback)); 426 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<2>(&callback));
427 connection.SendMessage(std::move(wire_message)); 427 connection.SendMessage(std::move(wire_message));
428 ASSERT_FALSE(callback.is_null()); 428 ASSERT_FALSE(callback.is_null());
429 429
430 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), true)); 430 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), true));
431 callback.Run(kSerializedMessageLength); 431 callback.Run(kSerializedMessageLength);
432 432
433 // The connection disconnects and unregisters as an observer upon destruction. 433 // The connection disconnects and unregisters as an observer upon destruction.
434 EXPECT_CALL(*socket_, Disconnect(_)); 434 EXPECT_CALL(*socket_, Disconnect(_));
435 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 435 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
436 } 436 }
437 437
438 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Failure) { 438 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Failure) {
439 // Create a connected connection. 439 // Create a connected connection.
440 StrictMock<MockBluetoothConnection> connection; 440 StrictMock<MockBluetoothConnection> connection;
441 Connect(&connection); 441 Connect(&connection);
442 442
443 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 443 std::unique_ptr<TestWireMessage> wire_message(new TestWireMessage);
444 // Ownership will be transfered below, so grab a reference here. 444 // Ownership will be transfered below, so grab a reference here.
445 TestWireMessage* expected_wire_message = wire_message.get(); 445 TestWireMessage* expected_wire_message = wire_message.get();
446 446
447 device::BluetoothSocket::ErrorCompletionCallback error_callback; 447 device::BluetoothSocket::ErrorCompletionCallback error_callback;
448 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<3>(&error_callback)); 448 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<3>(&error_callback));
449 connection.SendMessage(std::move(wire_message)); 449 connection.SendMessage(std::move(wire_message));
450 450
451 ASSERT_FALSE(error_callback.is_null()); 451 ASSERT_FALSE(error_callback.is_null());
452 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), false)); 452 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), false));
453 EXPECT_CALL(connection, SetStatusProxy(Connection::DISCONNECTED)); 453 EXPECT_CALL(connection, SetStatusProxy(Connection::DISCONNECTED));
(...skipping 25 matching lines...) Expand all
479 EXPECT_TRUE(connection.IsConnected()); 479 EXPECT_TRUE(connection.IsConnected());
480 connection.DeviceChanged(adapter_.get(), &device_); 480 connection.DeviceChanged(adapter_.get(), &device_);
481 EXPECT_TRUE(connection.IsConnected()); 481 EXPECT_TRUE(connection.IsConnected());
482 482
483 // The connection disconnects and unregisters as an observer upon destruction. 483 // The connection disconnects and unregisters as an observer upon destruction.
484 EXPECT_CALL(*socket_, Disconnect(_)); 484 EXPECT_CALL(*socket_, Disconnect(_));
485 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 485 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
486 } 486 }
487 487
488 } // namespace proximity_auth 488 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698