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

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

Powered by Google App Engine
This is Rietveld 408576698