OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/cert_loader.h" | 5 #include "chromeos/cert_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class CertLoaderTest : public testing::Test, | 46 class CertLoaderTest : public testing::Test, |
47 public CertLoader::Observer { | 47 public CertLoader::Observer { |
48 public: | 48 public: |
49 CertLoaderTest() : cert_loader_(NULL), | 49 CertLoaderTest() : cert_loader_(NULL), |
50 primary_user_("primary"), | 50 primary_user_("primary"), |
51 certificates_loaded_events_count_(0U) { | 51 certificates_loaded_events_count_(0U) { |
52 } | 52 } |
53 | 53 |
54 virtual ~CertLoaderTest() {} | 54 virtual ~CertLoaderTest() {} |
55 | 55 |
56 virtual void SetUp() OVERRIDE { | 56 virtual void SetUp() override { |
57 ASSERT_TRUE(primary_user_.constructed_successfully()); | 57 ASSERT_TRUE(primary_user_.constructed_successfully()); |
58 ASSERT_TRUE( | 58 ASSERT_TRUE( |
59 crypto::GetPublicSlotForChromeOSUser(primary_user_.username_hash())); | 59 crypto::GetPublicSlotForChromeOSUser(primary_user_.username_hash())); |
60 | 60 |
61 CertLoader::Initialize(); | 61 CertLoader::Initialize(); |
62 cert_loader_ = CertLoader::Get(); | 62 cert_loader_ = CertLoader::Get(); |
63 cert_loader_->AddObserver(this); | 63 cert_loader_->AddObserver(this); |
64 } | 64 } |
65 | 65 |
66 virtual void TearDown() { | 66 virtual void TearDown() { |
67 cert_loader_->RemoveObserver(this); | 67 cert_loader_->RemoveObserver(this); |
68 CertLoader::Shutdown(); | 68 CertLoader::Shutdown(); |
69 } | 69 } |
70 | 70 |
71 protected: | 71 protected: |
72 void StartCertLoaderWithPrimaryUser() { | 72 void StartCertLoaderWithPrimaryUser() { |
73 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); | 73 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); |
74 cert_loader_->StartWithNSSDB(primary_db_.get()); | 74 cert_loader_->StartWithNSSDB(primary_db_.get()); |
75 | 75 |
76 base::RunLoop().RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
77 GetAndResetCertificatesLoadedEventsCount(); | 77 GetAndResetCertificatesLoadedEventsCount(); |
78 } | 78 } |
79 | 79 |
80 // CertLoader::Observer: | 80 // CertLoader::Observer: |
81 // The test keeps count of times the observer method was called. | 81 // The test keeps count of times the observer method was called. |
82 virtual void OnCertificatesLoaded(const net::CertificateList& cert_list, | 82 virtual void OnCertificatesLoaded(const net::CertificateList& cert_list, |
83 bool initial_load) OVERRIDE { | 83 bool initial_load) override { |
84 EXPECT_TRUE(certificates_loaded_events_count_ == 0 || !initial_load); | 84 EXPECT_TRUE(certificates_loaded_events_count_ == 0 || !initial_load); |
85 certificates_loaded_events_count_++; | 85 certificates_loaded_events_count_++; |
86 } | 86 } |
87 | 87 |
88 // Returns the number of |OnCertificatesLoaded| calls observed since the | 88 // Returns the number of |OnCertificatesLoaded| calls observed since the |
89 // last call to this method equals |value|. | 89 // last call to this method equals |value|. |
90 size_t GetAndResetCertificatesLoadedEventsCount() { | 90 size_t GetAndResetCertificatesLoadedEventsCount() { |
91 size_t result = certificates_loaded_events_count_; | 91 size_t result = certificates_loaded_events_count_; |
92 certificates_loaded_events_count_ = 0; | 92 certificates_loaded_events_count_ = 0; |
93 return result; | 93 return result; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); | 314 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); |
315 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
316 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); | 316 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); |
317 } | 317 } |
318 | 318 |
319 } // namespace | 319 } // namespace |
320 } // namespace chromeos | 320 } // namespace chromeos |
321 | 321 |
322 #endif | 322 #endif |
323 | 323 |
OLD | NEW |