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

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

Issue 2845433003: [EasyUnlock] Update ProximityMonitor to only check for RSSI proximity. (Closed)
Patch Set: [EasyUnlock] Update ProximityMonitor to only check for RSSI proximity. Created 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/unlock_manager_impl.h" 5 #include "components/proximity_auth/unlock_manager_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "components/cryptauth/cryptauth_test_util.h" 15 #include "components/cryptauth/cryptauth_test_util.h"
16 #include "components/cryptauth/fake_connection.h"
16 #include "components/cryptauth/fake_secure_context.h" 17 #include "components/cryptauth/fake_secure_context.h"
17 #include "components/cryptauth/secure_context.h" 18 #include "components/cryptauth/secure_context.h"
18 #include "components/proximity_auth/fake_lock_handler.h" 19 #include "components/proximity_auth/fake_lock_handler.h"
20 #include "components/proximity_auth/fake_remote_device_life_cycle.h"
19 #include "components/proximity_auth/logging/logging.h" 21 #include "components/proximity_auth/logging/logging.h"
20 #include "components/proximity_auth/messenger.h" 22 #include "components/proximity_auth/messenger.h"
21 #include "components/proximity_auth/mock_proximity_auth_client.h" 23 #include "components/proximity_auth/mock_proximity_auth_client.h"
22 #include "components/proximity_auth/proximity_monitor.h" 24 #include "components/proximity_auth/proximity_monitor.h"
23 #include "components/proximity_auth/remote_device_life_cycle.h" 25 #include "components/proximity_auth/remote_device_life_cycle.h"
24 #include "components/proximity_auth/remote_status_update.h" 26 #include "components/proximity_auth/remote_status_update.h"
25 #include "components/proximity_auth/screenlock_bridge.h" 27 #include "components/proximity_auth/screenlock_bridge.h"
26 #include "device/bluetooth/bluetooth_adapter_factory.h" 28 #include "device/bluetooth/bluetooth_adapter_factory.h"
27 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 29 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
28 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 30 matching lines...) Expand all
59 61
60 class MockRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle { 62 class MockRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
61 public: 63 public:
62 MockRemoteDeviceLifeCycle() {} 64 MockRemoteDeviceLifeCycle() {}
63 ~MockRemoteDeviceLifeCycle() override {} 65 ~MockRemoteDeviceLifeCycle() override {}
64 66
65 MOCK_METHOD0(Start, void()); 67 MOCK_METHOD0(Start, void());
66 MOCK_CONST_METHOD0(GetRemoteDevice, cryptauth::RemoteDevice()); 68 MOCK_CONST_METHOD0(GetRemoteDevice, cryptauth::RemoteDevice());
67 MOCK_CONST_METHOD0(GetState, State()); 69 MOCK_CONST_METHOD0(GetState, State());
68 MOCK_METHOD0(GetMessenger, Messenger*()); 70 MOCK_METHOD0(GetMessenger, Messenger*());
71 MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*());
69 MOCK_METHOD1(AddObserver, void(Observer*)); 72 MOCK_METHOD1(AddObserver, void(Observer*));
70 MOCK_METHOD1(RemoveObserver, void(Observer*)); 73 MOCK_METHOD1(RemoveObserver, void(Observer*));
71 }; 74 };
72 75
73 class MockMessenger : public Messenger { 76 class MockMessenger : public Messenger {
74 public: 77 public:
75 MockMessenger() {} 78 MockMessenger() {}
76 ~MockMessenger() override {} 79 ~MockMessenger() override {}
77 80
78 MOCK_METHOD1(AddObserver, void(MessengerObserver* observer)); 81 MOCK_METHOD1(AddObserver, void(MessengerObserver* observer));
79 MOCK_METHOD1(RemoveObserver, void(MessengerObserver* observer)); 82 MOCK_METHOD1(RemoveObserver, void(MessengerObserver* observer));
80 MOCK_CONST_METHOD0(SupportsSignIn, bool()); 83 MOCK_CONST_METHOD0(SupportsSignIn, bool());
81 MOCK_METHOD0(DispatchUnlockEvent, void()); 84 MOCK_METHOD0(DispatchUnlockEvent, void());
82 MOCK_METHOD1(RequestDecryption, void(const std::string& challenge)); 85 MOCK_METHOD1(RequestDecryption, void(const std::string& challenge));
83 MOCK_METHOD0(RequestUnlock, void()); 86 MOCK_METHOD0(RequestUnlock, void());
84 MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*()); 87 MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*());
85 88
86 private: 89 private:
87 DISALLOW_COPY_AND_ASSIGN(MockMessenger); 90 DISALLOW_COPY_AND_ASSIGN(MockMessenger);
88 }; 91 };
89 92
90 class MockProximityMonitor : public ProximityMonitor { 93 class MockProximityMonitor : public ProximityMonitor {
91 public: 94 public:
92 MockProximityMonitor() { 95 MockProximityMonitor() : started_(false), stopped_(false) {
93 ON_CALL(*this, GetStrategy())
94 .WillByDefault(Return(ProximityMonitor::Strategy::NONE));
95 ON_CALL(*this, IsUnlockAllowed()).WillByDefault(Return(true)); 96 ON_CALL(*this, IsUnlockAllowed()).WillByDefault(Return(true));
96 ON_CALL(*this, IsInRssiRange()).WillByDefault(Return(false));
97 } 97 }
98 ~MockProximityMonitor() override {} 98 ~MockProximityMonitor() override {}
99 99
100 MOCK_METHOD0(Start, void()); 100 void Start() override { started_ = true; }
101 MOCK_METHOD0(Stop, void()); 101 void Stop() override { stopped_ = true; }
102 MOCK_CONST_METHOD0(GetStrategy, Strategy());
103 MOCK_CONST_METHOD0(IsUnlockAllowed, bool()); 102 MOCK_CONST_METHOD0(IsUnlockAllowed, bool());
104 MOCK_CONST_METHOD0(IsInRssiRange, bool());
105 MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void()); 103 MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void());
106 MOCK_METHOD1(AddObserver, void(ProximityMonitorObserver*)); 104 MOCK_METHOD1(AddObserver, void(ProximityMonitorObserver*));
107 MOCK_METHOD1(RemoveObserver, void(ProximityMonitorObserver*)); 105 MOCK_METHOD1(RemoveObserver, void(ProximityMonitorObserver*));
108 106
107 bool started() { return started_; }
108 bool stopped() { return stopped_; }
109
109 private: 110 private:
111 bool started_;
112 bool stopped_;
113
110 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor); 114 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor);
111 }; 115 };
112 116
113 class TestUnlockManager : public UnlockManagerImpl { 117 class TestUnlockManager : public UnlockManagerImpl {
114 public: 118 public:
115 TestUnlockManager(ProximityAuthSystem::ScreenlockType screenlock_type, 119 TestUnlockManager(ProximityAuthSystem::ScreenlockType screenlock_type,
116 ProximityAuthClient* proximity_auth_client) 120 ProximityAuthClient* proximity_auth_client)
117 : UnlockManagerImpl(screenlock_type, proximity_auth_client), 121 : UnlockManagerImpl(screenlock_type, proximity_auth_client),
118 proximity_monitor_(nullptr) {} 122 proximity_monitor_(nullptr) {}
119 ~TestUnlockManager() override {} 123 ~TestUnlockManager() override {}
120 124
121 using UnlockManager::OnAuthAttempted; 125 using UnlockManager::OnAuthAttempted;
122 using MessengerObserver::OnUnlockEventSent; 126 using MessengerObserver::OnUnlockEventSent;
123 using MessengerObserver::OnRemoteStatusUpdate; 127 using MessengerObserver::OnRemoteStatusUpdate;
124 using MessengerObserver::OnDecryptResponse; 128 using MessengerObserver::OnDecryptResponse;
125 using MessengerObserver::OnUnlockResponse; 129 using MessengerObserver::OnUnlockResponse;
126 using MessengerObserver::OnDisconnected; 130 using MessengerObserver::OnDisconnected;
127 using ScreenlockBridge::Observer::OnScreenDidLock; 131 using ScreenlockBridge::Observer::OnScreenDidLock;
128 using ScreenlockBridge::Observer::OnScreenDidUnlock; 132 using ScreenlockBridge::Observer::OnScreenDidUnlock;
129 using ScreenlockBridge::Observer::OnFocusedUserChanged; 133 using ScreenlockBridge::Observer::OnFocusedUserChanged;
130 134
131 MockProximityMonitor* proximity_monitor() { return proximity_monitor_; } 135 MockProximityMonitor* proximity_monitor() { return proximity_monitor_; }
132 136
133 private: 137 private:
134 std::unique_ptr<ProximityMonitor> CreateProximityMonitor( 138 std::unique_ptr<ProximityMonitor> CreateProximityMonitor(
135 const cryptauth::RemoteDevice& remote_device) override { 139 cryptauth::Connection* connection) override {
136 EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey, remote_device.public_key); 140 EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey,
141 connection->remote_device().public_key);
137 std::unique_ptr<MockProximityMonitor> proximity_monitor( 142 std::unique_ptr<MockProximityMonitor> proximity_monitor(
138 new NiceMock<MockProximityMonitor>()); 143 new NiceMock<MockProximityMonitor>());
139 proximity_monitor_ = proximity_monitor.get(); 144 proximity_monitor_ = proximity_monitor.get();
140 return std::move(proximity_monitor); 145 return std::move(proximity_monitor);
141 } 146 }
142 147
143 // Owned by the super class. 148 // Owned by the super class.
144 MockProximityMonitor* proximity_monitor_; 149 MockProximityMonitor* proximity_monitor_;
145 150
146 DISALLOW_COPY_AND_ASSIGN(TestUnlockManager); 151 DISALLOW_COPY_AND_ASSIGN(TestUnlockManager);
147 }; 152 };
148 153
149 // Creates a mock Bluetooth adapter and sets it as the global adapter for 154 // Creates a mock Bluetooth adapter and sets it as the global adapter for
150 // testing. 155 // testing.
151 scoped_refptr<device::MockBluetoothAdapter> 156 scoped_refptr<device::MockBluetoothAdapter>
152 CreateAndRegisterMockBluetoothAdapter() { 157 CreateAndRegisterMockBluetoothAdapter() {
153 scoped_refptr<device::MockBluetoothAdapter> adapter = 158 scoped_refptr<device::MockBluetoothAdapter> adapter =
154 new NiceMock<device::MockBluetoothAdapter>(); 159 new NiceMock<device::MockBluetoothAdapter>();
155 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); 160 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
156 return adapter; 161 return adapter;
157 } 162 }
158 163
159 } // namespace 164 } // namespace
160 165
161 class ProximityAuthUnlockManagerImplTest : public testing::Test { 166 class ProximityAuthUnlockManagerImplTest : public testing::Test {
162 public: 167 public:
163 ProximityAuthUnlockManagerImplTest() 168 ProximityAuthUnlockManagerImplTest()
164 : remote_device_(cryptauth::CreateClassicRemoteDeviceForTest()), 169 : remote_device_(cryptauth::CreateClassicRemoteDeviceForTest()),
170 life_cycle_(remote_device_),
171 connection_(remote_device_),
165 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), 172 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()),
166 task_runner_(new base::TestSimpleTaskRunner()), 173 task_runner_(new base::TestSimpleTaskRunner()),
167 thread_task_runner_handle_(task_runner_) { 174 thread_task_runner_handle_(task_runner_) {
168 ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true)); 175 ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true));
169 ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(&messenger_));
170 ON_CALL(life_cycle_, GetRemoteDevice())
171 .WillByDefault(Return(remote_device_));
172 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); 176 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true));
173 ON_CALL(messenger_, GetSecureContext()) 177 ON_CALL(messenger_, GetSecureContext())
174 .WillByDefault(Return(&secure_context_)); 178 .WillByDefault(Return(&secure_context_));
175 179
180 life_cycle_.set_connection(&connection_);
181 life_cycle_.set_messenger(&messenger_);
176 ScreenlockBridge::Get()->SetLockHandler(&lock_handler_); 182 ScreenlockBridge::Get()->SetLockHandler(&lock_handler_);
177 183
178 #if defined(OS_CHROMEOS) 184 #if defined(OS_CHROMEOS)
179 chromeos::DBusThreadManager::Initialize(); 185 chromeos::DBusThreadManager::Initialize();
180 #endif 186 #endif
181 } 187 }
182 188
183 ~ProximityAuthUnlockManagerImplTest() override { 189 ~ProximityAuthUnlockManagerImplTest() override {
184 // Make sure to verify the mock prior to the destruction of the unlock 190 // Make sure to verify the mock prior to the destruction of the unlock
185 // manager, as otherwise it's impossible to tell whether calls to Stop() 191 // manager, as otherwise it's impossible to tell whether calls to Stop()
(...skipping 14 matching lines...) Expand all
200 ScreenlockBridge::Get()->SetLockHandler(nullptr); 206 ScreenlockBridge::Get()->SetLockHandler(nullptr);
201 } 207 }
202 208
203 void CreateUnlockManager( 209 void CreateUnlockManager(
204 ProximityAuthSystem::ScreenlockType screenlock_type) { 210 ProximityAuthSystem::ScreenlockType screenlock_type) {
205 unlock_manager_.reset( 211 unlock_manager_.reset(
206 new TestUnlockManager(screenlock_type, &proximity_auth_client_)); 212 new TestUnlockManager(screenlock_type, &proximity_auth_client_));
207 } 213 }
208 214
209 void SimulateUserPresentState() { 215 void SimulateUserPresentState() {
210 ON_CALL(life_cycle_, GetState())
211 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
212 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 216 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
213 217 life_cycle_.ChangeState(
214 ON_CALL(life_cycle_, GetState()) 218 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
215 .WillByDefault(
216 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
217 unlock_manager_->OnLifeCycleStateChanged(); 219 unlock_manager_->OnLifeCycleStateChanged();
218
219 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 220 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
220 } 221 }
221 222
222 void RunPendingTasks() { task_runner_->RunPendingTasks(); } 223 void RunPendingTasks() { task_runner_->RunPendingTasks(); }
223 224
224 MockProximityMonitor* proximity_monitor() { 225 MockProximityMonitor* proximity_monitor() {
225 return unlock_manager_ ? unlock_manager_->proximity_monitor() : nullptr; 226 return unlock_manager_ ? unlock_manager_->proximity_monitor() : nullptr;
226 } 227 }
227 228
228 protected: 229 protected:
229 cryptauth::RemoteDevice remote_device_; 230 cryptauth::RemoteDevice remote_device_;
231 FakeRemoteDeviceLifeCycle life_cycle_;
232 cryptauth::FakeConnection connection_;
230 233
231 // Mock used for verifying interactions with the Bluetooth subsystem. 234 // Mock used for verifying interactions with the Bluetooth subsystem.
232 scoped_refptr<device::MockBluetoothAdapter> bluetooth_adapter_; 235 scoped_refptr<device::MockBluetoothAdapter> bluetooth_adapter_;
233 236
234 NiceMock<MockProximityAuthClient> proximity_auth_client_; 237 NiceMock<MockProximityAuthClient> proximity_auth_client_;
235 NiceMock<MockRemoteDeviceLifeCycle> life_cycle_;
236 NiceMock<MockMessenger> messenger_; 238 NiceMock<MockMessenger> messenger_;
237 std::unique_ptr<TestUnlockManager> unlock_manager_; 239 std::unique_ptr<TestUnlockManager> unlock_manager_;
238 cryptauth::FakeSecureContext secure_context_; 240 cryptauth::FakeSecureContext secure_context_;
239 241
240 private: 242 private:
241 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 243 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
242 base::ThreadTaskRunnerHandle thread_task_runner_handle_; 244 base::ThreadTaskRunnerHandle thread_task_runner_handle_;
243 FakeLockHandler lock_handler_; 245 FakeLockHandler lock_handler_;
244 ScopedDisableLoggingForTesting disable_logging_; 246 ScopedDisableLoggingForTesting disable_logging_;
245 }; 247 };
246 248
247 TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_InitialState) { 249 TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_InitialState) {
248 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 250 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
249 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 251 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
250 } 252 }
251 253
252 TEST_F(ProximityAuthUnlockManagerImplTest, 254 TEST_F(ProximityAuthUnlockManagerImplTest,
253 IsUnlockAllowed_SessionLock_AllGood) { 255 IsUnlockAllowed_SessionLock_AllGood) {
254 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 256 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
255 257
256 ON_CALL(life_cycle_, GetState())
257 .WillByDefault(
258 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
259 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 258 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
259 life_cycle_.ChangeState(
260 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
261 unlock_manager_->OnLifeCycleStateChanged();
260 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 262 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
261 263
262 EXPECT_TRUE(unlock_manager_->IsUnlockAllowed()); 264 EXPECT_TRUE(unlock_manager_->IsUnlockAllowed());
263 } 265 }
264 266
265 TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) { 267 TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) {
266 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); 268 CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
267
268 ON_CALL(life_cycle_, GetState())
269 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
270 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 269 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
271 270
272 ON_CALL(life_cycle_, GetState()) 271 life_cycle_.ChangeState(
273 .WillByDefault( 272 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
274 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
275 unlock_manager_->OnLifeCycleStateChanged(); 273 unlock_manager_->OnLifeCycleStateChanged();
276 274
277 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); 275 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true));
278 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 276 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
279 277
280 EXPECT_TRUE(unlock_manager_->IsUnlockAllowed()); 278 EXPECT_TRUE(unlock_manager_->IsUnlockAllowed());
281 } 279 }
282 280
283 TEST_F(ProximityAuthUnlockManagerImplTest, 281 TEST_F(ProximityAuthUnlockManagerImplTest,
284 IsUnlockAllowed_SignIn_MessengerDoesNotSupportSignIn) { 282 IsUnlockAllowed_SignIn_MessengerDoesNotSupportSignIn) {
285 CreateUnlockManager(ProximityAuthSystem::SIGN_IN); 283 CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
286
287 ON_CALL(life_cycle_, GetState())
288 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
289 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 284 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
290 285
291 ON_CALL(life_cycle_, GetState()) 286 life_cycle_.ChangeState(
292 .WillByDefault( 287 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
293 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
294 unlock_manager_->OnLifeCycleStateChanged(); 288 unlock_manager_->OnLifeCycleStateChanged();
295 289
296 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false)); 290 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false));
297 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 291 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
298 292
299 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 293 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
300 } 294 }
301 295
302 TEST_F(ProximityAuthUnlockManagerImplTest, 296 TEST_F(ProximityAuthUnlockManagerImplTest,
303 IsUnlockAllowed_SignIn_MessengerIsNull) {
304 CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
305
306 ON_CALL(life_cycle_, GetState())
307 .WillByDefault(
308 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
309 ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(nullptr));
310 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
311 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
312
313 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
314 }
315
316 TEST_F(ProximityAuthUnlockManagerImplTest,
317 IsUnlockAllowed_DisallowedByProximityMonitor) { 297 IsUnlockAllowed_DisallowedByProximityMonitor) {
318 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 298 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
319 299
320 ON_CALL(life_cycle_, GetState())
321 .WillByDefault(
322 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
323 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 300 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
324 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 301 life_cycle_.ChangeState(
302 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
303 unlock_manager_->OnLifeCycleStateChanged();
325 304
326 ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false)); 305 ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false));
306 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
327 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 307 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
328 } 308 }
329 309
330 TEST_F(ProximityAuthUnlockManagerImplTest, 310 TEST_F(ProximityAuthUnlockManagerImplTest,
331 IsUnlockAllowed_SecureChannelNotEstablished) { 311 IsUnlockAllowed_SecureChannelNotEstablished) {
332 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 312 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
333 313
334 ON_CALL(life_cycle_, GetState())
335 .WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING));
336 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 314 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
315 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
316 unlock_manager_->OnLifeCycleStateChanged();
337 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 317 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
338 318
339 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 319 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
340 } 320 }
341 321
342 TEST_F(ProximityAuthUnlockManagerImplTest, 322 TEST_F(ProximityAuthUnlockManagerImplTest,
343 IsUnlockAllowed_RemoteDeviceLifeCycleIsNull) { 323 IsUnlockAllowed_RemoteDeviceLifeCycleIsNull) {
344 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 324 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
345 325
346 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 326 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
347 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked); 327 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
348 328
349 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 329 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
350 } 330 }
351 331
352 TEST_F(ProximityAuthUnlockManagerImplTest, 332 TEST_F(ProximityAuthUnlockManagerImplTest,
353 IsUnlockAllowed_RemoteScreenlockStateLocked) { 333 IsUnlockAllowed_RemoteScreenlockStateLocked) {
354 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 334 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
355 335
356 ON_CALL(life_cycle_, GetState())
357 .WillByDefault(
358 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
359 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 336 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
337 life_cycle_.ChangeState(
338 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
339 unlock_manager_->OnLifeCycleStateChanged();
360 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenLocked); 340 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenLocked);
361 341
362 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 342 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
363 } 343 }
364 344
365 TEST_F(ProximityAuthUnlockManagerImplTest, 345 TEST_F(ProximityAuthUnlockManagerImplTest,
366 IsUnlockAllowed_RemoteScreenlockStateUnknown) { 346 IsUnlockAllowed_RemoteScreenlockStateUnknown) {
367 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 347 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
368 348
369 ON_CALL(life_cycle_, GetState())
370 .WillByDefault(
371 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
372 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 349 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
350 life_cycle_.ChangeState(
351 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
352 unlock_manager_->OnLifeCycleStateChanged();
373 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockStateUnknown); 353 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockStateUnknown);
374 354
375 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 355 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
376 } 356 }
377 357
378 TEST_F(ProximityAuthUnlockManagerImplTest, 358 TEST_F(ProximityAuthUnlockManagerImplTest,
379 IsUnlockAllowed_RemoteScreenlockStateDisabled) { 359 IsUnlockAllowed_RemoteScreenlockStateDisabled) {
380 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 360 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
381 361
382 ON_CALL(life_cycle_, GetState())
383 .WillByDefault(
384 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
385 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 362 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
363 life_cycle_.ChangeState(
364 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
365 unlock_manager_->OnLifeCycleStateChanged();
386 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockDisabled); 366 unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockDisabled);
387 367
388 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 368 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
389 } 369 }
390 370
391 TEST_F(ProximityAuthUnlockManagerImplTest, 371 TEST_F(ProximityAuthUnlockManagerImplTest,
392 IsUnlockAllowed_RemoteScreenlockStateNotYetReceived) { 372 IsUnlockAllowed_RemoteScreenlockStateNotYetReceived) {
393 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 373 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
394 374
395 ON_CALL(life_cycle_, GetState())
396 .WillByDefault(
397 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
398 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 375 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
376 life_cycle_.ChangeState(
377 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
378 unlock_manager_->OnLifeCycleStateChanged();
399 379
400 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed()); 380 EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
401 } 381 }
402 382
403 TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_SetToNull) { 383 TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_SetToNull) {
404 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 384 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
405 SimulateUserPresentState(); 385 SimulateUserPresentState();
406 386
407 EXPECT_CALL(proximity_auth_client_, 387 EXPECT_CALL(proximity_auth_client_,
408 UpdateScreenlockState(ScreenlockState::INACTIVE)); 388 UpdateScreenlockState(ScreenlockState::INACTIVE));
409 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 389 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
410 } 390 }
411 391
412 TEST_F(ProximityAuthUnlockManagerImplTest, 392 TEST_F(ProximityAuthUnlockManagerImplTest,
413 SetRemoteDeviceLifeCycle_ExistingRemoteDeviceLifeCycle) { 393 SetRemoteDeviceLifeCycle_ExistingRemoteDeviceLifeCycle) {
414 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 394 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
415 SimulateUserPresentState(); 395 SimulateUserPresentState();
416 396
417 EXPECT_CALL(proximity_auth_client_, UpdateScreenlockState(_)).Times(0); 397 EXPECT_CALL(proximity_auth_client_, UpdateScreenlockState(_)).Times(0);
418 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 398 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
419 } 399 }
420 400
421 TEST_F(ProximityAuthUnlockManagerImplTest, 401 TEST_F(ProximityAuthUnlockManagerImplTest,
422 SetRemoteDeviceLifeCycle_NullThenExistingRemoteDeviceLifeCycle) {
423 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
424 SimulateUserPresentState();
425
426 EXPECT_CALL(proximity_auth_client_,
427 UpdateScreenlockState(ScreenlockState::INACTIVE));
428 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
429
430 EXPECT_CALL(proximity_auth_client_,
431 UpdateScreenlockState(ScreenlockState::AUTHENTICATED));
432 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
433 }
434
435 TEST_F(ProximityAuthUnlockManagerImplTest,
436 SetRemoteDeviceLifeCycle_AuthenticationFailed) { 402 SetRemoteDeviceLifeCycle_AuthenticationFailed) {
437 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 403 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
438 SimulateUserPresentState(); 404 SimulateUserPresentState();
439 405
440 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 406 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
441 407
442 ON_CALL(life_cycle_, GetState()) 408 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
443 .WillByDefault( 409
444 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
445 EXPECT_CALL(proximity_auth_client_, 410 EXPECT_CALL(proximity_auth_client_,
446 UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED)); 411 UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED));
447 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 412 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
448 } 413 }
449 414
450 TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_WakingUp) { 415 TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_WakingUp) {
451 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 416 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
452 SimulateUserPresentState(); 417 SimulateUserPresentState();
453 418
454 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 419 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
455 420
456 ON_CALL(life_cycle_, GetState()) 421 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
457 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); 422
458 EXPECT_CALL(proximity_auth_client_, 423 EXPECT_CALL(proximity_auth_client_,
459 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); 424 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
460 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 425 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
461 } 426 }
462 427
463 TEST_F(ProximityAuthUnlockManagerImplTest, 428 TEST_F(ProximityAuthUnlockManagerImplTest,
464 SetRemoteDeviceLifeCycle_NullRemoteDeviceLifeCycle_NoProximityMonitor) { 429 SetRemoteDeviceLifeCycle_NullRemoteDeviceLifeCycle_NoProximityMonitor) {
465 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 430 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
466 SimulateUserPresentState(); 431 SimulateUserPresentState();
467 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 432 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
468 } 433 }
469 434
470 TEST_F( 435 TEST_F(
471 ProximityAuthUnlockManagerImplTest, 436 ProximityAuthUnlockManagerImplTest,
472 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) { 437 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) {
473 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 438 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
474 SimulateUserPresentState(); 439 SimulateUserPresentState();
475 440
476 ON_CALL(life_cycle_, GetState())
477 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
478
479 EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1));
480 unlock_manager_->OnLifeCycleStateChanged(); 441 unlock_manager_->OnLifeCycleStateChanged();
442 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
443 unlock_manager_->OnLifeCycleStateChanged();
444 EXPECT_TRUE(proximity_monitor()->stopped());
481 } 445 }
482 446
483 TEST_F( 447 TEST_F(
484 ProximityAuthUnlockManagerImplTest, 448 ProximityAuthUnlockManagerImplTest,
485 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) { 449 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) {
486 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 450 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
487
488 ON_CALL(life_cycle_, GetState())
489 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
490 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 451 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
491 452
492 ON_CALL(life_cycle_, GetState())
493 .WillByDefault(
494 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
495 EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1));
496 unlock_manager_->OnLifeCycleStateChanged(); 453 unlock_manager_->OnLifeCycleStateChanged();
454 life_cycle_.ChangeState(
455 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
456 unlock_manager_->OnLifeCycleStateChanged();
457 EXPECT_TRUE(proximity_monitor()->started());
497 } 458 }
498 459
499 TEST_F(ProximityAuthUnlockManagerImplTest, 460 TEST_F(ProximityAuthUnlockManagerImplTest,
500 OnLifeCycleStateChanged_SecureChannelEstablished_RegistersAsObserver) { 461 OnLifeCycleStateChanged_SecureChannelEstablished_RegistersAsObserver) {
501 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 462 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
502 SimulateUserPresentState(); 463 SimulateUserPresentState();
503 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get())); 464 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get()));
504 unlock_manager_->OnLifeCycleStateChanged(); 465 unlock_manager_->OnLifeCycleStateChanged();
505 } 466 }
506 467
507 TEST_F(ProximityAuthUnlockManagerImplTest, 468 TEST_F(ProximityAuthUnlockManagerImplTest,
508 OnLifeCycleStateChanged_StartsProximityMonitor) { 469 OnLifeCycleStateChanged_StartsProximityMonitor) {
509 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 470 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
510 SimulateUserPresentState(); 471 SimulateUserPresentState();
511 EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1)); 472 EXPECT_TRUE(proximity_monitor()->started());
512 unlock_manager_->OnLifeCycleStateChanged(); 473 unlock_manager_->OnLifeCycleStateChanged();
513 } 474 }
514 475
515 TEST_F(ProximityAuthUnlockManagerImplTest, 476 TEST_F(ProximityAuthUnlockManagerImplTest,
516 OnLifeCycleStateChanged_StopsProximityMonitor) { 477 OnLifeCycleStateChanged_StopsProximityMonitor) {
517 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 478 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
518 SimulateUserPresentState(); 479 SimulateUserPresentState();
519 480
520 ON_CALL(life_cycle_, GetState())
521 .WillByDefault(
522 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
523
524 EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1));
525 unlock_manager_->OnLifeCycleStateChanged(); 481 unlock_manager_->OnLifeCycleStateChanged();
482 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
483 unlock_manager_->OnLifeCycleStateChanged();
484 EXPECT_TRUE(proximity_monitor()->stopped());
526 } 485 }
527 486
528 TEST_F(ProximityAuthUnlockManagerImplTest, 487 TEST_F(ProximityAuthUnlockManagerImplTest,
529 OnLifeCycleStateChanged_Stopped_UpdatesScreenlockState) { 488 OnLifeCycleStateChanged_Stopped_UpdatesScreenlockState) {
530 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 489 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
531 SimulateUserPresentState(); 490 SimulateUserPresentState();
532 491
533 ON_CALL(life_cycle_, GetState())
534 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
535
536 EXPECT_CALL(proximity_auth_client_, 492 EXPECT_CALL(proximity_auth_client_,
537 UpdateScreenlockState(ScreenlockState::INACTIVE)); 493 UpdateScreenlockState(ScreenlockState::INACTIVE));
494 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::STOPPED);
538 unlock_manager_->OnLifeCycleStateChanged(); 495 unlock_manager_->OnLifeCycleStateChanged();
539 } 496 }
540 497
541 TEST_F(ProximityAuthUnlockManagerImplTest, 498 TEST_F(ProximityAuthUnlockManagerImplTest,
542 OnLifeCycleStateChanged_AuthenticationFailed_UpdatesScreenlockState) { 499 OnLifeCycleStateChanged_AuthenticationFailed_UpdatesScreenlockState) {
543 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 500 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
544 SimulateUserPresentState(); 501 SimulateUserPresentState();
545 502
546 ON_CALL(life_cycle_, GetState())
547 .WillByDefault(
548 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
549
550 EXPECT_CALL(proximity_auth_client_, 503 EXPECT_CALL(proximity_auth_client_,
551 UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED)); 504 UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED));
505 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
552 unlock_manager_->OnLifeCycleStateChanged(); 506 unlock_manager_->OnLifeCycleStateChanged();
553 } 507 }
554 508
555 TEST_F(ProximityAuthUnlockManagerImplTest, 509 TEST_F(ProximityAuthUnlockManagerImplTest,
556 OnLifeCycleStateChanged_FindingConnection_UpdatesScreenlockState) { 510 OnLifeCycleStateChanged_FindingConnection_UpdatesScreenlockState) {
557 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 511 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
558
559 ON_CALL(life_cycle_, GetState())
560 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
561 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 512 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
562 513
563 ON_CALL(life_cycle_, GetState())
564 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
565
566 EXPECT_CALL(proximity_auth_client_, 514 EXPECT_CALL(proximity_auth_client_,
567 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); 515 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
516 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
568 unlock_manager_->OnLifeCycleStateChanged(); 517 unlock_manager_->OnLifeCycleStateChanged();
569 } 518 }
570 519
571 TEST_F(ProximityAuthUnlockManagerImplTest, 520 TEST_F(ProximityAuthUnlockManagerImplTest,
572 OnLifeCycleStateChanged_Authenticating_UpdatesScreenlockState) { 521 OnLifeCycleStateChanged_Authenticating_UpdatesScreenlockState) {
573 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 522 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
574
575 ON_CALL(life_cycle_, GetState())
576 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
577 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 523 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
578 524
579 ON_CALL(life_cycle_, GetState())
580 .WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING));
581
582 EXPECT_CALL(proximity_auth_client_, 525 EXPECT_CALL(proximity_auth_client_,
583 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); 526 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
527 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
584 unlock_manager_->OnLifeCycleStateChanged(); 528 unlock_manager_->OnLifeCycleStateChanged();
585 } 529 }
586 530
587 TEST_F( 531 TEST_F(
588 ProximityAuthUnlockManagerImplTest, 532 ProximityAuthUnlockManagerImplTest,
589 OnLifeCycleStateChanged_SecureChannelEstablished_UpdatesScreenlockState) { 533 OnLifeCycleStateChanged_SecureChannelEstablished_UpdatesScreenlockState) {
590 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 534 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
591
592 ON_CALL(life_cycle_, GetState())
593 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
594 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 535 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
595 536
596 ON_CALL(life_cycle_, GetState())
597 .WillByDefault(
598 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
599
600 EXPECT_CALL(proximity_auth_client_, 537 EXPECT_CALL(proximity_auth_client_,
601 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); 538 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
539 life_cycle_.ChangeState(
540 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
602 unlock_manager_->OnLifeCycleStateChanged(); 541 unlock_manager_->OnLifeCycleStateChanged();
603 } 542 }
604 543
605 TEST_F(ProximityAuthUnlockManagerImplTest, 544 TEST_F(ProximityAuthUnlockManagerImplTest,
606 OnDisconnected_UnregistersAsObserver) { 545 OnDisconnected_UnregistersAsObserver) {
607 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 546 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
608 SimulateUserPresentState(); 547 SimulateUserPresentState();
609 548 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
610 ON_CALL(life_cycle_, GetState()) 549 unlock_manager_->OnLifeCycleStateChanged();
611 .WillByDefault(
612 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
613 550
614 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get())) 551 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get()))
615 .Times(testing::AtLeast(1)); 552 .Times(testing::AtLeast(1));
616 unlock_manager_.get()->OnDisconnected(); 553 unlock_manager_.get()->OnDisconnected();
617 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 554 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
618 } 555 }
619 556
620 TEST_F(ProximityAuthUnlockManagerImplTest, 557 TEST_F(ProximityAuthUnlockManagerImplTest,
621 OnScreenDidUnlock_StopsProximityMonitor) { 558 OnScreenDidUnlock_StopsProximityMonitor) {
622 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 559 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
623 SimulateUserPresentState(); 560 SimulateUserPresentState();
624 561
625 EXPECT_CALL(*proximity_monitor(), Stop());
626 unlock_manager_.get()->OnScreenDidUnlock( 562 unlock_manager_.get()->OnScreenDidUnlock(
627 ScreenlockBridge::LockHandler::LOCK_SCREEN); 563 ScreenlockBridge::LockHandler::LOCK_SCREEN);
564 EXPECT_TRUE(proximity_monitor()->stopped());
628 } 565 }
629 566
630 TEST_F(ProximityAuthUnlockManagerImplTest, 567 TEST_F(ProximityAuthUnlockManagerImplTest,
631 OnScreenDidLock_StartsProximityMonitor) { 568 OnScreenDidLock_StartsProximityMonitor) {
632 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 569 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
633
634 ON_CALL(life_cycle_, GetState())
635 .WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
636 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 570 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
637 571
638 ON_CALL(life_cycle_, GetState())
639 .WillByDefault(
640 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
641 unlock_manager_->OnLifeCycleStateChanged();
642
643 EXPECT_CALL(*proximity_monitor(), Start());
644 unlock_manager_.get()->OnScreenDidLock( 572 unlock_manager_.get()->OnScreenDidLock(
645 ScreenlockBridge::LockHandler::LOCK_SCREEN); 573 ScreenlockBridge::LockHandler::LOCK_SCREEN);
574
575 life_cycle_.ChangeState(
576 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
577 unlock_manager_->OnLifeCycleStateChanged();
578 EXPECT_TRUE(proximity_monitor()->started());
646 } 579 }
647 580
648 TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) { 581 TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) {
649 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 582 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
650 SimulateUserPresentState(); 583 SimulateUserPresentState();
651 584
652 unlock_manager_.get()->OnScreenDidUnlock( 585 unlock_manager_.get()->OnScreenDidUnlock(
653 ScreenlockBridge::LockHandler::LOCK_SCREEN); 586 ScreenlockBridge::LockHandler::LOCK_SCREEN);
654 587
655 ON_CALL(life_cycle_, GetState())
656 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
657 unlock_manager_->OnLifeCycleStateChanged();
658
659 EXPECT_CALL(proximity_auth_client_, 588 EXPECT_CALL(proximity_auth_client_,
660 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING)); 589 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
661 unlock_manager_.get()->OnScreenDidLock( 590
662 ScreenlockBridge::LockHandler::LOCK_SCREEN); 591 life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
592 unlock_manager_->OnLifeCycleStateChanged();
663 } 593 }
664 594
665 TEST_F(ProximityAuthUnlockManagerImplTest, 595 TEST_F(ProximityAuthUnlockManagerImplTest,
666 OnDecryptResponse_NoAuthAttemptInProgress) { 596 OnDecryptResponse_NoAuthAttemptInProgress) {
667 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK); 597 CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
668 SimulateUserPresentState(); 598 SimulateUserPresentState();
669 599
670 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0); 600 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(_)).Times(0);
671 unlock_manager_.get()->OnDecryptResponse(kSignInSecret); 601 unlock_manager_.get()->OnDecryptResponse(kSignInSecret);
672 } 602 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 })); 831 }));
902 832
903 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); 833 EXPECT_CALL(messenger_, RequestDecryption(kChallenge));
904 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); 834 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK);
905 835
906 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); 836 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string()));
907 unlock_manager_->OnDecryptResponse(std::string()); 837 unlock_manager_->OnDecryptResponse(std::string());
908 } 838 }
909 839
910 } // namespace proximity_auth 840 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698