Index: components/proximity_auth/unlock_manager_impl_unittest.cc |
diff --git a/components/proximity_auth/unlock_manager_impl_unittest.cc b/components/proximity_auth/unlock_manager_impl_unittest.cc |
index 6dec288b185cec37f015920ef043725e22be7048..004ae9d8024de72811c8a0e0f8eb0410c3d5f8c5 100644 |
--- a/components/proximity_auth/unlock_manager_impl_unittest.cc |
+++ b/components/proximity_auth/unlock_manager_impl_unittest.cc |
@@ -13,9 +13,11 @@ |
#include "base/threading/thread_task_runner_handle.h" |
#include "build/build_config.h" |
#include "components/cryptauth/cryptauth_test_util.h" |
+#include "components/cryptauth/fake_connection.h" |
#include "components/cryptauth/fake_secure_context.h" |
#include "components/cryptauth/secure_context.h" |
#include "components/proximity_auth/fake_lock_handler.h" |
+#include "components/proximity_auth/fake_remote_device_life_cycle.h" |
#include "components/proximity_auth/logging/logging.h" |
#include "components/proximity_auth/messenger.h" |
#include "components/proximity_auth/mock_proximity_auth_client.h" |
@@ -66,6 +68,7 @@ class MockRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle { |
MOCK_CONST_METHOD0(GetRemoteDevice, cryptauth::RemoteDevice()); |
MOCK_CONST_METHOD0(GetState, State()); |
MOCK_METHOD0(GetMessenger, Messenger*()); |
+ MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*()); |
MOCK_METHOD1(AddObserver, void(Observer*)); |
MOCK_METHOD1(RemoveObserver, void(Observer*)); |
}; |
@@ -82,6 +85,7 @@ class MockMessenger : public Messenger { |
MOCK_METHOD1(RequestDecryption, void(const std::string& challenge)); |
MOCK_METHOD0(RequestUnlock, void()); |
MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*()); |
+ MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*()); |
private: |
DISALLOW_COPY_AND_ASSIGN(MockMessenger); |
@@ -89,24 +93,25 @@ class MockMessenger : public Messenger { |
class MockProximityMonitor : public ProximityMonitor { |
public: |
- MockProximityMonitor() { |
- ON_CALL(*this, GetStrategy()) |
- .WillByDefault(Return(ProximityMonitor::Strategy::NONE)); |
+ MockProximityMonitor() : started_(false), stopped_(false) { |
ON_CALL(*this, IsUnlockAllowed()).WillByDefault(Return(true)); |
- ON_CALL(*this, IsInRssiRange()).WillByDefault(Return(false)); |
} |
~MockProximityMonitor() override {} |
- MOCK_METHOD0(Start, void()); |
- MOCK_METHOD0(Stop, void()); |
- MOCK_CONST_METHOD0(GetStrategy, Strategy()); |
+ void Start() override { started_ = true; } |
+ void Stop() override { stopped_ = true; } |
MOCK_CONST_METHOD0(IsUnlockAllowed, bool()); |
- MOCK_CONST_METHOD0(IsInRssiRange, bool()); |
MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void()); |
MOCK_METHOD1(AddObserver, void(ProximityMonitorObserver*)); |
MOCK_METHOD1(RemoveObserver, void(ProximityMonitorObserver*)); |
+ bool started() { return started_; } |
+ bool stopped() { return stopped_; } |
+ |
private: |
+ bool started_; |
+ bool stopped_; |
+ |
DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor); |
}; |
@@ -132,8 +137,9 @@ class TestUnlockManager : public UnlockManagerImpl { |
private: |
std::unique_ptr<ProximityMonitor> CreateProximityMonitor( |
- const cryptauth::RemoteDevice& remote_device) override { |
- EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey, remote_device.public_key); |
+ cryptauth::Connection* connection) override { |
+ EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey, |
+ connection->remote_device().public_key); |
std::unique_ptr<MockProximityMonitor> proximity_monitor( |
new NiceMock<MockProximityMonitor>()); |
proximity_monitor_ = proximity_monitor.get(); |
@@ -162,17 +168,18 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test { |
public: |
ProximityAuthUnlockManagerImplTest() |
: remote_device_(cryptauth::CreateClassicRemoteDeviceForTest()), |
+ life_cycle_(remote_device_), |
+ connection_(remote_device_), |
bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), |
task_runner_(new base::TestSimpleTaskRunner()), |
thread_task_runner_handle_(task_runner_) { |
ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true)); |
- ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(&messenger_)); |
- ON_CALL(life_cycle_, GetRemoteDevice()) |
- .WillByDefault(Return(remote_device_)); |
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
ON_CALL(messenger_, GetSecureContext()) |
.WillByDefault(Return(&secure_context_)); |
+ life_cycle_.set_connection(&connection_); |
+ life_cycle_.set_messenger(&messenger_); |
ScreenlockBridge::Get()->SetLockHandler(&lock_handler_); |
#if defined(OS_CHROMEOS) |
@@ -207,15 +214,10 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test { |
} |
void SimulateUserPresentState() { |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
unlock_manager_->OnLifeCycleStateChanged(); |
- |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
} |
@@ -227,12 +229,13 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test { |
protected: |
cryptauth::RemoteDevice remote_device_; |
+ FakeRemoteDeviceLifeCycle life_cycle_; |
+ cryptauth::FakeConnection connection_; |
// Mock used for verifying interactions with the Bluetooth subsystem. |
scoped_refptr<device::MockBluetoothAdapter> bluetooth_adapter_; |
NiceMock<MockProximityAuthClient> proximity_auth_client_; |
- NiceMock<MockRemoteDeviceLifeCycle> life_cycle_; |
NiceMock<MockMessenger> messenger_; |
std::unique_ptr<TestUnlockManager> unlock_manager_; |
cryptauth::FakeSecureContext secure_context_; |
@@ -253,10 +256,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_SessionLock_AllGood) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
EXPECT_TRUE(unlock_manager_->IsUnlockAllowed()); |
@@ -264,14 +267,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) { |
CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
unlock_manager_->OnLifeCycleStateChanged(); |
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
@@ -283,14 +282,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) { |
TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_SignIn_MessengerDoesNotSupportSignIn) { |
CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
unlock_manager_->OnLifeCycleStateChanged(); |
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); |
@@ -300,30 +295,16 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
- IsUnlockAllowed_SignIn_MessengerIsNull) { |
- CreateUnlockManager(ProximityAuthSystem::SIGN_IN); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
- ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(nullptr)); |
- unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
- |
- EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
-} |
- |
-TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_DisallowedByProximityMonitor) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false)); |
+ unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
} |
@@ -331,9 +312,9 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_SecureChannelNotEstablished) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
@@ -353,10 +334,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_RemoteScreenlockStateLocked) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenLocked); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
@@ -366,10 +347,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_RemoteScreenlockStateUnknown) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockStateUnknown); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
@@ -379,10 +360,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_RemoteScreenlockStateDisabled) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockDisabled); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
@@ -392,10 +373,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
IsUnlockAllowed_RemoteScreenlockStateNotYetReceived) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); |
} |
@@ -419,29 +400,14 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
- SetRemoteDeviceLifeCycle_NullThenExistingRemoteDeviceLifeCycle) { |
- CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- SimulateUserPresentState(); |
- |
- EXPECT_CALL(proximity_auth_client_, |
- UpdateScreenlockState(ScreenlockState::INACTIVE)); |
- unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
- |
- EXPECT_CALL(proximity_auth_client_, |
- UpdateScreenlockState(ScreenlockState::AUTHENTICATED)); |
- unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
-} |
- |
-TEST_F(ProximityAuthUnlockManagerImplTest, |
SetRemoteDeviceLifeCycle_AuthenticationFailed) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); |
+ |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
@@ -453,8 +419,8 @@ TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_WakingUp) { |
unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
+ |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
@@ -473,27 +439,23 @@ TEST_F( |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); |
- |
- EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1)); |
unlock_manager_->OnLifeCycleStateChanged(); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
+ EXPECT_TRUE(proximity_monitor()->stopped()); |
} |
TEST_F( |
ProximityAuthUnlockManagerImplTest, |
SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonitor) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
- EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1)); |
unlock_manager_->OnLifeCycleStateChanged(); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
+ EXPECT_TRUE(proximity_monitor()->started()); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
@@ -508,7 +470,7 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
OnLifeCycleStateChanged_StartsProximityMonitor) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1)); |
+ EXPECT_TRUE(proximity_monitor()->started()); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
@@ -517,12 +479,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); |
- |
- EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1)); |
unlock_manager_->OnLifeCycleStateChanged(); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
+ EXPECT_TRUE(proximity_monitor()->stopped()); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
@@ -530,11 +490,9 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::INACTIVE)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::STOPPED); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
@@ -543,44 +501,31 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
OnLifeCycleStateChanged_FindingConnection_UpdatesScreenlockState) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
OnLifeCycleStateChanged_Authenticating_UpdatesScreenlockState) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING)); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
@@ -588,17 +533,12 @@ TEST_F( |
ProximityAuthUnlockManagerImplTest, |
OnLifeCycleStateChanged_SecureChannelEstablished_UpdatesScreenlockState) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
unlock_manager_->OnLifeCycleStateChanged(); |
} |
@@ -606,10 +546,8 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
OnDisconnected_UnregistersAsObserver) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get())) |
.Times(testing::AtLeast(1)); |
@@ -622,27 +560,23 @@ TEST_F(ProximityAuthUnlockManagerImplTest, |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
SimulateUserPresentState(); |
- EXPECT_CALL(*proximity_monitor(), Stop()); |
unlock_manager_.get()->OnScreenDidUnlock( |
ScreenlockBridge::LockHandler::LOCK_SCREEN); |
+ EXPECT_TRUE(proximity_monitor()->stopped()); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |
OnScreenDidLock_StartsProximityMonitor) { |
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); |
- |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED)); |
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault( |
- Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); |
- unlock_manager_->OnLifeCycleStateChanged(); |
- |
- EXPECT_CALL(*proximity_monitor(), Start()); |
unlock_manager_.get()->OnScreenDidLock( |
ScreenlockBridge::LockHandler::LOCK_SCREEN); |
+ |
+ life_cycle_.ChangeState( |
+ RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
+ EXPECT_TRUE(proximity_monitor()->started()); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) { |
@@ -652,14 +586,11 @@ TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) { |
unlock_manager_.get()->OnScreenDidUnlock( |
ScreenlockBridge::LockHandler::LOCK_SCREEN); |
- ON_CALL(life_cycle_, GetState()) |
- .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); |
- unlock_manager_->OnLifeCycleStateChanged(); |
- |
EXPECT_CALL(proximity_auth_client_, |
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); |
- unlock_manager_.get()->OnScreenDidLock( |
- ScreenlockBridge::LockHandler::LOCK_SCREEN); |
+ |
+ life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
+ unlock_manager_->OnLifeCycleStateChanged(); |
} |
TEST_F(ProximityAuthUnlockManagerImplTest, |