Commit b338b429 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Cleanup pin_storage_prefs_unittest.cc

Bug: 826773
Change-Id: Iae8f5732fcfad8fbe81c9b9dab36cdcd9679c1dd
Reviewed-on: https://chromium-review.googlesource.com/990975
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548265}
parent ee27d202
...@@ -26,6 +26,11 @@ class PinStoragePrefsUnitTest : public testing::Test { ...@@ -26,6 +26,11 @@ class PinStoragePrefsUnitTest : public testing::Test {
quick_unlock::EnableForTesting(quick_unlock::PinStorageType::kPrefs); quick_unlock::EnableForTesting(quick_unlock::PinStorageType::kPrefs);
} }
quick_unlock::PinStoragePrefs* PinStoragePrefs() const {
return quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
->pin_storage_prefs();
}
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
...@@ -68,13 +73,10 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) { ...@@ -68,13 +73,10 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) {
EXPECT_EQ("", prefs->GetString(ash::prefs::kQuickUnlockPinSalt)); EXPECT_EQ("", prefs->GetString(ash::prefs::kQuickUnlockPinSalt));
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret));
quick_unlock::PinStoragePrefs* pin_storage = PinStoragePrefsTestApi pin_storage_test(PinStoragePrefs());
quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
->pin_storage_prefs();
PinStoragePrefsTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111"); PinStoragePrefs()->SetPin("1111");
EXPECT_TRUE(pin_storage->IsPinSet()); EXPECT_TRUE(PinStoragePrefs()->IsPinSet());
EXPECT_EQ(pin_storage_test.PinSalt(), EXPECT_EQ(pin_storage_test.PinSalt(),
prefs->GetString(ash::prefs::kQuickUnlockPinSalt)); prefs->GetString(ash::prefs::kQuickUnlockPinSalt));
EXPECT_EQ(pin_storage_test.PinSecret(), EXPECT_EQ(pin_storage_test.PinSecret(),
...@@ -82,8 +84,8 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) { ...@@ -82,8 +84,8 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) {
EXPECT_NE("", pin_storage_test.PinSalt()); EXPECT_NE("", pin_storage_test.PinSalt());
EXPECT_NE("", pin_storage_test.PinSecret()); EXPECT_NE("", pin_storage_test.PinSecret());
pin_storage->RemovePin(); PinStoragePrefs()->RemovePin();
EXPECT_FALSE(pin_storage->IsPinSet()); EXPECT_FALSE(PinStoragePrefs()->IsPinSet());
EXPECT_EQ("", prefs->GetString(ash::prefs::kQuickUnlockPinSalt)); EXPECT_EQ("", prefs->GetString(ash::prefs::kQuickUnlockPinSalt));
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret));
} }
...@@ -93,29 +95,22 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) { ...@@ -93,29 +95,22 @@ TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) {
// 2. Attempting unlock attempts correctly increases unlock attempt count. // 2. Attempting unlock attempts correctly increases unlock attempt count.
// 3. Resetting unlock attempt count correctly sets attempt count to 0. // 3. Resetting unlock attempt count correctly sets attempt count to 0.
TEST_F(PinStoragePrefsUnitTest, UnlockAttemptCount) { TEST_F(PinStoragePrefsUnitTest, UnlockAttemptCount) {
quick_unlock::PinStoragePrefs* pin_storage = EXPECT_EQ(0, PinStoragePrefs()->unlock_attempt_count());
quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
->pin_storage_prefs();
EXPECT_EQ(0, pin_storage->unlock_attempt_count());
pin_storage->AddUnlockAttempt(); PinStoragePrefs()->AddUnlockAttempt();
pin_storage->AddUnlockAttempt(); PinStoragePrefs()->AddUnlockAttempt();
pin_storage->AddUnlockAttempt(); PinStoragePrefs()->AddUnlockAttempt();
EXPECT_EQ(3, pin_storage->unlock_attempt_count()); EXPECT_EQ(3, PinStoragePrefs()->unlock_attempt_count());
pin_storage->ResetUnlockAttemptCount(); PinStoragePrefs()->ResetUnlockAttemptCount();
EXPECT_EQ(0, pin_storage->unlock_attempt_count()); EXPECT_EQ(0, PinStoragePrefs()->unlock_attempt_count());
} }
// Verifies that the correct pin can be used to authenticate. // Verifies that the correct pin can be used to authenticate.
TEST_F(PinStoragePrefsUnitTest, AuthenticationSucceedsWithRightPin) { TEST_F(PinStoragePrefsUnitTest, AuthenticationSucceedsWithRightPin) {
quick_unlock::PinStoragePrefs* pin_storage = PinStoragePrefsTestApi pin_storage_test(PinStoragePrefs());
quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
->pin_storage_prefs();
PinStoragePrefsTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111"); PinStoragePrefs()->SetPin("1111");
EXPECT_TRUE(pin_storage_test.TryAuthenticatePin( EXPECT_TRUE(pin_storage_test.TryAuthenticatePin(
"1111", Key::KEY_TYPE_PASSWORD_PLAIN)); "1111", Key::KEY_TYPE_PASSWORD_PLAIN));
...@@ -124,19 +119,17 @@ TEST_F(PinStoragePrefsUnitTest, AuthenticationSucceedsWithRightPin) { ...@@ -124,19 +119,17 @@ TEST_F(PinStoragePrefsUnitTest, AuthenticationSucceedsWithRightPin) {
// Verifies that the correct pin will fail to authenticate if too many // Verifies that the correct pin will fail to authenticate if too many
// authentication attempts have been made. // authentication attempts have been made.
TEST_F(PinStoragePrefsUnitTest, AuthenticationFailsFromTooManyAttempts) { TEST_F(PinStoragePrefsUnitTest, AuthenticationFailsFromTooManyAttempts) {
quick_unlock::PinStoragePrefs* pin_storage = PinStoragePrefsTestApi pin_storage_test(PinStoragePrefs());
quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get())
->pin_storage_prefs();
PinStoragePrefsTestApi pin_storage_test(pin_storage);
pin_storage->SetPin("1111"); PinStoragePrefs()->SetPin("1111");
// Use up all of the authentication attempts so authentication fails. // Use up all of the authentication attempts so authentication fails.
EXPECT_TRUE(pin_storage_test.IsPinAuthenticationAvailable()); EXPECT_TRUE(pin_storage_test.IsPinAuthenticationAvailable());
for (int i = 0; i < quick_unlock::PinStoragePrefs::kMaximumUnlockAttempts; for (int i = 0; i < quick_unlock::PinStoragePrefs::kMaximumUnlockAttempts;
++i) ++i) {
EXPECT_FALSE(pin_storage_test.TryAuthenticatePin( EXPECT_FALSE(pin_storage_test.TryAuthenticatePin(
"foobar", Key::KEY_TYPE_PASSWORD_PLAIN)); "foobar", Key::KEY_TYPE_PASSWORD_PLAIN));
}
// We used up all of the attempts, so entering the right PIN will still fail. // We used up all of the attempts, so entering the right PIN will still fail.
EXPECT_FALSE(pin_storage_test.IsPinAuthenticationAvailable()); EXPECT_FALSE(pin_storage_test.IsPinAuthenticationAvailable());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment