feae058b963d4a842f902395ba8197ec411344dc
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / easy_unlock_screenlock_state_handler_unittest.cc
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.
4
5 #include <string>
6 #include <vector>
7
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"
20
21 namespace {
22
23 // Resource URLs for icons used by EasyUnlockScreenlockStateHandler.
24 const char kLockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_LOCKED";
25 const char kUnlockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED";
26 const char kSpinnerIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_SPINNER";
27
28 // The expected size of user pod custom icons set by
29 // EasyUnlockScreenlockStateHandler.
30 const int kExpectedIconSize = 27;
31
32 // Checks if |input| string has any unreplaced placeholders.
33 bool StringHasPlaceholders(const base::string16& input) {
34   std::vector<size_t> offsets;
35   std::vector<base::string16> subst;
36   subst.push_back(base::string16());
37
38   base::string16 replaced = ReplaceStringPlaceholders(input, subst, &offsets);
39   return !offsets.empty();
40 }
41
42 // Fake lock handler to be used in these tests.
43 class TestLockHandler : public ScreenlockBridge::LockHandler {
44  public:
45   explicit TestLockHandler(const std::string& user_email)
46       : user_email_(user_email),
47         show_icon_count_(0u),
48         auth_type_(OFFLINE_PASSWORD) {
49   }
50   virtual ~TestLockHandler() {}
51
52   // ScreenlockBridge::LockHandler implementation:
53   virtual void ShowBannerMessage(const base::string16& message) OVERRIDE {
54     ASSERT_FALSE(true) << "Should not be reached.";
55   }
56
57   virtual void ShowUserPodCustomIcon(
58       const std::string& user_email,
59       const ScreenlockBridge::UserPodCustomIconOptions& icon) OVERRIDE {
60     ASSERT_EQ(user_email_, user_email);
61     ++show_icon_count_;
62     last_custom_icon_ = icon.ToDictionaryValue().Pass();
63     ValidateCustomIcon();
64   }
65
66   virtual void HideUserPodCustomIcon(const std::string& user_email) OVERRIDE {
67     ASSERT_EQ(user_email_, user_email);
68     last_custom_icon_.reset();
69   }
70
71   virtual void EnableInput() OVERRIDE {
72     ASSERT_FALSE(true) << "Should not be reached.";
73   }
74
75   virtual void SetAuthType(const std::string& user_email,
76                            AuthType auth_type,
77                            const base::string16& auth_value) OVERRIDE {
78     ASSERT_EQ(user_email_, user_email);
79     // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should
80     // avoid resetting the same auth type.
81     EXPECT_NE(auth_type_, auth_type);
82
83     auth_type_ = auth_type;
84     auth_value_ = auth_value;
85   }
86
87   virtual AuthType GetAuthType(const std::string& user_email) const OVERRIDE {
88     EXPECT_EQ(user_email_, user_email);
89     return auth_type_;
90   }
91
92   virtual void Unlock(const std::string& user_email) OVERRIDE {
93     ASSERT_FALSE(true) << "Should not be reached.";
94   }
95
96   virtual void AttemptEasySignin(const std::string& user_email,
97                                  const std::string& secret,
98                                  const std::string& key_label) OVERRIDE {
99     ASSERT_FALSE(true) << "Should not be reached.";
100   }
101
102   // Utility methods used by tests:
103
104   // Gets last set auth value.
105   base::string16 GetAuthValue() const {
106     return auth_value_;
107   }
108
109   // Sets the auth value.
110   void SetAuthValue(const base::string16& value) {
111     auth_value_ = value;
112   }
113
114   // Returns the number of times an icon was shown since the last call to this
115   // method.
116   size_t GetAndResetShowIconCount() {
117     size_t result = show_icon_count_;
118     show_icon_count_ = 0u;
119     return result;
120   }
121
122   // Whether the custom icon is set.
123   bool HasCustomIcon() const {
124     return last_custom_icon_;
125   }
126
127   // If custom icon is set, returns the icon's resource URL.
128   // If there is no icon, or if it doesn't have a resource URL set, returns
129   // an empty string.
130   std::string GetCustomIconURL() const {
131     std::string result;
132     if (last_custom_icon_)
133       last_custom_icon_->GetString("resourceUrl", &result);
134     return result;
135   }
136
137   // Whether the custom icon is set and it has a tooltip.
138   bool CustomIconHasTooltip() const {
139     return last_custom_icon_ && last_custom_icon_->HasKey("tooltip");
140   }
141
142   // Gets the custom icon's tooltip text, if one is set.
143   base::string16 GetCustomIconTooltip() const {
144     base::string16 result;
145     if (last_custom_icon_)
146       last_custom_icon_->GetString("tooltip.text", &result);
147     return result;
148   }
149
150   // Whether the custom icon's tooltip should be autoshown. If the icon is not
151   // set, or it doesn't have a tooltip, returns false.
152   bool IsCustomIconTooltipAutoshown() const {
153     bool result = false;
154     if (last_custom_icon_)
155       last_custom_icon_->GetBoolean("tooltip.autoshow", &result);
156     return result;
157   }
158
159   // Returns the custom icon's opacity. If the icon is not set, a negative value
160   // is returned.
161   int GetCustomIconOpacity() const {
162     int result = -1;
163     if (last_custom_icon_)
164       last_custom_icon_->GetInteger("opacity", &result);
165     return result;
166   }
167
168   // Whether the custom icon is set and if has hardlock capability enabed.
169   bool CustomIconHardlocksOnClick() const {
170     bool result = false;
171     if (last_custom_icon_)
172       last_custom_icon_->GetBoolean("hardlockOnClick", &result);
173     return result;
174   }
175
176   // Whether the custom icon is set and has an animation set.
177   bool IsCustomIconAnimated() const {
178     return last_custom_icon_ && last_custom_icon_->HasKey("animation");
179   }
180
181  private:
182   // Does some sanity checks on the last icon set by |ShowUserPodCustomIcon|.
183   // It will cause a test failure if the icon is not valid.
184   void ValidateCustomIcon() {
185     ASSERT_TRUE(last_custom_icon_.get());
186
187     EXPECT_FALSE(last_custom_icon_->HasKey("data"));
188
189     int height = 0;
190     last_custom_icon_->GetInteger("size.height", &height);
191     EXPECT_EQ(kExpectedIconSize, height);
192
193     int width = 0;
194     last_custom_icon_->GetInteger("size.width", &width);
195     EXPECT_EQ(kExpectedIconSize, width);
196
197     if (last_custom_icon_->HasKey("animation")) {
198       int animation_resource_width = -1;
199       EXPECT_TRUE(last_custom_icon_->GetInteger("animation.resourceWidth",
200                                                 &animation_resource_width));
201       EXPECT_GT(animation_resource_width, kExpectedIconSize);
202       EXPECT_EQ(0, animation_resource_width % kExpectedIconSize);
203       EXPECT_TRUE(
204           last_custom_icon_->GetInteger("animation.frameLengthMs", NULL));
205     }
206
207     if (last_custom_icon_->HasKey("tooltip")) {
208       base::string16 tooltip;
209       EXPECT_TRUE(last_custom_icon_->GetString("tooltip.text", &tooltip));
210       EXPECT_FALSE(tooltip.empty());
211       EXPECT_FALSE(StringHasPlaceholders(tooltip));
212     }
213   }
214
215   // The fake user email used in test. All methods called on |this| should be
216   // associated with this user.
217   const std::string user_email_;
218
219   // The last icon set using |SetUserPodCustomIcon|. Call to
220   // |HideUserPodcustomIcon| resets it.
221   scoped_ptr<base::DictionaryValue> last_custom_icon_;
222   size_t show_icon_count_;
223
224   // Auth type and value set using |SetAuthType|.
225   AuthType auth_type_;
226   base::string16 auth_value_;
227
228   DISALLOW_COPY_AND_ASSIGN(TestLockHandler);
229 };
230
231 class EasyUnlockScreenlockStateHandlerTest : public testing::Test {
232  public:
233   EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {}
234   virtual ~EasyUnlockScreenlockStateHandlerTest() {}
235
236   virtual void SetUp() OVERRIDE {
237     pref_service_.reset(new TestingPrefServiceSyncable());
238
239     // The preference used to determine if easy unlock was previously used by
240     // the user on the device ought to be registered by the EasyUnlockService.
241     EasyUnlockService::RegisterProfilePrefs(pref_service_->registry());
242
243     // Create and inject fake lock handler to the screenlock bridge.
244     lock_handler_.reset(new TestLockHandler(user_email_));
245     ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get();
246     screenlock_bridge->SetLockHandler(lock_handler_.get());
247
248     // Create the screenlock state handler object that will be tested.
249     state_handler_.reset(
250         new EasyUnlockScreenlockStateHandler(user_email_,
251                                              pref_service_.get(),
252                                              screenlock_bridge));
253   }
254
255   virtual void TearDown() OVERRIDE {
256     ScreenlockBridge::Get()->SetLockHandler(NULL);
257     lock_handler_.reset();
258     state_handler_.reset();
259   }
260
261  protected:
262   // The state handler that is being tested.
263   scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_;
264
265   // The user associated with |state_handler_|.
266   const std::string user_email_;
267
268   // Faked lock handler given to ScreenlockBridge during the test. Abstracts
269   // the screen lock UI.
270   scoped_ptr<TestLockHandler> lock_handler_;
271
272   // The user's preferences.
273   scoped_ptr<TestingPrefServiceSyncable> pref_service_;
274 };
275
276 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) {
277   state_handler_->ChangeState(
278       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
279
280   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
281   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
282             lock_handler_->GetAuthType(user_email_));
283
284   ASSERT_TRUE(lock_handler_->HasCustomIcon());
285   EXPECT_EQ(kUnlockedIconURL, lock_handler_->GetCustomIconURL());
286   EXPECT_TRUE(lock_handler_->CustomIconHasTooltip());
287   EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown());
288   EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick());
289   EXPECT_FALSE(lock_handler_->IsCustomIconAnimated());
290   EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity());
291
292   state_handler_->ChangeState(
293       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
294   // Duplicated state change should be ignored.
295   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
296 }
297
298 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) {
299   // Update preference for showing tutorial.
300   pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
301
302   state_handler_->ChangeState(
303       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
304
305   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
306   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
307             lock_handler_->GetAuthType(user_email_));
308
309   ASSERT_TRUE(lock_handler_->HasCustomIcon());
310   EXPECT_EQ(kUnlockedIconURL, lock_handler_->GetCustomIconURL());
311   EXPECT_TRUE(lock_handler_->CustomIconHasTooltip());
312   EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown());
313   EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
314   EXPECT_FALSE(lock_handler_->IsCustomIconAnimated());
315   EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity());
316 }
317
318 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) {
319   pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
320   state_handler_->ChangeState(
321       EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
322
323   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
324   EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
325             lock_handler_->GetAuthType(user_email_));
326
327   ASSERT_TRUE(lock_handler_->HasCustomIcon());
328   EXPECT_EQ(kSpinnerIconURL, lock_handler_->GetCustomIconURL());
329   EXPECT_FALSE(lock_handler_->CustomIconHasTooltip());
330   EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
331   EXPECT_TRUE(lock_handler_->IsCustomIconAnimated());
332   EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity());
333
334   state_handler_->ChangeState(
335       EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
336   // Duplicated state change should be ignored.
337   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
338 }
339
340 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) {
341   pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
342
343   std::vector<EasyUnlockScreenlockStateHandler::State> states;
344   states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH);
345   states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
346   states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED);
347   states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE);
348   states.push_back(
349       EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED);
350   states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
351
352   for (size_t i = 0; i < states.size(); ++i) {
353     state_handler_->ChangeState(states[i]);
354
355     EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount())
356         << "State: " << states[i];
357     EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
358               lock_handler_->GetAuthType(user_email_))
359         << "State: " << states[i];
360
361     ASSERT_TRUE(lock_handler_->HasCustomIcon())
362         << "State: " << states[i];
363     EXPECT_EQ(kLockedIconURL, lock_handler_->GetCustomIconURL())
364         << "State: " << states[i];
365     EXPECT_TRUE(lock_handler_->CustomIconHasTooltip())
366         << "State: " << states[i];
367     EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown())
368         << "State: " << states[i];
369     EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick())
370         << "State: " << states[i];
371     EXPECT_FALSE(lock_handler_->IsCustomIconAnimated())
372         << "State: " << states[i];
373     EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity())
374         << "State: " << states[i];
375
376     state_handler_->ChangeState(states[i]);
377     EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount())
378         << "State: " << states[i];
379   }
380 }
381
382 TEST_F(EasyUnlockScreenlockStateHandlerTest,
383        LockScreenClearedOnStateHandlerDestruction) {
384   state_handler_->ChangeState(
385       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
386
387   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
388   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
389             lock_handler_->GetAuthType(user_email_));
390
391   ASSERT_TRUE(lock_handler_->HasCustomIcon());
392
393   state_handler_.reset();
394
395   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
396   EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
397             lock_handler_->GetAuthType(user_email_));
398
399   ASSERT_FALSE(lock_handler_->HasCustomIcon());
400 }
401
402 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) {
403   state_handler_->ChangeState(
404       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
405
406   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
407   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
408             lock_handler_->GetAuthType(user_email_));
409   ASSERT_TRUE(lock_handler_->HasCustomIcon());
410
411   ScreenlockBridge::Get()->SetLockHandler(NULL);
412   lock_handler_.reset(new TestLockHandler(user_email_));
413   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
414   ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
415
416   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
417   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
418             lock_handler_->GetAuthType(user_email_));
419   ASSERT_TRUE(lock_handler_->HasCustomIcon());
420 }
421
422 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) {
423   state_handler_->ChangeState(
424       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
425
426   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
427   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
428             lock_handler_->GetAuthType(user_email_));
429   ASSERT_TRUE(lock_handler_->HasCustomIcon());
430
431   ScreenlockBridge::Get()->SetLockHandler(NULL);
432   lock_handler_.reset(new TestLockHandler(user_email_));
433   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
434
435   state_handler_->ChangeState(
436       EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
437
438   ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
439
440   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
441   EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
442             lock_handler_->GetAuthType(user_email_));
443   ASSERT_TRUE(lock_handler_->HasCustomIcon());
444   EXPECT_TRUE(lock_handler_->IsCustomIconAnimated());
445 }
446
447 TEST_F(EasyUnlockScreenlockStateHandlerTest,
448        HardlockEnabledAfterInitialUnlock) {
449   std::vector<EasyUnlockScreenlockStateHandler::State> states;
450   states.push_back(
451       EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
452   states.push_back(
453       EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED);
454   states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH);
455   states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
456   states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED);
457   states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE);
458   // This one should go last as changing state to AUTHENTICATED enables hard
459   // locking.
460   states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
461
462   for (size_t i = 0; i < states.size(); ++i) {
463     state_handler_->ChangeState(states[i]);
464     ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i];
465     EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick())
466         << "State: " << states[i];
467   }
468
469   ScreenlockBridge::Get()->SetLockHandler(NULL);
470   lock_handler_.reset(new TestLockHandler(user_email_));
471   ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
472
473   for (size_t i = 0; i < states.size(); ++i) {
474     state_handler_->ChangeState(states[i]);
475     ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i];
476     EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick())
477         << "State: " << states[i];
478   }
479 }
480
481 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) {
482   state_handler_->ChangeState(
483       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
484
485   ASSERT_TRUE(lock_handler_->HasCustomIcon());
486
487   state_handler_->ChangeState(
488       EasyUnlockScreenlockStateHandler::STATE_INACTIVE);
489
490   ASSERT_FALSE(lock_handler_->HasCustomIcon());
491 }
492
493 TEST_F(EasyUnlockScreenlockStateHandlerTest,
494        AuthenticatedStateClearsPreviousAuthValue) {
495   state_handler_->ChangeState(
496       EasyUnlockScreenlockStateHandler::STATE_INACTIVE);
497
498   lock_handler_->SetAuthValue(base::ASCIIToUTF16("xxx"));
499
500   state_handler_->ChangeState(
501       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
502
503   EXPECT_EQ(l10n_util::GetStringUTF16(
504                 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE),
505             lock_handler_->GetAuthValue());
506
507   state_handler_->ChangeState(
508       EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
509
510   EXPECT_EQ(base::string16(), lock_handler_->GetAuthValue());
511 }
512
513 TEST_F(EasyUnlockScreenlockStateHandlerTest,
514        ChangingStateDoesNotAffectAuthValueIfAuthTypeDoesNotChange) {
515   lock_handler_->SetAuthValue(base::ASCIIToUTF16("xxx"));
516
517   state_handler_->ChangeState(
518       EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
519   EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue());
520
521   state_handler_->ChangeState(
522       EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED);
523   EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue());
524
525   state_handler_->ChangeState(
526       EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
527   EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue());
528   EXPECT_TRUE(lock_handler_->IsCustomIconAnimated());
529 }
530
531 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) {
532   state_handler_->ChangeState(
533       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
534
535   lock_handler_->SetAuthType(
536       user_email_,
537       ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
538       base::string16());
539   lock_handler_->HideUserPodCustomIcon(user_email_);
540
541   state_handler_->ChangeState(
542       EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
543   EXPECT_FALSE(lock_handler_->HasCustomIcon());
544
545   state_handler_->ChangeState(
546       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
547   EXPECT_FALSE(lock_handler_->HasCustomIcon());
548   EXPECT_EQ(ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
549             lock_handler_->GetAuthType(user_email_));
550 }
551
552 TEST_F(EasyUnlockScreenlockStateHandlerTest,
553        LockScreenChangeableAfterHardlockUnlocked) {
554   state_handler_->ChangeState(
555       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
556
557   lock_handler_->SetAuthType(
558       user_email_,
559       ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
560       base::string16());
561   lock_handler_->HideUserPodCustomIcon(user_email_);
562
563   state_handler_->ChangeState(
564       EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
565   EXPECT_FALSE(lock_handler_->HasCustomIcon());
566
567   ScreenlockBridge::Get()->SetLockHandler(NULL);
568   lock_handler_.reset(new TestLockHandler(user_email_));
569   EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
570   ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
571
572   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
573   EXPECT_TRUE(lock_handler_->HasCustomIcon());
574   EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
575             lock_handler_->GetAuthType(user_email_));
576
577   state_handler_->ChangeState(
578       EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
579   EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
580   EXPECT_TRUE(lock_handler_->HasCustomIcon());
581   EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
582             lock_handler_->GetAuthType(user_email_));
583   EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
584 }
585
586 }  // namespace