Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/test/scoped_task_scheduler.h" | |
| 16 #include "crypto/scoped_nss_types.h" | 16 #include "crypto/scoped_nss_types.h" |
| 17 #include "crypto/scoped_test_nss_db.h" | 17 #include "crypto/scoped_test_nss_db.h" |
| 18 #include "net/cert/nss_cert_database_chromeos.h" | 18 #include "net/cert/nss_cert_database_chromeos.h" |
| 19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 20 #include "net/test/cert_test_util.h" | 20 #include "net/test/cert_test_util.h" |
| 21 #include "net/test/test_data_directory.h" | 21 #include "net/test/test_data_directory.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 namespace { | 25 namespace { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 return result; | 96 return result; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void CreateCertDatabase(crypto::ScopedTestNSSDB* db, | 99 void CreateCertDatabase(crypto::ScopedTestNSSDB* db, |
| 100 std::unique_ptr<TestNSSCertDatabase>* certdb) { | 100 std::unique_ptr<TestNSSCertDatabase>* certdb) { |
| 101 ASSERT_TRUE(db->is_open()); | 101 ASSERT_TRUE(db->is_open()); |
| 102 | 102 |
| 103 certdb->reset(new TestNSSCertDatabase( | 103 certdb->reset(new TestNSSCertDatabase( |
| 104 crypto::ScopedPK11Slot(PK11_ReferenceSlot(db->slot())), | 104 crypto::ScopedPK11Slot(PK11_ReferenceSlot(db->slot())), |
| 105 crypto::ScopedPK11Slot(PK11_ReferenceSlot(db->slot())))); | 105 crypto::ScopedPK11Slot(PK11_ReferenceSlot(db->slot())))); |
| 106 (*certdb)->SetSlowTaskRunnerForTest(message_loop_.task_runner()); | |
| 107 } | 106 } |
| 108 | 107 |
| 109 void ImportCACert(const std::string& cert_file, | 108 void ImportCACert(const std::string& cert_file, |
| 110 net::NSSCertDatabase* database, | 109 net::NSSCertDatabase* database, |
| 111 net::CertificateList* imported_certs) { | 110 net::CertificateList* imported_certs) { |
| 112 ASSERT_TRUE(database); | 111 ASSERT_TRUE(database); |
| 113 ASSERT_TRUE(imported_certs); | 112 ASSERT_TRUE(imported_certs); |
| 114 | 113 |
| 115 *imported_certs = net::CreateCertificateListFromFile( | 114 *imported_certs = net::CreateCertificateListFromFile( |
| 116 net::GetTestCertsDirectory(), | 115 net::GetTestCertsDirectory(), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 137 } | 136 } |
| 138 | 137 |
| 139 CertLoader* cert_loader_; | 138 CertLoader* cert_loader_; |
| 140 | 139 |
| 141 // The user is primary as the one whose certificates CertLoader handles, it | 140 // The user is primary as the one whose certificates CertLoader handles, it |
| 142 // has nothing to do with crypto::InitializeNSSForChromeOSUser is_primary_user | 141 // has nothing to do with crypto::InitializeNSSForChromeOSUser is_primary_user |
| 143 // parameter (which is irrelevant for these tests). | 142 // parameter (which is irrelevant for these tests). |
| 144 crypto::ScopedTestNSSDB primary_db_; | 143 crypto::ScopedTestNSSDB primary_db_; |
| 145 std::unique_ptr<TestNSSCertDatabase> primary_certdb_; | 144 std::unique_ptr<TestNSSCertDatabase> primary_certdb_; |
| 146 | 145 |
| 147 base::MessageLoop message_loop_; | 146 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
|
Ryan Sleevi
2017/01/27 00:51:58
Why don't you need to bind this to a message loop,
fdoray
2017/02/02 17:56:32
I improved the ScopedTaskScheduler documentation.
| |
| 148 | 147 |
| 149 private: | 148 private: |
| 150 size_t certificates_loaded_events_count_; | 149 size_t certificates_loaded_events_count_; |
| 151 }; | 150 }; |
| 152 | 151 |
| 153 } // namespace | 152 } // namespace |
| 154 | 153 |
| 155 TEST_F(CertLoaderTest, Basic) { | 154 TEST_F(CertLoaderTest, Basic) { |
| 156 EXPECT_FALSE(cert_loader_->CertificatesLoading()); | 155 EXPECT_FALSE(cert_loader_->CertificatesLoading()); |
| 157 EXPECT_FALSE(cert_loader_->certificates_loaded()); | 156 EXPECT_FALSE(cert_loader_->certificates_loaded()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 ASSERT_TRUE(primary_certdb_->SetCertTrust(certs[0].get(), net::CA_CERT, | 276 ASSERT_TRUE(primary_certdb_->SetCertTrust(certs[0].get(), net::CA_CERT, |
| 278 net::NSSCertDatabase::TRUSTED_SSL)); | 277 net::NSSCertDatabase::TRUSTED_SSL)); |
| 279 | 278 |
| 280 // Cert trust change should trigger certificate reload in cert_loader_. | 279 // Cert trust change should trigger certificate reload in cert_loader_. |
| 281 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); | 280 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); |
| 282 base::RunLoop().RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
| 283 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); | 282 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); |
| 284 } | 283 } |
| 285 | 284 |
| 286 } // namespace chromeos | 285 } // namespace chromeos |
| OLD | NEW |