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

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

Issue 655143002: Use scoped_ptr::Pass instead of scoped_ptr::PassAs<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "components/proximity_auth/remote_device.h" 10 #include "components/proximity_auth/remote_device.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 TEST_F(ProximityAuthBluetoothConnectionTest, 399 TEST_F(ProximityAuthBluetoothConnectionTest,
400 SendMessage_SendsExpectedDataOverTheWire) { 400 SendMessage_SendsExpectedDataOverTheWire) {
401 // Create a connected connection. 401 // Create a connected connection.
402 StrictMock<MockBluetoothConnection> connection; 402 StrictMock<MockBluetoothConnection> connection;
403 Connect(&connection); 403 Connect(&connection);
404 404
405 scoped_refptr<net::IOBuffer> buffer; 405 scoped_refptr<net::IOBuffer> buffer;
406 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 406 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage);
407 EXPECT_CALL(*socket_, Send(_, kSerializedMessageLength, _, _)) 407 EXPECT_CALL(*socket_, Send(_, kSerializedMessageLength, _, _))
408 .WillOnce(SaveArg<0>(&buffer)); 408 .WillOnce(SaveArg<0>(&buffer));
409 connection.SendMessage(wire_message.PassAs<WireMessage>()); 409 connection.SendMessage(wire_message.Pass());
410 ASSERT_TRUE(buffer.get()); 410 ASSERT_TRUE(buffer.get());
411 EXPECT_EQ(kSerializedMessage, 411 EXPECT_EQ(kSerializedMessage,
412 std::string(buffer->data(), kSerializedMessageLength)); 412 std::string(buffer->data(), kSerializedMessageLength));
413 413
414 // The connection disconnects and unregisters as an observer upon destruction. 414 // The connection disconnects and unregisters as an observer upon destruction.
415 EXPECT_CALL(*socket_, Disconnect(_)); 415 EXPECT_CALL(*socket_, Disconnect(_));
416 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 416 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
417 } 417 }
418 418
419 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Success) { 419 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Success) {
420 // Create a connected connection. 420 // Create a connected connection.
421 StrictMock<MockBluetoothConnection> connection; 421 StrictMock<MockBluetoothConnection> connection;
422 Connect(&connection); 422 Connect(&connection);
423 423
424 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 424 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage);
425 // Ownership will be transfered below, so grab a reference here. 425 // Ownership will be transfered below, so grab a reference here.
426 TestWireMessage* expected_wire_message = wire_message.get(); 426 TestWireMessage* expected_wire_message = wire_message.get();
427 427
428 device::BluetoothSocket::SendCompletionCallback callback; 428 device::BluetoothSocket::SendCompletionCallback callback;
429 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<2>(&callback)); 429 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<2>(&callback));
430 connection.SendMessage(wire_message.PassAs<WireMessage>()); 430 connection.SendMessage(wire_message.Pass());
431 ASSERT_FALSE(callback.is_null()); 431 ASSERT_FALSE(callback.is_null());
432 432
433 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), true)); 433 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), true));
434 callback.Run(kSerializedMessageLength); 434 callback.Run(kSerializedMessageLength);
435 435
436 // The connection disconnects and unregisters as an observer upon destruction. 436 // The connection disconnects and unregisters as an observer upon destruction.
437 EXPECT_CALL(*socket_, Disconnect(_)); 437 EXPECT_CALL(*socket_, Disconnect(_));
438 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 438 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
439 } 439 }
440 440
441 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Failure) { 441 TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Failure) {
442 // Create a connected connection. 442 // Create a connected connection.
443 StrictMock<MockBluetoothConnection> connection; 443 StrictMock<MockBluetoothConnection> connection;
444 Connect(&connection); 444 Connect(&connection);
445 445
446 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage); 446 scoped_ptr<TestWireMessage> wire_message(new TestWireMessage);
447 // Ownership will be transfered below, so grab a reference here. 447 // Ownership will be transfered below, so grab a reference here.
448 TestWireMessage* expected_wire_message = wire_message.get(); 448 TestWireMessage* expected_wire_message = wire_message.get();
449 449
450 device::BluetoothSocket::ErrorCompletionCallback error_callback; 450 device::BluetoothSocket::ErrorCompletionCallback error_callback;
451 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<3>(&error_callback)); 451 EXPECT_CALL(*socket_, Send(_, _, _, _)).WillOnce(SaveArg<3>(&error_callback));
452 connection.SendMessage(wire_message.PassAs<WireMessage>()); 452 connection.SendMessage(wire_message.Pass());
453 453
454 ASSERT_FALSE(error_callback.is_null()); 454 ASSERT_FALSE(error_callback.is_null());
455 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), false)); 455 EXPECT_CALL(connection, OnDidSendMessage(Ref(*expected_wire_message), false));
456 EXPECT_CALL(connection, SetStatusProxy(Connection::DISCONNECTED)); 456 EXPECT_CALL(connection, SetStatusProxy(Connection::DISCONNECTED));
457 EXPECT_CALL(*socket_, Disconnect(_)); 457 EXPECT_CALL(*socket_, Disconnect(_));
458 EXPECT_CALL(*adapter_, RemoveObserver(&connection)); 458 EXPECT_CALL(*adapter_, RemoveObserver(&connection));
459 error_callback.Run("The most helpful of error messages"); 459 error_callback.Run("The most helpful of error messages");
460 } 460 }
461 461
462 } // namespace proximity_auth 462 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/policy/core/common/registry_dict_win.cc ('k') | components/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698