| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h" |
| 6 |
| 7 #include "chrome/common/pref_names.h" |
| 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "components/prefs/pref_service.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 class PinStorageUnitTest : public testing::Test { |
| 15 protected: |
| 16 PinStorageUnitTest() : profile_(new TestingProfile()) {} |
| 17 |
| 18 std::unique_ptr<TestingProfile> profile_; |
| 19 |
| 20 DISALLOW_COPY_AND_ASSIGN(PinStorageUnitTest); |
| 21 }; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 // Verifies that: |
| 26 // 1. Prefs are initially empty |
| 27 // 2. Setting a PIN will update the pref system. |
| 28 // 3. Removing a PIN clears prefs. |
| 29 TEST_F(PinStorageUnitTest, PinStorageWritesToPrefs) { |
| 30 PrefService* prefs = profile_->GetPrefs(); |
| 31 |
| 32 EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt)); |
| 33 EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); |
| 34 |
| 35 chromeos::PinStorage* pin_storage = |
| 36 chromeos::PinStorage::GetInstance(profile_.get()); |
| 37 pin_storage->SetPin("foobar"); |
| 38 EXPECT_TRUE(pin_storage->HasPin()); |
| 39 EXPECT_EQ(pin_storage->pin_salt(), |
| 40 prefs->GetString(prefs::kQuickUnlockPinSalt)); |
| 41 EXPECT_EQ(pin_storage->pin_secret(), |
| 42 prefs->GetString(prefs::kQuickUnlockPinSecret)); |
| 43 |
| 44 pin_storage->RemovePin(); |
| 45 EXPECT_FALSE(pin_storage->HasPin()); |
| 46 EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSalt)); |
| 47 EXPECT_EQ("", prefs->GetString(prefs::kQuickUnlockPinSecret)); |
| 48 } |
| 49 |
| 50 // Verifies that: |
| 51 // 1. Initial unlock attempt count is zero. |
| 52 // 2. Attempting unlock attempts correctly increases unlock attempt count. |
| 53 // 3. Resetting unlock attempt count correctly sets attempt count to 0. |
| 54 TEST_F(PinStorageUnitTest, UnlockAttemptCount) { |
| 55 chromeos::PinStorage* pin_storage = |
| 56 chromeos::PinStorage::GetInstance(profile_.get()); |
| 57 |
| 58 EXPECT_EQ(0, pin_storage->UnlockAttemptCount()); |
| 59 |
| 60 pin_storage->AddUnlockAttempt(); |
| 61 pin_storage->AddUnlockAttempt(); |
| 62 pin_storage->AddUnlockAttempt(); |
| 63 EXPECT_EQ(3, pin_storage->UnlockAttemptCount()); |
| 64 |
| 65 pin_storage->ResetUnlockAttemptCount(); |
| 66 EXPECT_EQ(0, pin_storage->UnlockAttemptCount()); |
| 67 } |
| 68 |
| 69 // Verifies that: |
| 70 // 1. Marking the strong auth makes TimeSinceLastStrongAuth a > zero value. |
| 71 TEST_F(PinStorageUnitTest, MarkStrongAuth) { |
| 72 chromeos::PinStorage* pin_storage = |
| 73 chromeos::PinStorage::GetInstance(profile_.get()); |
| 74 pin_storage->MarkStrongAuth(); |
| 75 |
| 76 EXPECT_TRUE(pin_storage->TimeSinceLastStrongAuth() > |
| 77 base::TimeDelta::FromMinutes(0)); |
| 78 } |
| OLD | NEW |