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

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

Issue 1096293003: Move screenlock_bridge to components/proximity_auth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add proximity auth client and the chrome glue. Created 5 years, 8 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 "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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
14 #include "chrome/browser/signin/easy_unlock_metrics.h" 14 #include "chrome/browser/signin/easy_unlock_metrics.h"
15 #include "chrome/browser/signin/easy_unlock_service.h" 15 #include "chrome/browser/signin/easy_unlock_service.h"
16 #include "chrome/browser/signin/screenlock_bridge.h" 16 #include "chrome/browser/signin/easy_unlock_util.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/proximity_auth/screenlock_bridge.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the 24 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the
24 // same as the ones set by ScreenlockBridge. 25 // same as the ones set by ScreenlockBridge.
25 const char kLockedIconId[] = "locked"; 26 const char kLockedIconId[] = "locked";
26 const char kLockedToBeActivatedIconId[] = "locked-to-be-activated"; 27 const char kLockedToBeActivatedIconId[] = "locked-to-be-activated";
27 const char kUnlockedIconId[] = "unlocked"; 28 const char kUnlockedIconId[] = "unlocked";
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 }; 201 };
201 202
202 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { 203 class EasyUnlockScreenlockStateHandlerTest : public testing::Test {
203 public: 204 public:
204 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} 205 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {}
205 ~EasyUnlockScreenlockStateHandlerTest() override {} 206 ~EasyUnlockScreenlockStateHandlerTest() override {}
206 207
207 void SetUp() override { 208 void SetUp() override {
208 // Create and inject fake lock handler to the screenlock bridge. 209 // Create and inject fake lock handler to the screenlock bridge.
209 lock_handler_.reset(new TestLockHandler(user_email_)); 210 lock_handler_.reset(new TestLockHandler(user_email_));
210 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); 211 ScreenlockBridge* screenlock_bridge = GetScreenlockBridgeInstance();
211 screenlock_bridge->SetLockHandler(lock_handler_.get()); 212 screenlock_bridge->SetLockHandler(lock_handler_.get());
212 213
213 // Create the screenlock state handler object that will be tested. 214 // Create the screenlock state handler object that will be tested.
214 state_handler_.reset(new EasyUnlockScreenlockStateHandler( 215 state_handler_.reset(new EasyUnlockScreenlockStateHandler(
215 user_email_, 216 user_email_,
216 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, 217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK,
217 screenlock_bridge)); 218 screenlock_bridge));
218 } 219 }
219 220
220 void TearDown() override { 221 void TearDown() override {
221 ScreenlockBridge::Get()->SetLockHandler(NULL); 222 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
222 lock_handler_.reset(); 223 lock_handler_.reset();
223 state_handler_.reset(); 224 state_handler_.reset();
224 } 225 }
225 226
226 protected: 227 protected:
227 // The state handler that is being tested. 228 // The state handler that is being tested.
228 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; 229 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_;
229 230
230 // The user associated with |state_handler_|. 231 // The user associated with |state_handler_|.
231 const std::string user_email_; 232 const std::string user_email_;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 426
426 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { 427 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) {
427 state_handler_->ChangeState( 428 state_handler_->ChangeState(
428 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 429 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
429 430
430 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 431 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
431 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, 432 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
432 lock_handler_->GetAuthType(user_email_)); 433 lock_handler_->GetAuthType(user_email_));
433 ASSERT_TRUE(lock_handler_->HasCustomIcon()); 434 ASSERT_TRUE(lock_handler_->HasCustomIcon());
434 435
435 ScreenlockBridge::Get()->SetLockHandler(NULL); 436 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
436 lock_handler_.reset(new TestLockHandler(user_email_)); 437 lock_handler_.reset(new TestLockHandler(user_email_));
437 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 438 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
438 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 439 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
439 440
440 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 441 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
441 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, 442 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
442 lock_handler_->GetAuthType(user_email_)); 443 lock_handler_->GetAuthType(user_email_));
443 ASSERT_TRUE(lock_handler_->HasCustomIcon()); 444 ASSERT_TRUE(lock_handler_->HasCustomIcon());
444 } 445 }
445 446
446 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { 447 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) {
447 state_handler_->ChangeState( 448 state_handler_->ChangeState(
448 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 449 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
449 450
450 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 451 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
451 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, 452 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
452 lock_handler_->GetAuthType(user_email_)); 453 lock_handler_->GetAuthType(user_email_));
453 ASSERT_TRUE(lock_handler_->HasCustomIcon()); 454 ASSERT_TRUE(lock_handler_->HasCustomIcon());
454 455
455 ScreenlockBridge::Get()->SetLockHandler(NULL); 456 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
456 lock_handler_.reset(new TestLockHandler(user_email_)); 457 lock_handler_.reset(new TestLockHandler(user_email_));
457 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 458 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
458 459
459 state_handler_->ChangeState( 460 state_handler_->ChangeState(
460 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); 461 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
461 462
462 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 463 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
463 464
464 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 465 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
465 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 466 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
466 lock_handler_->GetAuthType(user_email_)); 467 lock_handler_->GetAuthType(user_email_));
467 ASSERT_TRUE(lock_handler_->HasCustomIcon()); 468 ASSERT_TRUE(lock_handler_->HasCustomIcon());
468 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); 469 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId());
469 } 470 }
470 471
471 TEST_F(EasyUnlockScreenlockStateHandlerTest, 472 TEST_F(EasyUnlockScreenlockStateHandlerTest,
472 HardlockEnabledAfterInitialUnlock) { 473 HardlockEnabledAfterInitialUnlock) {
(...skipping 12 matching lines...) Expand all
485 // locking. 486 // locking.
486 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 487 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
487 488
488 for (size_t i = 0; i < states.size(); ++i) { 489 for (size_t i = 0; i < states.size(); ++i) {
489 state_handler_->ChangeState(states[i]); 490 state_handler_->ChangeState(states[i]);
490 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; 491 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i];
491 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()) 492 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick())
492 << "State: " << states[i]; 493 << "State: " << states[i];
493 } 494 }
494 495
495 ScreenlockBridge::Get()->SetLockHandler(NULL); 496 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
496 lock_handler_.reset(new TestLockHandler(user_email_)); 497 lock_handler_.reset(new TestLockHandler(user_email_));
497 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 498 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
498 499
499 for (size_t i = 0; i < states.size(); ++i) { 500 for (size_t i = 0; i < states.size(); ++i) {
500 state_handler_->ChangeState(states[i]); 501 state_handler_->ChangeState(states[i]);
501 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; 502 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i];
502 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) 503 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick())
503 << "State: " << states[i]; 504 << "State: " << states[i];
504 } 505 }
505 } 506 }
506 507
507 TEST_F(EasyUnlockScreenlockStateHandlerTest, 508 TEST_F(EasyUnlockScreenlockStateHandlerTest,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 state_handler_->ChangeState( 649 state_handler_->ChangeState(
649 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 650 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
650 651
651 state_handler_->SetHardlockState( 652 state_handler_->SetHardlockState(
652 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); 653 EasyUnlockScreenlockStateHandler::USER_HARDLOCK);
653 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); 654 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
654 655
655 state_handler_->SetHardlockState( 656 state_handler_->SetHardlockState(
656 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); 657 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
657 658
658 ScreenlockBridge::Get()->SetLockHandler(NULL); 659 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
659 lock_handler_.reset(new TestLockHandler(user_email_)); 660 lock_handler_.reset(new TestLockHandler(user_email_));
660 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 661 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
661 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 662 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
662 663
663 state_handler_->ChangeState( 664 state_handler_->ChangeState(
664 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); 665 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
665 666
666 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); 667 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
667 EXPECT_TRUE(lock_handler_->HasCustomIcon()); 668 EXPECT_TRUE(lock_handler_->HasCustomIcon());
668 669
669 ScreenlockBridge::Get()->SetLockHandler(NULL); 670 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
670 lock_handler_.reset(new TestLockHandler(user_email_)); 671 lock_handler_.reset(new TestLockHandler(user_email_));
671 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 672 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
672 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 673 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
673 674
674 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 675 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
675 EXPECT_TRUE(lock_handler_->HasCustomIcon()); 676 EXPECT_TRUE(lock_handler_->HasCustomIcon());
676 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 677 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
677 lock_handler_->GetAuthType(user_email_)); 678 lock_handler_->GetAuthType(user_email_));
678 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); 679 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
679 680
680 state_handler_->ChangeState( 681 state_handler_->ChangeState(
681 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 682 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
682 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 683 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
683 EXPECT_TRUE(lock_handler_->HasCustomIcon()); 684 EXPECT_TRUE(lock_handler_->HasCustomIcon());
684 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, 685 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK,
685 lock_handler_->GetAuthType(user_email_)); 686 lock_handler_->GetAuthType(user_email_));
686 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); 687 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick());
687 } 688 }
688 689
689 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { 690 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) {
690 state_handler_->ChangeState( 691 state_handler_->ChangeState(
691 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 692 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
692 state_handler_->SetHardlockState( 693 state_handler_->SetHardlockState(
693 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); 694 EasyUnlockScreenlockStateHandler::USER_HARDLOCK);
694 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); 695 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount());
695 696
696 ScreenlockBridge::Get()->SetLockHandler(NULL); 697 GetScreenlockBridgeInstance()->SetLockHandler(NULL);
697 lock_handler_.reset(new TestLockHandler(user_email_)); 698 lock_handler_.reset(new TestLockHandler(user_email_));
698 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 699 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
699 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); 700 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get());
700 701
701 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); 702 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
702 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 703 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
703 lock_handler_->GetAuthType(user_email_)); 704 lock_handler_->GetAuthType(user_email_));
704 ASSERT_TRUE(lock_handler_->HasCustomIcon()); 705 ASSERT_TRUE(lock_handler_->HasCustomIcon());
705 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); 706 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId());
706 707
707 state_handler_->ChangeState( 708 state_handler_->ChangeState(
708 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); 709 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
709 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); 710 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 state_handler_->RecordClickOnLockIcon(); 771 state_handler_->RecordClickOnLockIcon();
771 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4); 772 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4);
772 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events", 773 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events",
773 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1); 774 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1);
774 histogram_tester.ExpectBucketCount( 775 histogram_tester.ExpectBucketCount(
775 "EasyUnlock.TrialRun.Events", 776 "EasyUnlock.TrialRun.Events",
776 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3); 777 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3);
777 } 778 }
778 779
779 } // namespace 780 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698