OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/quick_unlock_factory.h" |
| 6 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" |
| 7 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" |
| 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "components/prefs/pref_service.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace chromeos { |
| 15 namespace { |
| 16 |
| 17 class FingerprintStorageUnitTest : public testing::Test { |
| 18 protected: |
| 19 FingerprintStorageUnitTest() : profile_(new TestingProfile()) {} |
| 20 ~FingerprintStorageUnitTest() override {} |
| 21 |
| 22 // testing::Test: |
| 23 void SetUp() override { quick_unlock::EnableForTesting(); } |
| 24 |
| 25 content::TestBrowserThreadBundle thread_bundle_; |
| 26 std::unique_ptr<TestingProfile> profile_; |
| 27 |
| 28 DISALLOW_COPY_AND_ASSIGN(FingerprintStorageUnitTest); |
| 29 }; |
| 30 |
| 31 } // namespace |
| 32 |
| 33 // Provides test-only FingerprintStorage APIs. |
| 34 class FingerprintStorageTestApi { |
| 35 public: |
| 36 // Does *not* take ownership over |fingerprint_storage|. |
| 37 explicit FingerprintStorageTestApi( |
| 38 quick_unlock::FingerprintStorage* fingerprint_storage) |
| 39 : fingerprint_storage_(fingerprint_storage) {} |
| 40 |
| 41 void SetEnrollments(bool has_enrollments) { |
| 42 fingerprint_storage_->has_enrollments_ = has_enrollments; |
| 43 } |
| 44 |
| 45 bool IsFingerprintAuthenticationAvailable() const { |
| 46 return fingerprint_storage_->IsFingerprintAuthenticationAvailable(); |
| 47 } |
| 48 |
| 49 private: |
| 50 quick_unlock::FingerprintStorage* fingerprint_storage_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(FingerprintStorageTestApi); |
| 53 }; |
| 54 |
| 55 // Verifies that: |
| 56 // 1. Initial unlock attempt count is zero. |
| 57 // 2. Attempting unlock attempts correctly increases unlock attempt count. |
| 58 // 3. Resetting unlock attempt count correctly sets attempt count to 0. |
| 59 TEST_F(FingerprintStorageUnitTest, UnlockAttemptCount) { |
| 60 quick_unlock::FingerprintStorage* fingerprint_storage = |
| 61 quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
| 62 ->fingerprint_storage(); |
| 63 |
| 64 EXPECT_EQ(0, fingerprint_storage->unlock_attempt_count()); |
| 65 |
| 66 fingerprint_storage->AddUnlockAttempt(); |
| 67 fingerprint_storage->AddUnlockAttempt(); |
| 68 fingerprint_storage->AddUnlockAttempt(); |
| 69 EXPECT_EQ(3, fingerprint_storage->unlock_attempt_count()); |
| 70 |
| 71 fingerprint_storage->ResetUnlockAttemptCount(); |
| 72 EXPECT_EQ(0, fingerprint_storage->unlock_attempt_count()); |
| 73 } |
| 74 |
| 75 // Verifies that authentication is not available when |
| 76 // 1. No enrollments registered |
| 77 // 2. Too many authentication attempts |
| 78 TEST_F(FingerprintStorageUnitTest, AuthenticationUnAvailable) { |
| 79 quick_unlock::FingerprintStorage* fingerprint_storage = |
| 80 quick_unlock::QuickUnlockFactory::GetForProfile(profile_.get()) |
| 81 ->fingerprint_storage(); |
| 82 FingerprintStorageTestApi test_api(fingerprint_storage); |
| 83 |
| 84 EXPECT_FALSE(fingerprint_storage->HasEnrollment()); |
| 85 test_api.SetEnrollments(true); |
| 86 EXPECT_TRUE(fingerprint_storage->HasEnrollment()); |
| 87 EXPECT_EQ(0, fingerprint_storage->unlock_attempt_count()); |
| 88 EXPECT_TRUE(test_api.IsFingerprintAuthenticationAvailable()); |
| 89 |
| 90 // No enrollment registered makes fingerprint authentication unavailable. |
| 91 test_api.SetEnrollments(false); |
| 92 EXPECT_FALSE(test_api.IsFingerprintAuthenticationAvailable()); |
| 93 test_api.SetEnrollments(true); |
| 94 EXPECT_TRUE(test_api.IsFingerprintAuthenticationAvailable()); |
| 95 |
| 96 // Too many authentication attempts make fingerprint authentication |
| 97 // unavailable. |
| 98 for (int i = 0; i < quick_unlock::FingerprintStorage::kMaximumUnlockAttempts; |
| 99 ++i) { |
| 100 fingerprint_storage->AddUnlockAttempt(); |
| 101 } |
| 102 EXPECT_FALSE(test_api.IsFingerprintAuthenticationAvailable()); |
| 103 fingerprint_storage->ResetUnlockAttemptCount(); |
| 104 EXPECT_TRUE(test_api.IsFingerprintAuthenticationAvailable()); |
| 105 } |
| 106 |
| 107 } // namespace chromeos |
OLD | NEW |