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

Unified Diff: chrome/browser/chromeos/login/quick_unlock/pin_storage_unittest.cc

Issue 1977923002: Implement pin storage backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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));
+}

Powered by Google App Engine
This is Rietveld 408576698