OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 subst.push_back(base::string16()); | 39 subst.push_back(base::string16()); |
40 | 40 |
41 base::string16 replaced = | 41 base::string16 replaced = |
42 base::ReplaceStringPlaceholders(input, subst, &offsets); | 42 base::ReplaceStringPlaceholders(input, subst, &offsets); |
43 return !offsets.empty(); | 43 return !offsets.empty(); |
44 } | 44 } |
45 | 45 |
46 // Fake lock handler to be used in these tests. | 46 // Fake lock handler to be used in these tests. |
47 class TestLockHandler : public proximity_auth::ScreenlockBridge::LockHandler { | 47 class TestLockHandler : public proximity_auth::ScreenlockBridge::LockHandler { |
48 public: | 48 public: |
49 explicit TestLockHandler(const std::string& user_email) | 49 explicit TestLockHandler(const AccountId& account_id) |
50 : user_email_(user_email), | 50 : account_id_(account_id), |
51 show_icon_count_(0u), | 51 show_icon_count_(0u), |
52 auth_type_(OFFLINE_PASSWORD) { | 52 auth_type_(OFFLINE_PASSWORD) {} |
53 } | |
54 ~TestLockHandler() override {} | 53 ~TestLockHandler() override {} |
55 | 54 |
56 // proximity_auth::ScreenlockBridge::LockHandler implementation: | 55 // proximity_auth::ScreenlockBridge::LockHandler implementation: |
57 void ShowBannerMessage(const base::string16& message) override { | 56 void ShowBannerMessage(const base::string16& message) override { |
58 ASSERT_FALSE(true) << "Should not be reached."; | 57 ASSERT_FALSE(true) << "Should not be reached."; |
59 } | 58 } |
60 | 59 |
61 void ShowUserPodCustomIcon( | 60 void ShowUserPodCustomIcon( |
62 const std::string& user_email, | 61 const AccountId& account_id, |
63 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon) | 62 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon) |
64 override { | 63 override { |
65 ASSERT_EQ(user_email_, user_email); | 64 ASSERT_TRUE(account_id_ == account_id) |
| 65 << "account_id_=" << account_id_.Serialize() |
| 66 << " != account_id=" << account_id.Serialize(); |
66 ++show_icon_count_; | 67 ++show_icon_count_; |
67 last_custom_icon_ = icon.ToDictionaryValue().Pass(); | 68 last_custom_icon_ = icon.ToDictionaryValue().Pass(); |
68 ValidateCustomIcon(); | 69 ValidateCustomIcon(); |
69 } | 70 } |
70 | 71 |
71 void HideUserPodCustomIcon(const std::string& user_email) override { | 72 void HideUserPodCustomIcon(const AccountId& account_id) override { |
72 ASSERT_EQ(user_email_, user_email); | 73 ASSERT_TRUE(account_id_ == account_id) |
| 74 << "account_id_=" << account_id_.Serialize() |
| 75 << " != account_id=" << account_id.Serialize(); |
73 last_custom_icon_.reset(); | 76 last_custom_icon_.reset(); |
74 } | 77 } |
75 | 78 |
76 void EnableInput() override { | 79 void EnableInput() override { |
77 ASSERT_FALSE(true) << "Should not be reached."; | 80 ASSERT_FALSE(true) << "Should not be reached."; |
78 } | 81 } |
79 | 82 |
80 void SetAuthType(const std::string& user_email, | 83 void SetAuthType(const AccountId& account_id, |
81 AuthType auth_type, | 84 AuthType auth_type, |
82 const base::string16& auth_value) override { | 85 const base::string16& auth_value) override { |
83 ASSERT_EQ(user_email_, user_email); | 86 ASSERT_TRUE(account_id_ == account_id) |
| 87 << "account_id_=" << account_id_.Serialize() |
| 88 << " != account_id=" << account_id.Serialize(); |
84 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should | 89 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should |
85 // avoid resetting the same auth type. | 90 // avoid resetting the same auth type. |
86 EXPECT_NE(auth_type_, auth_type); | 91 EXPECT_NE(auth_type_, auth_type); |
87 | 92 |
88 auth_type_ = auth_type; | 93 auth_type_ = auth_type; |
89 auth_value_ = auth_value; | 94 auth_value_ = auth_value; |
90 } | 95 } |
91 | 96 |
92 AuthType GetAuthType(const std::string& user_email) const override { | 97 AuthType GetAuthType(const AccountId& account_id) const override { |
93 EXPECT_EQ(user_email_, user_email); | 98 EXPECT_TRUE(account_id_ == account_id) |
| 99 << "account_id_=" << account_id_.Serialize() |
| 100 << " != account_id=" << account_id.Serialize(); |
94 return auth_type_; | 101 return auth_type_; |
95 } | 102 } |
96 | 103 |
97 ScreenType GetScreenType() const override { | 104 ScreenType GetScreenType() const override { |
98 return LOCK_SCREEN; | 105 return LOCK_SCREEN; |
99 } | 106 } |
100 | 107 |
101 void Unlock(const std::string& user_email) override { | 108 void Unlock(const AccountId& account_id) override { |
102 ASSERT_FALSE(true) << "Should not be reached."; | 109 ASSERT_FALSE(true) << "Should not be reached."; |
103 } | 110 } |
104 | 111 |
105 void AttemptEasySignin(const std::string& user_email, | 112 void AttemptEasySignin(const AccountId& account_id, |
106 const std::string& secret, | 113 const std::string& secret, |
107 const std::string& key_label) override { | 114 const std::string& key_label) override { |
108 ASSERT_FALSE(true) << "Should not be reached."; | 115 ASSERT_FALSE(true) << "Should not be reached."; |
109 } | 116 } |
110 | 117 |
111 // Utility methods used by tests: | 118 // Utility methods used by tests: |
112 | 119 |
113 // Gets last set auth value. | 120 // Gets last set auth value. |
114 base::string16 GetAuthValue() const { | 121 base::string16 GetAuthValue() const { |
115 return auth_value_; | 122 return auth_value_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 EXPECT_TRUE(last_custom_icon_->HasKey("id")); | 189 EXPECT_TRUE(last_custom_icon_->HasKey("id")); |
183 | 190 |
184 if (last_custom_icon_->HasKey("tooltip")) { | 191 if (last_custom_icon_->HasKey("tooltip")) { |
185 base::string16 tooltip; | 192 base::string16 tooltip; |
186 EXPECT_TRUE(last_custom_icon_->GetString("tooltip.text", &tooltip)); | 193 EXPECT_TRUE(last_custom_icon_->GetString("tooltip.text", &tooltip)); |
187 EXPECT_FALSE(tooltip.empty()); | 194 EXPECT_FALSE(tooltip.empty()); |
188 EXPECT_FALSE(StringHasPlaceholders(tooltip)); | 195 EXPECT_FALSE(StringHasPlaceholders(tooltip)); |
189 } | 196 } |
190 } | 197 } |
191 | 198 |
192 // The fake user email used in test. All methods called on |this| should be | 199 // The fake account id used in test. All methods called on |this| should be |
193 // associated with this user. | 200 // associated with this user. |
194 const std::string user_email_; | 201 const AccountId account_id_; |
195 | 202 |
196 // The last icon set using |SetUserPodCustomIcon|. Call to | 203 // The last icon set using |SetUserPodCustomIcon|. Call to |
197 // |HideUserPodcustomIcon| resets it. | 204 // |HideUserPodcustomIcon| resets it. |
198 scoped_ptr<base::DictionaryValue> last_custom_icon_; | 205 scoped_ptr<base::DictionaryValue> last_custom_icon_; |
199 size_t show_icon_count_; | 206 size_t show_icon_count_; |
200 | 207 |
201 // Auth type and value set using |SetAuthType|. | 208 // Auth type and value set using |SetAuthType|. |
202 AuthType auth_type_; | 209 AuthType auth_type_; |
203 base::string16 auth_value_; | 210 base::string16 auth_value_; |
204 | 211 |
205 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); | 212 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); |
206 }; | 213 }; |
207 | 214 |
208 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { | 215 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
209 public: | 216 public: |
210 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} | 217 EasyUnlockScreenlockStateHandlerTest() {} |
211 ~EasyUnlockScreenlockStateHandlerTest() override {} | 218 ~EasyUnlockScreenlockStateHandlerTest() override {} |
212 | 219 |
213 void SetUp() override { | 220 void SetUp() override { |
214 // Create and inject fake lock handler to the screenlock bridge. | 221 // Create and inject fake lock handler to the screenlock bridge. |
215 lock_handler_.reset(new TestLockHandler(user_email_)); | 222 lock_handler_.reset(new TestLockHandler(account_id_)); |
216 proximity_auth::ScreenlockBridge* screenlock_bridge = | 223 proximity_auth::ScreenlockBridge* screenlock_bridge = |
217 proximity_auth::ScreenlockBridge::Get(); | 224 proximity_auth::ScreenlockBridge::Get(); |
218 screenlock_bridge->SetLockHandler(lock_handler_.get()); | 225 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
219 | 226 |
220 // Create the screenlock state handler object that will be tested. | 227 // Create the screenlock state handler object that will be tested. |
221 state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 228 state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
222 user_email_, | 229 account_id_, EasyUnlockScreenlockStateHandler::NO_HARDLOCK, |
223 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, | |
224 screenlock_bridge)); | 230 screenlock_bridge)); |
225 } | 231 } |
226 | 232 |
227 void TearDown() override { | 233 void TearDown() override { |
228 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 234 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
229 lock_handler_.reset(); | 235 lock_handler_.reset(); |
230 state_handler_.reset(); | 236 state_handler_.reset(); |
231 } | 237 } |
232 | 238 |
233 protected: | 239 protected: |
234 // The state handler that is being tested. | 240 // The state handler that is being tested. |
235 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; | 241 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
236 | 242 |
237 // The user associated with |state_handler_|. | 243 // The user associated with |state_handler_|. |
238 const std::string user_email_; | 244 const AccountId account_id_ = AccountId::FromUserEmail("test_user@gmail.com"); |
239 | 245 |
240 // Faked lock handler given to proximity_auth::ScreenlockBridge during the | 246 // Faked lock handler given to proximity_auth::ScreenlockBridge during the |
241 // test. Abstracts the screen lock UI. | 247 // test. Abstracts the screen lock UI. |
242 scoped_ptr<TestLockHandler> lock_handler_; | 248 scoped_ptr<TestLockHandler> lock_handler_; |
243 }; | 249 }; |
244 | 250 |
245 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedTrialRun) { | 251 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedTrialRun) { |
246 state_handler_->SetTrialRun(); | 252 state_handler_->SetTrialRun(); |
247 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 253 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
248 | 254 |
249 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 255 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
250 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 256 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
251 lock_handler_->GetAuthType(user_email_)); | 257 lock_handler_->GetAuthType(account_id_)); |
252 | 258 |
253 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 259 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
254 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 260 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
255 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 261 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
256 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 262 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
257 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 263 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
258 | 264 |
259 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 265 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
260 // Duplicated state change should be ignored. | 266 // Duplicated state change should be ignored. |
261 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 267 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
262 } | 268 } |
263 | 269 |
264 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { | 270 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { |
265 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 271 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
266 | 272 |
267 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 273 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
268 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 274 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
269 lock_handler_->GetAuthType(user_email_)); | 275 lock_handler_->GetAuthType(account_id_)); |
270 | 276 |
271 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 277 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
272 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 278 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
273 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 279 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
274 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 280 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
275 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 281 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
276 } | 282 } |
277 | 283 |
278 TEST_F(EasyUnlockScreenlockStateHandlerTest, IsActive) { | 284 TEST_F(EasyUnlockScreenlockStateHandlerTest, IsActive) { |
279 EXPECT_FALSE(state_handler_->IsActive()); | 285 EXPECT_FALSE(state_handler_->IsActive()); |
280 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 286 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
281 EXPECT_TRUE(state_handler_->IsActive()); | 287 EXPECT_TRUE(state_handler_->IsActive()); |
282 state_handler_->ChangeState(ScreenlockState::INACTIVE); | 288 state_handler_->ChangeState(ScreenlockState::INACTIVE); |
283 EXPECT_FALSE(state_handler_->IsActive()); | 289 EXPECT_FALSE(state_handler_->IsActive()); |
284 } | 290 } |
285 | 291 |
286 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { | 292 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { |
287 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); | 293 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); |
288 EXPECT_TRUE(state_handler_->IsActive()); | 294 EXPECT_TRUE(state_handler_->IsActive()); |
289 | 295 |
290 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 296 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
291 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 297 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
292 lock_handler_->GetAuthType(user_email_)); | 298 lock_handler_->GetAuthType(account_id_)); |
293 | 299 |
294 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 300 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
295 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 301 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
296 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); | 302 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); |
297 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 303 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
298 | 304 |
299 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); | 305 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); |
300 // Duplicated state change should be ignored. | 306 // Duplicated state change should be ignored. |
301 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 307 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
302 } | 308 } |
303 | 309 |
304 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { | 310 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { |
305 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 311 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
306 | 312 |
307 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 313 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
308 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 314 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
309 lock_handler_->GetAuthType(user_email_)); | 315 lock_handler_->GetAuthType(account_id_)); |
310 | 316 |
311 state_handler_->SetHardlockState( | 317 state_handler_->SetHardlockState( |
312 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 318 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
313 | 319 |
314 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 320 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
315 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 321 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
316 lock_handler_->GetAuthType(user_email_)); | 322 lock_handler_->GetAuthType(account_id_)); |
317 | 323 |
318 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 324 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
319 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 325 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
320 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 326 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
321 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 327 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
322 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 328 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
323 | 329 |
324 state_handler_->SetHardlockState( | 330 state_handler_->SetHardlockState( |
325 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 331 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
326 | 332 |
327 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 333 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
328 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 334 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
329 } | 335 } |
330 | 336 |
331 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { | 337 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { |
332 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 338 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
333 | 339 |
334 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 340 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
335 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 341 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
336 lock_handler_->GetAuthType(user_email_)); | 342 lock_handler_->GetAuthType(account_id_)); |
337 | 343 |
338 state_handler_->SetHardlockState( | 344 state_handler_->SetHardlockState( |
339 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 345 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
340 | 346 |
341 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 347 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
342 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 348 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
343 lock_handler_->GetAuthType(user_email_)); | 349 lock_handler_->GetAuthType(account_id_)); |
344 } | 350 } |
345 | 351 |
346 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { | 352 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { |
347 std::vector<ScreenlockState> states; | 353 std::vector<ScreenlockState> states; |
348 states.push_back(ScreenlockState::NO_BLUETOOTH); | 354 states.push_back(ScreenlockState::NO_BLUETOOTH); |
349 states.push_back(ScreenlockState::NO_PHONE); | 355 states.push_back(ScreenlockState::NO_PHONE); |
350 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); | 356 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); |
351 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); | 357 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); |
352 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); | 358 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); |
353 states.push_back(ScreenlockState::PHONE_LOCKED); | 359 states.push_back(ScreenlockState::PHONE_LOCKED); |
354 | 360 |
355 for (size_t i = 0; i < states.size(); ++i) { | 361 for (size_t i = 0; i < states.size(); ++i) { |
356 SCOPED_TRACE(base::SizeTToString(i)); | 362 SCOPED_TRACE(base::SizeTToString(i)); |
357 state_handler_->ChangeState(states[i]); | 363 state_handler_->ChangeState(states[i]); |
358 EXPECT_TRUE(state_handler_->IsActive()); | 364 EXPECT_TRUE(state_handler_->IsActive()); |
359 | 365 |
360 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 366 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
361 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 367 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
362 lock_handler_->GetAuthType(user_email_)); | 368 lock_handler_->GetAuthType(account_id_)); |
363 | 369 |
364 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 370 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
365 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); | 371 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
366 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 372 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
367 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 373 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
368 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 374 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
369 | 375 |
370 state_handler_->ChangeState(states[i]); | 376 state_handler_->ChangeState(states[i]); |
371 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 377 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
372 } | 378 } |
373 } | 379 } |
374 | 380 |
375 TEST_F(EasyUnlockScreenlockStateHandlerTest, SettingTrialRunUpdatesUI) { | 381 TEST_F(EasyUnlockScreenlockStateHandlerTest, SettingTrialRunUpdatesUI) { |
376 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 382 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
377 | 383 |
378 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 384 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
379 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 385 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
380 lock_handler_->GetAuthType(user_email_)); | 386 lock_handler_->GetAuthType(account_id_)); |
381 | 387 |
382 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 388 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
383 ASSERT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 389 ASSERT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
384 | 390 |
385 state_handler_->SetTrialRun(); | 391 state_handler_->SetTrialRun(); |
386 | 392 |
387 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 393 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
388 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 394 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
389 lock_handler_->GetAuthType(user_email_)); | 395 lock_handler_->GetAuthType(account_id_)); |
390 | 396 |
391 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 397 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
392 ASSERT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 398 ASSERT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
393 } | 399 } |
394 | 400 |
395 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 401 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
396 LockScreenClearedOnStateHandlerDestruction) { | 402 LockScreenClearedOnStateHandlerDestruction) { |
397 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 403 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
398 | 404 |
399 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 405 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
400 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 406 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
401 lock_handler_->GetAuthType(user_email_)); | 407 lock_handler_->GetAuthType(account_id_)); |
402 | 408 |
403 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 409 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
404 | 410 |
405 state_handler_.reset(); | 411 state_handler_.reset(); |
406 | 412 |
407 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 413 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
408 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 414 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
409 lock_handler_->GetAuthType(user_email_)); | 415 lock_handler_->GetAuthType(account_id_)); |
410 | 416 |
411 ASSERT_FALSE(lock_handler_->HasCustomIcon()); | 417 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
412 } | 418 } |
413 | 419 |
414 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { | 420 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { |
415 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 421 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
416 | 422 |
417 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 423 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
418 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 424 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
419 lock_handler_->GetAuthType(user_email_)); | 425 lock_handler_->GetAuthType(account_id_)); |
420 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 426 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
421 | 427 |
422 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 428 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
423 lock_handler_.reset(new TestLockHandler(user_email_)); | 429 lock_handler_.reset(new TestLockHandler(account_id_)); |
424 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 430 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
425 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 431 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
426 | 432 |
427 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 433 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
428 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 434 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
429 lock_handler_->GetAuthType(user_email_)); | 435 lock_handler_->GetAuthType(account_id_)); |
430 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 436 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
431 } | 437 } |
432 | 438 |
433 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { | 439 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { |
434 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 440 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
435 | 441 |
436 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 442 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
437 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 443 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
438 lock_handler_->GetAuthType(user_email_)); | 444 lock_handler_->GetAuthType(account_id_)); |
439 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 445 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
440 | 446 |
441 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 447 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
442 lock_handler_.reset(new TestLockHandler(user_email_)); | 448 lock_handler_.reset(new TestLockHandler(account_id_)); |
443 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 449 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
444 | 450 |
445 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); | 451 state_handler_->ChangeState(ScreenlockState::BLUETOOTH_CONNECTING); |
446 | 452 |
447 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 453 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
448 | 454 |
449 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 455 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
450 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 456 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
451 lock_handler_->GetAuthType(user_email_)); | 457 lock_handler_->GetAuthType(account_id_)); |
452 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 458 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
453 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 459 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
454 } | 460 } |
455 | 461 |
456 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 462 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
457 HardlockEnabledAfterInitialUnlock) { | 463 HardlockEnabledAfterInitialUnlock) { |
458 state_handler_->SetTrialRun(); | 464 state_handler_->SetTrialRun(); |
459 | 465 |
460 std::vector<ScreenlockState> states; | 466 std::vector<ScreenlockState> states; |
461 states.push_back(ScreenlockState::BLUETOOTH_CONNECTING); | 467 states.push_back(ScreenlockState::BLUETOOTH_CONNECTING); |
462 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); | 468 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); |
463 states.push_back(ScreenlockState::NO_BLUETOOTH); | 469 states.push_back(ScreenlockState::NO_BLUETOOTH); |
464 states.push_back(ScreenlockState::NO_PHONE); | 470 states.push_back(ScreenlockState::NO_PHONE); |
465 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); | 471 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); |
466 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); | 472 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); |
467 // This one should go last as changing state to AUTHENTICATED enables hard | 473 // This one should go last as changing state to AUTHENTICATED enables hard |
468 // locking. | 474 // locking. |
469 states.push_back(ScreenlockState::AUTHENTICATED); | 475 states.push_back(ScreenlockState::AUTHENTICATED); |
470 | 476 |
471 for (size_t i = 0; i < states.size(); ++i) { | 477 for (size_t i = 0; i < states.size(); ++i) { |
472 SCOPED_TRACE(base::SizeTToString(i)); | 478 SCOPED_TRACE(base::SizeTToString(i)); |
473 state_handler_->ChangeState(states[i]); | 479 state_handler_->ChangeState(states[i]); |
474 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 480 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
475 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 481 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
476 } | 482 } |
477 | 483 |
478 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 484 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
479 lock_handler_.reset(new TestLockHandler(user_email_)); | 485 lock_handler_.reset(new TestLockHandler(account_id_)); |
480 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 486 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
481 | 487 |
482 for (size_t i = 0; i < states.size(); ++i) { | 488 for (size_t i = 0; i < states.size(); ++i) { |
483 SCOPED_TRACE(base::SizeTToString(i)); | 489 SCOPED_TRACE(base::SizeTToString(i)); |
484 state_handler_->ChangeState(states[i]); | 490 state_handler_->ChangeState(states[i]); |
485 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 491 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
486 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 492 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
487 } | 493 } |
488 } | 494 } |
489 | 495 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); | 588 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
583 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 589 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
584 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 590 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
585 } | 591 } |
586 | 592 |
587 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { | 593 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { |
588 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 594 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
589 | 595 |
590 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 596 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
591 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 597 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
592 lock_handler_->GetAuthType(user_email_)); | 598 lock_handler_->GetAuthType(account_id_)); |
593 | 599 |
594 state_handler_->SetHardlockState( | 600 state_handler_->SetHardlockState( |
595 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 601 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
596 | 602 |
597 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 603 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
598 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 604 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
599 lock_handler_->GetAuthType(user_email_)); | 605 lock_handler_->GetAuthType(account_id_)); |
600 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 606 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
601 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 607 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
602 | 608 |
603 state_handler_->ChangeState(ScreenlockState::NO_PHONE); | 609 state_handler_->ChangeState(ScreenlockState::NO_PHONE); |
604 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 610 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
605 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 611 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
606 | 612 |
607 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 613 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
608 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 614 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
609 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 615 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
610 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 616 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
611 lock_handler_->GetAuthType(user_email_)); | 617 lock_handler_->GetAuthType(account_id_)); |
612 } | 618 } |
613 | 619 |
614 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 620 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
615 LockScreenChangeableOnLockAfterHardlockReset) { | 621 LockScreenChangeableOnLockAfterHardlockReset) { |
616 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 622 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
617 | 623 |
618 state_handler_->SetHardlockState( | 624 state_handler_->SetHardlockState( |
619 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 625 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
620 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 626 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
621 | 627 |
622 state_handler_->SetHardlockState( | 628 state_handler_->SetHardlockState( |
623 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 629 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
624 | 630 |
625 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 631 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
626 lock_handler_.reset(new TestLockHandler(user_email_)); | 632 lock_handler_.reset(new TestLockHandler(account_id_)); |
627 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 633 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
628 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 634 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
629 | 635 |
630 state_handler_->ChangeState(ScreenlockState::NO_PHONE); | 636 state_handler_->ChangeState(ScreenlockState::NO_PHONE); |
631 | 637 |
632 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 638 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
633 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 639 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
634 | 640 |
635 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 641 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
636 lock_handler_.reset(new TestLockHandler(user_email_)); | 642 lock_handler_.reset(new TestLockHandler(account_id_)); |
637 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 643 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
638 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 644 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
639 | 645 |
640 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 646 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
641 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 647 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
642 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 648 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
643 lock_handler_->GetAuthType(user_email_)); | 649 lock_handler_->GetAuthType(account_id_)); |
644 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); | 650 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
645 | 651 |
646 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 652 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
647 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 653 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
648 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 654 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
649 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, | 655 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
650 lock_handler_->GetAuthType(user_email_)); | 656 lock_handler_->GetAuthType(account_id_)); |
651 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 657 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
652 } | 658 } |
653 | 659 |
654 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { | 660 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { |
655 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 661 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
656 state_handler_->SetHardlockState( | 662 state_handler_->SetHardlockState( |
657 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 663 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
658 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 664 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
659 | 665 |
660 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 666 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
661 lock_handler_.reset(new TestLockHandler(user_email_)); | 667 lock_handler_.reset(new TestLockHandler(account_id_)); |
662 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 668 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
663 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 669 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
664 | 670 |
665 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 671 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
666 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 672 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
667 lock_handler_->GetAuthType(user_email_)); | 673 lock_handler_->GetAuthType(account_id_)); |
668 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 674 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
669 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 675 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
670 | 676 |
671 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); | 677 state_handler_->ChangeState(ScreenlockState::AUTHENTICATED); |
672 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 678 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
673 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 679 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
674 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 680 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
675 lock_handler_->GetAuthType(user_email_)); | 681 lock_handler_->GetAuthType(account_id_)); |
676 } | 682 } |
677 | 683 |
678 TEST_F(EasyUnlockScreenlockStateHandlerTest, NoOverrideOnlineSignin) { | 684 TEST_F(EasyUnlockScreenlockStateHandlerTest, NoOverrideOnlineSignin) { |
679 lock_handler_->SetAuthType( | 685 lock_handler_->SetAuthType( |
680 user_email_, | 686 account_id_, |
681 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 687 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
682 base::string16()); | 688 base::string16()); |
683 | 689 |
684 std::vector<ScreenlockState> states; | 690 std::vector<ScreenlockState> states; |
685 states.push_back(ScreenlockState::NO_BLUETOOTH); | 691 states.push_back(ScreenlockState::NO_BLUETOOTH); |
686 states.push_back(ScreenlockState::NO_PHONE); | 692 states.push_back(ScreenlockState::NO_PHONE); |
687 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); | 693 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); |
688 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); | 694 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); |
689 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); | 695 states.push_back(ScreenlockState::PHONE_NOT_AUTHENTICATED); |
690 states.push_back(ScreenlockState::PHONE_LOCKED); | 696 states.push_back(ScreenlockState::PHONE_LOCKED); |
691 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); | 697 states.push_back(ScreenlockState::PHONE_NOT_LOCKABLE); |
692 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); | 698 states.push_back(ScreenlockState::PHONE_UNSUPPORTED); |
693 states.push_back(ScreenlockState::RSSI_TOO_LOW); | 699 states.push_back(ScreenlockState::RSSI_TOO_LOW); |
694 states.push_back(ScreenlockState::TX_POWER_TOO_HIGH); | 700 states.push_back(ScreenlockState::TX_POWER_TOO_HIGH); |
695 states.push_back(ScreenlockState::AUTHENTICATED); | 701 states.push_back(ScreenlockState::AUTHENTICATED); |
696 | 702 |
697 for (size_t i = 0; i < states.size(); ++i) { | 703 for (size_t i = 0; i < states.size(); ++i) { |
698 state_handler_->ChangeState(states[i]); | 704 state_handler_->ChangeState(states[i]); |
699 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 705 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
700 lock_handler_->GetAuthType(user_email_)); | 706 lock_handler_->GetAuthType(account_id_)); |
701 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 707 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
702 } | 708 } |
703 | 709 |
704 std::vector<EasyUnlockScreenlockStateHandler::HardlockState> hardlock_states; | 710 std::vector<EasyUnlockScreenlockStateHandler::HardlockState> hardlock_states; |
705 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 711 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
706 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 712 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
707 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | 713 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
708 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_ADDED); | 714 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_ADDED); |
709 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_PAIRING); | 715 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_PAIRING); |
710 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::LOGIN_FAILED); | 716 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::LOGIN_FAILED); |
711 | 717 |
712 for (size_t i = 0; i < hardlock_states.size(); ++i) { | 718 for (size_t i = 0; i < hardlock_states.size(); ++i) { |
713 state_handler_->SetHardlockState(hardlock_states[i]); | 719 state_handler_->SetHardlockState(hardlock_states[i]); |
714 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 720 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
715 lock_handler_->GetAuthType(user_email_)); | 721 lock_handler_->GetAuthType(account_id_)); |
716 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 722 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
717 } | 723 } |
718 } | 724 } |
719 | 725 |
720 TEST_F(EasyUnlockScreenlockStateHandlerTest, TrialRunMetrics) { | 726 TEST_F(EasyUnlockScreenlockStateHandlerTest, TrialRunMetrics) { |
721 base::HistogramTester histogram_tester; | 727 base::HistogramTester histogram_tester; |
722 | 728 |
723 // Simulate the user clicking on the lock icon twice outside of a trial run. | 729 // Simulate the user clicking on the lock icon twice outside of a trial run. |
724 // No trial run metrics should be recorded. | 730 // No trial run metrics should be recorded. |
725 state_handler_->RecordClickOnLockIcon(); | 731 state_handler_->RecordClickOnLockIcon(); |
726 state_handler_->RecordClickOnLockIcon(); | 732 state_handler_->RecordClickOnLockIcon(); |
727 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 0); | 733 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 0); |
728 | 734 |
729 // Simulate the user clicking on the lock icon three times during a trial run. | 735 // Simulate the user clicking on the lock icon three times during a trial run. |
730 state_handler_->SetTrialRun(); | 736 state_handler_->SetTrialRun(); |
731 state_handler_->RecordClickOnLockIcon(); | 737 state_handler_->RecordClickOnLockIcon(); |
732 state_handler_->RecordClickOnLockIcon(); | 738 state_handler_->RecordClickOnLockIcon(); |
733 state_handler_->RecordClickOnLockIcon(); | 739 state_handler_->RecordClickOnLockIcon(); |
734 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4); | 740 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4); |
735 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events", | 741 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events", |
736 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1); | 742 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1); |
737 histogram_tester.ExpectBucketCount( | 743 histogram_tester.ExpectBucketCount( |
738 "EasyUnlock.TrialRun.Events", | 744 "EasyUnlock.TrialRun.Events", |
739 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3); | 745 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3); |
740 } | 746 } |
741 | 747 |
742 } // namespace | 748 } // namespace |
OLD | NEW |