Commit 274542fe authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

CryptAuth: Make Connection::Status enum class.

For compiler protection in switch statements, etc.

R=khorimoto@chromium.org

Bug: none
Test: none
Change-Id: Icf86013c87d89b233d6bc27646bad8f79830af6e
Reviewed-on: https://chromium-review.googlesource.com/1043098
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555895}
parent eba6af48
......@@ -24,11 +24,11 @@ const char kEasyUnlockFeatureName[] = "easy_unlock";
api::easy_unlock_private::ConnectionStatus ToApiConnectionStatus(
Connection::Status status) {
switch (status) {
case Connection::DISCONNECTED:
case Connection::Status::DISCONNECTED:
return api::easy_unlock_private::CONNECTION_STATUS_DISCONNECTED;
case Connection::IN_PROGRESS:
case Connection::Status::IN_PROGRESS:
return api::easy_unlock_private::CONNECTION_STATUS_IN_PROGRESS;
case Connection::CONNECTED:
case Connection::Status::CONNECTED:
return api::easy_unlock_private::CONNECTION_STATUS_CONNECTED;
}
return api::easy_unlock_private::CONNECTION_STATUS_NONE;
......
......@@ -251,7 +251,7 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged(
FROM_HERE,
base::BindOnce(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync,
weak_ptr_factory_.GetWeakPtr()));
} else if (old_status == cryptauth::Connection::IN_PROGRESS) {
} else if (old_status == cryptauth::Connection::Status::IN_PROGRESS) {
PA_LOG(WARNING) << "Connection failed. Retrying.";
connection_->RemoveObserver(this);
connection_.reset();
......
......@@ -322,8 +322,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Creating a connection.
base::RunLoop run_loop;
EXPECT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED);
connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle();
EXPECT_TRUE(last_found_connection_);
}
......@@ -341,7 +341,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Trying to create a connection.
connection_finder_.DeviceAdded(adapter_.get(), device_.get());
ASSERT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
// Preparing to restart the discovery session.
device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
......@@ -353,7 +353,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Connection fails.
{
base::RunLoop run_loop;
connection->SetStatus(cryptauth::Connection::DISCONNECTED);
connection->SetStatus(cryptauth::Connection::Status::DISCONNECTED);
run_loop.RunUntilIdle();
}
......@@ -375,8 +375,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
{
base::RunLoop run_loop;
EXPECT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED);
connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle();
}
EXPECT_TRUE(last_found_connection_);
......@@ -426,8 +426,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Completing the connection.
base::RunLoop run_loop;
ASSERT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED);
connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle();
EXPECT_TRUE(last_found_connection_);
}
......
......@@ -271,7 +271,7 @@ void MessengerImpl::OnConnectionStatusChanged(
cryptauth::Connection::Status old_status,
cryptauth::Connection::Status new_status) {
DCHECK_EQ(connection, connection_.get());
if (new_status == cryptauth::Connection::DISCONNECTED) {
if (new_status == cryptauth::Connection::Status::DISCONNECTED) {
PA_LOG(INFO) << "Secure channel disconnected...";
connection_->RemoveObserver(this);
for (auto& observer : observers_)
......
......@@ -405,7 +405,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
mock_bluetooth_device_.get(), should_set_low_connection_latency));
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
// Add the mock observer to observe on OnDidMessageSend.
connection_observer_ =
......@@ -445,14 +445,14 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
// Handle setting the connection latency.
EXPECT_EQ(connection->sub_status(),
SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null());
connection_latency_callback_.Run();
}
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Preparing |connection| to run |create_gatt_connection_success_callback_|.
EXPECT_FALSE(create_gatt_connection_error_callback_.is_null());
......@@ -468,7 +468,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
adapter_, kTestRemoteDeviceBluetoothAddress));
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
}
// Transitions |connection| from WAITING_CHARACTERISTICS to
......@@ -487,7 +487,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
{rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
}
// Transitions |connection| from WAITING_NOTIFY_SESSION to
......@@ -516,7 +516,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
EXPECT_EQ(last_value_written_on_tx_characteristic_, kConnectionRequest);
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_RESPONSE);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
}
// Transitions |connection| from WAITING_CONNECTION_RESPONSE to CONNECTED.
......@@ -547,7 +547,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
}
EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_IDLE);
EXPECT_EQ(connection->status(), Connection::CONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::CONNECTED);
}
// Transitions |connection| to a DISCONNECTED state regardless of its initial
......@@ -570,7 +570,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
}
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
}
void DeleteConnectionWithoutCallingDisconnect(
......@@ -775,7 +775,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
BLE_WEAVE_CONNECTION_RESULT_CLOSED_NORMALLY);
......@@ -849,7 +849,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
{rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult(
......@@ -876,7 +876,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
{rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult(
......@@ -901,7 +901,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
VerifyGattNotifySessionResult(false);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -940,7 +940,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
}
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1112,7 +1112,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
}
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1130,7 +1130,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(receiver_->GetReasonForClose(), ReasonForClose::UNKNOWN_ERROR);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1160,7 +1160,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 2 /* num_writes */);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1204,7 +1204,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 3 /* num_writes */);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1320,7 +1320,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
}
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1344,7 +1344,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// No GATT connection should be created before the delay.
connection->Connect();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
EXPECT_TRUE(create_gatt_connection_error_callback_.is_null());
EXPECT_TRUE(create_gatt_connection_success_callback_.is_null());
......@@ -1439,7 +1439,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// Call Connect(), which should set the connection latency.
connection->Connect();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null());
......@@ -1447,7 +1447,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1474,19 +1474,19 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// Handle setting the connection latency.
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null());
connection_latency_callback_.Run();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout.
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1499,13 +1499,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
CreateConnection(true /* should_set_low_connection_latency */));
ConnectGatt(connection.get());
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout.
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult(
......@@ -1520,13 +1520,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
ConnectGatt(connection.get());
CharacteristicsFound(connection.get());
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout.
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1545,7 +1545,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......@@ -1569,7 +1569,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......
......@@ -16,13 +16,13 @@ namespace cryptauth {
Connection::Connection(const RemoteDevice& remote_device)
: remote_device_(remote_device),
status_(DISCONNECTED),
status_(Status::DISCONNECTED),
is_sending_message_(false) {}
Connection::~Connection() {}
bool Connection::IsConnected() const {
return status_ == CONNECTED;
return status_ == Status::CONNECTED;
}
void Connection::SendMessage(std::unique_ptr<WireMessage> message) {
......
......@@ -22,7 +22,7 @@ class WireMessage;
// persistent bidirectional channel for sending and receiving wire messages.
class Connection {
public:
enum Status {
enum class Status {
DISCONNECTED,
IN_PROGRESS,
CONNECTED,
......
......@@ -101,19 +101,19 @@ TEST(CryptAuthConnectionTest, IsConnected) {
StrictMock<MockConnection> connection;
EXPECT_FALSE(connection.IsConnected());
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
EXPECT_TRUE(connection.IsConnected());
connection.SetStatus(Connection::DISCONNECTED);
connection.SetStatus(Connection::Status::DISCONNECTED);
EXPECT_FALSE(connection.IsConnected());
connection.SetStatus(Connection::IN_PROGRESS);
connection.SetStatus(Connection::Status::IN_PROGRESS);
EXPECT_FALSE(connection.IsConnected());
}
TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) {
StrictMock<MockConnection> connection;
connection.SetStatus(Connection::IN_PROGRESS);
connection.SetStatus(Connection::Status::IN_PROGRESS);
EXPECT_CALL(connection, GetDeviceAddress()).Times(1);
EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0);
......@@ -123,7 +123,7 @@ TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) {
TEST(CryptAuthConnectionTest,
SendMessage_FailsWhenAnotherMessageSendIsInProgress) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>());
EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0);
......@@ -132,7 +132,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) {
StrictMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
EXPECT_CALL(connection, SendMessageImplProxy(_));
connection.SendMessage(std::unique_ptr<WireMessage>());
......@@ -141,7 +141,7 @@ TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) {
TEST(CryptAuthConnectionTest,
SendMessage_SucceedsAfterPreviousMessageSendCompletes) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>());
connection.OnDidSendMessage(TestWireMessage(), true /* success */);
......@@ -151,33 +151,33 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, SetStatus_NotifiesObserversOfStatusChange) {
StrictMock<MockConnection> connection;
EXPECT_EQ(Connection::DISCONNECTED, connection.status());
EXPECT_EQ(Connection::Status::DISCONNECTED, connection.status());
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
EXPECT_CALL(observer,
OnConnectionStatusChanged(&connection, Connection::DISCONNECTED,
Connection::CONNECTED));
connection.SetStatus(Connection::CONNECTED);
EXPECT_CALL(observer, OnConnectionStatusChanged(
&connection, Connection::Status::DISCONNECTED,
Connection::Status::CONNECTED));
connection.SetStatus(Connection::Status::CONNECTED);
}
TEST(CryptAuthConnectionTest,
SetStatus_DoesntNotifyObserversIfStatusUnchanged) {
StrictMock<MockConnection> connection;
EXPECT_EQ(Connection::DISCONNECTED, connection.status());
EXPECT_EQ(Connection::Status::DISCONNECTED, connection.status());
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
EXPECT_CALL(observer, OnConnectionStatusChanged(_, _, _)).Times(0);
connection.SetStatus(Connection::DISCONNECTED);
connection.SetStatus(Connection::Status::DISCONNECTED);
}
TEST(CryptAuthConnectionTest,
OnDidSendMessage_NotifiesObserversIfMessageSendInProgress) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>());
StrictMock<MockConnectionObserver> observer;
......@@ -190,7 +190,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest,
OnDidSendMessage_DoesntNotifyObserversIfNoMessageSendInProgress) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
......@@ -202,7 +202,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest,
OnBytesReceived_NotifiesObserversOnValidMessage) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
......@@ -217,7 +217,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfNotConnected) {
StrictMock<MockConnection> connection;
connection.SetStatus(Connection::IN_PROGRESS);
connection.SetStatus(Connection::Status::IN_PROGRESS);
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
......@@ -230,7 +230,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfMessageIsIncomplete) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
......@@ -244,7 +244,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfMessageIsInvalid) {
NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED);
connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
......
......@@ -224,7 +224,7 @@ void DeviceToDeviceAuthenticator::OnConnectionStatusChanged(
Connection::Status old_status,
Connection::Status new_status) {
// We do not expect the connection to drop during authentication.
if (new_status == Connection::DISCONNECTED) {
if (new_status == Connection::Status::DISCONNECTED) {
Fail("Disconnected while authentication is in progress",
Result::DISCONNECTED);
}
......
......@@ -28,14 +28,14 @@ FakeConnection::~FakeConnection() {
void FakeConnection::Connect() {
if (should_auto_connect_) {
SetStatus(CONNECTED);
SetStatus(Status::CONNECTED);
} else {
SetStatus(IN_PROGRESS);
SetStatus(Status::IN_PROGRESS);
}
}
void FakeConnection::Disconnect() {
SetStatus(DISCONNECTED);
SetStatus(Status::DISCONNECTED);
}
std::string FakeConnection::GetDeviceAddress() {
......@@ -56,12 +56,12 @@ void FakeConnection::RemoveObserver(ConnectionObserver* observer) {
void FakeConnection::CompleteInProgressConnection(bool success) {
DCHECK(!should_auto_connect_);
DCHECK(status() == IN_PROGRESS);
DCHECK(status() == Status::IN_PROGRESS);
if (success) {
SetStatus(CONNECTED);
SetStatus(Status::CONNECTED);
} else {
SetStatus(DISCONNECTED);
SetStatus(Status::DISCONNECTED);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment