| Index: chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
|
| diff --git a/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc b/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..192294c3c15bf62d2efa3f635792e7e472bb2d1d
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// 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.h"
|
| +
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "components/prefs/pref_service.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +class PinStorageUnitTest : public testing::Test {
|
| + protected:
|
| + PinStorageUnitTest() : profile_(new TestingProfile()) {}
|
| +
|
| + std::unique_ptr<TestingProfile> profile_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// Verifies that:
|
| +// 1. Prefs are initially empty
|
| +// 2. Setting a PIN will update the pref system.
|
| +// 3. Removing a PIN clears prefs.
|
| +TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) {
|
| + PrefService* prefs = profile_->GetPrefs();
|
| +
|
| + EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt));
|
| + EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret));
|
| +
|
| + chromeos::PinStorage* pin_storage =
|
| + chromeos::PinStorage::GetInstance(profile_.get());
|
| + pin_storage->SetPin("foobar");
|
| + EXPECT_TRUE(pin_storage->HasPin());
|
| + EXPECT_EQ(pin_storage->pin_salt(),
|
| + prefs->GetString(prefs::kQuickUnlockPinSalt));
|
| + EXPECT_EQ(pin_storage->pin_secret(),
|
| + prefs->GetString(prefs::kQuickUnlockPinSecret));
|
| +
|
| + pin_storage->RemovePin();
|
| + EXPECT_FALSE(pin_storage->HasPin());
|
| + EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt));
|
| + EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret));
|
| +}
|
| +
|
| +// Verifies that:
|
| +// 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) {
|
| + chromeos::PinStorage* pin_storage =
|
| + chromeos::PinStorage::GetInstance(profile_.get());
|
| +
|
| + EXPECT_EQ(0, pin_storage->UnlockAttemptCount());
|
| +
|
| + pin_storage->AddUnlockAttempt();
|
| + pin_storage->AddUnlockAttempt();
|
| + pin_storage->AddUnlockAttempt();
|
| + EXPECT_EQ(3, pin_storage->UnlockAttemptCount());
|
| +
|
| + pin_storage->ResetUnlockAttemptCount();
|
| + EXPECT_EQ(0, pin_storage->UnlockAttemptCount());
|
| +}
|
| +
|
| +// Verifies that:
|
| +// 1. Marking the strong auth makes TimeSinceLastStrongAuth a > zero value.
|
| +TEST_F(PinStorageUnitTest, MarkStrongAuth) {
|
| + chromeos::PinStorage* pin_storage =
|
| + chromeos::PinStorage::GetInstance(profile_.get());
|
| + pin_storage->MarkStrongAuth();
|
| +
|
| + EXPECT_TRUE(pin_storage->TimeSinceLastStrongAuth() >
|
| + base::TimeDelta::FromMinutes(0));
|
| +}
|
|
|