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
3 // found in the LICENSE file.
8 #include "base/strings/string16.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/browser/signin/screenlock_bridge.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/l10n/l10n_util.h"
23 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the
24 // same as the ones set by ScreenlockBridge.
25 const char kLockedIconId
[] = "locked";
26 const char kUnlockedIconId
[] = "unlocked";
27 const char kSpinnerIconId
[] = "spinner";
28 const char kHardlockedIconId
[] = "hardlocked";
30 // Checks if |input| string has any unreplaced placeholders.
31 bool StringHasPlaceholders(const base::string16
& input
) {
32 std::vector
<size_t> offsets
;
33 std::vector
<base::string16
> subst
;
34 subst
.push_back(base::string16());
36 base::string16 replaced
= ReplaceStringPlaceholders(input
, subst
, &offsets
);
37 return !offsets
.empty();
40 // Fake lock handler to be used in these tests.
41 class TestLockHandler
: public ScreenlockBridge::LockHandler
{
43 explicit TestLockHandler(const std::string
& user_email
)
44 : user_email_(user_email
),
46 auth_type_(OFFLINE_PASSWORD
) {
48 virtual ~TestLockHandler() {}
50 // ScreenlockBridge::LockHandler implementation:
51 virtual void ShowBannerMessage(const base::string16
& message
) OVERRIDE
{
52 ASSERT_FALSE(true) << "Should not be reached.";
55 virtual void ShowUserPodCustomIcon(
56 const std::string
& user_email
,
57 const ScreenlockBridge::UserPodCustomIconOptions
& icon
) OVERRIDE
{
58 ASSERT_EQ(user_email_
, user_email
);
60 last_custom_icon_
= icon
.ToDictionaryValue().Pass();
64 virtual void HideUserPodCustomIcon(const std::string
& user_email
) OVERRIDE
{
65 ASSERT_EQ(user_email_
, user_email
);
66 last_custom_icon_
.reset();
69 virtual void EnableInput() OVERRIDE
{
70 ASSERT_FALSE(true) << "Should not be reached.";
73 virtual void SetAuthType(const std::string
& user_email
,
75 const base::string16
& auth_value
) OVERRIDE
{
76 ASSERT_EQ(user_email_
, user_email
);
77 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should
78 // avoid resetting the same auth type.
79 EXPECT_NE(auth_type_
, auth_type
);
81 auth_type_
= auth_type
;
82 auth_value_
= auth_value
;
85 virtual AuthType
GetAuthType(const std::string
& user_email
) const OVERRIDE
{
86 EXPECT_EQ(user_email_
, user_email
);
90 virtual void Unlock(const std::string
& user_email
) OVERRIDE
{
91 ASSERT_FALSE(true) << "Should not be reached.";
94 virtual void AttemptEasySignin(const std::string
& user_email
,
95 const std::string
& secret
,
96 const std::string
& key_label
) OVERRIDE
{
97 ASSERT_FALSE(true) << "Should not be reached.";
100 // Utility methods used by tests:
102 // Gets last set auth value.
103 base::string16
GetAuthValue() const {
107 // Sets the auth value.
108 void SetAuthValue(const base::string16
& value
) {
112 // Returns the number of times an icon was shown since the last call to this
114 size_t GetAndResetShowIconCount() {
115 size_t result
= show_icon_count_
;
116 show_icon_count_
= 0u;
120 // Whether the custom icon is set.
121 bool HasCustomIcon() const {
122 return last_custom_icon_
;
125 // If custom icon is set, returns the icon's id.
126 // If there is no icon, or if it doesn't have an id set, returns an empty
128 std::string
GetCustomIconId() const {
130 if (last_custom_icon_
)
131 last_custom_icon_
->GetString("id", &result
);
135 // Whether the custom icon is set and it has a tooltip.
136 bool CustomIconHasTooltip() const {
137 return last_custom_icon_
&& last_custom_icon_
->HasKey("tooltip");
140 // Gets the custom icon's tooltip text, if one is set.
141 base::string16
GetCustomIconTooltip() const {
142 base::string16 result
;
143 if (last_custom_icon_
)
144 last_custom_icon_
->GetString("tooltip.text", &result
);
148 // Whether the custom icon's tooltip should be autoshown. If the icon is not
149 // set, or it doesn't have a tooltip, returns false.
150 bool IsCustomIconTooltipAutoshown() const {
152 if (last_custom_icon_
)
153 last_custom_icon_
->GetBoolean("tooltip.autoshow", &result
);
157 // Whether the custom icon is set and if has hardlock capability enabed.
158 bool CustomIconHardlocksOnClick() const {
160 if (last_custom_icon_
)
161 last_custom_icon_
->GetBoolean("hardlockOnClick", &result
);
166 // Does some sanity checks on the last icon set by |ShowUserPodCustomIcon|.
167 // It will cause a test failure if the icon is not valid.
168 void ValidateCustomIcon() {
169 ASSERT_TRUE(last_custom_icon_
.get());
171 EXPECT_TRUE(last_custom_icon_
->HasKey("id"));
173 if (last_custom_icon_
->HasKey("tooltip")) {
174 base::string16 tooltip
;
175 EXPECT_TRUE(last_custom_icon_
->GetString("tooltip.text", &tooltip
));
176 EXPECT_FALSE(tooltip
.empty());
177 EXPECT_FALSE(StringHasPlaceholders(tooltip
));
181 // The fake user email used in test. All methods called on |this| should be
182 // associated with this user.
183 const std::string user_email_
;
185 // The last icon set using |SetUserPodCustomIcon|. Call to
186 // |HideUserPodcustomIcon| resets it.
187 scoped_ptr
<base::DictionaryValue
> last_custom_icon_
;
188 size_t show_icon_count_
;
190 // Auth type and value set using |SetAuthType|.
192 base::string16 auth_value_
;
194 DISALLOW_COPY_AND_ASSIGN(TestLockHandler
);
197 class EasyUnlockScreenlockStateHandlerTest
: public testing::Test
{
199 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {}
200 virtual ~EasyUnlockScreenlockStateHandlerTest() {}
202 virtual void SetUp() OVERRIDE
{
203 pref_service_
.reset(new TestingPrefServiceSyncable());
205 // The preference used to determine if easy unlock was previously used by
206 // the user on the device ought to be registered by the EasyUnlockService.
207 EasyUnlockService::RegisterProfilePrefs(pref_service_
->registry());
209 // Create and inject fake lock handler to the screenlock bridge.
210 lock_handler_
.reset(new TestLockHandler(user_email_
));
211 ScreenlockBridge
* screenlock_bridge
= ScreenlockBridge::Get();
212 screenlock_bridge
->SetLockHandler(lock_handler_
.get());
214 // Create the screenlock state handler object that will be tested.
215 state_handler_
.reset(new EasyUnlockScreenlockStateHandler(
217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK
,
222 virtual void TearDown() OVERRIDE
{
223 ScreenlockBridge::Get()->SetLockHandler(NULL
);
224 lock_handler_
.reset();
225 state_handler_
.reset();
229 // The state handler that is being tested.
230 scoped_ptr
<EasyUnlockScreenlockStateHandler
> state_handler_
;
232 // The user associated with |state_handler_|.
233 const std::string user_email_
;
235 // Faked lock handler given to ScreenlockBridge during the test. Abstracts
236 // the screen lock UI.
237 scoped_ptr
<TestLockHandler
> lock_handler_
;
239 // The user's preferences.
240 scoped_ptr
<TestingPrefServiceSyncable
> pref_service_
;
243 TEST_F(EasyUnlockScreenlockStateHandlerTest
, AuthenticatedInitialRun
) {
244 state_handler_
->ChangeState(
245 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
247 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
248 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
249 lock_handler_
->GetAuthType(user_email_
));
251 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
252 EXPECT_EQ(kUnlockedIconId
, lock_handler_
->GetCustomIconId());
253 EXPECT_TRUE(lock_handler_
->CustomIconHasTooltip());
254 EXPECT_TRUE(lock_handler_
->IsCustomIconTooltipAutoshown());
255 EXPECT_FALSE(lock_handler_
->CustomIconHardlocksOnClick());
257 state_handler_
->ChangeState(
258 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
259 // Duplicated state change should be ignored.
260 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
263 TEST_F(EasyUnlockScreenlockStateHandlerTest
, AuthenticatedNotInitialRun
) {
264 // Update preference for showing tutorial.
265 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
267 state_handler_
->ChangeState(
268 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
270 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
271 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
272 lock_handler_
->GetAuthType(user_email_
));
274 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
275 EXPECT_EQ(kUnlockedIconId
, lock_handler_
->GetCustomIconId());
276 EXPECT_TRUE(lock_handler_
->CustomIconHasTooltip());
277 EXPECT_FALSE(lock_handler_
->IsCustomIconTooltipAutoshown());
278 EXPECT_TRUE(lock_handler_
->CustomIconHardlocksOnClick());
281 TEST_F(EasyUnlockScreenlockStateHandlerTest
, BluetoothConnecting
) {
282 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
283 state_handler_
->ChangeState(
284 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING
);
286 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
287 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
288 lock_handler_
->GetAuthType(user_email_
));
290 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
291 EXPECT_EQ(kSpinnerIconId
, lock_handler_
->GetCustomIconId());
292 EXPECT_FALSE(lock_handler_
->CustomIconHasTooltip());
293 EXPECT_TRUE(lock_handler_
->CustomIconHardlocksOnClick());
295 state_handler_
->ChangeState(
296 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING
);
297 // Duplicated state change should be ignored.
298 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
301 TEST_F(EasyUnlockScreenlockStateHandlerTest
, HardlockedState
) {
302 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
303 state_handler_
->ChangeState(
304 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
306 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
307 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
308 lock_handler_
->GetAuthType(user_email_
));
310 state_handler_
->SetHardlockState(
311 EasyUnlockScreenlockStateHandler::USER_HARDLOCK
);
313 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
314 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
315 lock_handler_
->GetAuthType(user_email_
));
317 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
318 EXPECT_EQ(kHardlockedIconId
, lock_handler_
->GetCustomIconId());
319 EXPECT_TRUE(lock_handler_
->CustomIconHasTooltip());
320 EXPECT_FALSE(lock_handler_
->CustomIconHardlocksOnClick());
322 state_handler_
->SetHardlockState(
323 EasyUnlockScreenlockStateHandler::USER_HARDLOCK
);
325 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
326 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
329 TEST_F(EasyUnlockScreenlockStateHandlerTest
, HardlockedStateNoPairing
) {
330 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
331 state_handler_
->ChangeState(
332 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
334 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
335 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
336 lock_handler_
->GetAuthType(user_email_
));
338 state_handler_
->SetHardlockState(
339 EasyUnlockScreenlockStateHandler::NO_PAIRING
);
341 EXPECT_FALSE(lock_handler_
->HasCustomIcon());
342 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
343 lock_handler_
->GetAuthType(user_email_
));
346 TEST_F(EasyUnlockScreenlockStateHandlerTest
, StatesWithLockedIcon
) {
347 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
349 std::vector
<EasyUnlockScreenlockStateHandler::State
> states
;
350 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH
);
351 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
352 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED
);
353 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE
);
355 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED
);
356 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED
);
358 for (size_t i
= 0; i
< states
.size(); ++i
) {
359 state_handler_
->ChangeState(states
[i
]);
361 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount())
362 << "State: " << states
[i
];
363 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
364 lock_handler_
->GetAuthType(user_email_
))
365 << "State: " << states
[i
];
367 ASSERT_TRUE(lock_handler_
->HasCustomIcon())
368 << "State: " << states
[i
];
369 EXPECT_EQ(kLockedIconId
, lock_handler_
->GetCustomIconId())
370 << "State: " << states
[i
];
371 EXPECT_TRUE(lock_handler_
->CustomIconHasTooltip())
372 << "State: " << states
[i
];
373 EXPECT_FALSE(lock_handler_
->IsCustomIconTooltipAutoshown())
374 << "State: " << states
[i
];
375 EXPECT_TRUE(lock_handler_
->CustomIconHardlocksOnClick())
376 << "State: " << states
[i
];
378 state_handler_
->ChangeState(states
[i
]);
379 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount())
380 << "State: " << states
[i
];
384 TEST_F(EasyUnlockScreenlockStateHandlerTest
,
385 LockScreenClearedOnStateHandlerDestruction
) {
386 state_handler_
->ChangeState(
387 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
389 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
390 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
391 lock_handler_
->GetAuthType(user_email_
));
393 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
395 state_handler_
.reset();
397 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
398 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
399 lock_handler_
->GetAuthType(user_email_
));
401 ASSERT_FALSE(lock_handler_
->HasCustomIcon());
404 TEST_F(EasyUnlockScreenlockStateHandlerTest
, StatePreservedWhenScreenUnlocks
) {
405 state_handler_
->ChangeState(
406 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
408 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
409 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
410 lock_handler_
->GetAuthType(user_email_
));
411 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
413 ScreenlockBridge::Get()->SetLockHandler(NULL
);
414 lock_handler_
.reset(new TestLockHandler(user_email_
));
415 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
416 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
418 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
419 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
420 lock_handler_
->GetAuthType(user_email_
));
421 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
424 TEST_F(EasyUnlockScreenlockStateHandlerTest
, StateChangeWhileScreenUnlocked
) {
425 state_handler_
->ChangeState(
426 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
428 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
429 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
430 lock_handler_
->GetAuthType(user_email_
));
431 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
433 ScreenlockBridge::Get()->SetLockHandler(NULL
);
434 lock_handler_
.reset(new TestLockHandler(user_email_
));
435 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
437 state_handler_
->ChangeState(
438 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING
);
440 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
442 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
443 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
444 lock_handler_
->GetAuthType(user_email_
));
445 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
446 EXPECT_EQ(kSpinnerIconId
, lock_handler_
->GetCustomIconId());
449 TEST_F(EasyUnlockScreenlockStateHandlerTest
,
450 HardlockEnabledAfterInitialUnlock
) {
451 std::vector
<EasyUnlockScreenlockStateHandler::State
> states
;
453 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING
);
455 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED
);
456 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH
);
457 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
458 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED
);
459 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE
);
460 // This one should go last as changing state to AUTHENTICATED enables hard
462 states
.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
464 for (size_t i
= 0; i
< states
.size(); ++i
) {
465 state_handler_
->ChangeState(states
[i
]);
466 ASSERT_TRUE(lock_handler_
->HasCustomIcon()) << "State: " << states
[i
];
467 EXPECT_FALSE(lock_handler_
->CustomIconHardlocksOnClick())
468 << "State: " << states
[i
];
471 ScreenlockBridge::Get()->SetLockHandler(NULL
);
472 lock_handler_
.reset(new TestLockHandler(user_email_
));
473 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
475 for (size_t i
= 0; i
< states
.size(); ++i
) {
476 state_handler_
->ChangeState(states
[i
]);
477 ASSERT_TRUE(lock_handler_
->HasCustomIcon()) << "State: " << states
[i
];
478 EXPECT_TRUE(lock_handler_
->CustomIconHardlocksOnClick())
479 << "State: " << states
[i
];
483 TEST_F(EasyUnlockScreenlockStateHandlerTest
, InactiveStateHidesIcon
) {
484 state_handler_
->ChangeState(
485 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
487 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
489 state_handler_
->ChangeState(
490 EasyUnlockScreenlockStateHandler::STATE_INACTIVE
);
492 ASSERT_FALSE(lock_handler_
->HasCustomIcon());
495 TEST_F(EasyUnlockScreenlockStateHandlerTest
,
496 AuthenticatedStateClearsPreviousAuthValue
) {
497 state_handler_
->ChangeState(
498 EasyUnlockScreenlockStateHandler::STATE_INACTIVE
);
500 lock_handler_
->SetAuthValue(base::ASCIIToUTF16("xxx"));
502 state_handler_
->ChangeState(
503 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
505 EXPECT_EQ(l10n_util::GetStringUTF16(
506 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE
),
507 lock_handler_
->GetAuthValue());
509 state_handler_
->ChangeState(
510 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
512 EXPECT_EQ(base::string16(), lock_handler_
->GetAuthValue());
515 TEST_F(EasyUnlockScreenlockStateHandlerTest
,
516 ChangingStateDoesNotAffectAuthValueIfAuthTypeDoesNotChange
) {
517 lock_handler_
->SetAuthValue(base::ASCIIToUTF16("xxx"));
519 state_handler_
->ChangeState(
520 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
521 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_
->GetAuthValue());
523 state_handler_
->ChangeState(
524 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED
);
525 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_
->GetAuthValue());
527 state_handler_
->ChangeState(
528 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING
);
529 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_
->GetAuthValue());
530 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
531 EXPECT_EQ(kSpinnerIconId
, lock_handler_
->GetCustomIconId());
534 TEST_F(EasyUnlockScreenlockStateHandlerTest
, StateChangesIgnoredIfHardlocked
) {
535 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
536 state_handler_
->ChangeState(
537 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
539 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
540 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
541 lock_handler_
->GetAuthType(user_email_
));
543 state_handler_
->SetHardlockState(
544 EasyUnlockScreenlockStateHandler::USER_HARDLOCK
);
546 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
547 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
548 lock_handler_
->GetAuthType(user_email_
));
549 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
550 EXPECT_EQ(kHardlockedIconId
, lock_handler_
->GetCustomIconId());
552 state_handler_
->ChangeState(
553 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
554 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
555 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
557 state_handler_
->ChangeState(
558 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
559 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
560 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
561 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
562 lock_handler_
->GetAuthType(user_email_
));
565 TEST_F(EasyUnlockScreenlockStateHandlerTest
,
566 LockScreenChangeableOnLockAfterHardlockReset
) {
567 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
568 state_handler_
->ChangeState(
569 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
571 state_handler_
->SetHardlockState(
572 EasyUnlockScreenlockStateHandler::USER_HARDLOCK
);
573 EXPECT_EQ(2u, lock_handler_
->GetAndResetShowIconCount());
575 state_handler_
->SetHardlockState(
576 EasyUnlockScreenlockStateHandler::NO_HARDLOCK
);
578 ScreenlockBridge::Get()->SetLockHandler(NULL
);
579 lock_handler_
.reset(new TestLockHandler(user_email_
));
580 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
581 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
583 state_handler_
->ChangeState(
584 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE
);
586 EXPECT_EQ(2u, lock_handler_
->GetAndResetShowIconCount());
587 EXPECT_TRUE(lock_handler_
->HasCustomIcon());
589 ScreenlockBridge::Get()->SetLockHandler(NULL
);
590 lock_handler_
.reset(new TestLockHandler(user_email_
));
591 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
592 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
594 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
595 EXPECT_TRUE(lock_handler_
->HasCustomIcon());
596 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
597 lock_handler_
->GetAuthType(user_email_
));
598 EXPECT_EQ(kLockedIconId
, lock_handler_
->GetCustomIconId());
600 state_handler_
->ChangeState(
601 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
602 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
603 EXPECT_TRUE(lock_handler_
->HasCustomIcon());
604 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK
,
605 lock_handler_
->GetAuthType(user_email_
));
606 EXPECT_TRUE(lock_handler_
->CustomIconHardlocksOnClick());
609 TEST_F(EasyUnlockScreenlockStateHandlerTest
, HardlockStatePersistsOverUnlocks
) {
610 pref_service_
->SetBoolean(prefs::kEasyUnlockShowTutorial
, false);
611 state_handler_
->ChangeState(
612 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
613 state_handler_
->SetHardlockState(
614 EasyUnlockScreenlockStateHandler::USER_HARDLOCK
);
615 EXPECT_EQ(2u, lock_handler_
->GetAndResetShowIconCount());
617 ScreenlockBridge::Get()->SetLockHandler(NULL
);
618 lock_handler_
.reset(new TestLockHandler(user_email_
));
619 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
620 ScreenlockBridge::Get()->SetLockHandler(lock_handler_
.get());
622 EXPECT_EQ(1u, lock_handler_
->GetAndResetShowIconCount());
623 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
624 lock_handler_
->GetAuthType(user_email_
));
625 ASSERT_TRUE(lock_handler_
->HasCustomIcon());
626 EXPECT_EQ(kHardlockedIconId
, lock_handler_
->GetCustomIconId());
628 state_handler_
->ChangeState(
629 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED
);
630 EXPECT_EQ(0u, lock_handler_
->GetAndResetShowIconCount());
631 EXPECT_TRUE(lock_handler_
->HasCustomIcon());
632 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
,
633 lock_handler_
->GetAuthType(user_email_
));