Index: chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs_unittest.cc |
diff --git a/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc b/chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs_unittest.cc |
similarity index 63% |
rename from chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc |
rename to chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs_unittest.cc |
index ee5225c1d61f50c5fb8efc3b62f4ca392ed8e696..bf0ec2795aeed5c8a5679425e959b65540608053 100644 |
--- a/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc |
+++ b/chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs.h" |
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" |
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" |
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" |
@@ -15,20 +16,25 @@ |
namespace chromeos { |
namespace { |
-class PinStorageUnitTest : public testing::Test { |
+class PinStoragePrefsUnitTest : public testing::Test { |
protected: |
- PinStorageUnitTest() : profile_(base::MakeUnique<TestingProfile>()) {} |
- ~PinStorageUnitTest() override {} |
+ PinStoragePrefsUnitTest() : profile_(base::MakeUnique<TestingProfile>()) {} |
+ ~PinStoragePrefsUnitTest() override {} |
// testing::Test: |
void SetUp() override { |
quick_unlock::EnableForTesting(quick_unlock::PinStorageType::kPrefs); |
} |
+ quick_unlock::PinStoragePrefs* PinStorage() const { |
+ return quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
+ ->pin_storage_prefs(); |
+ } |
+ |
content::TestBrowserThreadBundle thread_bundle_; |
std::unique_ptr<TestingProfile> profile_; |
- DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest); |
+ DISALLOW_COPY_AND_ASSIGN(PinStoragePrefsUnitTest); |
}; |
} // namespace |
@@ -37,7 +43,7 @@ class PinStorageUnitTest : public testing::Test { |
class PinStorageTestApi { |
public: |
// Does *not* take ownership over |pin_storage|. |
- explicit PinStorageTestApi(quick_unlock::PinStorage* pin_storage) |
+ explicit PinStorageTestApi(quick_unlock::PinStoragePrefs* pin_storage) |
: pin_storage_(pin_storage) {} |
std::string PinSalt() const { return pin_storage_->PinSalt(); } |
@@ -52,7 +58,7 @@ class PinStorageTestApi { |
} |
private: |
- quick_unlock::PinStorage* pin_storage_; |
+ quick_unlock::PinStoragePrefs* pin_storage_; |
DISALLOW_COPY_AND_ASSIGN(PinStorageTestApi); |
}; |
@@ -61,19 +67,16 @@ class PinStorageTestApi { |
// 1. Prefs are initially empty |
// 2. Setting a PIN will update the pref system. |
// 3. Removing a PIN clears prefs. |
-TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) { |
+TEST_F(PinStoragePrefsUnitTest, PinStorageWritesToPrefs) { |
PrefService* prefs = profile_->GetPrefs(); |
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt)); |
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); |
- quick_unlock::PinStorage* pin_storage = |
- quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
- ->pin_storage(); |
- PinStorageTestApi pin_storage_test(pin_storage); |
+ PinStorageTestApi pin_storage_test(PinStorage()); |
- pin_storage->SetPin("1111"); |
- EXPECT_TRUE(pin_storage->IsPinSet()); |
+ PinStorage()->SetPin("1111"); |
+ EXPECT_TRUE(PinStorage()->IsPinSet()); |
EXPECT_EQ(pin_storage_test.PinSalt(), |
prefs->GetString(prefs::kQuickUnlockPinSalt)); |
EXPECT_EQ(pin_storage_test.PinSecret(), |
@@ -81,8 +84,8 @@ TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) { |
EXPECT_NE("", pin_storage_test.PinSalt()); |
EXPECT_NE("", pin_storage_test.PinSecret()); |
- pin_storage->RemovePin(); |
- EXPECT_FALSE(pin_storage->IsPinSet()); |
+ PinStorage()->RemovePin(); |
+ EXPECT_FALSE(PinStorage()->IsPinSet()); |
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt)); |
EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); |
} |
@@ -91,48 +94,40 @@ TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) { |
// 1. Initial unlock attempt count is zero. |
// 2. Attempting unlock attempts correctly increases unlock attempt count. |
// 3. Resetting unlock attempt count correctly sets attempt count to 0. |
-TEST_F(PinStorageUnitTest, UnlockAttemptCount) { |
- quick_unlock::PinStorage* pin_storage = |
- quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
- ->pin_storage(); |
+TEST_F(PinStoragePrefsUnitTest, UnlockAttemptCount) { |
+ EXPECT_EQ(0, PinStorage()->unlock_attempt_count()); |
- EXPECT_EQ(0, pin_storage->unlock_attempt_count()); |
+ PinStorage()->AddUnlockAttempt(); |
+ PinStorage()->AddUnlockAttempt(); |
+ PinStorage()->AddUnlockAttempt(); |
+ EXPECT_EQ(3, PinStorage()->unlock_attempt_count()); |
- pin_storage->AddUnlockAttempt(); |
- pin_storage->AddUnlockAttempt(); |
- pin_storage->AddUnlockAttempt(); |
- EXPECT_EQ(3, pin_storage->unlock_attempt_count()); |
- |
- pin_storage->ResetUnlockAttemptCount(); |
- EXPECT_EQ(0, pin_storage->unlock_attempt_count()); |
+ PinStorage()->ResetUnlockAttemptCount(); |
+ EXPECT_EQ(0, PinStorage()->unlock_attempt_count()); |
} |
// Verifies that the correct pin can be used to authenticate. |
-TEST_F(PinStorageUnitTest, AuthenticationSucceedsWithRightPin) { |
- quick_unlock::PinStorage* pin_storage = |
- quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
- ->pin_storage(); |
- PinStorageTestApi pin_storage_test(pin_storage); |
+TEST_F(PinStoragePrefsUnitTest, AuthenticationSucceedsWithRightPin) { |
+ PinStorageTestApi pin_storage_test(PinStorage()); |
- pin_storage->SetPin("1111"); |
+ PinStorage()->SetPin("1111"); |
EXPECT_TRUE(pin_storage_test.TryAuthenticatePin("1111")); |
} |
// Verifies that the correct pin will fail to authenticate if too many |
// authentication attempts have been made. |
-TEST_F(PinStorageUnitTest, AuthenticationFailsFromTooManyAttempts) { |
- quick_unlock::PinStorage* pin_storage = |
- quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
- ->pin_storage(); |
- PinStorageTestApi pin_storage_test(pin_storage); |
+TEST_F(PinStoragePrefsUnitTest, AuthenticationFailsFromTooManyAttempts) { |
+ PinStorageTestApi pin_storage_test(PinStorage()); |
- pin_storage->SetPin("1111"); |
+ PinStorage()->SetPin("1111"); |
// Use up all of the authentication attempts so authentication fails. |
EXPECT_TRUE(pin_storage_test.IsPinAuthenticationAvailable()); |
- for (int i = 0; i < quick_unlock::PinStorage::kMaximumUnlockAttempts; ++i) |
+ for (int i = 0; i < quick_unlock::PinStoragePrefs::kMaximumUnlockAttempts; |
+ ++i) { |
EXPECT_FALSE(pin_storage_test.TryAuthenticatePin("foobar")); |
+ } |
// We used up all of the attempts, so entering the right PIN will still fail. |
EXPECT_FALSE(pin_storage_test.IsPinAuthenticationAvailable()); |