| Index: chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc
|
| diff --git a/chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc b/chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc
|
| index 600175cf78d23e8a58ab61ad3d55c409e7ec4a9d..866315d6338066fb03a6200daf1e7911e2d66371 100644
|
| --- a/chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc
|
| +++ b/chrome/browser/signin/easy_unlock_screenlock_state_handler_unittest.cc
|
| @@ -5,6 +5,8 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| +#include "base/prefs/scoped_user_pref_update.h"
|
| +#include "base/prefs/testing_pref_service.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| @@ -13,8 +15,7 @@
|
| #include "chrome/browser/signin/screenlock_bridge.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/grit/generated_resources.h"
|
| -#include "chrome/test/base/testing_pref_service_syncable.h"
|
| -#include "components/pref_registry/pref_registry_syncable.h"
|
| +#include "chrome/test/base/testing_browser_process.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -200,11 +201,13 @@ class EasyUnlockScreenlockStateHandlerTest : public testing::Test {
|
| virtual ~EasyUnlockScreenlockStateHandlerTest() {}
|
|
|
| virtual void SetUp() override {
|
| - pref_service_.reset(new TestingPrefServiceSyncable());
|
| + pref_service_.reset(new TestingPrefServiceSimple());
|
| +
|
| + TestingBrowserProcess::GetGlobal()->SetApplicationLocale("en-US");
|
|
|
| // The preference used to determine if easy unlock was previously used by
|
| // the user on the device ought to be registered by the EasyUnlockService.
|
| - EasyUnlockService::RegisterProfilePrefs(pref_service_->registry());
|
| + EasyUnlockService::RegisterPrefs(pref_service_->registry());
|
|
|
| // Create and inject fake lock handler to the screenlock bridge.
|
| lock_handler_.reset(new TestLockHandler(user_email_));
|
| @@ -225,6 +228,12 @@ class EasyUnlockScreenlockStateHandlerTest : public testing::Test {
|
| state_handler_.reset();
|
| }
|
|
|
| + void SetFirstRunCompleteValue(bool value) {
|
| + DictionaryPrefUpdate update(pref_service_.get(),
|
| + prefs::kEasyUnlockFirstRunComplete);
|
| + update->SetBooleanWithoutPathExpansion(user_email_, value);
|
| + }
|
| +
|
| protected:
|
| // The state handler that is being tested.
|
| scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_;
|
| @@ -237,7 +246,7 @@ class EasyUnlockScreenlockStateHandlerTest : public testing::Test {
|
| scoped_ptr<TestLockHandler> lock_handler_;
|
|
|
| // The user's preferences.
|
| - scoped_ptr<TestingPrefServiceSyncable> pref_service_;
|
| + scoped_ptr<TestingPrefServiceSimple> pref_service_;
|
| };
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) {
|
| @@ -261,8 +270,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) {
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) {
|
| - // Update preference for showing tutorial.
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
|
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
| @@ -279,7 +287,8 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) {
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| +
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
|
|
|
| @@ -299,7 +308,8 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) {
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| +
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
|
|
| @@ -327,7 +337,8 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) {
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| +
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
|
|
| @@ -344,7 +355,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) {
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
|
|
| std::vector<EasyUnlockScreenlockStateHandler::State> states;
|
| states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH);
|
| @@ -381,6 +392,44 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) {
|
| }
|
| }
|
|
|
| +// Verifies tooltips are autoshown on initial run.
|
| +TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon_InitialRun) {
|
| + std::vector<EasyUnlockScreenlockStateHandler::State> states;
|
| + states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH);
|
| + states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE);
|
| + states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED);
|
| + states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE);
|
| + states.push_back(
|
| + EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED);
|
| + states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
|
| +
|
| + for (size_t i = 0; i < states.size(); ++i) {
|
| + state_handler_->ChangeState(states[i]);
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon())
|
| + << "State: " << states[i];
|
| + EXPECT_TRUE(lock_handler_->CustomIconHasTooltip())
|
| + << "State: " << states[i];
|
| + EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown())
|
| + << "State: " << states[i];
|
| + }
|
| +
|
| + ScreenlockBridge::Get()->SetLockHandler(NULL);
|
| + lock_handler_.reset(new TestLockHandler(user_email_));
|
| + EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
|
| + ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get());
|
| +
|
| + // After the screen unlocks the tooltips should not be shown anymore.
|
| + for (size_t i = 0; i < states.size(); ++i) {
|
| + state_handler_->ChangeState(states[i]);
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon())
|
| + << "State: " << states[i];
|
| + EXPECT_TRUE(lock_handler_->CustomIconHasTooltip())
|
| + << "State: " << states[i];
|
| + EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown())
|
| + << "State: " << states[i];
|
| + }
|
| +}
|
| +
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| LockScreenClearedOnStateHandlerDestruction) {
|
| state_handler_->ChangeState(
|
| @@ -480,6 +529,82 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| }
|
| }
|
|
|
| +TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| + NoPairingHardlockClearsIcon) {
|
| + SetFirstRunCompleteValue(true);
|
| +
|
| + state_handler_->ChangeState(
|
| + EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
|
| +
|
| + state_handler_->SetHardlockState(
|
| + EasyUnlockScreenlockStateHandler::NO_PAIRING);
|
| +
|
| + EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_FALSE(lock_handler_->HasCustomIcon());
|
| +}
|
| +
|
| +TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| + NoPairingHardlockIgnoredOnInitialRun) {
|
| + state_handler_->ChangeState(
|
| + EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
|
| +
|
| + state_handler_->SetHardlockState(
|
| + EasyUnlockScreenlockStateHandler::NO_PAIRING);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
|
| +}
|
| +
|
| +TEST_F(EasyUnlockScreenlockStateHandlerTest, PairingChangedHardlock) {
|
| + SetFirstRunCompleteValue(true);
|
| + state_handler_->ChangeState(
|
| + EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
|
| +
|
| + state_handler_->SetHardlockState(
|
| + EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId());
|
| +
|
| + state_handler_->ChangeState(
|
| + EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
| +
|
| + EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId());
|
| +}
|
| +
|
| +TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| + PairingChangedHardlockEffectiveOnInitialRun) {
|
| + state_handler_->ChangeState(
|
| + EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId());
|
| +
|
| + state_handler_->SetHardlockState(
|
| + EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
|
| +
|
| + EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount());
|
| + ASSERT_TRUE(lock_handler_->HasCustomIcon());
|
| + EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId());
|
| +}
|
| +
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) {
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
| @@ -532,7 +657,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
|
|
| @@ -564,7 +689,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) {
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| LockScreenChangeableOnLockAfterHardlockReset) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
|
|
| @@ -607,7 +732,7 @@ TEST_F(EasyUnlockScreenlockStateHandlerTest,
|
| }
|
|
|
| TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) {
|
| - pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false);
|
| + SetFirstRunCompleteValue(true);
|
| state_handler_->ChangeState(
|
| EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED);
|
| state_handler_->SetHardlockState(
|
|
|