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

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

Issue 608693006: [Easy Unlock] When hardlocking, show a different icon on user (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 2 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
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" 11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
12 #include "chrome/browser/signin/easy_unlock_service.h" 12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/browser/signin/screenlock_bridge.h" 13 #include "chrome/browser/signin/screenlock_bridge.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 16 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "components/pref_registry/pref_registry_syncable.h" 17 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 20
21 namespace { 21 namespace {
22 22
23 // Resource URLs for icons used by EasyUnlockScreenlockStateHandler. 23 // Resource URLs for icons used by EasyUnlockScreenlockStateHandler.
24 const char kLockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; 24 const char kLockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_LOCKED";
25 const char kUnlockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; 25 const char kUnlockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED";
26 const char kSpinnerIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; 26 const char kSpinnerIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_SPINNER";
27 const char kHardlockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_HARDLOCKED";
27 28
28 // The expected size of user pod custom icons set by 29 // The expected size of user pod custom icons set by
29 // EasyUnlockScreenlockStateHandler. 30 // EasyUnlockScreenlockStateHandler.
30 const int kExpectedIconSize = 27; 31 const int kExpectedIconSize = 27;
31 32
32 // Checks if |input| string has any unreplaced placeholders. 33 // Checks if |input| string has any unreplaced placeholders.
33 bool StringHasPlaceholders(const base::string16& input) { 34 bool StringHasPlaceholders(const base::string16& input) {
34 std::vector<size_t> offsets; 35 std::vector<size_t> offsets;
35 std::vector<base::string16> subst; 36 std::vector<base::string16> subst;
36 subst.push_back(base::string16()); 37 subst.push_back(base::string16());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); 242 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry());
242 243
243 // Create and inject fake lock handler to the screenlock bridge. 244 // Create and inject fake lock handler to the screenlock bridge.
244 lock_handler_.reset(new TestLockHandler(user_email_)); 245 lock_handler_.reset(new TestLockHandler(user_email_));
245 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); 246 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get();
246 screenlock_bridge->SetLockHandler(lock_handler_.get()); 247 screenlock_bridge->SetLockHandler(lock_handler_.get());
247 248
248 // Create the screenlock state handler object that will be tested. 249 // Create the screenlock state handler object that will be tested.
249 state_handler_.reset( 250 state_handler_.reset(
250 new EasyUnlockScreenlockStateHandler(user_email_, 251 new EasyUnlockScreenlockStateHandler(user_email_,
252 false,
251 pref_service_.get(), 253 pref_service_.get(),
252 screenlock_bridge)); 254 screenlock_bridge));
253 } 255 }
254 256
255 virtual void TearDown() OVERRIDE { 257 virtual void TearDown() OVERRIDE {
256 ScreenlockBridge::Get()->SetLockHandler(NULL); 258 ScreenlockBridge::Get()->SetLockHandler(NULL);
257 lock_handler_.reset(); 259 lock_handler_.reset();
258 state_handler_.reset(); 260 state_handler_.reset();
259 } 261 }
260 262
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); 332 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
331 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated()); 333 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated());
332 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); 334 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity());
333 335
334 state_handler_->ChangeState( 336 state_handler_->ChangeState(
335 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); 337 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
336 // Duplicated state change should be ignored. 338 // Duplicated state change should be ignored.
337 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 339 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
338 } 340 }
339 341
342 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) {
343 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
344 state_handler_->ChangeState(
345 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
346
347 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
348 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
349 lock_handler_->GetAuthType(user_email_));
350
351 state_handler_->SetHardlocked(true);
352
353 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
354 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
355 lock_handler_->GetAuthType(user_email_));
356
357 ASSERT_TRUE(lock_handler_->HasCustomIcon());
358 EXPECT_EQ(kHardlockedIconURL, lock_handler_->GetCustomIconURL());
359 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip());
360 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick());
361 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated());
362 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity());
363
364 state_handler_->SetHardlocked(true);
365
366 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
367 ASSERT_TRUE(lock_handler_->HasCustomIcon());
368 }
369
340 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { 370 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) {
341 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); 371 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
342 372
343 std::vector<EasyUnlockScreenlockStateHandler::State> states; 373 std::vector<EasyUnlockScreenlockStateHandler::State> states;
344 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); 374 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH);
345 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); 375 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
346 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); 376 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED);
347 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); 377 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE);
348 states.push_back( 378 states.push_back(
349 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); 379 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 state_handler_->ChangeState( 555 state_handler_->ChangeState(
526 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); 556 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
527 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); 557 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue());
528 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated()); 558 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated());
529 } 559 }
530 560
531 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { 561 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) {
532 state_handler_->ChangeState( 562 state_handler_->ChangeState(
533 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 563 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
534 564
535 lock_handler_->SetAuthType( 565 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
536 user_email_, 566 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
537 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 567 lock_handler_->GetAuthType(user_email_));
538 base::string16()); 568
539 lock_handler_->HideUserPodCustomIcon(user_email_); 569 state_handler_->SetHardlocked(true);
570
571 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
572 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
573 lock_handler_->GetAuthType(user_email_));
574 ASSERT_TRUE(lock_handler_->HasCustomIcon());
575 EXPECT_EQ(kHardlockedIconURL, lock_handler_->GetCustomIconURL());
540 576
541 state_handler_->ChangeState( 577 state_handler_->ChangeState(
542 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); 578 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
543 EXPECT_FALSE(lock_handler_->HasCustomIcon()); 579 ASSERT_TRUE(lock_handler_->HasCustomIcon());
580 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
544 581
545 state_handler_->ChangeState( 582 state_handler_->ChangeState(
546 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 583 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
547 EXPECT_FALSE(lock_handler_->HasCustomIcon()); 584 ASSERT_TRUE(lock_handler_->HasCustomIcon());
548 EXPECT_EQ(ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 585 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
586 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
549 lock_handler_->GetAuthType(user_email_)); 587 lock_handler_->GetAuthType(user_email_));
550 } 588 }
551 589
552 TEST_F(EasyUnlockScreenlockStateHandlerTest, 590 TEST_F(EasyUnlockScreenlockStateHandlerTest,
553 LockScreenChangeableAfterHardlockUnlocked) { 591 LockScreenChangeableOnLockAfterHardlockReset) {
554 state_handler_->ChangeState( 592 state_handler_->ChangeState(
555 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 593 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
556 594
557 lock_handler_->SetAuthType( 595 state_handler_->SetHardlocked(true);
558 user_email_, 596 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
559 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 597
560 base::string16()); 598 state_handler_->SetHardlocked(false);
561 lock_handler_->HideUserPodCustomIcon(user_email_); 599
600 ScreenlockBridge::Get()->SetLockHandler(NULL);
601 lock_handler_.reset(new TestLockHandler(user_email_));
602 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
603 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
562 604
563 state_handler_->ChangeState( 605 state_handler_->ChangeState(
564 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); 606 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
565 EXPECT_FALSE(lock_handler_->HasCustomIcon()); 607
608 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
609 EXPECT_TRUE(lock_handler_->HasCustomIcon());
566 610
567 ScreenlockBridge::Get()->SetLockHandler(NULL); 611 ScreenlockBridge::Get()->SetLockHandler(NULL);
568 lock_handler_.reset(new TestLockHandler(user_email_)); 612 lock_handler_.reset(new TestLockHandler(user_email_));
569 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 613 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
570 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 614 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
571 615
572 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 616 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
573 EXPECT_TRUE(lock_handler_->HasCustomIcon()); 617 EXPECT_TRUE(lock_handler_->HasCustomIcon());
574 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 618 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
575 lock_handler_->GetAuthType(user_email_)); 619 lock_handler_->GetAuthType(user_email_));
620 EXPECT_EQ(kLockedIconURL, lock_handler_->GetCustomIconURL());
576 621
577 state_handler_->ChangeState( 622 state_handler_->ChangeState(
578 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 623 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
579 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 624 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
580 EXPECT_TRUE(lock_handler_->HasCustomIcon()); 625 EXPECT_TRUE(lock_handler_->HasCustomIcon());
581 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, 626 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
582 lock_handler_->GetAuthType(user_email_)); 627 lock_handler_->GetAuthType(user_email_));
583 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); 628 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
584 } 629 }
585 630
631 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) {
632 state_handler_->ChangeState(
633 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
634 state_handler_->SetHardlocked(true);
635 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
636
637 ScreenlockBridge::Get()->SetLockHandler(NULL);
638 lock_handler_.reset(new TestLockHandler(user_email_));
639 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
640 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
641
642 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
643 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
644 lock_handler_->GetAuthType(user_email_));
645 ASSERT_TRUE(lock_handler_->HasCustomIcon());
646 EXPECT_EQ(kHardlockedIconURL, lock_handler_->GetCustomIconURL());
647
648 state_handler_->ChangeState(
649 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
650 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
651 EXPECT_TRUE(lock_handler_->HasCustomIcon());
652 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
653 lock_handler_->GetAuthType(user_email_));
654 }
655
586 } // namespace 656 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_screenlock_state_handler.cc ('k') | chrome/browser/signin/easy_unlock_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698