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

Unified Diff: components/proximity_auth/bluetooth_connection_unittest.cc

Issue 1359043005: Fix BluetoothConnection to disconnect when the underlying device disconnects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proximity_auth_system2
Patch Set: fix test Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/proximity_auth/bluetooth_connection.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/proximity_auth/bluetooth_connection_unittest.cc
diff --git a/components/proximity_auth/bluetooth_connection_unittest.cc b/components/proximity_auth/bluetooth_connection_unittest.cc
index c298a8fe0dd8649334ae43885579e1df2493d7b3..ea93f93ac5449ad9c76ddedefb2a30df79cef193 100644
--- a/components/proximity_auth/bluetooth_connection_unittest.cc
+++ b/components/proximity_auth/bluetooth_connection_unittest.cc
@@ -73,6 +73,7 @@ class MockBluetoothConnection : public BluetoothConnection {
using BluetoothConnection::status;
using BluetoothConnection::Connect;
+ using BluetoothConnection::DeviceChanged;
using BluetoothConnection::DeviceRemoved;
using BluetoothConnection::Disconnect;
@@ -114,6 +115,7 @@ class ProximityAuthBluetoothConnectionTest : public testing::Test {
// Transition the connection into an in-progress state.
void BeginConnecting(MockBluetoothConnection* connection) {
EXPECT_EQ(Connection::DISCONNECTED, connection->status());
+ ON_CALL(device_, IsConnected()).WillByDefault(Return(false));
ON_CALL(*adapter_, GetDevice(_)).WillByDefault(Return(&device_));
EXPECT_CALL(*connection, SetStatusProxy(Connection::IN_PROGRESS));
@@ -146,6 +148,7 @@ class ProximityAuthBluetoothConnectionTest : public testing::Test {
callback.Run(socket_);
EXPECT_EQ(Connection::CONNECTED, connection->status());
+ ON_CALL(device_, IsConnected()).WillByDefault(Return(true));
}
device::BluetoothSocket::ReceiveCompletionCallback* receive_callback() {
@@ -456,4 +459,33 @@ TEST_F(ProximityAuthBluetoothConnectionTest, SendMessage_Failure) {
error_callback.Run("The most helpful of error messages");
}
+TEST_F(ProximityAuthBluetoothConnectionTest, DeviceChanged_Disconnected) {
+ // Create a connected connection.
+ StrictMock<MockBluetoothConnection> connection;
+ Connect(&connection);
+ EXPECT_TRUE(connection.IsConnected());
+
+ // If the remote device disconnects, |connection| should also disconnect.
+ ON_CALL(device_, IsConnected()).WillByDefault(Return(false));
+ EXPECT_CALL(connection, SetStatusProxy(Connection::DISCONNECTED));
+ EXPECT_CALL(*socket_, Disconnect(_));
+ EXPECT_CALL(*adapter_, RemoveObserver(&connection));
+ connection.DeviceChanged(adapter_.get(), &device_);
+ EXPECT_FALSE(connection.IsConnected());
+}
+
+TEST_F(ProximityAuthBluetoothConnectionTest, DeviceChanged_NotDisconnected) {
+ // Nothing should happen if DeviceChanged is called, but the remote device is
+ // not disconnected.
+ StrictMock<MockBluetoothConnection> connection;
+ Connect(&connection);
+ EXPECT_TRUE(connection.IsConnected());
+ connection.DeviceChanged(adapter_.get(), &device_);
+ EXPECT_TRUE(connection.IsConnected());
+
+ // The connection disconnects and unregisters as an observer upon destruction.
+ EXPECT_CALL(*socket_, Disconnect(_));
+ EXPECT_CALL(*adapter_, RemoveObserver(&connection));
+}
+
} // namespace proximity_auth
« no previous file with comments | « components/proximity_auth/bluetooth_connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698