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

Side by Side Diff: chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698